[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/with-simulated-input 708051c57f 105/134: Improve error mes
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/with-simulated-input 708051c57f 105/134: Improve error messages for invalid/incomplete KEYS |
Date: |
Mon, 10 Jan 2022 23:00:10 -0500 (EST) |
branch: elpa/with-simulated-input
commit 708051c57f4fa51f67c0ff8bc77ca73bad97b816
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>
Improve error messages for invalid/incomplete KEYS
---
tests/test-with-simulated-input.el | 22 +++++++++++++++++
with-simulated-input.el | 48 +++++++++++++++++---------------------
2 files changed, 43 insertions(+), 27 deletions(-)
diff --git a/tests/test-with-simulated-input.el
b/tests/test-with-simulated-input.el
index 35fd79de22..8aada68dfe 100644
--- a/tests/test-with-simulated-input.el
+++ b/tests/test-with-simulated-input.el
@@ -178,6 +178,28 @@
(expect my-non-lexical-var
:to-be-truthy))))
+ (describe "should throw an error when KEYS"
+
+ (it "is an invalid literal expression"
+ (expect
+ (with-simulated-input :invalid-input
+ (read-string "Enter a string: "))
+ :to-throw 'error)
+ (expect
+ (with-simulated-input ["vectors" "are" "invalid"]
+ (read-string "Enter a string: "))
+ :to-throw 'error))
+
+ (it "is a variable with an invalid value"
+ (cl-loop
+ for input in
+ '(:invalid-input
+ ["vectors" "are" "invalid"])
+ do (expect
+ (with-simulated-input input
+ (read-string "Enter a string: "))
+ :to-throw 'error))))
+
(describe "should correctly propagate an error when it"
(it "is thrown directly from expressions in KEYS"
diff --git a/with-simulated-input.el b/with-simulated-input.el
index d1ea286e37..b193ce9f58 100644
--- a/with-simulated-input.el
+++ b/with-simulated-input.el
@@ -120,7 +120,7 @@ functions, which are called only for their side effects)."
(throw result-sym (funcall main))))
(cl-remove-if-not #'functionp keys)
(list (lambda ()
- (error "Reached end of simulated input while evaluating
body")))))
+ (error "Aborted evaluation of BODY after reaching end of
KEYS without returning")))))
(overriding-terminal-local-map
(if overriding-terminal-local-map
(copy-keymap overriding-terminal-local-map)
@@ -192,45 +192,39 @@ in `progn'."
;; TODO Support integers (i.e. single characters) in KEYS
(cond
((null keys)
- ;; (message "Keys is nil")
`(with-simulated-input-1
(lambda ()
,@body)
nil))
((and keys (symbolp keys))
- ;; (message "keys is symbol: %S" keys)
- `(progn
- (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 "INVALID VAR VALUE: %S" ,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))))
- ;; (message "Keys is lisp form: %S" keys)
`(let ((evaluated-keys (,@keys)))
- ;; (message "Evaluated keys: %S" evaluated-keys)
(pcase evaluated-keys
(`(quote ,x) (setq evaluated-keys x))
((guard (not (listp evaluated-keys))) (cl-callf list evaluated-keys)))
- ;; (message "Evaluated keys transformed: %S"
- ;; (cl-loop for key in evaluated-keys collect (if (stringp
key) key `(lambda () ,key))))
(apply
#'with-simulated-input-1
(lambda ()
- [nongnu] elpa/with-simulated-input 02b5d2c77f 072/134: Fix checkdoc warnings, (continued)
- [nongnu] elpa/with-simulated-input 02b5d2c77f 072/134: Fix checkdoc warnings, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 4e45836cc0 078/134: Autoload `with-simulated-input--1', ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 89e63ebf6a 073/134: Fix tests for older Emacsen, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 0aeff5f17f 079/134: `with-simulated-input': remove legacy syntax, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 6f7787df80 082/134: Add an unload function, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 26fc928f42 092/134: Work around an incompatibility in Emacs 24 in tests, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input ef9d5164ca 094/134: Fix interpolation test, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input d3696fb04c 098/134: Check errors more strictly in tests, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 703fc3c9ec 118/134: Update the docstring for "with-simulated-input", ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 73fa2256df 123/134: Move helper function next to macro, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 708051c57f 105/134: Improve error messages for invalid/incomplete KEYS,
ELPA Syncer <=
- [nongnu] elpa/with-simulated-input e7cc96e7df 102/134: Update the debug declaration for "with-simulated-input" macro, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 2f54a2550b 117/134: Clean up code for "with-simulated-input" macro, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input a86f35f3b0 100/134: Add tests for un-quoted lists, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 07bdfbe9ab 124/134: Increment version to 3.0, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 670c23e615 004/134: Update minimum Emacs version to 24.4, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input c97f27da20 005/134: Autoload the macro, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 369ca97402 006/134: Fix issues found by package-lint, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 00ed837502 012/134: Standardize on internal Emacs time type, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input f0dbf2fdd9 017/134: Fix a typo, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 69d91e4b51 025/134: Add a failing test for lexical variable access, ELPA Syncer, 2022/01/10