[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
- [nongnu] elpa/buttercup 459bffb 282/340: test: Add color tests for buttercup-done, (continued)
- [nongnu] elpa/buttercup 459bffb 282/340: test: Add color tests for buttercup-done, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a1c7bff 101/340: Do not ignore errors when after-each succeeds, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b120003 108/340: Merge pull request #60 from howdoicomputer/feature/windows-bin-support, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 06c9699 104/340: Merge pull request #58 from Fuco1/to-equal-as-set, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a6d9bde 105/340: Support more emacs parameters useful for pre-test initialization, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup abf2abe 109/340: Exclude hidden files and dirs in test root, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f60ed2a 119/340: Bump version: 1.5 → 1.6, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 677d6d3 118/340: Merge pull request #70 from xendk/color-output, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d8dc80d 126/340: Bump version: 1.6 → 1.7, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b6deeff 128/340: Set Emacs 24.3 as minimum and clean outdated code (close #89), ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 39c7d8c 132/340: Allow ERT "should" and similar to work with buttercup,
ELPA Syncer <=
- [nongnu] elpa/buttercup e8140aa 133/340: Implement configurable stack traces, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup e6f97d0 136/340: Release 1.8, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup e26ea54 137/340: Let spy-on :and-return-value work with lists and symbols (close #104), ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup e55e3d8 138/340: travis: Test on 25.1 and 25.2, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c032c8f 141/340: Exec code blocks in markdown labeled as "emacs-lisp" and "elisp", ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b97714d 144/340: Declare all variables before first use, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 4128f3e 147/340: Document ERT support in writing-tests.md, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 47dd72c 156/340: Set file local variables for consistent code style, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 5458dcc 158/340: Replace buttercup-*-parents with buttercup-suite-or-spec-parents, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 77367d3 165/340: Change shebang to use /usr/bin/env, ELPA Syncer, 2021/12/16