aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Porter2022-08-14 13:44:04 -0700
committerJim Porter2022-08-15 20:40:27 -0700
commitc1f1be4b73072440518f02356998cf58ba127ebd (patch)
treec56338d1c699bb6ca1cbdf39a13fd939f9d0ff3a
parent07b8fb197a3057a3419be0335236547e4d7a326b (diff)
downloademacs-c1f1be4b73072440518f02356998cf58ba127ebd.tar.gz
emacs-c1f1be4b73072440518f02356998cf58ba127ebd.zip
Add 'eshell-command-result-equal' with an ERT explainer
* test/lisp/eshell/eshell-tests-helpers.el (eshell-command-result--equal, eshell-command-result--equal-explainer) (eshell-command-result-equal): New functions. * test/lisp/eshell/em-basic-tests.el * test/lisp/eshell/em-dirs-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.el: Use 'eshell-command-result-equal'.
-rw-r--r--test/lisp/eshell/em-basic-tests.el18
-rw-r--r--test/lisp/eshell/em-dirs-tests.el16
-rw-r--r--test/lisp/eshell/esh-cmd-tests.el19
-rw-r--r--test/lisp/eshell/esh-proc-tests.el31
-rw-r--r--test/lisp/eshell/esh-var-tests.el391
-rw-r--r--test/lisp/eshell/eshell-tests-helpers.el21
-rw-r--r--test/lisp/eshell/eshell-tests.el31
7 files changed, 254 insertions, 273 deletions
diff --git a/test/lisp/eshell/em-basic-tests.el b/test/lisp/eshell/em-basic-tests.el
index 7a24f8b46c3..bc8baeaa035 100644
--- a/test/lisp/eshell/em-basic-tests.el
+++ b/test/lisp/eshell/em-basic-tests.el
@@ -36,25 +36,25 @@
36(ert-deftest em-basic-test/umask-print-numeric () 36(ert-deftest em-basic-test/umask-print-numeric ()
37 "Test printing umask numerically." 37 "Test printing umask numerically."
38 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o775))) 38 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o775)))
39 (should (equal (eshell-test-command-result "umask") "002\n"))) 39 (eshell-command-result-equal "umask" "002\n"))
40 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o654))) 40 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o654)))
41 (should (equal (eshell-test-command-result "umask") "123\n"))) 41 (eshell-command-result-equal "umask" "123\n"))
42 ;; Make sure larger numbers don't cause problems. 42 ;; Make sure larger numbers don't cause problems.
43 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o1775))) 43 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o1775)))
44 (should (equal (eshell-test-command-result "umask") "002\n")))) 44 (eshell-command-result-equal "umask" "002\n")))
45 45
46(ert-deftest em-basic-test/umask-read-symbolic () 46(ert-deftest em-basic-test/umask-read-symbolic ()
47 "Test printing umask symbolically." 47 "Test printing umask symbolically."
48 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o775))) 48 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o775)))
49 (should (equal (eshell-test-command-result "umask -S") 49 (eshell-command-result-equal "umask -S"
50 "u=rwx,g=rwx,o=rx\n"))) 50 "u=rwx,g=rwx,o=rx\n"))
51 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o654))) 51 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o654)))
52 (should (equal (eshell-test-command-result "umask -S") 52 (eshell-command-result-equal "umask -S"
53 "u=wx,g=rx,o=x\n"))) 53 "u=wx,g=rx,o=x\n"))
54 ;; Make sure larger numbers don't cause problems. 54 ;; Make sure larger numbers don't cause problems.
55 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o1775))) 55 (cl-letf (((symbol-function 'default-file-modes) (lambda () #o1775)))
56 (should (equal (eshell-test-command-result "umask -S") 56 (eshell-command-result-equal "umask -S"
57 "u=rwx,g=rwx,o=rx\n")))) 57 "u=rwx,g=rwx,o=rx\n")))
58 58
59(ert-deftest em-basic-test/umask-set () 59(ert-deftest em-basic-test/umask-set ()
60 "Test setting umask." 60 "Test setting umask."
diff --git a/test/lisp/eshell/em-dirs-tests.el b/test/lisp/eshell/em-dirs-tests.el
index 9e44ef98512..f72d708dcae 100644
--- a/test/lisp/eshell/em-dirs-tests.el
+++ b/test/lisp/eshell/em-dirs-tests.el
@@ -37,22 +37,22 @@
37(ert-deftest em-dirs-test/pwd-var () 37(ert-deftest em-dirs-test/pwd-var ()
38 "Test using the $PWD variable." 38 "Test using the $PWD variable."
39 (let ((default-directory "/some/path")) 39 (let ((default-directory "/some/path"))
40 (should (equal (eshell-test-command-result "echo $PWD") 40 (eshell-command-result-equal "echo $PWD"
41 (expand-file-name default-directory))))) 41 (expand-file-name default-directory))))
42 42
43(ert-deftest em-dirs-test/pwd-var-indices () 43(ert-deftest em-dirs-test/pwd-var-indices ()
44 "Test using the $PWD variable with indices." 44 "Test using the $PWD variable with indices."
45 (let ((default-directory "/some/path/here")) 45 (let ((default-directory "/some/path/here"))
46 (should (equal (eshell-test-command-result "echo $PWD[/ 1]") 46 (eshell-command-result-equal "echo $PWD[/ 1]"
47 "some")) 47 "some")
48 (should (equal (eshell-test-command-result "echo $PWD[/ 1 3]") 48 (eshell-command-result-equal "echo $PWD[/ 1 3]"
49 '("some" "here"))))) 49 '("some" "here"))))
50 50
51(ert-deftest em-dirs-test/short-pwd-var () 51(ert-deftest em-dirs-test/short-pwd-var ()
52 "Test using the $+ (current directory) variable." 52 "Test using the $+ (current directory) variable."
53 (let ((default-directory "/some/path")) 53 (let ((default-directory "/some/path"))
54 (should (equal (eshell-test-command-result "echo $+") 54 (eshell-command-result-equal "echo $+"
55 (expand-file-name default-directory))))) 55 (expand-file-name default-directory))))
56 56
57(ert-deftest em-dirs-test/oldpwd-var () 57(ert-deftest em-dirs-test/oldpwd-var ()
58 "Test using the $OLDPWD variable." 58 "Test using the $OLDPWD variable."
diff --git a/test/lisp/eshell/esh-cmd-tests.el b/test/lisp/eshell/esh-cmd-tests.el
index 05635e8a7b5..c5d780a399d 100644
--- a/test/lisp/eshell/esh-cmd-tests.el
+++ b/test/lisp/eshell/esh-cmd-tests.el
@@ -41,37 +41,37 @@
41 41
42(ert-deftest esh-cmd-test/simple-command-result () 42(ert-deftest esh-cmd-test/simple-command-result ()
43 "Test invocation with a simple command." 43 "Test invocation with a simple command."
44 (should (equal (eshell-test-command-result "+ 1 2") 3))) 44 (eshell-command-result-equal "+ 1 2" 3))
45 45
46(ert-deftest esh-cmd-test/lisp-command () 46(ert-deftest esh-cmd-test/lisp-command ()
47 "Test invocation with an elisp command." 47 "Test invocation with an elisp command."
48 (should (equal (eshell-test-command-result "(+ 1 2)") 3))) 48 (eshell-command-result-equal "(+ 1 2)" 3))
49 49
50(ert-deftest esh-cmd-test/lisp-command-with-quote () 50(ert-deftest esh-cmd-test/lisp-command-with-quote ()
51 "Test invocation with an elisp command containing a quote." 51 "Test invocation with an elisp command containing a quote."
52 (should (equal (eshell-test-command-result "(eq 'foo nil)") nil))) 52 (eshell-command-result-equal "(eq 'foo nil)" nil))
53 53
54(ert-deftest esh-cmd-test/lisp-command-args () 54(ert-deftest esh-cmd-test/lisp-command-args ()
55 "Test invocation with elisp and trailing args. 55 "Test invocation with elisp and trailing args.
56Test that trailing arguments outside the S-expression are 56Test that trailing arguments outside the S-expression are
57ignored. e.g. \"(+ 1 2) 3\" => 3" 57ignored. e.g. \"(+ 1 2) 3\" => 3"
58 (should (equal (eshell-test-command-result "(+ 1 2) 3") 3))) 58 (eshell-command-result-equal "(+ 1 2) 3" 3))
59 59
60(ert-deftest esh-cmd-test/subcommand () 60(ert-deftest esh-cmd-test/subcommand ()
61 "Test invocation with a simple subcommand." 61 "Test invocation with a simple subcommand."
62 (should (equal (eshell-test-command-result "{+ 1 2}") 3))) 62 (eshell-command-result-equal "{+ 1 2}" 3))
63 63
64(ert-deftest esh-cmd-test/subcommand-args () 64(ert-deftest esh-cmd-test/subcommand-args ()
65 "Test invocation with a subcommand and trailing args. 65 "Test invocation with a subcommand and trailing args.
66Test that trailing arguments outside the subcommand are ignored. 66Test that trailing arguments outside the subcommand are ignored.
67e.g. \"{+ 1 2} 3\" => 3" 67e.g. \"{+ 1 2} 3\" => 3"
68 (should (equal (eshell-test-command-result "{+ 1 2} 3") 3))) 68 (eshell-command-result-equal "{+ 1 2} 3" 3))
69 69
70(ert-deftest esh-cmd-test/subcommand-lisp () 70(ert-deftest esh-cmd-test/subcommand-lisp ()
71 "Test invocation with an elisp subcommand and trailing args. 71 "Test invocation with an elisp subcommand and trailing args.
72Test that trailing arguments outside the subcommand are ignored. 72Test that trailing arguments outside the subcommand are ignored.
73e.g. \"{(+ 1 2)} 3\" => 3" 73e.g. \"{(+ 1 2)} 3\" => 3"
74 (should (equal (eshell-test-command-result "{(+ 1 2)} 3") 3))) 74 (eshell-command-result-equal "{(+ 1 2)} 3" 3))
75 75
76 76
77;; Logical operators 77;; Logical operators
@@ -118,9 +118,8 @@ e.g. \"{(+ 1 2)} 3\" => 3"
118(ert-deftest esh-cmd-test/for-name-loop () ; bug#15231 118(ert-deftest esh-cmd-test/for-name-loop () ; bug#15231
119 "Test invocation of a for loop using `name'." 119 "Test invocation of a for loop using `name'."
120 (let ((process-environment (cons "name" process-environment))) 120 (let ((process-environment (cons "name" process-environment)))
121 (should (equal (eshell-test-command-result 121 (eshell-command-result-equal "for name in 3 { echo $name }"
122 "for name in 3 { echo $name }") 122 3)))
123 3))))
124 123
125(ert-deftest esh-cmd-test/for-name-shadow-loop () ; bug#15372 124(ert-deftest esh-cmd-test/for-name-shadow-loop () ; bug#15372
126 "Test invocation of a for loop using an env-var." 125 "Test invocation of a for loop using an env-var."
diff --git a/test/lisp/eshell/esh-proc-tests.el b/test/lisp/eshell/esh-proc-tests.el
index f538e8c43a0..2369bb5cc00 100644
--- a/test/lisp/eshell/esh-proc-tests.el
+++ b/test/lisp/eshell/esh-proc-tests.el
@@ -56,36 +56,37 @@
56(ert-deftest esh-proc-test/pipeline-connection-type/no-pipeline () 56(ert-deftest esh-proc-test/pipeline-connection-type/no-pipeline ()
57 "Test that all streams are PTYs when a command is not in a pipeline." 57 "Test that all streams are PTYs when a command is not in a pipeline."
58 (skip-unless (executable-find "sh")) 58 (skip-unless (executable-find "sh"))
59 (should (equal (eshell-test-command-result esh-proc-test--detect-pty-cmd) 59 (eshell-command-result-equal
60 ;; PTYs aren't supported on MS-Windows. 60 esh-proc-test--detect-pty-cmd
61 (unless (eq system-type 'windows-nt) 61 ;; PTYs aren't supported on MS-Windows.
62 "stdin\nstdout\nstderr\n")))) 62 (unless (eq system-type 'windows-nt)
63 "stdin\nstdout\nstderr\n")))
63 64
64(ert-deftest esh-proc-test/pipeline-connection-type/first () 65(ert-deftest esh-proc-test/pipeline-connection-type/first ()
65 "Test that only stdin is a PTY when a command starts a pipeline." 66 "Test that only stdin is a PTY when a command starts a pipeline."
66 (skip-unless (and (executable-find "sh") 67 (skip-unless (and (executable-find "sh")
67 (executable-find "cat"))) 68 (executable-find "cat")))
68 (should (equal (eshell-test-command-result 69 (eshell-command-result-equal
69 (concat esh-proc-test--detect-pty-cmd " | cat")) 70 (concat esh-proc-test--detect-pty-cmd " | cat")
70 (unless (eq system-type 'windows-nt) 71 (unless (eq system-type 'windows-nt)
71 "stdin\n")))) 72 "stdin\n")))
72 73
73(ert-deftest esh-proc-test/pipeline-connection-type/middle () 74(ert-deftest esh-proc-test/pipeline-connection-type/middle ()
74 "Test that all streams are pipes when a command is in the middle of a 75 "Test that all streams are pipes when a command is in the middle of a
75pipeline." 76pipeline."
76 (skip-unless (and (executable-find "sh") 77 (skip-unless (and (executable-find "sh")
77 (executable-find "cat"))) 78 (executable-find "cat")))
78 (should (equal (eshell-test-command-result 79 (eshell-command-result-equal
79 (concat "echo | " esh-proc-test--detect-pty-cmd " | cat")) 80 (concat "echo | " esh-proc-test--detect-pty-cmd " | cat")
80 nil))) 81 nil))
81 82
82(ert-deftest esh-proc-test/pipeline-connection-type/last () 83(ert-deftest esh-proc-test/pipeline-connection-type/last ()
83 "Test that only output streams are PTYs when a command ends a pipeline." 84 "Test that only output streams are PTYs when a command ends a pipeline."
84 (skip-unless (executable-find "sh")) 85 (skip-unless (executable-find "sh"))
85 (should (equal (eshell-test-command-result 86 (eshell-command-result-equal
86 (concat "echo | " esh-proc-test--detect-pty-cmd)) 87 (concat "echo | " esh-proc-test--detect-pty-cmd)
87 (unless (eq system-type 'windows-nt) 88 (unless (eq system-type 'windows-nt)
88 "stdout\nstderr\n")))) 89 "stdout\nstderr\n")))
89 90
90(ert-deftest esh-proc-test/kill-pipeline () 91(ert-deftest esh-proc-test/kill-pipeline ()
91 "Test that killing a pipeline of processes only emits a single 92 "Test that killing a pipeline of processes only emits a single
diff --git a/test/lisp/eshell/esh-var-tests.el b/test/lisp/eshell/esh-var-tests.el
index ca74ad1959d..bebc57d3592 100644
--- a/test/lisp/eshell/esh-var-tests.el
+++ b/test/lisp/eshell/esh-var-tests.el
@@ -41,113 +41,107 @@
41 41
42(ert-deftest esh-var-test/interp-var () 42(ert-deftest esh-var-test/interp-var ()
43 "Interpolate variable" 43 "Interpolate variable"
44 (should (equal (eshell-test-command-result "echo $user-login-name") 44 (eshell-command-result-equal "echo $user-login-name"
45 user-login-name))) 45 user-login-name))
46 46
47(ert-deftest esh-var-test/interp-quoted-var () 47(ert-deftest esh-var-test/interp-quoted-var ()
48 "Interpolate quoted variable" 48 "Interpolate quoted variable"
49 (should (equal (eshell-test-command-result "echo $'user-login-name'") 49 (eshell-command-result-equal "echo $'user-login-name'"
50 user-login-name)) 50 user-login-name)
51 (should (equal (eshell-test-command-result "echo $\"user-login-name\"") 51 (eshell-command-result-equal "echo $\"user-login-name\""
52 user-login-name))) 52 user-login-name))
53 53
54(ert-deftest esh-var-test/interp-quoted-var-concat () 54(ert-deftest esh-var-test/interp-quoted-var-concat ()
55 "Interpolate and concat quoted variable" 55 "Interpolate and concat quoted variable"
56 (should (equal (eshell-test-command-result "echo $'user-login-name'-foo") 56 (eshell-command-result-equal "echo $'user-login-name'-foo"
57 (concat user-login-name "-foo"))) 57 (concat user-login-name "-foo"))
58 (should (equal (eshell-test-command-result "echo $\"user-login-name\"-foo") 58 (eshell-command-result-equal "echo $\"user-login-name\"-foo"
59 (concat user-login-name "-foo")))) 59 (concat user-login-name "-foo")))
60 60
61(ert-deftest esh-var-test/interp-var-indices () 61(ert-deftest esh-var-test/interp-var-indices ()
62 "Interpolate list variable with indices" 62 "Interpolate list variable with indices"
63 (let ((eshell-test-value '("zero" "one" "two" "three" "four"))) 63 (let ((eshell-test-value '("zero" "one" "two" "three" "four")))
64 (should (equal (eshell-test-command-result "echo $eshell-test-value[0]") 64 (eshell-command-result-equal "echo $eshell-test-value[0]"
65 "zero")) 65 "zero")
66 (should (equal (eshell-test-command-result "echo $eshell-test-value[0 2]") 66 (eshell-command-result-equal "echo $eshell-test-value[0 2]"
67 '("zero" "two"))) 67 '("zero" "two"))
68 (should (equal (eshell-test-command-result "echo $eshell-test-value[0 2 4]") 68 (eshell-command-result-equal "echo $eshell-test-value[0 2 4]"
69 '("zero" "two" "four"))))) 69 '("zero" "two" "four"))))
70 70
71(ert-deftest esh-var-test/interp-var-split-indices () 71(ert-deftest esh-var-test/interp-var-split-indices ()
72 "Interpolate string variable with indices" 72 "Interpolate string variable with indices"
73 (let ((eshell-test-value "zero one two three four")) 73 (let ((eshell-test-value "zero one two three four"))
74 (should (equal (eshell-test-command-result "echo $eshell-test-value[0]") 74 (eshell-command-result-equal "echo $eshell-test-value[0]"
75 "zero")) 75 "zero")
76 (should (equal (eshell-test-command-result "echo $eshell-test-value[0 2]") 76 (eshell-command-result-equal "echo $eshell-test-value[0 2]"
77 '("zero" "two"))) 77 '("zero" "two"))
78 (should (equal (eshell-test-command-result "echo $eshell-test-value[0 2 4]") 78 (eshell-command-result-equal "echo $eshell-test-value[0 2 4]"
79 '("zero" "two" "four"))))) 79 '("zero" "two" "four"))))
80 80
81(ert-deftest esh-var-test/interp-var-string-split-indices () 81(ert-deftest esh-var-test/interp-var-string-split-indices ()
82 "Interpolate string variable with string splitter and indices" 82 "Interpolate string variable with string splitter and indices"
83 (let ((eshell-test-value "zero:one:two:three:four")) 83 (let ((eshell-test-value "zero:one:two:three:four"))
84 (should (equal (eshell-test-command-result "echo $eshell-test-value[: 0]") 84 (eshell-command-result-equal "echo $eshell-test-value[: 0]"
85 "zero")) 85 "zero")
86 (should (equal (eshell-test-command-result "echo $eshell-test-value[: 0 2]") 86 (eshell-command-result-equal "echo $eshell-test-value[: 0 2]"
87 '("zero" "two")))) 87 '("zero" "two")))
88 (let ((eshell-test-value "zeroXoneXtwoXthreeXfour")) 88 (let ((eshell-test-value "zeroXoneXtwoXthreeXfour"))
89 (should (equal (eshell-test-command-result "echo $eshell-test-value[X 0]") 89 (eshell-command-result-equal "echo $eshell-test-value[X 0]"
90 "zero")) 90 "zero")
91 (should (equal (eshell-test-command-result "echo $eshell-test-value[X 0 2]") 91 (eshell-command-result-equal "echo $eshell-test-value[X 0 2]"
92 '("zero" "two"))))) 92 '("zero" "two"))))
93 93
94(ert-deftest esh-var-test/interp-var-regexp-split-indices () 94(ert-deftest esh-var-test/interp-var-regexp-split-indices ()
95 "Interpolate string variable with regexp splitter and indices" 95 "Interpolate string variable with regexp splitter and indices"
96 (let ((eshell-test-value "zero:one!two:three!four")) 96 (let ((eshell-test-value "zero:one!two:three!four"))
97 (should (equal (eshell-test-command-result 97 (eshell-command-result-equal "echo $eshell-test-value['[:!]' 0]"
98 "echo $eshell-test-value['[:!]' 0]") 98 "zero")
99 "zero")) 99 (eshell-command-result-equal "echo $eshell-test-value['[:!]' 0 2]"
100 (should (equal (eshell-test-command-result 100 '("zero" "two"))
101 "echo $eshell-test-value['[:!]' 0 2]") 101 (eshell-command-result-equal "echo $eshell-test-value[\"[:!]\" 0]"
102 '("zero" "two"))) 102 "zero")
103 (should (equal (eshell-test-command-result 103 (eshell-command-result-equal "echo $eshell-test-value[\"[:!]\" 0 2]"
104 "echo $eshell-test-value[\"[:!]\" 0]") 104 '("zero" "two"))))
105 "zero"))
106 (should (equal (eshell-test-command-result
107 "echo $eshell-test-value[\"[:!]\" 0 2]")
108 '("zero" "two")))))
109 105
110(ert-deftest esh-var-test/interp-var-assoc () 106(ert-deftest esh-var-test/interp-var-assoc ()
111 "Interpolate alist variable with index" 107 "Interpolate alist variable with index"
112 (let ((eshell-test-value '(("foo" . 1)))) 108 (let ((eshell-test-value '(("foo" . 1))))
113 (should (eq (eshell-test-command-result "echo $eshell-test-value[foo]") 109 (eshell-command-result-equal "echo $eshell-test-value[foo]"
114 1)))) 110 1)))
115 111
116(ert-deftest esh-var-test/interp-var-length-list () 112(ert-deftest esh-var-test/interp-var-length-list ()
117 "Interpolate length of list variable" 113 "Interpolate length of list variable"
118 (let ((eshell-test-value '((1 2) (3) (5 (6 7 8 9))))) 114 (let ((eshell-test-value '((1 2) (3) (5 (6 7 8 9)))))
119 (should (eq (eshell-test-command-result "echo $#eshell-test-value") 3)) 115 (eshell-command-result-equal "echo $#eshell-test-value" 3)
120 (should (eq (eshell-test-command-result "echo $#eshell-test-value[1]") 1)) 116 (eshell-command-result-equal "echo $#eshell-test-value[1]" 1)
121 (should (eq (eshell-test-command-result "echo $#eshell-test-value[2][1]") 117 (eshell-command-result-equal "echo $#eshell-test-value[2][1]" 4)))
122 4))))
123 118
124(ert-deftest esh-var-test/interp-var-length-string () 119(ert-deftest esh-var-test/interp-var-length-string ()
125 "Interpolate length of string variable" 120 "Interpolate length of string variable"
126 (let ((eshell-test-value "foobar")) 121 (let ((eshell-test-value "foobar"))
127 (should (eq (eshell-test-command-result "echo $#eshell-test-value") 6)))) 122 (eshell-command-result-equal "echo $#eshell-test-value" 6)))
128 123
129(ert-deftest esh-var-test/interp-var-length-alist () 124(ert-deftest esh-var-test/interp-var-length-alist ()
130 "Interpolate length of alist variable" 125 "Interpolate length of alist variable"
131 (let ((eshell-test-value '(("foo" . (1 2 3))))) 126 (let ((eshell-test-value '(("foo" . (1 2 3)))))
132 (should (eq (eshell-test-command-result "echo $#eshell-test-value") 1)) 127 (eshell-command-result-equal "echo $#eshell-test-value" 1)
133 (should (eq (eshell-test-command-result "echo $#eshell-test-value[foo]") 128 (eshell-command-result-equal "echo $#eshell-test-value[foo]" 3)))
134 3))))
135 129
136(ert-deftest esh-var-test/interp-lisp () 130(ert-deftest esh-var-test/interp-lisp ()
137 "Interpolate Lisp form evaluation" 131 "Interpolate Lisp form evaluation"
138 (should (equal (eshell-test-command-result "+ $(+ 1 2) 3") 6))) 132 (eshell-command-result-equal "+ $(+ 1 2) 3" 6))
139 133
140(ert-deftest esh-var-test/interp-lisp-indices () 134(ert-deftest esh-var-test/interp-lisp-indices ()
141 "Interpolate Lisp form evaluation with index" 135 "Interpolate Lisp form evaluation with index"
142 (should (equal (eshell-test-command-result "+ $(list 1 2)[1] 3") 5))) 136 (eshell-command-result-equal "+ $(list 1 2)[1] 3" 5))
143 137
144(ert-deftest esh-var-test/interp-cmd () 138(ert-deftest esh-var-test/interp-cmd ()
145 "Interpolate command result" 139 "Interpolate command result"
146 (should (equal (eshell-test-command-result "+ ${+ 1 2} 3") 6))) 140 (eshell-command-result-equal "+ ${+ 1 2} 3" 6))
147 141
148(ert-deftest esh-var-test/interp-cmd-indices () 142(ert-deftest esh-var-test/interp-cmd-indices ()
149 "Interpolate command result with index" 143 "Interpolate command result with index"
150 (should (equal (eshell-test-command-result "+ ${listify 1 2}[1] 3") 5))) 144 (eshell-command-result-equal "+ ${listify 1 2}[1] 3" 5))
151 145
152(ert-deftest esh-var-test/interp-cmd-external () 146(ert-deftest esh-var-test/interp-cmd-external ()
153 "Interpolate command result from external command" 147 "Interpolate command result from external command"
@@ -165,32 +159,32 @@
165 159
166(ert-deftest esh-var-test/interp-temp-cmd () 160(ert-deftest esh-var-test/interp-temp-cmd ()
167 "Interpolate command result redirected to temp file" 161 "Interpolate command result redirected to temp file"
168 (should (equal (eshell-test-command-result "cat $<echo hi>") "hi"))) 162 (eshell-command-result-equal "cat $<echo hi>" "hi"))
169 163
170(ert-deftest esh-var-test/interp-concat-lisp () 164(ert-deftest esh-var-test/interp-concat-lisp ()
171 "Interpolate and concat Lisp form" 165 "Interpolate and concat Lisp form"
172 (should (equal (eshell-test-command-result "+ $(+ 1 2)3 3") 36))) 166 (eshell-command-result-equal "+ $(+ 1 2)3 3" 36))
173 167
174(ert-deftest esh-var-test/interp-concat-lisp2 () 168(ert-deftest esh-var-test/interp-concat-lisp2 ()
175 "Interpolate and concat two Lisp forms" 169 "Interpolate and concat two Lisp forms"
176 (should (equal (eshell-test-command-result "+ $(+ 1 2)$(+ 1 2) 3") 36))) 170 (eshell-command-result-equal "+ $(+ 1 2)$(+ 1 2) 3" 36))
177 171
178(ert-deftest esh-var-test/interp-concat-cmd () 172(ert-deftest esh-var-test/interp-concat-cmd ()
179 "Interpolate and concat command with literal" 173 "Interpolate and concat command with literal"
180 (should (equal (eshell-test-command-result "+ ${+ 1 2}3 3") 36)) 174 (eshell-command-result-equal "+ ${+ 1 2}3 3" 36)
181 (should (equal (eshell-test-command-result "echo ${*echo \"foo\nbar\"}-baz") 175 (eshell-command-result-equal "echo ${*echo \"foo\nbar\"}-baz"
182 '("foo" "bar-baz"))) 176 '("foo" "bar-baz"))
183 ;; Concatenating to a number in a list should produce a number... 177 ;; Concatenating to a number in a list should produce a number...
184 (should (equal (eshell-test-command-result "echo ${*echo \"1\n2\"}3") 178 (eshell-command-result-equal "echo ${*echo \"1\n2\"}3"
185 '(1 23))) 179 '(1 23))
186 ;; ... but concatenating to a string that looks like a number in a list 180 ;; ... but concatenating to a string that looks like a number in a list
187 ;; should produce a string. 181 ;; should produce a string.
188 (should (equal (eshell-test-command-result "echo ${*echo \"hi\n2\"}3") 182 (eshell-command-result-equal "echo ${*echo \"hi\n2\"}3"
189 '("hi" "23")))) 183 '("hi" "23")))
190 184
191(ert-deftest esh-var-test/interp-concat-cmd2 () 185(ert-deftest esh-var-test/interp-concat-cmd2 ()
192 "Interpolate and concat two commands" 186 "Interpolate and concat two commands"
193 (should (equal (eshell-test-command-result "+ ${+ 1 2}${+ 1 2} 3") 36))) 187 (eshell-command-result-equal "+ ${+ 1 2}${+ 1 2} 3" 36))
194 188
195(ert-deftest esh-var-test/interp-concat-cmd-external () 189(ert-deftest esh-var-test/interp-concat-cmd-external ()
196 "Interpolate command result from external command with concatenation" 190 "Interpolate command result from external command with concatenation"
@@ -201,151 +195,128 @@
201 195
202(ert-deftest esh-var-test/quoted-interp-var () 196(ert-deftest esh-var-test/quoted-interp-var ()
203 "Interpolate variable inside double-quotes" 197 "Interpolate variable inside double-quotes"
204 (should (equal (eshell-test-command-result "echo \"$user-login-name\"") 198 (eshell-command-result-equal "echo \"$user-login-name\""
205 user-login-name))) 199 user-login-name))
206 200
207(ert-deftest esh-var-test/quoted-interp-quoted-var () 201(ert-deftest esh-var-test/quoted-interp-quoted-var ()
208 "Interpolate quoted variable inside double-quotes" 202 "Interpolate quoted variable inside double-quotes"
209 (should (equal (eshell-test-command-result 203 (eshell-command-result-equal "echo \"hi, $'user-login-name'\""
210 "echo \"hi, $'user-login-name'\"") 204 (concat "hi, " user-login-name))
211 (concat "hi, " user-login-name))) 205 (eshell-command-result-equal "echo \"hi, $\\\"user-login-name\\\"\""
212 (should (equal (eshell-test-command-result 206 (concat "hi, " user-login-name)))
213 "echo \"hi, $\\\"user-login-name\\\"\"")
214 (concat "hi, " user-login-name))))
215 207
216(ert-deftest esh-var-test/quoted-interp-var-indices () 208(ert-deftest esh-var-test/quoted-interp-var-indices ()
217 "Interpolate string variable with indices inside double-quotes" 209 "Interpolate string variable with indices inside double-quotes"
218 (let ((eshell-test-value '("zero" "one" "two" "three" "four"))) 210 (let ((eshell-test-value '("zero" "one" "two" "three" "four")))
219 (should (equal (eshell-test-command-result 211 (eshell-command-result-equal "echo \"$eshell-test-value[0]\""
220 "echo \"$eshell-test-value[0]\"") 212 "zero")
221 "zero"))
222 ;; FIXME: These tests would use the 0th index like the other tests 213 ;; FIXME: These tests would use the 0th index like the other tests
223 ;; here, but evaluating the command just above adds an `escaped' 214 ;; here, but evaluating the command just above adds an `escaped'
224 ;; property to the string "zero". This results in the output 215 ;; property to the string "zero". This results in the output
225 ;; printing the string properties, which is probably the wrong 216 ;; printing the string properties, which is probably the wrong
226 ;; behavior. See bug#54486. 217 ;; behavior. See bug#54486.
227 (should (equal (eshell-test-command-result 218 (eshell-command-result-equal "echo \"$eshell-test-value[1 2]\""
228 "echo \"$eshell-test-value[1 2]\"") 219 "(\"one\" \"two\")")
229 "(\"one\" \"two\")")) 220 (eshell-command-result-equal "echo \"$eshell-test-value[1 2 4]\""
230 (should (equal (eshell-test-command-result 221 "(\"one\" \"two\" \"four\")")))
231 "echo \"$eshell-test-value[1 2 4]\"")
232 "(\"one\" \"two\" \"four\")"))))
233 222
234(ert-deftest esh-var-test/quoted-interp-var-split-indices () 223(ert-deftest esh-var-test/quoted-interp-var-split-indices ()
235 "Interpolate string variable with indices inside double-quotes" 224 "Interpolate string variable with indices inside double-quotes"
236 (let ((eshell-test-value "zero one two three four")) 225 (let ((eshell-test-value "zero one two three four"))
237 (should (equal (eshell-test-command-result 226 (eshell-command-result-equal "echo \"$eshell-test-value[0]\""
238 "echo \"$eshell-test-value[0]\"") 227 "zero")
239 "zero")) 228 (eshell-command-result-equal "echo \"$eshell-test-value[0 2]\""
240 (should (equal (eshell-test-command-result 229 "(\"zero\" \"two\")")))
241 "echo \"$eshell-test-value[0 2]\"")
242 "(\"zero\" \"two\")"))))
243 230
244(ert-deftest esh-var-test/quoted-interp-var-string-split-indices () 231(ert-deftest esh-var-test/quoted-interp-var-string-split-indices ()
245 "Interpolate string variable with string splitter and indices 232 "Interpolate string variable with string splitter and indices
246inside double-quotes" 233inside double-quotes"
247 (let ((eshell-test-value "zero:one:two:three:four")) 234 (let ((eshell-test-value "zero:one:two:three:four"))
248 (should (equal (eshell-test-command-result 235 (eshell-command-result-equal "echo \"$eshell-test-value[: 0]\""
249 "echo \"$eshell-test-value[: 0]\"") 236 "zero")
250 "zero")) 237 (eshell-command-result-equal "echo \"$eshell-test-value[: 0 2]\""
251 (should (equal (eshell-test-command-result 238 "(\"zero\" \"two\")"))
252 "echo \"$eshell-test-value[: 0 2]\"")
253 "(\"zero\" \"two\")")))
254 (let ((eshell-test-value "zeroXoneXtwoXthreeXfour")) 239 (let ((eshell-test-value "zeroXoneXtwoXthreeXfour"))
255 (should (equal (eshell-test-command-result 240 (eshell-command-result-equal "echo \"$eshell-test-value[X 0]\""
256 "echo \"$eshell-test-value[X 0]\"") 241 "zero")
257 "zero")) 242 (eshell-command-result-equal "echo \"$eshell-test-value[X 0 2]\""
258 (should (equal (eshell-test-command-result 243 "(\"zero\" \"two\")")))
259 "echo \"$eshell-test-value[X 0 2]\"")
260 "(\"zero\" \"two\")"))))
261 244
262(ert-deftest esh-var-test/quoted-interp-var-regexp-split-indices () 245(ert-deftest esh-var-test/quoted-interp-var-regexp-split-indices ()
263 "Interpolate string variable with regexp splitter and indices" 246 "Interpolate string variable with regexp splitter and indices"
264 (let ((eshell-test-value "zero:one!two:three!four")) 247 (let ((eshell-test-value "zero:one!two:three!four"))
265 (should (equal (eshell-test-command-result 248 (eshell-command-result-equal "echo \"$eshell-test-value['[:!]' 0]\""
266 "echo \"$eshell-test-value['[:!]' 0]\"") 249 "zero")
267 "zero")) 250 (eshell-command-result-equal "echo \"$eshell-test-value['[:!]' 0 2]\""
268 (should (equal (eshell-test-command-result 251 "(\"zero\" \"two\")")
269 "echo \"$eshell-test-value['[:!]' 0 2]\"") 252 (eshell-command-result-equal "echo \"$eshell-test-value[\\\"[:!]\\\" 0]\""
270 "(\"zero\" \"two\")")) 253 "zero")
271 (should (equal (eshell-test-command-result 254 (eshell-command-result-equal
272 "echo \"$eshell-test-value[\\\"[:!]\\\" 0]\"") 255 "echo \"$eshell-test-value[\\\"[:!]\\\" 0 2]\""
273 "zero")) 256 "(\"zero\" \"two\")")))
274 (should (equal (eshell-test-command-result
275 "echo \"$eshell-test-value[\\\"[:!]\\\" 0 2]\"")
276 "(\"zero\" \"two\")"))))
277 257
278(ert-deftest esh-var-test/quoted-interp-var-assoc () 258(ert-deftest esh-var-test/quoted-interp-var-assoc ()
279 "Interpolate alist variable with index inside double-quotes" 259 "Interpolate alist variable with index inside double-quotes"
280 (let ((eshell-test-value '(("foo" . 1)))) 260 (let ((eshell-test-value '(("foo" . 1))))
281 (should (equal (eshell-test-command-result 261 (eshell-command-result-equal "echo \"$eshell-test-value[foo]\""
282 "echo \"$eshell-test-value[foo]\"") 262 "1")))
283 "1"))))
284 263
285(ert-deftest esh-var-test/quoted-interp-var-length-list () 264(ert-deftest esh-var-test/quoted-interp-var-length-list ()
286 "Interpolate length of list variable inside double-quotes" 265 "Interpolate length of list variable inside double-quotes"
287 (let ((eshell-test-value '((1 2) (3) (5 (6 7 8 9))))) 266 (let ((eshell-test-value '((1 2) (3) (5 (6 7 8 9)))))
288 (should (equal (eshell-test-command-result "echo \"$#eshell-test-value\"") 267 (eshell-command-result-equal "echo \"$#eshell-test-value\""
289 "3")) 268 "3")
290 (should (equal (eshell-test-command-result 269 (eshell-command-result-equal "echo \"$#eshell-test-value[1]\""
291 "echo \"$#eshell-test-value[1]\"") 270 "1")
292 "1")) 271 (eshell-command-result-equal "echo \"$#eshell-test-value[2][1]\""
293 (should (equal (eshell-test-command-result 272 "4")))
294 "echo \"$#eshell-test-value[2][1]\"")
295 "4"))))
296 273
297(ert-deftest esh-var-test/quoted-interp-var-length-string () 274(ert-deftest esh-var-test/quoted-interp-var-length-string ()
298 "Interpolate length of string variable inside double-quotes" 275 "Interpolate length of string variable inside double-quotes"
299 (let ((eshell-test-value "foobar")) 276 (let ((eshell-test-value "foobar"))
300 (should (equal (eshell-test-command-result "echo \"$#eshell-test-value\"") 277 (eshell-command-result-equal "echo \"$#eshell-test-value\""
301 "6")))) 278 "6")))
302 279
303(ert-deftest esh-var-test/quoted-interp-var-length-alist () 280(ert-deftest esh-var-test/quoted-interp-var-length-alist ()
304 "Interpolate length of alist variable inside double-quotes" 281 "Interpolate length of alist variable inside double-quotes"
305 (let ((eshell-test-value '(("foo" . (1 2 3))))) 282 (let ((eshell-test-value '(("foo" . (1 2 3)))))
306 (should (equal (eshell-test-command-result "echo \"$#eshell-test-value\"") 283 (eshell-command-result-equal "echo \"$#eshell-test-value\""
307 "1")) 284 "1")
308 (should (equal (eshell-test-command-result 285 (eshell-command-result-equal "echo \"$#eshell-test-value[foo]\""
309 "echo \"$#eshell-test-value[foo]\"") 286 "3"))
310 "3"))))
311 287
312(ert-deftest esh-var-test/quoted-interp-lisp () 288(ert-deftest esh-var-test/quoted-interp-lisp ()
313 "Interpolate Lisp form evaluation inside double-quotes" 289 "Interpolate Lisp form evaluation inside double-quotes"
314 (should (equal (eshell-test-command-result 290 (eshell-command-result-equal "echo \"hi $(concat \\\"the\\\" \\\"re\\\")\""
315 "echo \"hi $(concat \\\"the\\\" \\\"re\\\")\"") 291 "hi there"))
316 "hi there")))
317 292
318(ert-deftest esh-var-test/quoted-interp-lisp-indices () 293(ert-deftest esh-var-test/quoted-interp-lisp-indices ()
319 "Interpolate Lisp form evaluation with index" 294 "Interpolate Lisp form evaluation with index"
320 (should (equal (eshell-test-command-result "concat \"$(list 1 2)[1]\" cool") 295 (eshell-command-result-equal "concat \"$(list 1 2)[1]\" cool"
321 "2cool"))) 296 "2cool"))
322 297
323(ert-deftest esh-var-test/quoted-interp-cmd () 298(ert-deftest esh-var-test/quoted-interp-cmd ()
324 "Interpolate command result inside double-quotes" 299 "Interpolate command result inside double-quotes"
325 (should (equal (eshell-test-command-result 300 (eshell-command-result-equal "echo \"hi ${echo \\\"there\\\"}\""
326 "echo \"hi ${echo \\\"there\\\"}\"") 301 "hi there"))
327 "hi there")))
328 302
329(ert-deftest esh-var-test/quoted-interp-cmd-indices () 303(ert-deftest esh-var-test/quoted-interp-cmd-indices ()
330 "Interpolate command result with index inside double-quotes" 304 "Interpolate command result with index inside double-quotes"
331 (should (equal (eshell-test-command-result 305 (eshell-command-result-equal "concat \"${listify 1 2}[1]\" cool"
332 "concat \"${listify 1 2}[1]\" cool") 306 "2cool"))
333 "2cool")))
334 307
335(ert-deftest esh-var-test/quoted-interp-temp-cmd () 308(ert-deftest esh-var-test/quoted-interp-temp-cmd ()
336 "Interpolate command result redirected to temp file inside double-quotes" 309 "Interpolate command result redirected to temp file inside double-quotes"
337 (let ((temporary-file-directory 310 (let ((temporary-file-directory
338 (file-name-as-directory (make-temp-file "esh-vars-tests" t)))) 311 (file-name-as-directory (make-temp-file "esh-vars-tests" t))))
339 (unwind-protect 312 (unwind-protect
340 (should (equal (eshell-test-command-result "cat \"$<echo hi>\"") 313 (eshell-command-result-equal "cat \"$<echo hi>\"" "hi"))
341 "hi"))
342 (delete-directory temporary-file-directory t)))) 314 (delete-directory temporary-file-directory t))))
343 315
344(ert-deftest esh-var-test/quoted-interp-concat-cmd () 316(ert-deftest esh-var-test/quoted-interp-concat-cmd ()
345 "Interpolate and concat command with literal" 317 "Interpolate and concat command with literal"
346 (should (equal (eshell-test-command-result 318 (eshell-command-result-equal "echo \"${echo \\\"foo\nbar\\\"} baz\""
347 "echo \"${echo \\\"foo\nbar\\\"} baz\"") 319 "foo\nbar baz"))
348 "foo\nbar baz")))
349 320
350 321
351;; Interpolated variable conversion 322;; Interpolated variable conversion
@@ -353,139 +324,129 @@ inside double-quotes"
353(ert-deftest esh-var-test/interp-convert-var-number () 324(ert-deftest esh-var-test/interp-convert-var-number ()
354 "Interpolate numeric variable" 325 "Interpolate numeric variable"
355 (let ((eshell-test-value 123)) 326 (let ((eshell-test-value 123))
356 (should (equal (eshell-test-command-result "type-of $eshell-test-value") 327 (eshell-command-result-equal "type-of $eshell-test-value"
357 'integer)))) 328 'integer)))
358 329
359(ert-deftest esh-var-test/interp-convert-var-split-indices () 330(ert-deftest esh-var-test/interp-convert-var-split-indices ()
360 "Interpolate and convert string variable with indices" 331 "Interpolate and convert string variable with indices"
361 ;; Check that numeric forms are converted to numbers. 332 ;; Check that numeric forms are converted to numbers.
362 (let ((eshell-test-value "000 010 020 030 040")) 333 (let ((eshell-test-value "000 010 020 030 040"))
363 (should (equal (eshell-test-command-result "echo $eshell-test-value[0]") 334 (eshell-command-result-equal "echo $eshell-test-value[0]"
364 0)) 335 0)
365 (should (equal (eshell-test-command-result "echo $eshell-test-value[0 2]") 336 (eshell-command-result-equal "echo $eshell-test-value[0 2]"
366 '(0 20)))) 337 '(0 20)))
367 ;; Check that multiline forms are preserved as-is. 338 ;; Check that multiline forms are preserved as-is.
368 (let ((eshell-test-value "foo\nbar:baz\n")) 339 (let ((eshell-test-value "foo\nbar:baz\n"))
369 (should (equal (eshell-test-command-result "echo $eshell-test-value[: 0]") 340 (eshell-command-result-equal "echo $eshell-test-value[: 0]"
370 "foo\nbar")) 341 "foo\nbar")
371 (should (equal (eshell-test-command-result "echo $eshell-test-value[: 1]") 342 (eshell-command-result-equal "echo $eshell-test-value[: 1]"
372 "baz\n")))) 343 "baz\n")))
373 344
374(ert-deftest esh-var-test/interp-convert-quoted-var-number () 345(ert-deftest esh-var-test/interp-convert-quoted-var-number ()
375 "Interpolate numeric quoted numeric variable" 346 "Interpolate numeric quoted numeric variable"
376 (let ((eshell-test-value 123)) 347 (let ((eshell-test-value 123))
377 (should (equal (eshell-test-command-result "type-of $'eshell-test-value'") 348 (eshell-command-result-equal "type-of $'eshell-test-value'"
378 'integer)) 349 'integer)
379 (should (equal (eshell-test-command-result "type-of $\"eshell-test-value\"") 350 (eshell-command-result-equal "type-of $\"eshell-test-value\""
380 'integer)))) 351 'integer)))
381 352
382(ert-deftest esh-var-test/interp-convert-quoted-var-split-indices () 353(ert-deftest esh-var-test/interp-convert-quoted-var-split-indices ()
383 "Interpolate and convert quoted string variable with indices" 354 "Interpolate and convert quoted string variable with indices"
384 (let ((eshell-test-value "000 010 020 030 040")) 355 (let ((eshell-test-value "000 010 020 030 040"))
385 (should (equal (eshell-test-command-result "echo $'eshell-test-value'[0]") 356 (eshell-command-result-equal "echo $'eshell-test-value'[0]"
386 0)) 357 0)
387 (should (equal (eshell-test-command-result "echo $'eshell-test-value'[0 2]") 358 (eshell-command-result-equal "echo $'eshell-test-value'[0 2]"
388 '(0 20))))) 359 '(0 20))))
389 360
390(ert-deftest esh-var-test/interp-convert-cmd-string-newline () 361(ert-deftest esh-var-test/interp-convert-cmd-string-newline ()
391 "Interpolate trailing-newline command result" 362 "Interpolate trailing-newline command result"
392 (should (equal (eshell-test-command-result "echo ${echo \"foo\n\"}") "foo"))) 363 (eshell-command-result-equal "echo ${echo \"foo\n\"}" "foo"))
393 364
394(ert-deftest esh-var-test/interp-convert-cmd-multiline () 365(ert-deftest esh-var-test/interp-convert-cmd-multiline ()
395 "Interpolate multi-line command result" 366 "Interpolate multi-line command result"
396 (should (equal (eshell-test-command-result "echo ${echo \"foo\nbar\"}") 367 (eshell-command-result-equal "echo ${echo \"foo\nbar\"}"
397 '("foo" "bar"))) 368 '("foo" "bar"))
398 ;; Numeric output should be converted to numbers... 369 ;; Numeric output should be converted to numbers...
399 (should (equal (eshell-test-command-result "echo ${echo \"01\n02\n03\"}") 370 (eshell-command-result-equal "echo ${echo \"01\n02\n03\"}"
400 '(1 2 3))) 371 '(1 2 3))
401 ;; ... but only if every line is numeric. 372 ;; ... but only if every line is numeric.
402 (should (equal (eshell-test-command-result "echo ${echo \"01\n02\nhi\"}") 373 (eshell-command-result-equal "echo ${echo \"01\n02\nhi\"}"
403 '("01" "02" "hi")))) 374 '("01" "02" "hi")))
404 375
405(ert-deftest esh-var-test/interp-convert-cmd-number () 376(ert-deftest esh-var-test/interp-convert-cmd-number ()
406 "Interpolate numeric command result" 377 "Interpolate numeric command result"
407 (should (equal (eshell-test-command-result "echo ${echo \"1\"}") 1))) 378 (eshell-command-result-equal "echo ${echo \"1\"}" 1))
408 379
409(ert-deftest esh-var-test/interp-convert-cmd-split-indices () 380(ert-deftest esh-var-test/interp-convert-cmd-split-indices ()
410 "Interpolate command result with indices" 381 "Interpolate command result with indices"
411 (should (equal (eshell-test-command-result "echo ${echo \"000 010 020\"}[0]") 382 (eshell-command-result-equal "echo ${echo \"000 010 020\"}[0]"
412 0)) 383 0)
413 (should (equal (eshell-test-command-result 384 (eshell-command-result-equal "echo ${echo \"000 010 020\"}[0 2]"
414 "echo ${echo \"000 010 020\"}[0 2]") 385 '(0 20)))
415 '(0 20))))
416 386
417(ert-deftest esh-var-test/quoted-interp-convert-var-number () 387(ert-deftest esh-var-test/quoted-interp-convert-var-number ()
418 "Interpolate numeric variable inside double-quotes" 388 "Interpolate numeric variable inside double-quotes"
419 (let ((eshell-test-value 123)) 389 (let ((eshell-test-value 123))
420 (should (equal (eshell-test-command-result "type-of \"$eshell-test-value\"") 390 (eshell-command-result-equal "type-of \"$eshell-test-value\""
421 'string)))) 391 'string)))
422 392
423(ert-deftest esh-var-test/quoted-interp-convert-var-split-indices () 393(ert-deftest esh-var-test/quoted-interp-convert-var-split-indices ()
424 "Interpolate string variable with indices inside double-quotes" 394 "Interpolate string variable with indices inside double-quotes"
425 (let ((eshell-test-value "000 010 020 030 040")) 395 (let ((eshell-test-value "000 010 020 030 040"))
426 (should (equal (eshell-test-command-result 396 (eshell-command-result-equal "echo \"$eshell-test-value[0]\""
427 "echo \"$eshell-test-value[0]\"") 397 "000")
428 "000")) 398 (eshell-command-result-equal "echo \"$eshell-test-value[0 2]\""
429 (should (equal (eshell-test-command-result 399 "(\"000\" \"020\")")))
430 "echo \"$eshell-test-value[0 2]\"")
431 "(\"000\" \"020\")"))))
432 400
433(ert-deftest esh-var-test/quoted-interp-convert-quoted-var-number () 401(ert-deftest esh-var-test/quoted-interp-convert-quoted-var-number ()
434 "Interpolate numeric quoted variable inside double-quotes" 402 "Interpolate numeric quoted variable inside double-quotes"
435 (let ((eshell-test-value 123)) 403 (let ((eshell-test-value 123))
436 (should (equal (eshell-test-command-result 404 (eshell-command-result-equal "type-of \"$'eshell-test-value'\""
437 "type-of \"$'eshell-test-value'\"") 405 'string)
438 'string)) 406 (eshell-command-result-equal "type-of \"$\\\"eshell-test-value\\\"\""
439 (should (equal (eshell-test-command-result 407 'string)))
440 "type-of \"$\\\"eshell-test-value\\\"\"")
441 'string))))
442 408
443(ert-deftest esh-var-test/quoted-interp-convert-quoted-var-split-indices () 409(ert-deftest esh-var-test/quoted-interp-convert-quoted-var-split-indices ()
444 "Interpolate quoted string variable with indices inside double-quotes" 410 "Interpolate quoted string variable with indices inside double-quotes"
445 (let ((eshell-test-value "000 010 020 030 040")) 411 (let ((eshell-test-value "000 010 020 030 040"))
446 (should (equal (eshell-test-command-result 412 (eshell-command-result-equal "echo \"$eshell-test-value[0]\""
447 "echo \"$eshell-test-value[0]\"") 413 "000")
448 "000")) 414 (eshell-command-result-equal "echo \"$eshell-test-value[0 2]\""
449 (should (equal (eshell-test-command-result 415 "(\"000\" \"020\")")))
450 "echo \"$eshell-test-value[0 2]\"")
451 "(\"000\" \"020\")"))))
452 416
453(ert-deftest esh-var-test/quoted-interp-convert-cmd-string-newline () 417(ert-deftest esh-var-test/quoted-interp-convert-cmd-string-newline ()
454 "Interpolate trailing-newline command result inside double-quotes" 418 "Interpolate trailing-newline command result inside double-quotes"
455 (should (equal (eshell-test-command-result "echo \"${echo \\\"foo\n\\\"}\"") 419 (eshell-command-result-equal "echo \"${echo \\\"foo\n\\\"}\""
456 "foo")) 420 "foo")
457 (should (equal (eshell-test-command-result "echo \"${echo \\\"foo\n\n\\\"}\"") 421 (eshell-command-result-equal "echo \"${echo \\\"foo\n\n\\\"}\""
458 "foo"))) 422 "foo"))
459 423
460(ert-deftest esh-var-test/quoted-interp-convert-cmd-multiline () 424(ert-deftest esh-var-test/quoted-interp-convert-cmd-multiline ()
461 "Interpolate multi-line command result inside double-quotes" 425 "Interpolate multi-line command result inside double-quotes"
462 (should (equal (eshell-test-command-result 426 (eshell-command-result-equal "echo \"${echo \\\"foo\nbar\\\"}\""
463 "echo \"${echo \\\"foo\nbar\\\"}\"") 427 "foo\nbar"))
464 "foo\nbar")))
465 428
466(ert-deftest esh-var-test/quoted-interp-convert-cmd-number () 429(ert-deftest esh-var-test/quoted-interp-convert-cmd-number ()
467 "Interpolate numeric command result inside double-quotes" 430 "Interpolate numeric command result inside double-quotes"
468 (should (equal (eshell-test-command-result "echo \"${echo \\\"1\\\"}\"") 431 (eshell-command-result-equal "echo \"${echo \\\"1\\\"}\"" "1"))
469 "1")))
470 432
471(ert-deftest esh-var-test/quoted-interp-convert-cmd-split-indices () 433(ert-deftest esh-var-test/quoted-interp-convert-cmd-split-indices ()
472 "Interpolate command result with indices inside double-quotes" 434 "Interpolate command result with indices inside double-quotes"
473 (should (equal (eshell-test-command-result 435 (eshell-command-result-equal "echo \"${echo \\\"000 010 020\\\"}[0]\""
474 "echo \"${echo \\\"000 010 020\\\"}[0]\"") 436 "000"))
475 "000")))
476 437
477 438
478;; Built-in variables 439;; Built-in variables
479 440
480(ert-deftest esh-var-test/lines-var () 441(ert-deftest esh-var-test/lines-var ()
481 "$LINES should equal (window-body-height nil 'remap)" 442 "$LINES should equal (window-body-height nil 'remap)"
482 (should (equal (eshell-test-command-result "echo $LINES") 443 (eshell-command-result-equal "echo $LINES"
483 (window-body-height nil 'remap)))) 444 (window-body-height nil 'remap)))
484 445
485(ert-deftest esh-var-test/columns-var () 446(ert-deftest esh-var-test/columns-var ()
486 "$COLUMNS should equal (window-body-width nil 'remap)" 447 "$COLUMNS should equal (window-body-width nil 'remap)"
487 (should (equal (eshell-test-command-result "echo $COLUMNS") 448 (eshell-command-result-equal "echo $COLUMNS"
488 (window-body-width nil 'remap)))) 449 (window-body-width nil 'remap)))
489 450
490(ert-deftest esh-var-test/inside-emacs-var () 451(ert-deftest esh-var-test/inside-emacs-var ()
491 "Test presence of \"INSIDE_EMACS\" in subprocesses" 452 "Test presence of \"INSIDE_EMACS\" in subprocesses"
diff --git a/test/lisp/eshell/eshell-tests-helpers.el b/test/lisp/eshell/eshell-tests-helpers.el
index 778087bd755..8f0f993447f 100644
--- a/test/lisp/eshell/eshell-tests-helpers.el
+++ b/test/lisp/eshell/eshell-tests-helpers.el
@@ -104,6 +104,27 @@ After inserting, call FUNC. If FUNC is nil, instead call
104 (let ((eshell-history-file-name nil)) 104 (let ((eshell-history-file-name nil))
105 (eshell-command-result command)))) 105 (eshell-command-result command))))
106 106
107(defun eshell-command-result--equal (_command actual expected)
108 "Compare the ACTUAL result of a COMMAND with its EXPECTED value."
109 (equal actual expected))
110
111(defun eshell-command-result--equal-explainer (command actual expected)
112 "Explain the result of `eshell-command-result--equal'."
113 `(nonequal-result
114 (command ,command)
115 (result ,actual)
116 (expected ,expected)))
117
118(put 'eshell-command-result--equal 'ert-explainer
119 #'eshell-command-result--equal-explainer)
120
121(defun eshell-command-result-equal (command result)
122 "Execute COMMAND non-interactively and compare it to RESULT."
123 (should (eshell-command-result--equal
124 command
125 (eshell-test-command-result command)
126 result)))
127
107(provide 'eshell-tests-helpers) 128(provide 'eshell-tests-helpers)
108 129
109;;; eshell-tests-helpers.el ends here 130;;; eshell-tests-helpers.el ends here
diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el
index c7a9516bea4..1845dba2809 100644
--- a/test/lisp/eshell/eshell-tests.el
+++ b/test/lisp/eshell/eshell-tests.el
@@ -83,28 +83,27 @@
83 (dolist (template '("echo {%s} | *cat" 83 (dolist (template '("echo {%s} | *cat"
84 "echo ${%s} | *cat" 84 "echo ${%s} | *cat"
85 "*cat $<%s> | *cat")) 85 "*cat $<%s> | *cat"))
86 (should (equal (eshell-test-command-result 86 (eshell-command-result-equal
87 (format template "echo $eshell-in-pipeline-p")) 87 (format template "echo $eshell-in-pipeline-p")
88 nil)) 88 nil)
89 (should (equal (eshell-test-command-result 89 (eshell-command-result-equal
90 (format template "echo | echo $eshell-in-pipeline-p")) 90 (format template "echo | echo $eshell-in-pipeline-p")
91 "last")) 91 "last")
92 (should (equal (eshell-test-command-result 92 (eshell-command-result-equal
93 (format template "echo $eshell-in-pipeline-p | echo")) 93 (format template "echo $eshell-in-pipeline-p | echo")
94 "first")) 94 "first")
95 (should (equal (eshell-test-command-result 95 (eshell-command-result-equal
96 (format template 96 (format template "echo | echo $eshell-in-pipeline-p | echo")
97 "echo | echo $eshell-in-pipeline-p | echo")) 97 "t")))
98 "t"))))
99 98
100(ert-deftest eshell-test/lisp-reset-in-pipeline () 99(ert-deftest eshell-test/lisp-reset-in-pipeline ()
101 "Check that interpolated Lisp forms reset `eshell-in-pipeline-p'." 100 "Check that interpolated Lisp forms reset `eshell-in-pipeline-p'."
102 (skip-unless (executable-find "cat")) 101 (skip-unless (executable-find "cat"))
103 (dolist (template '("echo (%s) | *cat" 102 (dolist (template '("echo (%s) | *cat"
104 "echo $(%s) | *cat")) 103 "echo $(%s) | *cat"))
105 (should (equal (eshell-test-command-result 104 (eshell-command-result-equal
106 (format template "format \"%s\" eshell-in-pipeline-p")) 105 (format template "format \"%s\" eshell-in-pipeline-p")
107 "nil")))) 106 "nil")))
108 107
109(ert-deftest eshell-test/redirect-buffer () 108(ert-deftest eshell-test/redirect-buffer ()
110 "Check that piping to a buffer works" 109 "Check that piping to a buffer works"