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

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

[nongnu] elpa/buttercup 0124cc4 129/340: Signal an error when ":to-throw


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup 0124cc4 129/340: Signal an error when ":to-throw" is used on a non-function (#97)
Date: Thu, 16 Dec 2021 14:59:18 -0500 (EST)

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

    Signal an error when ":to-throw" is used on a non-function (#97)
    
    * Signal an error when ":to-throw" is used on a non-function
    
    Fixes #53.
    
    * Add a test for using :to-throw on non-functions
---
 buttercup.el          | 4 ++++
 docs/writing-tests.md | 7 ++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/buttercup.el b/buttercup.el
index 4d5dc3c..4389902 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -203,6 +203,10 @@ MATCHER is either a matcher defined with
                       a b precision))))
 
 (buttercup-define-matcher :to-throw (function &optional signal signal-args)
+  ;; This will trigger errors relating to FUNCTION not being a
+  ;; function outside the following `condition-case'.
+  (when (not (functionp function))
+    (funcall function))
   (condition-case err
       (progn
         (funcall function)
diff --git a/docs/writing-tests.md b/docs/writing-tests.md
index 007d1d9..2bb5dbc 100644
--- a/docs/writing-tests.md
+++ b/docs/writing-tests.md
@@ -165,7 +165,12 @@ that are not included below.
       (let ((foo (lambda () (+ a 1)))
             (bar (lambda () (+ a 1))))
         (expect foo :not :to-throw 'void-variable '(b))
-        (expect bar :to-throw 'void-variable '(a))))))
+        (expect bar :to-throw 'void-variable '(a))))
+    (it "only works on functions"
+      (expect (lambda () (expect nil :to-throw 'error))
+              :to-throw 'void-function)
+      (expect (lambda () (expect "hello" :not :to-throw 'error))
+              :to-throw 'invalid-function))))
 ```
 
 ## Grouping Related Specs with `describe`



reply via email to

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