[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/with-simulated-input 1a610d6587 089/134: Reorganize test s
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/with-simulated-input 1a610d6587 089/134: Reorganize test suite |
Date: |
Mon, 10 Jan 2022 23:00:08 -0500 (EST) |
branch: elpa/with-simulated-input
commit 1a610d65876db558930b8bb130743769792febef
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>
Reorganize test suite
Note that the tests here still reflect the behavior of the 2.x branch.
---
tests/test-with-simulated-input.el | 248 ++++++++++++++++++++++++-------------
1 file changed, 160 insertions(+), 88 deletions(-)
diff --git a/tests/test-with-simulated-input.el
b/tests/test-with-simulated-input.el
index 7aa6f7e6aa..2a85a62db0 100644
--- a/tests/test-with-simulated-input.el
+++ b/tests/test-with-simulated-input.el
@@ -26,30 +26,173 @@
(describe "`with-simulated-input'"
- (it "should work for basic string input"
- (expect
- (with-simulated-input "hello RET"
- (read-string "Enter a string: "))
- :to-equal "hello"))
+ (describe "should work when KEYS"
+
+ (it "is a literal string"
+ (expect
+ (with-simulated-input "hello RET"
+ (read-string "Enter a string: "))
+ :to-equal "hello"))
+
+ (it "is a quoted list of literal strings"
+ (expect
+ (with-simulated-input '("hello" "RET")
+ (read-string "Enter a string: "))
+ :to-equal "hello"))
+
+ (it "is a quoted list of lisp forms"
+ (expect
+ (with-simulated-input '((insert "hello") (exit-minibuffer))
+ (read-string "Enter a string: "))
+ :to-equal "hello"))
+
+ (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"))
+
+ (it "is a variable containing any of the above"
+ (cl-loop
+ for input in
+ '("hello RET"
+ ("hello" "RET")
+ ((insert "hello") (exit-minibuffer))
+ ((insert "hello") "RET")
+ ("hello" (exit-minibuffer)))
+ do (expect
+ (with-simulated-input input
+ (read-string "Enter a string: "))
+ :to-equal "hello")))
+
+ (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 '(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 "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")))
+ (it "is evaluated at run time in a lexical environment"
+ (let ((my-input "hello"))
+ (expect
+ (with-simulated-input `((insert ,my-input) "RET")
+ (read-string "Enter a string: "))
+ :to-equal "hello"))
+ (let ((greeting "hello")
+ (target "world"))
+ (expect
+ (with-simulated-input
+ (list greeting "SPC"
+ (list 'insert target)
+ "RET")
+ (read-string "Say hello: "))
+ :to-equal "hello world"))
+ (let ((my-lexical-var nil))
+ (with-simulated-input '("hello"
+ (setq my-lexical-var t)
+ "RET")
+ (read-string "Enter a string: "))
+ (expect my-lexical-var
+ :to-be-truthy)))
+
+ (it "is evaluated at run time in a non-lexical environment"
+ (let ((my-non-lexical-var nil))
+ (eval
+ '(with-simulated-input '("hello"
+ (setq my-non-lexical-var t)
+ "RET")
+ (read-string "Enter a string: "))
+ nil)
+ (expect my-non-lexical-var
+ :to-be-truthy))))
+
+ (describe "should correctly propagate errors"
+
+ (it "thrown directly from expressions in KEYS"
+ (expect
+ (with-simulated-input '("hello" (error "Throwing an error from KEYS")
"RET")
+ (read-string "Enter a string: "))
+ :to-throw))
+
+ (it "caused indirectly by the inputs in KEYS"
+ (expect
+ (with-simulated-input
+ "(error SPC \"Manually SPC throwing SPC an SPC error\") RET"
+ (command-execute 'eval-expression))
+ :to-throw))
+
+ (it "thrown by BODY"
+ (expect
+ (with-simulated-input
+ "hello RET"
+ (read-string "Enter a string: ")
+ (error "Throwing an error after reading input"))
+ :to-throw)
+ (expect
+ (with-simulated-input
+ "hello RET"
+ (error "Throwing an error before reading input")
+ (read-string "Enter a string: "))
+ :to-throw))
+
+ (it "from aborting via C-g in KEYS"
+ (expect
+ (condition-case nil
+ (with-simulated-input "C-g"
+ (read-string "Enter a string: "))
+ (quit 'caught-quit))
+ :to-be 'caught-quit)))
+
+ ;; TODO: Warn on no-op elements like this: any variable or
+ ;; non-string literal, or any expression known to involve only pure
+ ;; functions.
+ (it "should ignore the return value of expressions in KEYS"
+ (let ((desired-input "hello")
+ (undesired-input "goodbye"))
+ (expect
+ (with-simulated-input '((insert desired-input) undesired-input "RET")
+ (read-string "Enter a string: "))
+ :to-equal desired-input)))
(it "should throw an error if the input is incomplete"
(expect
- (with-simulated-input "hello"
+ (with-simulated-input "hello" ; No RET
(read-string "Enter a string: "))
:to-throw))
- (it "should allow the input to trigger errors"
+ (it "should discard any extra input after BODY has completed"
(expect
-
(with-simulated-input
- "(error SPC \"Manually SPC throwing SPC an SPC error\") RET"
- (command-execute 'eval-expression))
- :to-throw))
-
- (it "should ignore extra input after BODY has completed"
+ "hello RET M-x eval-expression (error SPC \"Manually SPC throwing SPC
an SPC error\") RET"
+ (read-string "Enter a string: "))
+ :to-equal "hello")
(expect
(with-simulated-input
- "hello RET M-x eval-expression (error SPC \"Manually SPC throwing SPC
an SPC error\") RET"
+ '("hello RET" (error "Throwing an error after BODY has completeld."))
(read-string "Enter a string: "))
:to-equal "hello"))
@@ -60,16 +203,8 @@
(read-string "Second word: ")))
:to-equal '("hello" "world")))
- (it "should allow aborting via C-g in KEYS"
- (expect
- (condition-case nil
- (with-simulated-input "C-g"
- (read-string "Enter a string: "))
- (quit 'caught-quit))
- :to-be 'caught-quit))
-
;; https://github.com/DarwinAwardWinner/with-simulated-input/issues/4
- (it "should work inside code that switches buffer (issue #4)"
+ (it "should work inside code that switches buffers (issue #4)"
(let ((orig-current-buffer (current-buffer)))
(with-temp-buffer
(let ((temp-buffer (current-buffer)))
@@ -77,7 +212,7 @@
(expect (current-buffer) :to-equal temp-buffer)
(expect (current-buffer) :not :to-equal orig-current-buffer)))))
- (it "should work in byte-compiled code (issue #6)"
+ (xit "should work in byte-compiled code (issue #6)"
(expect (call-wsi-from-bytecomp-fun)
:not :to-throw))
@@ -110,70 +245,7 @@
(with-simulated-input "bl TAB C-j"
(completing-read "Choose: " my-collection nil t))
- :to-throw)))
-
- (describe "using lisp forms in KEYS argument of `with-simulated-input'"
-
- (it "should allow evaluating arbitrary lisp forms"
- (expect
- (with-simulated-input '("hello SPC" (insert "world") "RET")
- (read-string "Enter a string: "))
- :to-equal "hello world"))
-
- (it "should allow KEYS to be evaluated at run time"
- (let ((greeting "hello")
- (target "world"))
- (expect
- (with-simulated-input
- (list greeting "SPC"
- (list 'insert target)
- "RET")
- (read-string "Say hello: "))
- :to-equal "hello world")))
-
- (it "should allow lisp forms to throw errors"
- (expect
- (with-simulated-input '("hello SPC" (error "Throwing an error") "RET")
- (read-string "Enter a string: "))
- :to-throw))
-
- (it "should not interpret lisp forms once BODY has finished"
- (expect
- (with-simulated-input '("hello SPC world RET RET"
- (error "Should not reach this error"))
- (read-string "Enter a string: "))
- :to-equal "hello world"))
-
- (it "should evaluate lisp forms in the proper lexical environment"
- (let ((my-lexical-var nil))
- (with-simulated-input '("hello"
- (setq my-lexical-var t)
- "RET")
- (read-string "Enter a string: "))
- (expect my-lexical-var
- :to-be-truthy)))
-
- (it "should work in a non-lexical environment"
- (let ((my-non-lexical-var nil))
- (eval
- '(with-simulated-input '("hello"
- (setq my-non-lexical-var t)
- "RET")
- (read-string "Enter a string: "))
- nil)
- (expect my-non-lexical-var
- :to-be-truthy)))
-
- (it "should allow interpolation of variables into KEYS"
- (let ((my-key-sequence "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")))))
+ :to-throw))))
(defun time-equal-p (t1 t2)
"Return non-nil if T1 and T2 represent the same time.
- [nongnu] elpa/with-simulated-input d66b8b853f 041/134: Test in Emacs 26 on Travis, (continued)
- [nongnu] elpa/with-simulated-input d66b8b853f 041/134: Test in Emacs 26 on Travis, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 3d88179352 044/134: Version 2.4, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input b030953ca0 050/134: Fix a bug with actually-wait, and add tests for it, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input a71ecf18f7 051/134: Fix a bug in current-idle-time advice and add a test for it, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input ea666ecab7 064/134: Remove hacky closure modification, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input cc15ccfe5a 062/134: Switch CI to Github Actions, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input af15d1a1f5 068/134: Remove interpolation test, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 6ac56316df 074/134: Revert version change, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 057946280f 070/134: Greeting test: don't use dynamic forms, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 214ca2c4b1 087/134: Improve test coverage for current-idle-time advice, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 1a610d6587 089/134: Reorganize test suite,
ELPA Syncer <=
- [nongnu] elpa/with-simulated-input c8389984e6 088/134: Update Eldev file, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 15581a4459 076/134: (symbol ...) KEYS are now function-call strings, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 38454eae74 086/134: Improve test coverage for wsi-get-unbound-key, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 82f8bada42 077/134: Fix tests, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 37047a2073 090/134: Add tests for loading and unloading, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 2f40b160f5 096/134: Re-enable test for byte-compiled code, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 3525ed7dc5 095/134: Merge branch 'bleeding-edge' into rewrite-bleed, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 8f335ad321 108/134: Implement warnings for inputs that have no effect, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input 8b4d44c3aa 104/134: Clean up wording in tests, ELPA Syncer, 2022/01/10
- [nongnu] elpa/with-simulated-input ee4d2b75fd 133/134: Version 3.0, ELPA Syncer, 2022/01/10