diff options
author | Jim Porter <jporterbugs@gmail.com> | 2022-08-13 20:31:11 -0700 |
---|---|---|
committer | Jim Porter <jporterbugs@gmail.com> | 2022-08-15 20:40:27 -0700 |
commit | 07b8fb197a3057a3419be0335236547e4d7a326b (patch) | |
tree | 52b631c5f3cc6370223e1d9f7920b7b3af37f197 /test | |
parent | 1973d4ac1b613bdd6c70e1ef2bac97b538fbb2ed (diff) | |
download | emacs-07b8fb197a3057a3419be0335236547e4d7a326b.tar.gz |
Provide ERT explainer for 'eshell-match-command-output'
This was formerly named 'eshell-command-result-p', but "result" isn't
quite the right terminology, since this function specifically tested
the output of a command, not its Lisp result (as
'eshell-command-result' would return).
* test/lisp/eshell/eshell-tests-helpers.el (eshell-insert-command):
Provide a more-complete docstring.
(eshell-match-result): Rename to...
(eshell-match-output): ... this.
(eshell-match-output--explainer): New function.
(eshell-command-result-p): Rename to...
(eshell-match-command-output): ... this.
* test/lisp/eshell/em-alias-tests.el
* test/lisp/eshell/em-dirs-tests.el
* test/lisp/eshell/em-extpipe-tests.el
* test/lisp/eshell/em-script-tests.el
* test/lisp/eshell/esh-cmd-tests.el
* test/lisp/eshell/esh-proc-tests.el
* test/lisp/eshell/esh-var-tests.el
* test/lisp/eshell/eshell-tests-helpers.el
* test/lisp/eshell/eshell-tests.el: Use 'eshell-match-command-output'.
Diffstat (limited to 'test')
-rw-r--r-- | test/lisp/eshell/em-alias-tests.el | 28 | ||||
-rw-r--r-- | test/lisp/eshell/em-dirs-tests.el | 40 | ||||
-rw-r--r-- | test/lisp/eshell/em-extpipe-tests.el | 18 | ||||
-rw-r--r-- | test/lisp/eshell/em-script-tests.el | 20 | ||||
-rw-r--r-- | test/lisp/eshell/esh-cmd-tests.el | 128 | ||||
-rw-r--r-- | test/lisp/eshell/esh-proc-tests.el | 4 | ||||
-rw-r--r-- | test/lisp/eshell/esh-var-tests.el | 110 | ||||
-rw-r--r-- | test/lisp/eshell/eshell-tests-helpers.el | 38 | ||||
-rw-r--r-- | test/lisp/eshell/eshell-tests.el | 44 |
9 files changed, 222 insertions, 208 deletions
diff --git a/test/lisp/eshell/em-alias-tests.el b/test/lisp/eshell/em-alias-tests.el index 497159e3460..aca622220e3 100644 --- a/test/lisp/eshell/em-alias-tests.el +++ b/test/lisp/eshell/em-alias-tests.el @@ -38,50 +38,50 @@ "Test a simple alias with no arguments" (with-temp-eshell (eshell-insert-command "alias say-hi 'echo hi'") - (eshell-command-result-p "say-hi" "hi\n") - (eshell-command-result-p "say-hi bye" "hi\n"))) + (eshell-match-command-output "say-hi" "hi\n") + (eshell-match-command-output "say-hi bye" "hi\n"))) (ert-deftest em-alias-test/alias-arg-vars () "Test alias with $0, $1, ... variables" (with-temp-eshell (eshell-insert-command "alias show-args 'printnl $0 \"$1 $2\"'") - (eshell-command-result-p "show-args one two" "show-args\none two\n"))) + (eshell-match-command-output "show-args one two" "show-args\none two\n"))) (ert-deftest em-alias-test/alias-arg-vars-indices () "Test alias with $1, $2, ... variables using indices" (with-temp-eshell (eshell-insert-command "alias funny-sum '+ $1[0] $2[1]'") - (eshell-command-result-p "funny-sum (list 1 2) (list 3 4)" - "5\n"))) + (eshell-match-command-output "funny-sum (list 1 2) (list 3 4)" + "5\n"))) (ert-deftest em-alias-test/alias-arg-vars-split-indices () "Test alias with $0, $1, ... variables using split indices" (with-temp-eshell (eshell-insert-command "alias my-prefix 'echo $0[- 0]'") - (eshell-command-result-p "my-prefix" - "my\n") + (eshell-match-command-output "my-prefix" + "my\n") (eshell-insert-command "alias funny-sum '+ $1[: 0] $2[: 1]'") - (eshell-command-result-p "funny-sum 1:2 3:4" - "5\n"))) + (eshell-match-command-output "funny-sum 1:2 3:4" + "5\n"))) (ert-deftest em-alias-test/alias-all-args-var () "Test alias with the $* variable" (with-temp-eshell (eshell-insert-command "alias show-all-args 'printnl $*'") - (eshell-command-result-p "show-all-args" "\\`\\'") - (eshell-command-result-p "show-all-args a" "a\n") - (eshell-command-result-p "show-all-args a b c" "a\nb\nc\n"))) + (eshell-match-command-output "show-all-args" "\\`\\'") + (eshell-match-command-output "show-all-args a" "a\n") + (eshell-match-command-output "show-all-args a b c" "a\nb\nc\n"))) (ert-deftest em-alias-test/alias-all-args-var-indices () "Test alias with the $* variable using indices" (with-temp-eshell (eshell-insert-command "alias add-pair '+ $*[0] $*[1]'") - (eshell-command-result-p "add-pair 1 2" "3\n"))) + (eshell-match-command-output "add-pair 1 2" "3\n"))) (ert-deftest em-alias-test/alias-all-args-var-split-indices () "Test alias with the $* variable using split indices" (with-temp-eshell (eshell-insert-command "alias add-funny-pair '+ $*[0][: 0] $*[1][: 1]'") - (eshell-command-result-p "add-funny-pair 1:2 3:4" "5\n"))) + (eshell-match-command-output "add-funny-pair 1:2 3:4" "5\n"))) ;; em-alias-tests.el ends here diff --git a/test/lisp/eshell/em-dirs-tests.el b/test/lisp/eshell/em-dirs-tests.el index 8e96cc07471..9e44ef98512 100644 --- a/test/lisp/eshell/em-dirs-tests.el +++ b/test/lisp/eshell/em-dirs-tests.el @@ -58,45 +58,45 @@ "Test using the $OLDPWD variable." (let (eshell-last-dir-ring-file-name) (with-temp-eshell - (eshell-command-result-p "echo $OLDPWD" - "\\`\\'") + (eshell-match-command-output "echo $OLDPWD" + "\\`\\'") (ring-insert eshell-last-dir-ring "/some/path") - (eshell-command-result-p "echo $OLDPWD" - "/some/path\n")))) + (eshell-match-command-output "echo $OLDPWD" + "/some/path\n")))) (ert-deftest em-dirs-test/oldpwd-var-indices () "Test using the $OLDPWD variable with indices." (let (eshell-last-dir-ring-file-name) (with-temp-eshell (ring-insert eshell-last-dir-ring "/some/path/here") - (eshell-command-result-p "echo $OLDPWD[/ 1]" - "some\n") - (eshell-command-result-p "echo $OLDPWD[/ 1 3]" - "(\"some\" \"here\")\n")))) + (eshell-match-command-output "echo $OLDPWD[/ 1]" + "some\n") + (eshell-match-command-output "echo $OLDPWD[/ 1 3]" + "(\"some\" \"here\")\n")))) (ert-deftest em-dirs-test/directory-ring-var () "Test using the $- (directory ring) variable." (let (eshell-last-dir-ring-file-name) (with-temp-eshell - (eshell-command-result-p "echo $-" - "\\`\\'") + (eshell-match-command-output "echo $-" + "\\`\\'") (ring-insert eshell-last-dir-ring "/some/path") (ring-insert eshell-last-dir-ring "/other/path") - (eshell-command-result-p "echo $-" - "/other/path\n") - (eshell-command-result-p "echo $-[0]" - "/other/path\n") - (eshell-command-result-p "echo $-[1]" - "/some/path\n")))) + (eshell-match-command-output "echo $-" + "/other/path\n") + (eshell-match-command-output "echo $-[0]" + "/other/path\n") + (eshell-match-command-output "echo $-[1]" + "/some/path\n")))) (ert-deftest em-dirs-test/directory-ring-var-indices () "Test using the $- (directory ring) variable with multiple indices." (let (eshell-last-dir-ring-file-name) (with-temp-eshell (ring-insert eshell-last-dir-ring "/some/path/here") - (eshell-command-result-p "echo $-[0][/ 1]" - "some\n") - (eshell-command-result-p "echo $-[1][/ 1 3]" - "(\"some\" \"here\")\n")))) + (eshell-match-command-output "echo $-[0][/ 1]" + "some\n") + (eshell-match-command-output "echo $-[1][/ 1 3]" + "(\"some\" \"here\")\n")))) ;; em-dirs-tests.el ends here diff --git a/test/lisp/eshell/em-extpipe-tests.el b/test/lisp/eshell/em-extpipe-tests.el index 29f5dc05512..04e78279427 100644 --- a/test/lisp/eshell/em-extpipe-tests.el +++ b/test/lisp/eshell/em-extpipe-tests.el @@ -80,7 +80,7 @@ (should-parse '(eshell-named-command "sh" (list "-c" "echo \"bar\" | rev >temp"))) (with-substitute-for-temp - (eshell-command-result-p input "^$") + (eshell-match-command-output input "^$") (temp-should-string= "rab"))) (em-extpipe-tests--deftest em-extpipe-test-2 @@ -91,7 +91,7 @@ '((eshell-named-command "echo" (list (eshell-escape-arg "bar"))) (eshell-named-command "sh" (list "-c" "rev >temp"))))) (with-substitute-for-temp - (eshell-command-result-p input "^$") + (eshell-match-command-output input "^$") (temp-should-string= "rab"))) (em-extpipe-tests--deftest em-extpipe-test-3 "foo *| bar | baz -d" @@ -111,7 +111,7 @@ (eshell-named-command "sh" (list "-c" "echo \"bar\" | rev")))) (with-substitute-for-temp - (eshell-command-result-p input "^$") + (eshell-match-command-output input "^$") (temp-buffer-should-string= "rab"))) (em-extpipe-tests--deftest em-extpipe-test-5 @@ -177,7 +177,7 @@ (should-parse '(eshell-named-command "sh" (list "-c" "tac <temp"))) (with-substitute-for-temp (with-temp-buffer (insert "bar\nbaz\n") (write-file temp)) - (eshell-command-result-p input "baz\nbar"))) + (eshell-match-command-output input "baz\nbar"))) (em-extpipe-tests--deftest em-extpipe-test-15 "echo \"bar\" *| cat" (skip-unless (executable-find "cat")) @@ -185,8 +185,8 @@ '(eshell-named-command "sh" (list "-c" "echo \"bar\" | cat"))) (cl-letf (((symbol-function 'eshell/cat) (lambda (&rest _args) (eshell-print "nonsense")))) - (eshell-command-result-p input "bar") - (eshell-command-result-p "echo \"bar\" | cat" "nonsense"))) + (eshell-match-command-output input "bar") + (eshell-match-command-output "echo \"bar\" | cat" "nonsense"))) (em-extpipe-tests--deftest em-extpipe-test-16 "echo \"bar\" *| rev" (skip-unless (executable-find "rev")) @@ -195,11 +195,11 @@ (let ((eshell-prefer-lisp-functions t)) (cl-letf (((symbol-function 'rev) (lambda (&rest _args) (eshell-print "nonsense")))) - (eshell-command-result-p input "rab") - (eshell-command-result-p "echo \"bar\" | rev" "nonsense")))) + (eshell-match-command-output input "rab") + (eshell-match-command-output "echo \"bar\" | rev" "nonsense")))) ;; Confirm we don't break input of sharp-quoted symbols (Bug#53518). (em-extpipe-tests--deftest em-extpipe-test-17 "funcall #'upcase foo" - (eshell-command-result-p input "FOO")) + (eshell-match-command-output input "FOO")) ;;; em-extpipe-tests.el ends here diff --git a/test/lisp/eshell/em-script-tests.el b/test/lisp/eshell/em-script-tests.el index a34f9434021..b837d464ccd 100644 --- a/test/lisp/eshell/em-script-tests.el +++ b/test/lisp/eshell/em-script-tests.el @@ -38,25 +38,25 @@ "Test sourcing script with no argumentss" (ert-with-temp-file temp-file :text "echo hi" (with-temp-eshell - (eshell-command-result-p (format "source %s" temp-file) - "hi\n")))) + (eshell-match-command-output (format "source %s" temp-file) + "hi\n")))) (ert-deftest em-script-test/source-script-arg-vars () "Test sourcing script with $0, $1, ... variables" (ert-with-temp-file temp-file :text "printnl $0 \"$1 $2\"" (with-temp-eshell - (eshell-command-result-p (format "source %s one two" temp-file) - (format "%s\none two\n" temp-file))))) + (eshell-match-command-output (format "source %s one two" temp-file) + (format "%s\none two\n" temp-file))))) (ert-deftest em-script-test/source-script-all-args-var () "Test sourcing script with the $* variable" (ert-with-temp-file temp-file :text "printnl $*" (with-temp-eshell - (eshell-command-result-p (format "source %s" temp-file) - "\\`\\'") - (eshell-command-result-p (format "source %s a" temp-file) - "a\n") - (eshell-command-result-p (format "source %s a b c" temp-file) - "a\nb\nc\n")))) + (eshell-match-command-output (format "source %s" temp-file) + "\\`\\'") + (eshell-match-command-output (format "source %s a" temp-file) + "a\n") + (eshell-match-command-output (format "source %s a b c" temp-file) + "a\nb\nc\n")))) ;; em-script-tests.el ends here diff --git a/test/lisp/eshell/esh-cmd-tests.el b/test/lisp/eshell/esh-cmd-tests.el index e86985ec717..05635e8a7b5 100644 --- a/test/lisp/eshell/esh-cmd-tests.el +++ b/test/lisp/eshell/esh-cmd-tests.el @@ -80,19 +80,19 @@ e.g. \"{(+ 1 2)} 3\" => 3" "Test logical && operator." (skip-unless (executable-find "[")) (with-temp-eshell - (eshell-command-result-p "[ foo = foo ] && echo hi" - "hi\n") - (eshell-command-result-p "[ foo = bar ] && echo hi" - "\\`\\'"))) + (eshell-match-command-output "[ foo = foo ] && echo hi" + "hi\n") + (eshell-match-command-output "[ foo = bar ] && echo hi" + "\\`\\'"))) (ert-deftest esh-cmd-test/or-operator () "Test logical || operator." (skip-unless (executable-find "[")) (with-temp-eshell - (eshell-command-result-p "[ foo = foo ] || echo hi" - "\\`\\'") - (eshell-command-result-p "[ foo = bar ] || echo hi" - "hi\n"))) + (eshell-match-command-output "[ foo = foo ] || echo hi" + "\\`\\'") + (eshell-match-command-output "[ foo = bar ] || echo hi" + "hi\n"))) ;; Control flow statements @@ -100,20 +100,20 @@ e.g. \"{(+ 1 2)} 3\" => 3" (ert-deftest esh-cmd-test/for-loop () "Test invocation of a for loop." (with-temp-eshell - (eshell-command-result-p "for i in 5 { echo $i }" - "5\n"))) + (eshell-match-command-output "for i in 5 { echo $i }" + "5\n"))) (ert-deftest esh-cmd-test/for-loop-list () "Test invocation of a for loop iterating over a list." (with-temp-eshell - (eshell-command-result-p "for i in (list 1 2 (list 3 4)) { echo $i }" - "1\n2\n(3 4)\n"))) + (eshell-match-command-output "for i in (list 1 2 (list 3 4)) { echo $i }" + "1\n2\n(3 4)\n"))) (ert-deftest esh-cmd-test/for-loop-multiple-args () "Test invocation of a for loop iterating over multiple arguments." (with-temp-eshell - (eshell-command-result-p "for i in 1 2 (list 3 4) { echo $i }" - "1\n2\n3\n4\n"))) + (eshell-match-command-output "for i in 1 2 (list 3 4) { echo $i }" + "1\n2\n3\n4\n"))) (ert-deftest esh-cmd-test/for-name-loop () ; bug#15231 "Test invocation of a for loop using `name'." @@ -126,7 +126,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" "Test invocation of a for loop using an env-var." (let ((process-environment (cons "name=env-value" process-environment))) (with-temp-eshell - (eshell-command-result-p + (eshell-match-command-output "echo $name; for name in 3 { echo $name }; echo $name" "env-value\n3\nenv-value\n")))) @@ -134,7 +134,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" "Test invocation of a while loop." (with-temp-eshell (let ((eshell-test-value '(0 1 2))) - (eshell-command-result-p + (eshell-match-command-output (concat "while $eshell-test-value " "{ setq eshell-test-value (cdr eshell-test-value) }") "(1 2)\n(2)\n")))) @@ -143,7 +143,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" "Test invocation of a while loop using a Lisp form." (with-temp-eshell (let ((eshell-test-value 0)) - (eshell-command-result-p + (eshell-match-command-output (concat "while (/= eshell-test-value 3) " "{ setq eshell-test-value (1+ eshell-test-value) }") "1\n2\n3\n")))) @@ -153,7 +153,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" (skip-unless (executable-find "[")) (with-temp-eshell (let ((eshell-test-value 0)) - (eshell-command-result-p + (eshell-match-command-output (concat "while {[ $eshell-test-value -ne 3 ]} " "{ setq eshell-test-value (1+ eshell-test-value) }") "1\n2\n3\n")))) @@ -162,7 +162,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" "Test invocation of an until loop." (with-temp-eshell (let ((eshell-test-value nil)) - (eshell-command-result-p + (eshell-match-command-output (concat "until $eshell-test-value " "{ setq eshell-test-value t }") "t\n")))) @@ -172,7 +172,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" (skip-unless (executable-find "[")) (with-temp-eshell (let ((eshell-test-value 0)) - (eshell-command-result-p + (eshell-match-command-output (concat "until (= eshell-test-value 3) " "{ setq eshell-test-value (1+ eshell-test-value) }") "1\n2\n3\n")))) @@ -182,7 +182,7 @@ e.g. \"{(+ 1 2)} 3\" => 3" (skip-unless (executable-find "[")) (with-temp-eshell (let ((eshell-test-value 0)) - (eshell-command-result-p + (eshell-match-command-output (concat "until {[ $eshell-test-value -eq 3 ]} " "{ setq eshell-test-value (1+ eshell-test-value) }") "1\n2\n3\n")))) @@ -191,93 +191,95 @@ e.g. \"{(+ 1 2)} 3\" => 3" "Test invocation of an if statement." (with-temp-eshell (let ((eshell-test-value t)) - (eshell-command-result-p "if $eshell-test-value {echo yes}" - "yes\n")) + (eshell-match-command-output "if $eshell-test-value {echo yes}" + "yes\n")) (let ((eshell-test-value nil)) - (eshell-command-result-p "if $eshell-test-value {echo yes}" - "\\`\\'")))) + (eshell-match-command-output "if $eshell-test-value {echo yes}" + "\\`\\'")))) (ert-deftest esh-cmd-test/if-else-statement () "Test invocation of an if/else statement." (with-temp-eshell (let ((eshell-test-value t)) - (eshell-command-result-p "if $eshell-test-value {echo yes} {echo no}" - "yes\n")) + (eshell-match-command-output "if $eshell-test-value {echo yes} {echo no}" + "yes\n")) (let ((eshell-test-value nil)) - (eshell-command-result-p "if $eshell-test-value {echo yes} {echo no}" - "no\n")))) + (eshell-match-command-output "if $eshell-test-value {echo yes} {echo no}" + "no\n")))) (ert-deftest esh-cmd-test/if-else-statement-lisp-form () "Test invocation of an if/else statement using a Lisp form." (with-temp-eshell - (eshell-command-result-p "if (zerop 0) {echo yes} {echo no}" - "yes\n") - (eshell-command-result-p "if (zerop 1) {echo yes} {echo no}" - "no\n") + (eshell-match-command-output "if (zerop 0) {echo yes} {echo no}" + "yes\n") + (eshell-match-command-output "if (zerop 1) {echo yes} {echo no}" + "no\n") (let ((debug-on-error nil)) - (eshell-command-result-p "if (zerop \"foo\") {echo yes} {echo no}" - "no\n")))) + (eshell-match-command-output "if (zerop \"foo\") {echo yes} {echo no}" + "no\n")))) (ert-deftest esh-cmd-test/if-else-statement-lisp-form-2 () "Test invocation of an if/else statement using a Lisp form. This tests when `eshell-lisp-form-nil-is-failure' is nil." (let ((eshell-lisp-form-nil-is-failure nil)) (with-temp-eshell - (eshell-command-result-p "if (zerop 0) {echo yes} {echo no}" - "yes\n") - (eshell-command-result-p "if (zerop 1) {echo yes} {echo no}" - "yes\n") + (eshell-match-command-output "if (zerop 0) {echo yes} {echo no}" + "yes\n") + (eshell-match-command-output "if (zerop 1) {echo yes} {echo no}" + "yes\n") (let ((debug-on-error nil)) - (eshell-command-result-p "if (zerop \"foo\") {echo yes} {echo no}" - "no\n"))))) + (eshell-match-command-output "if (zerop \"foo\") {echo yes} {echo no}" + "no\n"))))) (ert-deftest esh-cmd-test/if-else-statement-ext-cmd () "Test invocation of an if/else statement using an external command." (skip-unless (executable-find "[")) (with-temp-eshell - (eshell-command-result-p "if {[ foo = foo ]} {echo yes} {echo no}" - "yes\n") - (eshell-command-result-p "if {[ foo = bar ]} {echo yes} {echo no}" - "no\n"))) + (eshell-match-command-output "if {[ foo = foo ]} {echo yes} {echo no}" + "yes\n") + (eshell-match-command-output "if {[ foo = bar ]} {echo yes} {echo no}" + "no\n"))) (ert-deftest esh-cmd-test/unless-statement () "Test invocation of an unless statement." (with-temp-eshell (let ((eshell-test-value t)) - (eshell-command-result-p "unless $eshell-test-value {echo no}" - "\\`\\'")) + (eshell-match-command-output "unless $eshell-test-value {echo no}" + "\\`\\'")) (let ((eshell-test-value nil)) - (eshell-command-result-p "unless $eshell-test-value {echo no}" - "no\n")))) + (eshell-match-command-output "unless $eshell-test-value {echo no}" + "no\n")))) (ert-deftest esh-cmd-test/unless-else-statement () "Test invocation of an unless/else statement." (with-temp-eshell (let ((eshell-test-value t)) - (eshell-command-result-p "unless $eshell-test-value {echo no} {echo yes}" - "yes\n")) + (eshell-match-command-output + "unless $eshell-test-value {echo no} {echo yes}" + "yes\n")) (let ((eshell-test-value nil)) - (eshell-command-result-p "unless $eshell-test-value {echo no} {echo yes}" - "no\n")))) + (eshell-match-command-output + "unless $eshell-test-value {echo no} {echo yes}" + "no\n")))) (ert-deftest esh-cmd-test/unless-else-statement-lisp-form () "Test invocation of an unless/else statement using a Lisp form." (with-temp-eshell - (eshell-command-result-p "unless (zerop 0) {echo no} {echo yes}" - "yes\n") - (eshell-command-result-p "unless (zerop 1) {echo no} {echo yes}" - "no\n") + (eshell-match-command-output "unless (zerop 0) {echo no} {echo yes}" + "yes\n") + (eshell-match-command-output "unless (zerop 1) {echo no} {echo yes}" + "no\n") (let ((debug-on-error nil)) - (eshell-command-result-p "unless (zerop \"foo\") {echo no} {echo yes}" - "no\n")))) + (eshell-match-command-output "unless (zerop \"foo\") {echo no} {echo yes}" + "no\n")))) (ert-deftest esh-cmd-test/unless-else-statement-ext-cmd () "Test invocation of an unless/else statement using an external command." (skip-unless (executable-find "[")) (with-temp-eshell - (eshell-command-result-p "unless {[ foo = foo ]} {echo no} {echo yes}" - "yes\n") - (eshell-command-result-p "unless {[ foo = bar ]} {echo no} {echo yes}" - "no\n"))) + (eshell-match-command-output "unless {[ foo = foo ]} {echo no} {echo yes}" + "yes\n") + (eshell-match-command-output "unless {[ foo = bar ]} {echo no} {echo yes}" + "no\n"))) ;; esh-cmd-tests.el ends here diff --git a/test/lisp/eshell/esh-proc-tests.el b/test/lisp/eshell/esh-proc-tests.el index 734bb91a6a5..f538e8c43a0 100644 --- a/test/lisp/eshell/esh-proc-tests.el +++ b/test/lisp/eshell/esh-proc-tests.el @@ -43,7 +43,7 @@ (executable-find "echo") (executable-find "sleep"))) (with-temp-eshell - (eshell-command-result-p + (eshell-match-command-output ;; The first command is like `yes' but slower. This is to prevent ;; it from taxing Emacs's process filter too much and causing a ;; hang. @@ -136,4 +136,4 @@ prompt. See bug#54136." (kill-process (caar eshell-process-list)) ;; Give `eshell-sentinel' a chance to run. (sit-for 0.1) - (eshell-match-result "\\[sh\\(\\.exe\\)?\\] [[:digit:]]+\n"))) + (should (eshell-match-output "\\[sh\\(\\.exe\\)?\\] [[:digit:]]+\n")))) diff --git a/test/lisp/eshell/esh-var-tests.el b/test/lisp/eshell/esh-var-tests.el index 0c094ee5a79..ca74ad1959d 100644 --- a/test/lisp/eshell/esh-var-tests.el +++ b/test/lisp/eshell/esh-var-tests.el @@ -153,15 +153,15 @@ "Interpolate command result from external command" (skip-unless (executable-find "echo")) (with-temp-eshell - (eshell-command-result-p "echo ${*echo hi}" - "hi\n"))) + (eshell-match-command-output "echo ${*echo hi}" + "hi\n"))) (ert-deftest esh-var-test/interp-cmd-external-indices () "Interpolate command result from external command with index" (skip-unless (executable-find "echo")) (with-temp-eshell - (eshell-command-result-p "echo ${*echo \"hi\nbye\"}[1]" - "bye\n"))) + (eshell-match-command-output "echo ${*echo \"hi\nbye\"}[1]" + "bye\n"))) (ert-deftest esh-var-test/interp-temp-cmd () "Interpolate command result redirected to temp file" @@ -196,8 +196,8 @@ "Interpolate command result from external command with concatenation" (skip-unless (executable-find "echo")) (with-temp-eshell - (eshell-command-result-p "echo ${echo hi}-${*echo there}" - "hi-there\n"))) + (eshell-match-command-output "echo ${echo hi}-${*echo there}" + "hi-there\n"))) (ert-deftest esh-var-test/quoted-interp-var () "Interpolate variable inside double-quotes" @@ -490,72 +490,72 @@ inside double-quotes" (ert-deftest esh-var-test/inside-emacs-var () "Test presence of \"INSIDE_EMACS\" in subprocesses" (with-temp-eshell - (eshell-command-result-p "env" - (format "INSIDE_EMACS=%s,eshell" - emacs-version)))) + (eshell-match-command-output "env" + (format "INSIDE_EMACS=%s,eshell" + emacs-version)))) (ert-deftest esh-var-test/inside-emacs-var-split-indices () "Test using \"INSIDE_EMACS\" with split indices" (with-temp-eshell - (eshell-command-result-p "echo $INSIDE_EMACS[, 1]" - "eshell"))) + (eshell-match-command-output "echo $INSIDE_EMACS[, 1]" + "eshell"))) (ert-deftest esh-var-test/last-status-var-lisp-command () "Test using the \"last exit status\" ($?) variable with a Lisp command" (with-temp-eshell - (eshell-command-result-p "zerop 0; echo $?" - "t\n0\n") - (eshell-command-result-p "zerop 1; echo $?" - "0\n") + (eshell-match-command-output "zerop 0; echo $?" + "t\n0\n") + (eshell-match-command-output "zerop 1; echo $?" + "0\n") (let ((debug-on-error nil)) - (eshell-command-result-p "zerop foo; echo $?" - "1\n")))) + (eshell-match-command-output "zerop foo; echo $?" + "1\n")))) (ert-deftest esh-var-test/last-status-var-lisp-form () "Test using the \"last exit status\" ($?) variable with a Lisp form" (let ((eshell-lisp-form-nil-is-failure t)) - (with-temp-eshell - (eshell-command-result-p "(zerop 0); echo $?" - "t\n0\n") - (eshell-command-result-p "(zerop 1); echo $?" - "2\n") - (let ((debug-on-error nil)) - (eshell-command-result-p "(zerop \"foo\"); echo $?" - "1\n"))))) + (with-temp-eshell + (eshell-match-command-output "(zerop 0); echo $?" + "t\n0\n") + (eshell-match-command-output "(zerop 1); echo $?" + "2\n") + (let ((debug-on-error nil)) + (eshell-match-command-output "(zerop \"foo\"); echo $?" + "1\n"))))) (ert-deftest esh-var-test/last-status-var-lisp-form-2 () "Test using the \"last exit status\" ($?) variable with a Lisp form. This tests when `eshell-lisp-form-nil-is-failure' is nil." (let ((eshell-lisp-form-nil-is-failure nil)) (with-temp-eshell - (eshell-command-result-p "(zerop 0); echo $?" - "0\n") - (eshell-command-result-p "(zerop 0); echo $?" - "0\n") + (eshell-match-command-output "(zerop 0); echo $?" + "0\n") + (eshell-match-command-output "(zerop 0); echo $?" + "0\n") (let ((debug-on-error nil)) - (eshell-command-result-p "(zerop \"foo\"); echo $?" - "1\n"))))) + (eshell-match-command-output "(zerop \"foo\"); echo $?" + "1\n"))))) (ert-deftest esh-var-test/last-status-var-ext-cmd () "Test using the \"last exit status\" ($?) variable with an external command" (skip-unless (executable-find "[")) (with-temp-eshell - (eshell-command-result-p "[ foo = foo ]; echo $?" - "0\n") - (eshell-command-result-p "[ foo = bar ]; echo $?" - "1\n"))) + (eshell-match-command-output "[ foo = foo ]; echo $?" + "0\n") + (eshell-match-command-output "[ foo = bar ]; echo $?" + "1\n"))) (ert-deftest esh-var-test/last-result-var () "Test using the \"last result\" ($$) variable" (with-temp-eshell - (eshell-command-result-p "+ 1 2; + $$ 2" - "3\n5\n"))) + (eshell-match-command-output "+ 1 2; + $$ 2" + "3\n5\n"))) (ert-deftest esh-var-test/last-result-var-twice () "Test using the \"last result\" ($$) variable twice" (with-temp-eshell - (eshell-command-result-p "+ 1 2; + $$ $$" - "3\n6\n"))) + (eshell-match-command-output "+ 1 2; + $$ $$" + "3\n6\n"))) (ert-deftest esh-var-test/last-result-var-ext-cmd () "Test using the \"last result\" ($$) variable with an external command" @@ -564,41 +564,41 @@ This tests when `eshell-lisp-form-nil-is-failure' is nil." ;; MS-DOS/MS-Windows have an external command 'format', which we ;; don't want here. (let ((eshell-prefer-lisp-functions t)) - (eshell-command-result-p "[ foo = foo ]; format \"%s\" $$" - "t\n") - (eshell-command-result-p "[ foo = bar ]; format \"%s\" $$" - "nil\n")))) + (eshell-match-command-output "[ foo = foo ]; format \"%s\" $$" + "t\n") + (eshell-match-command-output "[ foo = bar ]; format \"%s\" $$" + "nil\n")))) (ert-deftest esh-var-test/last-result-var-split-indices () "Test using the \"last result\" ($$) variable with split indices" (with-temp-eshell - (eshell-command-result-p + (eshell-match-command-output "string-join (list \"01\" \"02\") :; + $$[: 1] 3" "01:02\n5\n") - (eshell-command-result-p + (eshell-match-command-output "string-join (list \"01\" \"02\") :; echo \"$$[: 1]\"" "01:02\n02\n"))) (ert-deftest esh-var-test/last-arg-var () "Test using the \"last arg\" ($_) variable" (with-temp-eshell - (eshell-command-result-p "+ 1 2; + $_ 4" - "3\n6\n"))) + (eshell-match-command-output "+ 1 2; + $_ 4" + "3\n6\n"))) (ert-deftest esh-var-test/last-arg-var-indices () "Test using the \"last arg\" ($_) variable with indices" (with-temp-eshell - (eshell-command-result-p "+ 1 2; + $_[0] 4" - "3\n5\n") - (eshell-command-result-p "+ 1 2; + $_[1] 4" - "3\n6\n"))) + (eshell-match-command-output "+ 1 2; + $_[0] 4" + "3\n5\n") + (eshell-match-command-output "+ 1 2; + $_[1] 4" + "3\n6\n"))) (ert-deftest esh-var-test/last-arg-var-split-indices () "Test using the \"last arg\" ($_) variable with split indices" (with-temp-eshell - (eshell-command-result-p "concat 01:02 03:04; + $_[0][: 1] 5" - "01:0203:04\n7\n") - (eshell-command-result-p "concat 01:02 03:04; echo \"$_[0][: 1]\"" - "01:0203:04\n02\n"))) + (eshell-match-command-output "concat 01:02 03:04; + $_[0][: 1] 5" + "01:0203:04\n7\n") + (eshell-match-command-output "concat 01:02 03:04; echo \"$_[0][: 1]\"" + "01:0203:04\n02\n"))) ;; esh-var-tests.el ends here diff --git a/test/lisp/eshell/eshell-tests-helpers.el b/test/lisp/eshell/eshell-tests-helpers.el index 4ad76ca6978..778087bd755 100644 --- a/test/lisp/eshell/eshell-tests-helpers.el +++ b/test/lisp/eshell/eshell-tests-helpers.el @@ -65,24 +65,36 @@ raise an error." (error "timed out waiting for subprocess(es)")) (sit-for 0.1)))) -(defun eshell-insert-command (text &optional func) - "Insert a command at the end of the buffer." +(defun eshell-insert-command (command &optional func) + "Insert a COMMAND at the end of the buffer. +After inserting, call FUNC. If FUNC is nil, instead call +`eshell-send-input'." (goto-char eshell-last-output-end) - (insert-and-inherit text) + (insert-and-inherit command) (funcall (or func 'eshell-send-input))) -(defun eshell-match-result (regexp) - "Check that output of last command matches REGEXP." - (should - (string-match-p +(defun eshell-match-output (regexp) + "Test whether the output of the last command matches REGEXP." + (string-match-p regexp (buffer-substring-no-properties - (eshell-beginning-of-output) (eshell-end-of-output))))) - -(defun eshell-command-result-p (text regexp &optional func) - "Insert a command at the end of the buffer." - (eshell-insert-command text func) + (eshell-beginning-of-output) (eshell-end-of-output)))) + +(defun eshell-match-output--explainer (regexp) + "Explain the result of `eshell-match-output'." + `(mismatched-output + (command ,(buffer-substring-no-properties + eshell-last-input-start eshell-last-input-end)) + (output ,(buffer-substring-no-properties + (eshell-beginning-of-output) (eshell-end-of-output))) + (regexp ,regexp))) + +(put 'eshell-match-output 'ert-explainer #'eshell-match-output--explainer) + +(defun eshell-match-command-output (command regexp &optional func) + "Insert a COMMAND at the end of the buffer and match the output with REGEXP." + (eshell-insert-command command func) (eshell-wait-for-subprocess) - (eshell-match-result regexp)) + (should (eshell-match-output regexp))) (defvar eshell-history-file-name) diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index 8423500ea7d..c7a9516bea4 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -40,15 +40,15 @@ "Check that piping a non-process to a process command waits for the process" (skip-unless (executable-find "cat")) (with-temp-eshell - (eshell-command-result-p "echo hi | *cat" - "hi"))) + (eshell-match-command-output "echo hi | *cat" + "hi"))) (ert-deftest eshell-test/pipe-tailproc () "Check that piping a process to a non-process command waits for the process" (skip-unless (executable-find "echo")) (with-temp-eshell - (eshell-command-result-p "*echo hi | echo bye" - "bye\nhi\n"))) + (eshell-match-command-output "*echo hi | echo bye" + "bye\nhi\n"))) (ert-deftest eshell-test/pipe-headproc-stdin () "Check that standard input is sent to the head process in a pipeline" @@ -59,23 +59,23 @@ (eshell-insert-command "hello") (eshell-send-eof-to-process) (eshell-wait-for-subprocess) - (eshell-match-result "OLLEH\n"))) + (should (eshell-match-output "OLLEH\n")))) (ert-deftest eshell-test/pipe-subcommand () "Check that piping with an asynchronous subcommand works" (skip-unless (and (executable-find "echo") (executable-find "cat"))) (with-temp-eshell - (eshell-command-result-p "echo ${*echo hi} | *cat" - "hi"))) + (eshell-match-command-output "echo ${*echo hi} | *cat" + "hi"))) (ert-deftest eshell-test/pipe-subcommand-with-pipe () "Check that piping with an asynchronous subcommand with its own pipe works" (skip-unless (and (executable-find "echo") (executable-find "cat"))) (with-temp-eshell - (eshell-command-result-p "echo ${*echo hi | *cat} | *cat" - "hi"))) + (eshell-match-command-output "echo ${*echo hi | *cat} | *cat" + "hi"))) (ert-deftest eshell-test/subcommand-reset-in-pipeline () "Check that subcommands reset `eshell-in-pipeline-p'." @@ -129,32 +129,32 @@ "Test that \"\\c\" and \"c\" are equivalent when \"c\" is not a special character." (with-temp-eshell - (eshell-command-result-p "echo he\\llo" - "hello\n"))) + (eshell-match-command-output "echo he\\llo" + "hello\n"))) (ert-deftest eshell-test/escape-nonspecial-unicode () "Test that \"\\c\" and \"c\" are equivalent when \"c\" is a unicode character (unicode characters are nonspecial by definition)." (with-temp-eshell - (eshell-command-result-p "echo Vid\\éos" - "Vidéos\n"))) + (eshell-match-command-output "echo Vid\\éos" + "Vidéos\n"))) (ert-deftest eshell-test/escape-nonspecial-quoted () "Test that the backslash is preserved for escaped nonspecial chars" (with-temp-eshell - (eshell-command-result-p "echo \"h\\i\"" - ;; Backslashes are doubled for regexp. - "h\\\\i\n"))) + (eshell-match-command-output "echo \"h\\i\"" + ;; Backslashes are doubled for regexp. + "h\\\\i\n"))) (ert-deftest eshell-test/escape-special-quoted () "Test that the backslash is not preserved for escaped special chars" (with-temp-eshell - (eshell-command-result-p "echo \"\\\"hi\\\\\"" - ;; Backslashes are doubled for regexp. - "\\\"hi\\\\\n"))) + (eshell-match-command-output "echo \"\\\"hi\\\\\"" + ;; Backslashes are doubled for regexp. + "\\\"hi\\\\\n"))) (ert-deftest eshell-test/command-running-p () "Modeline should show no command running" @@ -188,15 +188,15 @@ chars" (> count 0)) (sit-for 1) (setq count (1- count)))) - (eshell-match-result "alpha\n"))) + (should (eshell-match-output "alpha\n")))) (ert-deftest eshell-test/flush-output () "Test flushing of previous output" (with-temp-eshell (eshell-insert-command "echo alpha") (eshell-kill-output) - (eshell-match-result - (concat "^" (regexp-quote "*** output flushed ***\n") "$")))) + (should (eshell-match-output + (concat "^" (regexp-quote "*** output flushed ***\n") "$"))))) (ert-deftest eshell-test/run-old-command () "Re-run an old command" |