emacs-elpa-diffs
[Top][All Lists]
Advanced

[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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]