[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/with-simulated-input 9ecf7c3f84 107/134: Improve code for
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/with-simulated-input 9ecf7c3f84 107/134: Improve code for detecting warnings in tests |
Date: |
Mon, 10 Jan 2022 23:00:10 -0500 (EST) |
branch: elpa/with-simulated-input
commit 9ecf7c3f84165b89c684eb22911b7d9698cc7935
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>
Improve code for detecting warnings in tests
---
tests/test-with-simulated-input.el | 213 ++++++++++++++++++++-----------------
1 file changed, 116 insertions(+), 97 deletions(-)
diff --git a/tests/test-with-simulated-input.el
b/tests/test-with-simulated-input.el
index 6c3c5bd24f..d7140867aa 100644
--- a/tests/test-with-simulated-input.el
+++ b/tests/test-with-simulated-input.el
@@ -24,10 +24,37 @@
(expect (wsi-get-unbound-key "" '("abc" "123"))
:to-throw 'error)))
+(defmacro progn-at-runtime (&rest body)
+ "Like `progn', but evaluate BODY entirely at runtime.
+
+This is useful if BODY involves macros and you want to defer the
+expansion of those macros until BODY is evaluated."
+ `(eval
+ '(progn
+ ,@(cl-loop for expr in body
+ collect `(funcall (lambda () ,expr)))
+ lexical-binding)))
+
+(defvar warnings-displayed-count 0
+ "Count of warnings that have been displayed.")
+(defsubst reset-warnings-count (&optional n)
+ (setq warnings-displayed-count (or n 0)))
+(define-advice display-warning (:before (&rest _args) count-calls)
+ (cl-incf warnings-displayed-count))
+
+(defmacro expect-warning (&rest body)
+ "Evaluate BODY and verify that it produces a warning.
+
+BODY is wrapped in `progn-at-runtime', so warnings produced
+during macro expansion will be caught as well."
+ `(let ((warnings-displayed-count 0))
+ (prog1 (progn-at-runtime ,@body)
+ (expect warnings-displayed-count :to-be-greater-than 0))))
+
(describe "`with-simulated-input'"
(before-each
- (spy-on 'display-warning :and-call-through))
+ (setq warnings-displayed-count 0))
(describe "should work when KEYS"
@@ -37,31 +64,39 @@
(read-string "Enter a string: "))
:to-equal "hello"))
+ ;; Deprecated
(it "is a quoted list of literal strings"
- (expect
- (with-simulated-input '("hello" "RET")
- (read-string "Enter a string: "))
- :to-equal "hello"))
+ (expect-warning
+ (expect
+ (with-simulated-input '("hello" "RET")
+ (read-string "Enter a string: "))
+ :to-equal "hello")))
+ ;; Deprecated
(it "is a quoted list of lisp forms"
- (expect
- (with-simulated-input '((insert "hello") (exit-minibuffer))
- (read-string "Enter a string: "))
- :to-equal "hello"))
+ (expect-warning
+ (expect
+ (with-simulated-input '((insert "hello") (exit-minibuffer))
+ (read-string "Enter a string: "))
+ :to-equal "hello")))
+ ;; Deprecated
(it "is a quoted list of strings and lisp forms"
- (expect
- (with-simulated-input '((insert "hello") "RET")
- (read-string "Enter a string: "))
- :to-equal "hello")
- (expect
- (with-simulated-input '("hello" (exit-minibuffer))
- (read-string "Enter a string: "))
- :to-equal "hello")
- (expect
- (with-simulated-input '("hello SPC" (insert "world") "RET")
- (read-string "Enter a string: "))
- :to-equal "hello world"))
+ (expect-warning
+ (expect
+ (with-simulated-input '((insert "hello") "RET")
+ (read-string "Enter a string: "))
+ :to-equal "hello"))
+ (expect-warning
+ (expect
+ (with-simulated-input '("hello" (exit-minibuffer))
+ (read-string "Enter a string: "))
+ :to-equal "hello"))
+ (expect-warning
+ (expect
+ (with-simulated-input '("hello SPC" (insert "world") "RET")
+ (read-string "Enter a string: "))
+ :to-equal "hello world")))
(it "is an un-quoted list of literal strings"
(expect
@@ -89,6 +124,7 @@
(read-string "Enter a string: "))
:to-equal "hello world"))
+ ;; TODO: Decide whether to deprecate this
(it "is a variable containing any of the above"
(cl-loop
for input in
@@ -102,49 +138,57 @@
(read-string "Enter a string: "))
:to-equal "hello")))
- ;; This syntax is not known to be used in any real code
+ ;; This syntax is not known to be used in any real code.
+ ;; Deprecated.
(it "is an arbitrary expression evaluating to any of the above"
- (expect
- (with-simulated-input (list "hello" "RET")
- (read-string "Enter a string: "))
- :to-equal "hello")
- (expect
- (let ((my-input "hello"))
- (with-simulated-input (list (list 'insert my-input) "RET")
- (read-string "Enter a string: ")))
- :to-equal "hello")
- (expect
- (with-simulated-input (concat "hello" " " "RET")
- (read-string "Enter a string: "))
- :to-equal "hello")
- (let ((my-key-sequence (kbd "hello"))
- (my-lisp-form '(insert " world")))
- (expect
- (with-simulated-input (list
- my-key-sequence
- my-lisp-form
- "RET")
- (read-string "Enter a string: "))
- :to-equal "hello world")
- (expect
- (with-simulated-input '((execute-kbd-macro my-key-sequence)
- (eval my-lisp-form)
- "RET")
- (read-string "Enter a string: "))
- :to-equal "hello world")
- (expect
- (with-simulated-input (list
- `(execute-kbd-macro ,my-key-sequence)
- `(eval ,my-lisp-form)
- "RET")
- (read-string "Enter a string: "))
- :to-equal "hello world")
- (expect
- (with-simulated-input `((execute-kbd-macro ,my-key-sequence)
- (eval ,my-lisp-form)
- "RET")
- (read-string "Enter a string: "))
- :to-equal "hello world")))
+ (expect-warning
+ (expect
+ (with-simulated-input (list "hello" "RET")
+ (read-string "Enter a string: "))
+ :to-equal "hello"))
+ (expect-warning
+ (expect
+ (let ((my-input "hello"))
+ (with-simulated-input (list (list 'insert my-input) "RET")
+ (read-string "Enter a string: ")))
+ :to-equal "hello"))
+ (expect-warning
+ (expect
+ (with-simulated-input (concat "hello" " " "RET")
+ (read-string "Enter a string: "))
+ :to-equal "hello")
+ (let ((my-key-sequence (kbd "hello"))
+ (my-lisp-form '(insert " world")))
+ (expect-warning
+ (expect
+ (with-simulated-input (list
+ my-key-sequence
+ my-lisp-form
+ "RET")
+ (read-string "Enter a string: "))
+ :to-equal "hello world"))
+ (expect-warning
+ (expect
+ (with-simulated-input '((execute-kbd-macro my-key-sequence)
+ (eval my-lisp-form)
+ "RET")
+ (read-string "Enter a string: "))
+ :to-equal "hello world"))
+ (expect-warning
+ (expect
+ (with-simulated-input (list
+ `(execute-kbd-macro ,my-key-sequence)
+ `(eval ,my-lisp-form)
+ "RET")
+ (read-string "Enter a string: "))
+ :to-equal "hello world"))
+ (expect-warning
+ (expect
+ (with-simulated-input `((execute-kbd-macro ,my-key-sequence)
+ (eval ,my-lisp-form)
+ "RET")
+ (read-string "Enter a string: "))
+ :to-equal "hello world")))))
;; This syntax is not known to be used in any real code
(it "is evaluated at run time in a lexical environment"
@@ -181,31 +225,6 @@
(expect my-non-lexical-var
:to-be-truthy))))
- (describe "should display a deprecation warning when KEYS"
-
- ;; We need `eval' in these tests to ensure the macro is evalauted
- ;; during the test, not while loading the file.
- (it "is a quoted list of literal strings"
- (eval '(with-simulated-input '("hello" "RET")
- (read-string "Enter a string: ")))
- (expect #'display-warning :to-have-been-called))
-
- (it "is a quoted list of lisp forms"
- (eval '(with-simulated-input '((insert "hello") (exit-minibuffer))
- (read-string "Enter a string: ")))
- (expect #'display-warning :to-have-been-called))
-
- (it "is a quoted list of strings and lisp forms"
- (eval
- '(progn
- (with-simulated-input '((insert "hello") "RET")
- (read-string "Enter a string: "))
- (with-simulated-input '("hello" (exit-minibuffer))
- (read-string "Enter a string: "))
- (with-simulated-input '("hello SPC" (insert "world") "RET")
- (read-string "Enter a string: "))))
- (expect #'display-warning :to-have-been-called-times 3)))
-
(describe "should throw an error when KEYS"
(it "is an invalid literal expression"
@@ -356,15 +375,15 @@
(it "should allow an empty/constant BODY, with a warning"
;; We need `eval' to ensure the macro is evalauted during the
;; test, not while loading the file.
- (eval
- '(progn
- (expect (with-simulated-input "Is SPC anybody SPC listening? RET")
- :to-be nil)
- (expect (with-simulated-input "Is SPC anybody SPC listening? RET" t)
- :to-be t)
- (expect (with-simulated-input "Is SPC anybody SPC listening? RET" 1 2
3)
- :to-equal 3)))
- (expect #'display-warning :to-have-been-called-times 3))
+ (expect-warning
+ (expect (with-simulated-input "Is SPC anybody SPC listening? RET")
+ :to-be nil))
+ (expect-warning
+ (expect (with-simulated-input "Is SPC anybody SPC listening? RET" t)
+ :to-be t))
+ (expect-warning
+ (expect (with-simulated-input "Is SPC anybody SPC listening? RET" 1 2 3)
+ :to-equal 3)))
(describe "used with `completing-read'"
- [nongnu] elpa/with-simulated-input d32cbc3ac9 093/134: Revert "Remove interpolation test", (continued)
- [nongnu] elpa/with-simulated-input d32cbc3ac9 093/134: Revert "Remove interpolation test", ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 39dbadff0b 120/134: Update the README to reflect current supported syntax, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input e7a7a6c39d 109/134: Don't use "define-advice" in tests, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 334f9f244f 119/134: Implement support for characters in KEYS, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 00209c2be3 128/134: Test on 27.2 instead of 27.1, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 1006e93000 125/134: Add more tests to improve coverage, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 9c160b2d81 106/134: Add warnings for quoted list KEYS and nil/constant BODY, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 4eedb0eee8 126/134: Use an alternate method to disable eager macro-expansion for testing, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 9d082a372a 113/134: Be more selective about which file changes trigger a CI run, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 681397b90d 130/134: Also test variables containing characters, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 9ecf7c3f84 107/134: Improve code for detecting warnings in tests,
ELPA Syncer <=
- [nongnu] elpa/with-simulated-input ddd7bd71b1 011/134: Add "wsi-simulate-idle-time" and tests for it, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 662055c0a5 029/134: Handle non-lexical contexts as well as lexical, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 7f37451dcf 019/134: Use closures instead of quoted expressions, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input e7e8829eee 020/134: Make SECS arg to wsi-simulated-idle-time optional, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 47aa40dbe1 021/134: Handle the case where SECS exactly equals a timer's time, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 5ce98adda7 022/134: Add test for SECS = nil and for repeated idle simulations, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input e860a39bba 024/134: Version 2.1, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input c57ba13c17 043/134: Disable Travis testing emacs snapshot because it hangs, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 9fc83ac95d 047/134: Put spies in before-each form, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 2917358875 054/134: Minor CI tweaks, ELPA Syncer, 2022/01/10