[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup 162b862 060/340: The buttercup--funcall function
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup 162b862 060/340: The buttercup--funcall function. |
Date: |
Thu, 16 Dec 2021 14:59:04 -0500 (EST) |
branch: elpa/buttercup
commit 162b862c603bed00637efdb88780d188df538307
Author: Jorgen Schaefer <contact@jorgenschaefer.de>
Commit: Jorgen Schaefer <contact@jorgenschaefer.de>
The buttercup--funcall function.
---
buttercup-test.el | 18 ++++++++++++++++++
buttercup.el | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+)
diff --git a/buttercup-test.el b/buttercup-test.el
index 574c03b..12c859d 100644
--- a/buttercup-test.el
+++ b/buttercup-test.el
@@ -576,3 +576,21 @@
(it "should handle the end event"
(buttercup-reporter-batch 'buttercup-done nil))))
+
+;;;;;;;;;;;;;
+;;; Utilities
+
+(describe "The `buttercup--funcall' function'"
+ (it "should return passed if everything works fine"
+ (let ((res (buttercup--funcall (lambda () (+ 2 3)))))
+ (expect res
+ :to-equal
+ (list 'passed 5 nil))))
+
+ (it "should return failed with the correct stack if an exception occurred"
+ (let ((res (buttercup--funcall (lambda () (/ 1 0)))))
+ (expect res
+ :to-equal
+ (list 'failed
+ '(error (arith-error))
+ (list '(t / 1 0)))))))
diff --git a/buttercup.el b/buttercup.el
index 9012789..5f2ae75 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -707,5 +707,53 @@ buttercup-done -- All suites have run, the test run is
over.")
(t
(error "Unknown event %s" event))))
+;;;;;;;;;;;;;
+;;; Utilities
+
+(defun buttercup--funcall (function &rest arguments)
+ "Call FUNCTION with ARGUMENTS.
+
+Returns a list of three values. The first is the state:
+
+passed -- The second value is the return value of the function
+ call, the third is nil.
+
+failed -- The second value is the error that occurred, the third
+ is the stack trace."
+ (catch 'buttercup-debugger-continue
+ (let ((debugger #'buttercup--debugger)
+ (debug-on-error t)
+ (debug-ignored-errors nil))
+ (list 'passed
+ (apply function arguments)
+ nil))))
+
+(defun buttercup--debugger (&rest args)
+ ;; If we do not do this, Emacs will not run this handler on
+ ;; subsequent calls. Thanks to ert for this.
+ (setq num-nonmacro-input-events (1+ num-nonmacro-input-events))
+ (throw 'buttercup-debugger-continue
+ (list 'failed args (buttercup--backtrace))))
+
+
+(defun buttercup--backtrace ()
+ (let* ((n 0)
+ (frame (backtrace-frame n))
+ (frame-list nil)
+ (in-program-stack nil))
+ (while frame
+ (when in-program-stack
+ (push frame frame-list))
+ (when (eq (elt frame 1)
+ 'buttercup--debugger)
+ (setq in-program-stack t))
+ (when (eq (elt frame 1)
+ 'buttercup--funcall)
+ (setq in-program-stack nil
+ frame-list (nthcdr 6 frame-list)))
+ (setq n (1+ n)
+ frame (backtrace-frame n)))
+ frame-list))
+
(provide 'buttercup)
;;; buttercup.el ends here
- [nongnu] elpa/buttercup 993ddda 040/340: Add .gitignore, (continued)
- [nongnu] elpa/buttercup 993ddda 040/340: Add .gitignore, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 1dcd2cd 041/340: Prepare release, add bumpversion and pkg.el, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f046eef 042/340: Bump version: 0.1 → 1.0, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 537b729 044/340: Merge pull request #6 from myeffort/master, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bcaa087 046/340: Add buttercup executable to run buttercup tests more easily., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 7250873 047/340: Rename patch to minor in bumpversion.cfg, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 13c463a 050/340: Add more extensive usage instructions to the README., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c783259 052/340: Add MELPA Stable badge., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bdc3721 056/340: Documentation for the buttercup-reporter variable., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 329d2f9 051/340: Add autoload markers to test runners., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 162b862 060/340: The buttercup--funcall function.,
ELPA Syncer <=
- [nongnu] elpa/buttercup 638a836 061/340: The batch reporter now displays failures and stack traces., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c61a69a 066/340: A rudimentary interactive reporter., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 182a974 068/340: Pending specs and disabled suites., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b3bb12a 070/340: buttercup-run-discover: Fix regexp., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 26f8117 071/340: Rename buttercup-test.el and move it to the right directory., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f593486 092/340: Use pattern _ not t in pcase, as t is deprecated, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0a889e2 098/340: Merge pull request #43 from spwhitton/apt-get, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup afbaae1 091/340: Document file names for test discovery, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 25cb350 089/340: Rename docs to be more easily understandable, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 6d96ea3 093/340: Add format specifier to error call with argument, ELPA Syncer, 2021/12/16