[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup 5752a57 295/340: Control errors from buttercup-r
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup 5752a57 295/340: Control errors from buttercup-run with noerror argument |
Date: |
Thu, 16 Dec 2021 14:59:53 -0500 (EST) |
branch: elpa/buttercup
commit 5752a570797d1be1b442e874281c5e7ded471112
Author: Ola Nilsson <ola.nilsson@gmail.com>
Commit: Ola Nilsson <ola.nilsson@gmail.com>
Control errors from buttercup-run with noerror argument
When the noerror argument is non-nil, indicate failure with return
value instead of signalling an error. This simplifies calling
buttercup-run from other emacs-lisp code.
Extract buttercup--run-suites from buttercup-run.
The new function and argument will be useful in testing.
Fixes #175.
---
buttercup.el | 29 ++++++++++++++++++++---------
tests/test-buttercup.el | 11 +++++++++++
2 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/buttercup.el b/buttercup.el
index 12e5b06..4109a2b 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -1457,16 +1457,27 @@ A suite must be defined within a Markdown \"lisp\" code
block."
;; Defined below in a dedicated section
(defvar buttercup-reporter))
-(defun buttercup-run ()
- "Run all described suites."
+(defun buttercup-run (&optional noerror)
+ "Run all described suites.
+Signal an error if any spec fail or if no suites have been
+defined. Signal no errors if NOERROR is non-nil. Return t if all
+specs pass, nil if at least one spec fail, and :no-suites if no suites
+have been defined."
(if buttercup-suites
- (progn
- (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 "")))
- (error "No suites defined")))
+ (buttercup--run-suites buttercup-suites noerror)
+ (or (and noerror :no-suites)
+ (error "No suites defined"))))
+
+(defun buttercup--run-suites (suites &optional noerror)
+ "Run a list of SUITES.
+Signal an error if any spec fail. Signal no error if NOERROR is
+non-nil. Return t if all specs pass, nil if at least one spec
+fail."
+ (funcall buttercup-reporter 'buttercup-started suites)
+ (mapc #'buttercup--run-suite suites)
+ (funcall buttercup-reporter 'buttercup-done suites)
+ (or (zerop (buttercup-suites-total-specs-failed suites))
+ (not (or noerror (error "")))))
(defvar buttercup--before-each nil
"A list of functions to call before each spec.
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index 02bc561..2525241 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -1335,10 +1335,21 @@ text properties using `ansi-color-apply'."
(it "should signal an error if no suites are defined"
(with-local-buttercup
(expect (buttercup-run) :to-throw 'error '("No suites defined"))))
+ (it "should return :no-suites for no suites and noerror"
+ (with-local-buttercup
+ (expect (buttercup-run t) :to-equal :no-suites)))
(it "should raise an error if at least one spec failed"
(setf (buttercup-spec-status spec) 'failed)
(with-local-buttercup :suites (list parent-suite)
(expect (buttercup-run) :to-throw 'error '(""))))
+ (it "should return nil for failing specs and noerror"
+ (setf (buttercup-spec-status spec) 'failed)
+ (with-local-buttercup :suites (list parent-suite)
+ (expect (buttercup-run t) :not :to-be-truthy)))
+ (it "should return t for passing specs"
+ (with-local-buttercup :suites (list parent-suite)
+ (expect (buttercup-run) :to-be-truthy)
+ (expect (buttercup-run t) :to-be-truthy)))
(it "should call the reporter twice with events buttercup-started and -done"
(with-local-buttercup :suites (list parent-suite) :reporter 'reporter
(expect (buttercup-run) :not :to-throw)
- [nongnu] elpa/buttercup 521b71b 253/340: Add tests to ensure pending spec state is not overwritten, (continued)
- [nongnu] elpa/buttercup 521b71b 253/340: Add tests to ensure pending spec state is not overwritten, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 9265f83 258/340: Add test for buttercup-suites-total-specs-pending, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b360e35 264/340: test: Add tests for buttercup--mark-skipped, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 9b94921 276/340: test: Add tests for buttercup-reporter-batch buttercup-done handling, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 2040757 277/340: test: Add reporter test for buttercup-started with pending specs, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a91f282 283/340: Handle multiline spec descriptions in buttercup-reporter-batch-color, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 532d082 284/340: test: Fix tab stops in send-string-to-ansi-buffer for Emacs 24.3, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 8afc407 286/340: Switch from to pcase for spec-done in buttercup-reporter-batch-color, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d5c3ed5 289/340: Switch to Github Actions, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 41424d5 292/340: Add new public function buttercup-mark-skipped, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 5752a57 295/340: Control errors from buttercup-run with noerror argument,
ELPA Syncer <=
- [nongnu] elpa/buttercup 2d77e18 300/340: test: Correct descriptions for some suite-done specs, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d41c6dc 301/340: Extract buttercup-reporter-batch--print-summary, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 74e74e2 302/340: Extract buttercup-reporter-batch--print-failed-spec-report, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 52f0bec 305/340: Make buttercup-colorize treat nil as no color, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a8f4cff 311/340: test: Correct descriptions for ERT compatibility specs, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 995a4f1 312/340: Add missing docstrings, correct some other docstrings, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 110a9b6 314/340: test: Use pretty traceback, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a9647cb 316/340: Bump version: 1.22 → 1.23, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b76ff35 317/340: Update buttercup.bat to handle all options, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 62a34c7 322/340: Remove elc files in tests on make clean, ELPA Syncer, 2021/12/16