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

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

[nongnu] elpa/buttercup 2aa840c 088/340: Merge pull request #40 from lun


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup 2aa840c 088/340: Merge pull request #40 from lunaryorn/assume-form
Date: Thu, 16 Dec 2021 14:59:09 -0500 (EST)

branch: elpa/buttercup
commit 2aa840cb0e99251d299507859e98eb7341758fc9
Merge: e1f71ac 673f84d
Author: Jorgen Schäfer <Jorgen.Schaefer@gmail.com>
Commit: Jorgen Schäfer <Jorgen.Schaefer@gmail.com>

    Merge pull request #40 from lunaryorn/assume-form
    
    Add assume form to cancel tests if conditions fail
---
 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))
 



reply via email to

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