aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJim Porter2023-03-18 19:18:28 -0700
committerJim Porter2023-04-01 16:24:31 -0700
commit97e35b149874a105a9975853a7fcd6f0034ddeab (patch)
tree5d2193a924799dc93aeec94083755b4a652f7ae4 /test
parent626f2f744104bc14c28456134cf75ff2f16d9901 (diff)
downloademacs-97e35b149874a105a9975853a7fcd6f0034ddeab.tar.gz
emacs-97e35b149874a105a9975853a7fcd6f0034ddeab.zip
Avoid shadowing variables in some Eshell command forms
* lisp/eshell/esh-cmd.el (eshell-rewrite-for-command): Make 'for-items' an uninterned symbol. (eshell-as-subcommand): Correct docstring. (eshell-do-command-to-value): Mark obsolete. (eshell-command-to-value): Move binding of 'value' outside of the macro's result, and remove call to 'eshell-do-command-to-value'. * test/lisp/eshell/esh-cmd-tests.el (esh-cmd-test/subcommand-shadow-value) (esh-cmd-test/for-loop-for-items-shadow): New tests. (esh-cmd-test/for-name-loop, esh-cmd-test/for-name-shadow-loop): Rename to... (esh-cmd-test/for-loop-name, esh-cmd-test/for-loop-name-shadow): ... these.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/eshell/esh-cmd-tests.el18
1 files changed, 16 insertions, 2 deletions
diff --git a/test/lisp/eshell/esh-cmd-tests.el b/test/lisp/eshell/esh-cmd-tests.el
index 94763954622..a7208eb3a0b 100644
--- a/test/lisp/eshell/esh-cmd-tests.el
+++ b/test/lisp/eshell/esh-cmd-tests.el
@@ -73,6 +73,13 @@ Test that trailing arguments outside the subcommand are ignored.
73e.g. \"{(+ 1 2)} 3\" => 3" 73e.g. \"{(+ 1 2)} 3\" => 3"
74 (eshell-command-result-equal "{(+ 1 2)} 3" 3)) 74 (eshell-command-result-equal "{(+ 1 2)} 3" 3))
75 75
76(ert-deftest esh-cmd-test/subcommand-shadow-value ()
77 "Test that the variable `value' isn't shadowed inside subcommands."
78 (with-temp-eshell
79 (with-no-warnings (setq-local value "hello"))
80 (eshell-match-command-output "echo ${echo $value}"
81 "hello\n")))
82
76(ert-deftest esh-cmd-test/let-rebinds-after-defer () 83(ert-deftest esh-cmd-test/let-rebinds-after-defer ()
77 "Test that let-bound values are properly updated after `eshell-defer'. 84 "Test that let-bound values are properly updated after `eshell-defer'.
78When inside a `let' block in an Eshell command form, we need to 85When inside a `let' block in an Eshell command form, we need to
@@ -151,13 +158,13 @@ bug#59469."
151 (eshell-match-command-output "for i in 1 2 (list 3 4) { echo $i }" 158 (eshell-match-command-output "for i in 1 2 (list 3 4) { echo $i }"
152 "1\n2\n3\n4\n"))) 159 "1\n2\n3\n4\n")))
153 160
154(ert-deftest esh-cmd-test/for-name-loop () ; bug#15231 161(ert-deftest esh-cmd-test/for-loop-name () ; bug#15231
155 "Test invocation of a for loop using `name'." 162 "Test invocation of a for loop using `name'."
156 (let ((process-environment (cons "name" process-environment))) 163 (let ((process-environment (cons "name" process-environment)))
157 (eshell-command-result-equal "for name in 3 { echo $name }" 164 (eshell-command-result-equal "for name in 3 { echo $name }"
158 3))) 165 3)))
159 166
160(ert-deftest esh-cmd-test/for-name-shadow-loop () ; bug#15372 167(ert-deftest esh-cmd-test/for-loop-name-shadow () ; bug#15372
161 "Test invocation of a for loop using an env-var." 168 "Test invocation of a for loop using an env-var."
162 (let ((process-environment (cons "name=env-value" process-environment))) 169 (let ((process-environment (cons "name=env-value" process-environment)))
163 (with-temp-eshell 170 (with-temp-eshell
@@ -165,6 +172,13 @@ bug#59469."
165 "echo $name; for name in 3 { echo $name }; echo $name" 172 "echo $name; for name in 3 { echo $name }; echo $name"
166 "env-value\n3\nenv-value\n")))) 173 "env-value\n3\nenv-value\n"))))
167 174
175(ert-deftest esh-cmd-test/for-loop-for-items-shadow ()
176 "Test that the variable `for-items' isn't shadowed inside for loops."
177 (with-temp-eshell
178 (with-no-warnings (setq-local for-items "hello"))
179 (eshell-match-command-output "for i in 1 { echo $for-items }"
180 "hello\n")))
181
168(ert-deftest esh-cmd-test/for-loop-pipe () 182(ert-deftest esh-cmd-test/for-loop-pipe ()
169 "Test invocation of a for loop piped to another command." 183 "Test invocation of a for loop piped to another command."
170 (skip-unless (executable-find "rev")) 184 (skip-unless (executable-find "rev"))