[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup fc4276a 247/340: Make it possible to abort test
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup fc4276a 247/340: Make it possible to abort test run cleanly |
Date: |
Thu, 16 Dec 2021 14:59:43 -0500 (EST) |
branch: elpa/buttercup
commit fc4276aabd8e2e7e2816192d1590b72c3a9e97d9
Author: Paul Pogonyshev <pogonyshev@gmail.com>
Commit: Jorgen Schäfer <Jorgen.Schaefer@gmail.com>
Make it possible to abort test run cleanly
---
buttercup.el | 66 ++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 42 insertions(+), 24 deletions(-)
diff --git a/buttercup.el b/buttercup.el
index ef8cc5d..2e7afa8 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -117,6 +117,14 @@ a call to `save-match-data', as `format-spec' modifies
that."
(define-error 'buttercup-pending
"Buttercup test is pending")
+(define-error 'buttercup-abort
+ "Abort Buttercup testing")
+
+(defvar buttercup-abort-message nil
+ "The message explaining why Buttercup testing is aborted.
+Reporters may want to print it if non-nil when handling
+`buttercup-done' event.")
+
(defmacro expect (arg &optional matcher &rest args)
"Expect a condition to be true.
@@ -1422,12 +1430,15 @@ A suite must be defined within a Markdown \"lisp\" code
block."
(defun buttercup-run ()
"Run all described suites."
(if buttercup-suites
- (progn
+ (let (buttercup-abort-message)
(funcall buttercup-reporter 'buttercup-started buttercup-suites)
- (mapc #'buttercup--run-suite buttercup-suites)
- (funcall buttercup-reporter 'buttercup-done buttercup-suites)
- (when (> (buttercup-suites-total-specs-failed buttercup-suites) 0)
- (error "")))
+ (unwind-protect
+ (condition-case error
+ (mapc #'buttercup--run-suite buttercup-suites)
+ (buttercup-abort (setf buttercup-abort-message (cdr error))))
+ (funcall buttercup-reporter 'buttercup-done buttercup-suites)
+ (when (> (buttercup-suites-total-specs-failed buttercup-suites) 0)
+ (error ""))))
(error "No suites defined")))
(defvar buttercup--before-each nil
@@ -1448,18 +1459,20 @@ Do not change the global value.")
(buttercup--after-each (append (buttercup-suite-after-each suite)
buttercup--after-each)))
(funcall buttercup-reporter 'suite-started suite)
- (dolist (f (buttercup-suite-before-all suite))
- (buttercup--update-with-funcall suite f))
- (dolist (sub (buttercup-suite-children suite))
- (cond
- ((buttercup-suite-p sub)
- (buttercup--run-suite sub))
- ((buttercup-spec-p sub)
- (buttercup--run-spec sub))))
- (dolist (f (buttercup-suite-after-all suite))
- (buttercup--update-with-funcall suite f))
- (buttercup--set-end-time suite)
- (funcall buttercup-reporter 'suite-done suite)))
+ (unwind-protect
+ (progn
+ (dolist (f (buttercup-suite-before-all suite))
+ (buttercup--update-with-funcall suite f))
+ (dolist (sub (buttercup-suite-children suite))
+ (cond
+ ((buttercup-suite-p sub)
+ (buttercup--run-suite sub))
+ ((buttercup-spec-p sub)
+ (buttercup--run-spec sub))))
+ (dolist (f (buttercup-suite-after-all suite))
+ (buttercup--update-with-funcall suite f)))
+ (buttercup--set-end-time suite)
+ (funcall buttercup-reporter 'suite-done suite))))
(defun buttercup--run-spec (spec)
(buttercup--set-start-time spec)
@@ -1471,13 +1484,14 @@ Do not change the global value.")
(get-buffer-create buttercup-warning-buffer-name)
(funcall buttercup-reporter 'spec-started spec)
- (buttercup-with-cleanup
- (dolist (f buttercup--before-each)
- (buttercup--update-with-funcall spec f))
- (buttercup--update-with-funcall spec (buttercup-spec-function spec))
- (dolist (f buttercup--after-each)
- (buttercup--update-with-funcall spec f)))
- (funcall buttercup-reporter 'spec-done spec)
+ (unwind-protect
+ (buttercup-with-cleanup
+ (dolist (f buttercup--before-each)
+ (buttercup--update-with-funcall spec f))
+ (buttercup--update-with-funcall spec (buttercup-spec-function
spec))
+ (dolist (f buttercup--after-each)
+ (buttercup--update-with-funcall spec f)))
+ (funcall buttercup-reporter 'spec-done spec))
;; Display warnings that were issued while running the the
;; spec, if any
(with-current-buffer buttercup-warning-buffer-name
@@ -1587,6 +1601,8 @@ EVENT and ARG are described in `buttercup-reporter'."
(dolist (failed buttercup-reporter-batch--failures)
(let ((description (buttercup-spec-failure-description failed))
(stack (buttercup-spec-failure-stack failed)))
+ (when buttercup-abort-message
+ (buttercup--print "%s\n" (if (stringp buttercup-abort-message)
buttercup-abort-message (prin1-to-string buttercup-abort-message))))
(buttercup--print "%s\n" (make-string 40 ?=))
(buttercup--print "%s\n" (buttercup-spec-full-name failed))
(when stack
@@ -1663,6 +1679,8 @@ EVENT and ARG are described in `buttercup-reporter'."
(dolist (failed buttercup-reporter-batch--failures)
(let ((description (buttercup-spec-failure-description failed))
(stack (buttercup-spec-failure-stack failed)))
+ (when (stringp buttercup-abort-message)
+ (buttercup--print "%s\n" (buttercup-colorize
buttercup-abort-message 'red)))
(buttercup--print "%s\n" (make-string 40 ?=))
(buttercup--print (buttercup-colorize "%s\n" 'red)
(buttercup-spec-full-name failed))
(when stack
- [nongnu] elpa/buttercup 25462dd 223/340: Record calls to spied-on functions that throw errors, (continued)
- [nongnu] elpa/buttercup 25462dd 223/340: Record calls to spied-on functions that throw errors, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bf48137 224/340: Add some tests for error-call recording, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup fc19598 225/340: Add examples for checking return value and thrown signal of a spy, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 6590360 226/340: Fix a few typos and other small errors, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 8a28489 230/340: Bump version: 1.18 → 1.19, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0e40587 231/340: Tweak the spy-contexts to be more backward compatible, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 60028db 236/340: docs: Clarify the spy lifespan in writing-tests.md, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 9c4b473 237/340: test: Add missing apostrophe in spec title, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 90654ec 238/340: Update some docstrings, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 178c795 242/340: README: Add '-L .' to test runner example, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup fc4276a 247/340: Make it possible to abort test run cleanly,
ELPA Syncer <=
- [nongnu] elpa/buttercup dbcd3d4 256/340: Calculate total test run time with current-time, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c83ba7d 268/340: Extract function buttercup-elapsed-time-string, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 38cfa6f 270/340: Fix spy-on on Emacs 24.3 for symbols that are not fbound, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 81bfed4 272/340: test: Add utility function send-string-to-ansi-buffer, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup cf4eee8 274/340: test: Verify output in the "The batch reporter" suite, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 4159111 275/340: test: Verify full line for reporter spec-done tests, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup fbb790b 278/340: test: Add tests for buttercup-started and buttercup-reporter-batch-color, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d563e18 281/340: test: Add color tests for suite-done, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b910b71 285/340: Extract buttercup--indented-description from the batch reporters, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup e71a40f 287/340: Make sure carriage movement characters are not colorized, ELPA Syncer, 2021/12/16