[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup bf48137 224/340: Add some tests for error-call r
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup bf48137 224/340: Add some tests for error-call recording |
Date: |
Thu, 16 Dec 2021 14:59:39 -0500 (EST) |
branch: elpa/buttercup
commit bf481374073a408835f8caffadc85511f420faf2
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>
Add some tests for error-call recording
---
tests/test-buttercup.el | 68 +++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 63 insertions(+), 5 deletions(-)
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index e99a964..8c27bf8 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -613,27 +613,40 @@
;;; Spies
(describe "The Spy "
- (let (saved-test-function saved-test-command)
+ (let (saved-test-function
+ saved-test-command
+ saved-test-function-throws-on-negative)
;; We use `before-all' here because some tests need to access the
;; same function as previous tests in order to work, so overriding
;; the function before each test would invalidate those tests.
+ ;; Unfortunately there's no way to do this lexically, so these
+ ;; function definitions are leaked after the tests run.
(before-all
(setq saved-test-function (and (fboundp 'test-function)
(symbol-function 'test-function))
saved-test-command (and (fboundp 'test-command)
- (symbol-function 'test-command)))
+ (symbol-function 'test-command))
+ saved-test-function-throws-on-negative
+ (and (fboundp 'test-function-throws-on-negative)
+ (symbol-function 'test-function-throws-on-negative)))
(fset 'test-function (lambda (a b)
(+ a b)))
(fset 'test-command (lambda ()
(interactive)
- t)))
+ t))
+ (fset 'test-function-throws-on-negative
+ (lambda (x) (if (>= x 0) x (error "x is less than zero")))))
(after-all
(if saved-test-function
(fset 'test-function saved-test-function)
(fmakunbound 'test-function))
(if saved-test-command
(fset 'test-command saved-test-command)
- (fmakunbound 'test-command)))
+ (fmakunbound 'test-command))
+ (if saved-test-function-throws-on-negative
+ (fset 'test-test-function-throws-on-negative
+ test-function-throws-on-negative)
+ (fmakunbound 'test-function-throws-on-negative)))
(describe "`spy-on' function"
(it "replaces a symbol's function slot"
@@ -881,7 +894,52 @@
(it "throws an error when called"
(expect (test-function 1 2)
:to-throw
- 'error "Stubbed error")))))
+ 'error "Stubbed error")))
+
+ (describe "error-recording functionality"
+ (before-each
+ (spy-on 'test-function-throws-on-negative :and-call-through))
+
+ (it "records the function as called even if it throws an error"
+ (expect (test-function-throws-on-negative -5) :to-throw)
+ (expect (buttercup--apply-matcher
+ :to-have-been-called
+ (list (lambda () 'test-function-throws-on-negative)))
+ :to-be
+ t))
+
+ (it "counts both successful calls and calls that threw errors"
+ (test-function-throws-on-negative 5)
+ (expect (test-function-throws-on-negative -5) :to-throw)
+ (expect (buttercup--apply-matcher
+ :to-have-been-called-times
+ (make-list-of-closures '(test-function-throws-on-negative 2)))
+ :to-equal t))
+
+ (it "records args to the function whether it throw an error or not"
+ (test-function-throws-on-negative 5)
+ (expect (test-function-throws-on-negative -5) :to-throw)
+ (expect (buttercup--apply-matcher
+ :to-have-been-called-with
+ (make-list-of-closures '(test-function-throws-on-negative 5)))
+ :to-be
+ t)
+ (expect (buttercup--apply-matcher
+ :to-have-been-called-with
+ (make-list-of-closures '(test-function-throws-on-negative
-5)))
+ :to-be
+ t))
+
+ (it "records the signal thrown by a call to the function"
+ (test-function-throws-on-negative 5)
+ (expect (test-function-throws-on-negative -5) :to-throw 'error)
+ (expect (spy-context-thrown-signal
+ (spy-calls-first 'test-function-throws-on-negative))
+ :to-be nil)
+ (expect (car
+ (spy-context-thrown-signal
+ (spy-calls-most-recent 'test-function-throws-on-negative)))
+ :to-be 'error)))))
;;;;;;;;;;;;;
;;; Reporters
- [nongnu] elpa/buttercup a394fea 191/340: Bump version: 1.13 → 1.14, (continued)
- [nongnu] elpa/buttercup a394fea 191/340: Bump version: 1.13 → 1.14, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 7cea4c6 192/340: Test buttercup-run, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b410c78 193/340: Separate return code from reporter, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 9b230dc 202/340: Fix the "should print the elapsed time for all specs" test, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 9d172a7 205/340: Merge pull request #145 from snogge/test-fixes, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c100fad 210/340: Implement buttercup-suppress-warning-capture, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c994aea 212/340: Add LICENSE file., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d9ce620 213/340: Merge branch 'license-file' into master, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 49f01fc 219/340: Merge branch 'master' into test-emacs-26.3, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 25462dd 223/340: Record calls to spied-on functions that throw errors, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bf48137 224/340: Add some tests for error-call recording,
ELPA Syncer <=
- [nongnu] elpa/buttercup fc19598 225/340: Add examples for checking return value and thrown signal of a spy, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 6590360 226/340: Fix a few typos and other small errors, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 8a28489 230/340: Bump version: 1.18 → 1.19, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0e40587 231/340: Tweak the spy-contexts to be more backward compatible, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 60028db 236/340: docs: Clarify the spy lifespan in writing-tests.md, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 9c4b473 237/340: test: Add missing apostrophe in spec title, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 90654ec 238/340: Update some docstrings, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 178c795 242/340: README: Add '-L .' to test runner example, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup fc4276a 247/340: Make it possible to abort test run cleanly, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup dbcd3d4 256/340: Calculate total test run time with current-time, ELPA Syncer, 2021/12/16