[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/with-simulated-input 9c160b2d81 106/134: Add warnings for
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/with-simulated-input 9c160b2d81 106/134: Add warnings for quoted list KEYS and nil/constant BODY |
Date: |
Mon, 10 Jan 2022 23:00:10 -0500 (EST) |
branch: elpa/with-simulated-input
commit 9c160b2d81a2de7aa348a75545012ff0b924dd93
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>
Add warnings for quoted list KEYS and nil/constant BODY
The former is deprecated and the latter is a likely the unintended
result of a typo.
---
tests/test-with-simulated-input.el | 55 ++++++++++++++++++++++----
with-simulated-input.el | 79 +++++++++++++++++++++++---------------
2 files changed, 97 insertions(+), 37 deletions(-)
diff --git a/tests/test-with-simulated-input.el
b/tests/test-with-simulated-input.el
index 8aada68dfe..6c3c5bd24f 100644
--- a/tests/test-with-simulated-input.el
+++ b/tests/test-with-simulated-input.el
@@ -26,6 +26,9 @@
(describe "`with-simulated-input'"
+ (before-each
+ (spy-on 'display-warning :and-call-through))
+
(describe "should work when KEYS"
(it "is a literal string"
@@ -178,6 +181,31 @@
(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"
@@ -258,30 +286,30 @@
(expect
(with-simulated-input "hello" ; No RET
(read-string "Enter a string: "))
- :to-throw 'error '("Reached end of simulated input while evaluating
body")))
+ :to-throw 'error))
(it "should throw an error if the input is empty and BODY reads input"
(expect
(with-simulated-input nil
(read-string "Enter a string: "))
- :to-throw 'error '("Reached end of simulated input while evaluating
body"))
+ :to-throw 'error)
(expect
(with-simulated-input '()
(read-string "Enter a string: "))
- :to-throw 'error '("Reached end of simulated input while evaluating
body"))
+ :to-throw 'error)
(expect
(with-simulated-input ()
(read-string "Enter a string: "))
- :to-throw 'error '("Reached end of simulated input while evaluating
body"))
+ :to-throw 'error)
(expect
(with-simulated-input '(nil)
(read-string "Enter a string: "))
- :to-throw 'error '("Reached end of simulated input while evaluating
body"))
+ :to-throw 'error)
(let ((my-input nil))
(expect
(with-simulated-input my-input
(read-string "Enter a string: "))
- :to-throw 'error '("Reached end of simulated input while evaluating
body"))))
+ :to-throw 'error)))
(it "should not throw an error if the input is empty unless BODY reads input"
(expect
@@ -325,6 +353,19 @@
(read-string "Second word: ")))
:to-equal '("hello" "world")))
+ (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))
+
(describe "used with `completing-read'"
:var (completing-read-function)
@@ -353,7 +394,7 @@
(expect
(with-simulated-input "bl TAB C-j"
(completing-read "Choose: " my-collection nil t))
- :to-throw 'error '("Reached end of simulated input while evaluating
body"))))
+ :to-throw 'error)))
(describe "should not reproduce past issues:"
;; https://github.com/DarwinAwardWinner/with-simulated-input/issues/4
diff --git a/with-simulated-input.el b/with-simulated-input.el
index b193ce9f58..ea94a0565a 100644
--- a/with-simulated-input.el
+++ b/with-simulated-input.el
@@ -44,6 +44,7 @@
;;
;;; Code:
+(require 'files)
(require 'cl-lib)
(cl-defun wsi-key-bound-p (key)
@@ -188,9 +189,18 @@ in `progn'."
([&or functionp macrop] &rest form) ; arbitrary lisp function
call
]
body)))
- ;; TODO Warn on empty body
;; TODO Support integers (i.e. single characters) in KEYS
(cond
+ ((null body)
+ (display-warning 'with-simulated-input
+ "BODY is empty; KEYS will not be used")
+ nil)
+ ((not (cl-find-if-not #'hack-one-local-variable-constantp body))
+ (display-warning 'with-simulated-input
+ "BODY consists of only constant expressions; KEYS will
not be used")
+ ;; Since all the expressions are constant, there's no point in
+ ;; evaluating any of them except the last one.
+ (car (last body)))
((null keys)
`(with-simulated-input-1
(lambda ()
@@ -198,42 +208,51 @@ in `progn'."
nil))
((and keys (symbolp keys))
`(cond
- ((null ,keys)
- (with-simulated-input-1
- (lambda ()
- ,@body)
- nil))
- ((stringp ,keys)
- (with-simulated-input-1
- (lambda ()
- ,@body)
- ,keys))
- ((listp ,keys)
- (apply
- #'with-simulated-input-1
- (lambda ()
- ,@body)
- (cl-loop for key in ,keys collect (if (stringp key) key `(lambda ()
,key)))))
- (t
- (error "KEYS must be a string or list, not %s: %s = %S"
- (type-of ,keys) ',keys ,keys))))
- ((and (listp keys)
- (not (eq (car keys) 'quote))
- (or (functionp (car keys))
- (macrop (car keys))))
- `(let ((evaluated-keys (,@keys)))
- (pcase evaluated-keys
- (`(quote ,x) (setq evaluated-keys x))
- ((guard (not (listp evaluated-keys))) (cl-callf list evaluated-keys)))
+ ((null ,keys)
+ (with-simulated-input-1
+ (lambda ()
+ ,@body)
+ nil))
+ ((stringp ,keys)
+ (with-simulated-input-1
+ (lambda ()
+ ,@body)
+ ,keys))
+ ((listp ,keys)
(apply
#'with-simulated-input-1
(lambda ()
,@body)
- (cl-loop for key in evaluated-keys collect (if (stringp key) key
`(lambda () ,key))))))
+ (cl-loop for key in ,keys collect (if (stringp key) key `(lambda ()
,key)))))
+ (t
+ (error "KEYS must be a string or list, not %s: %s = %S"
+ (type-of ,keys) ',keys ,keys))))
+ ((and (listp keys)
+ (not (eq (car keys) 'quote))
+ (or (functionp (car keys))
+ (macrop (car keys))))
+ (let ((evaluated-keys-sym (make-symbol "evaluated-keys")))
+ `(let ((,evaluated-keys-sym (,@keys)))
+ (pcase ,evaluated-keys-sym
+ (`(quote ,x)
+ (prog1 (setq ,evaluated-keys-sym x)
+ (display-warning
+ 'with-simulated-input
+ "Passing KEYS as a quoted list is deprecated.")))
+ ((guard (not (listp ,evaluated-keys-sym))) (cl-callf list
,evaluated-keys-sym)))
+ (apply
+ #'with-simulated-input-1
+ (lambda ()
+ ,@body)
+ (cl-loop for key in ,evaluated-keys-sym collect (if (stringp key)
key `(lambda () ,key)))))))
(t
;; (message "Keys is something else: %S" keys)
(pcase keys
- (`(quote ,x) (setq keys x))
+ (`(quote ,x)
+ (prog1 (setq keys x)
+ (display-warning
+ 'with-simulated-input
+ "Passing KEYS as a quoted list is deprecated.")))
((guard (not (listp keys))) (cl-callf list keys)))
`(with-simulated-input-1
(lambda ()
- [nongnu] elpa/with-simulated-input 568bfb8e1d 015/134: Version 2.0, (continued)
- [nongnu] elpa/with-simulated-input 568bfb8e1d 015/134: Version 2.0, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 5bdbde591d 058/134: Eliminate spurious warning in test file, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 433ee087ce 066/134: Test: handle `undercover' not being installed, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input ea6735cf1b 083/134: KEYS: support a single variable, ELPA Syncer, 2022/01/10
- [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 <=
- [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, 2022/01/10
- [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