[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup a970d10 228/340: Implement spy-calls-count-retur
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup a970d10 228/340: Implement spy-calls-count-returned and spy-calls-count-errors |
Date: |
Thu, 16 Dec 2021 14:59:40 -0500 (EST) |
branch: elpa/buttercup
commit a970d10c2f681b65e205d52189c36cd1b0122e43
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>
Implement spy-calls-count-returned and spy-calls-count-errors
A test is added for both functions.
---
buttercup.el | 10 ++++++++++
docs/writing-tests.md | 23 +++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/buttercup.el b/buttercup.el
index 29d8a16..2bed332 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -1195,6 +1195,16 @@ responsibility to ensure ARG is a command."
"Return the number of times SPY has been called so far."
(length (spy-calls-all spy)))
+(defun spy-calls-count-returned (spy)
+ "Return the number of times SPY has been called successfully so far."
+ (length (cl-remove-if-not 'spy-context-return-p
+ (spy-calls-all spy))))
+
+(defun spy-calls-count-errors (spy)
+ "Return the number of times SPY has been called and thrown errors so far."
+ (length (cl-remove-if-not 'spy-context-thrown-p
+ (spy-calls-all spy))))
+
(defun spy-calls-args-for (spy index)
"Return the context of the INDEXth call to SPY."
(let ((context (elt (spy-calls-all spy)
diff --git a/docs/writing-tests.md b/docs/writing-tests.md
index 9307f43..bd23376 100644
--- a/docs/writing-tests.md
+++ b/docs/writing-tests.md
@@ -657,6 +657,29 @@ Finally, `spy-calls-reset` clears all tracking for a spy.
(spy-calls-most-recent 'set-foo))
:to-throw))
+ (it "counts the number of successful and failed calls"
+ ;; Set up `set-foo' so that it can either return a value or throw
+ ;; an error
+ (spy-on 'set-foo :and-call-fake
+ (lambda (val &rest ignored)
+ (if (>= val 0)
+ val
+ (error "Value must not be negative"))))
+ (expect (set-foo 1) :to-be 1)
+ (expect (set-foo 2) :to-be 2)
+ (expect (set-foo 3) :to-be 3)
+ (expect (set-foo -1) :to-throw 'error)
+ (expect (set-foo -2) :to-throw 'error)
+ (expect (set-foo -3) :to-throw 'error)
+ (expect (set-foo -4) :to-throw 'error)
+
+ (expect (spy-calls-count 'set-foo)
+ :to-be 7)
+ (expect (spy-calls-count-returned 'set-foo)
+ :to-be 3)
+ (expect (spy-calls-count-errors 'set-foo)
+ :to-be 4))
+
(it "can be reset"
(set-foo 123)
(set-foo 456 "baz")
- [nongnu] elpa/buttercup 34e12fd 154/340: Get rid of 60 compile-time warnings out of 97, (continued)
- [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
- [nongnu] elpa/buttercup debe7cc 204/340: Merge pull request #144 from kevinjfoley/support-var-star, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c2d75e9 209/340: Bump version: 1.17 → 1.18, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bb3fba3 227/340: Properly handle return values and thrown signals in spies, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a970d10 228/340: Implement spy-calls-count-returned and spy-calls-count-errors,
ELPA Syncer <=
- [nongnu] elpa/buttercup 8d91893 232/340: Optimize spy-calls-count-errors and spy-calls-count-returned, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 83141f7 243/340: Raise an error if spy-on is used in the wrong context, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 16e3530 090/340: Also update Makefile to the new docs names, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 794afbf 114/340: Merge pull request #65 from DamienCassou/patch-1, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d5c9a19 120/340: Make --with-cleanup public so spies can be used without specs, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 79286cf 055/340: Test for the batch reporter., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 87e0c0d 073/340: Bump version: 1.0 → 1.1, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 10e0537 150/340: Manually fix bumpversion.cfg, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 18a8879 151/340: Bump version: 1.8 → 1.9, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 62c416a 164/340: Rewrite the pattern loop of buttercup-run-discover, ELPA Syncer, 2021/12/16