From d5e106d57c736f0c44ccecaf7834aeafa35e5a9d Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sat, 13 Aug 2022 20:31:11 -0700 Subject: [PATCH 1/3] 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'. --- test/lisp/eshell/em-alias-tests.el | 28 ++--- test/lisp/eshell/em-dirs-tests.el | 40 +++---- test/lisp/eshell/em-extpipe-tests.el | 18 ++-- test/lisp/eshell/em-script-tests.el | 20 ++-- test/lisp/eshell/esh-cmd-tests.el | 128 ++++++++++++----------- test/lisp/eshell/esh-proc-tests.el | 4 +- test/lisp/eshell/esh-var-tests.el | 110 +++++++++---------- test/lisp/eshell/eshell-tests-helpers.el | 38 ++++--- 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 497159e346..aca622220e 100644 --- a/test/lisp/eshell/em-alias-tests.el +++ b/test/lisp/eshell/em-alias-tests.el @@ -38,50 +38,50 @@ em-alias-test/simple-alias "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 8e96cc0747..9e44ef9851 100644 --- a/test/lisp/eshell/em-dirs-tests.el +++ b/test/lisp/eshell/em-dirs-tests.el @@ -58,45 +58,45 @@ em-dirs-test/oldpwd-var "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 29f5dc0551..04e7827942 100644 --- a/test/lisp/eshell/em-extpipe-tests.el +++ b/test/lisp/eshell/em-extpipe-tests.el @@ -80,7 +80,7 @@ em-extpipe-test-1 (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 @@ em-extpipe-test-2 '((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 @@ em-extpipe-test-4 (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 @@ em-extpipe-test-14 (should-parse '(eshell-named-command "sh" (list "-c" "tac 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" -- 2.25.1