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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/buttercup 39c7d8c 132/340: Allow ERT "should" and similar


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup 39c7d8c 132/340: Allow ERT "should" and similar to work with buttercup
Date: Thu, 16 Dec 2021 14:59:19 -0500 (EST)

branch: elpa/buttercup
commit 39c7d8c39629005657453220c06327641965fbc7
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Jorgen Schäfer <Jorgen.Schaefer@gmail.com>

    Allow ERT "should" and similar to work with buttercup
    
    This defines a new macro "buttercup-with-converted-ert-signals" that
    converts ERT failure and test-skipping signals to the equivalent
    buttercup ones. This allows "should" and other ERT test functions to
    work within buttercup test specs, thus making it easier for people to
    port ERT tests to buttercup.
    
    The test for the macro expansion of "it" has been modified for the new
    expansion, and a few tests have been added to verify the new
    functionality.
---
 buttercup.el            | 21 ++++++++++++++++++++-
 tests/test-buttercup.el | 24 +++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/buttercup.el b/buttercup.el
index 286f9a1..dc7e48f 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -418,11 +418,15 @@ form.")
   "Define a spec."
   (declare (indent 1) (debug (&define sexp def-body)))
   (if body
-      `(buttercup-it ,description (lambda () ,@body))
+      `(buttercup-it ,description
+         (lambda ()
+           (buttercup-with-converted-ert-signals
+             ,@body)))
     `(buttercup-xit ,description)))
 
 (defun buttercup-it (description body-function)
   "Function to handle an `it' form."
+  (declare (indent 1))
   (when (not buttercup--current-suite)
     (error "`it' has to be called from within a `describe' form."))
   (buttercup-suite-add-child buttercup--current-suite
@@ -508,6 +512,7 @@ A disabled spec is not run."
   "Like `buttercup-it', but mark the spec as disabled.
 
 A disabled spec is not run."
+  (declare (indent 1))
   (buttercup-it description (lambda ()
                               (signal 'buttercup-pending "PENDING")))
   (let ((spec (car (last (buttercup-suite-children
@@ -1149,6 +1154,20 @@ failed -- The second value is the description of the 
expectation
             frame (backtrace-frame n)))
     frame-list))
 
+(defmacro buttercup-with-converted-ert-signals (&rest body)
+  "Convert ERT signals to buttercup signals in BODY.
+
+Specifically, `ert-test-failed' is converted to
+`buttercup-failed' and `ert-test-skipped' is converted to
+`buttercup-pending'."
+  (declare (indent 0))
+  `(condition-case err
+       (progn ,@body)
+     (ert-test-failed
+      (buttercup-fail "%S" err))
+     (ert-test-skipped
+      (buttercup-skip "Skipping: %S" err))))
+
 ;;;###autoload
 (define-minor-mode buttercup-minor-mode
   "Activate buttercup minor mode.
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index f591c5e..e488b61 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -18,6 +18,7 @@
 ;;; Code:
 
 (require 'buttercup)
+(require 'ert)
 
 ;;;;;;;;;;
 ;;; expect
@@ -342,7 +343,10 @@
   (it "should expand to a call to the `buttercup-it' function"
     (expect (macroexpand '(it "description" body))
             :to-equal
-            '(buttercup-it "description" (lambda () body))))
+            '(buttercup-it "description"
+               (lambda ()
+                 (buttercup-with-converted-ert-signals
+                   body)))))
 
   (it "without argument should expand to xit."
     (expect (macroexpand '(it "description"))
@@ -763,6 +767,24 @@
             :to-have-been-called-with
             "Hello, world")))
 
+;;;;;;;;;;;;;;;;;;;;;
+;;; ERT Compatibility
+
+(describe "Buttercup's ERT compatibility wrapper"
+  (it "should convert `ert-test-failed' into `buttercup-failed"
+    (expect
+     (lambda ()
+       (buttercup-with-converted-ert-signals
+         (should (equal 1 2))))
+     :to-throw 'buttercup-failed))
+  (it "should convert `ert-test-skipped' into `buttercup-pending"
+    (assume (functionp 'ert-skip) "Loaded ERT version does not provide 
`ert-skip'")
+    (expect
+     (lambda ()
+       (buttercup-with-converted-ert-signals
+         (ert-skip "Skipped this test")))
+     :to-throw 'buttercup-pending)))
+
 ;;;;;;;;;;;;;
 ;;; Utilities
 



reply via email to

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