[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup 673f84d 087/340: Add assume form to cancel tests
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup 673f84d 087/340: Add assume form to cancel tests if conditions fail |
Date: |
Thu, 16 Dec 2021 14:59:09 -0500 (EST) |
branch: elpa/buttercup
commit 673f84dede8e4a1915e8401bb00a6d865f5c18ce
Author: Sebastian Wiesner <swiesner@lunaryorn.com>
Commit: Sebastian Wiesner <swiesner@lunaryorn.com>
Add assume form to cancel tests if conditions fail
The assume form cancels the current test if the given condition is not
met. It is intended to be used in tests that depend on a certain
global state that might not be present, e.g. a tool in "exec-path" or a
network connection, etc.
Example:
(describe "Eggs"
(it "gets eggs from the internet"
(assume (network-available-p) "No network connection")
(my/get-eggs)))
Output if the assumption is not met
Eggs
gets eggs from the internet !! CANCELLED !! No network connection
---
buttercup.el | 14 ++++++++++++++
tests/test-buttercup.el | 25 +++++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/buttercup.el b/buttercup.el
index a2eb57e..7a60143 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -104,6 +104,20 @@ This is the mechanism underlying `expect'. You can use it
directly if you want to write your own testing functionality."
(signal 'buttercup-failed (apply #'format format args)))
+(defun buttercup-skip (format &rest args)
+ "Skip the current test with the given description."
+ (signal 'buttercup-pending (apply #'format format args)))
+
+(defmacro assume (condition &optional message)
+ "Assume CONDITIION for the current test.
+
+Assume that CONDITION evaluates to non-nil in the current test.
+If it evaluates to nil cancel the current test with MESSAGE. If
+MESSAGE is omitted or nil show the condition form instead."
+ (let ((message (or message (format "%S => nil" condition))))
+ `(unless ,condition
+ (buttercup-skip "!! CANCELLED !! %s" ,message))))
+
(defmacro buttercup-define-matcher (matcher args &rest body)
"Define a matcher to be used in `expect'.
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index ec8d037..eb8ca14 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -103,6 +103,31 @@
:to-throw
'buttercup-failed "Explanation")))
+(describe "The `assume' form"
+ (it "should raise a signal if the condition is nil"
+ (expect (lambda ()
+ (assume nil "Explanation"))
+ :to-throw
+ 'buttercup-pending "!! CANCELLED !! Explanation"))
+
+ (it "should show the format if no message is given"
+ (expect (lambda ()
+ (assume (< 1 0)))
+ :to-throw
+ 'buttercup-pending "!! CANCELLED !! (< 1 0) => nil"))
+
+ (it "should not raise a signal if the condition is non-nil"
+ (expect (lambda ()
+ (assume 'non-nil "Explanation"))
+ :not :to-throw)))
+
+(describe "The `buttercup-skip function"
+ (it "should raise a signal with its arguments"
+ (expect (lambda ()
+ (buttercup-skip "Explanation" ))
+ :to-throw
+ 'buttercup-pending "Explanation")))
+
(buttercup-define-matcher :test-matcher (a b)
(+ a b))
- [nongnu] elpa/buttercup 14718c0 081/340: Use the new Travis infrastructure, (continued)
- [nongnu] elpa/buttercup 14718c0 081/340: Use the new Travis infrastructure, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d00c164 083/340: Display description for pending specs, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup ad901b5 149/340: Do not modify global match data in matchers, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c1187b3 152/340: Extract function buttercup-suites-total-spces-status, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f565eda 157/340: Extract super-struct buttercup-suite-or-spec, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0c1dcda 161/340: Fix docstring of buttercup--specs-and-suite, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 8d27bb9 169/340: Bump version: 1.10 → 1.11, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 45f40c7 174/340: Restore obsoletion version for buttercup-*-parents, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d7ab592 080/340: Bump version: 1.1 → 1.2, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup e1f71ac 086/340: Bump version: 1.3 → 1.4, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 673f84d 087/340: Add assume form to cancel tests if conditions fail,
ELPA Syncer <=
- [nongnu] elpa/buttercup 2aa840c 088/340: Merge pull request #40 from lunaryorn/assume-form, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 6c11d8e 097/340: Debian and Ubuntu installation instructions, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup ae606fc 153/340: Set failure description to empty string for pending specs, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 34e12fd 154/340: Get rid of 60 compile-time warnings out of 97, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 897d0e7 155/340: Remove some warnings on test-buttercup.el, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 25046d3 160/340: Rewrite buttercup--update-with-funcall with suite-or-spec functions, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 85aebcd 168/340: Fix issue #121, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 4089d5f 194/340: Bump version: 1.14 → 1.15, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 1850253 195/340: Remove duplicate buttercup-color declaration, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 2bc55fe 201/340: Add emacs-26.2 to CI config, ELPA Syncer, 2021/12/16