diff options
| author | Jim Porter | 2022-08-08 21:24:27 -0700 |
|---|---|---|
| committer | Jim Porter | 2022-08-12 22:07:13 -0700 |
| commit | 9d4fa4ed4b1f2b081e8ed14cbe16d9ec4b993988 (patch) | |
| tree | 2831401200113ed59e4ebb1385f99ca612c0c73c /test/lisp/eshell/esh-cmd-tests.el | |
| parent | 30320d9420b2850341e94fa1b10476344bfa9589 (diff) | |
| download | emacs-9d4fa4ed4b1f2b081e8ed14cbe16d9ec4b993988.tar.gz emacs-9d4fa4ed4b1f2b081e8ed14cbe16d9ec4b993988.zip | |
Allow using dollar expansions in Eshell conditionals
* lisp/eshell/esh-cmd.el (eshell-structure-basic-command): Forms
beginning with 'eshell-escape-arg' are "data-wise".
* test/lisp/eshell/esh-cmd-tests.el (esh-cmd-test/while-loop)
(esh-cmd-test/until-loop, esh-cmd-test/if-statement)
(esh-cmd-test/if-else-statement, esh-cmd-test/unless-statement)
(esh-cmd-test/unless-else-statement): Use variable interpolation.
(esh-cmd-test/while-loop-ext-cmd, esh-cmd-test/until-loop-ext-cmd)
(esh-cmd-test/if-else-statement-ext-cmd)
(esh-cmd-test/unless-else-statement-ext-cmd): New tests, adapted from
the existing ones.
* doc/misc/eshell.texi (Control Flow): Update documentation for
conditionals (bug#57129).
Diffstat (limited to 'test/lisp/eshell/esh-cmd-tests.el')
| -rw-r--r-- | test/lisp/eshell/esh-cmd-tests.el | 60 |
1 files changed, 50 insertions, 10 deletions
diff --git a/test/lisp/eshell/esh-cmd-tests.el b/test/lisp/eshell/esh-cmd-tests.el index 1d5cd29d7cf..b31159a1a8f 100644 --- a/test/lisp/eshell/esh-cmd-tests.el +++ b/test/lisp/eshell/esh-cmd-tests.el | |||
| @@ -132,6 +132,15 @@ e.g. \"{(+ 1 2)} 3\" => 3" | |||
| 132 | 132 | ||
| 133 | (ert-deftest esh-cmd-test/while-loop () | 133 | (ert-deftest esh-cmd-test/while-loop () |
| 134 | "Test invocation of a while loop." | 134 | "Test invocation of a while loop." |
| 135 | (with-temp-eshell | ||
| 136 | (let ((eshell-test-value '(0 1 2))) | ||
| 137 | (eshell-command-result-p | ||
| 138 | (concat "while $eshell-test-value " | ||
| 139 | "{ setq eshell-test-value (cdr eshell-test-value) }") | ||
| 140 | "(1 2)\n(2)\n")))) | ||
| 141 | |||
| 142 | (ert-deftest esh-cmd-test/while-loop-ext-cmd () | ||
| 143 | "Test invocation of a while loop using an external command." | ||
| 135 | (skip-unless (executable-find "[")) | 144 | (skip-unless (executable-find "[")) |
| 136 | (with-temp-eshell | 145 | (with-temp-eshell |
| 137 | (let ((eshell-test-value 0)) | 146 | (let ((eshell-test-value 0)) |
| @@ -142,6 +151,15 @@ e.g. \"{(+ 1 2)} 3\" => 3" | |||
| 142 | 151 | ||
| 143 | (ert-deftest esh-cmd-test/until-loop () | 152 | (ert-deftest esh-cmd-test/until-loop () |
| 144 | "Test invocation of an until loop." | 153 | "Test invocation of an until loop." |
| 154 | (with-temp-eshell | ||
| 155 | (let ((eshell-test-value nil)) | ||
| 156 | (eshell-command-result-p | ||
| 157 | (concat "until $eshell-test-value " | ||
| 158 | "{ setq eshell-test-value t }") | ||
| 159 | "t\n")))) | ||
| 160 | |||
| 161 | (ert-deftest esh-cmd-test/until-loop-ext-cmd () | ||
| 162 | "Test invocation of an until loop using an external command." | ||
| 145 | (skip-unless (executable-find "[")) | 163 | (skip-unless (executable-find "[")) |
| 146 | (with-temp-eshell | 164 | (with-temp-eshell |
| 147 | (let ((eshell-test-value 0)) | 165 | (let ((eshell-test-value 0)) |
| @@ -152,15 +170,26 @@ e.g. \"{(+ 1 2)} 3\" => 3" | |||
| 152 | 170 | ||
| 153 | (ert-deftest esh-cmd-test/if-statement () | 171 | (ert-deftest esh-cmd-test/if-statement () |
| 154 | "Test invocation of an if statement." | 172 | "Test invocation of an if statement." |
| 155 | (skip-unless (executable-find "[")) | ||
| 156 | (with-temp-eshell | 173 | (with-temp-eshell |
| 157 | (eshell-command-result-p "if {[ foo = foo ]} {echo yes}" | 174 | (let ((eshell-test-value t)) |
| 158 | "yes\n") | 175 | (eshell-command-result-p "if $eshell-test-value {echo yes}" |
| 159 | (eshell-command-result-p "if {[ foo = bar ]} {echo yes}" | 176 | "yes\n")) |
| 160 | "\\`\\'"))) | 177 | (let ((eshell-test-value nil)) |
| 178 | (eshell-command-result-p "if $eshell-test-value {echo yes}" | ||
| 179 | "\\`\\'")))) | ||
| 161 | 180 | ||
| 162 | (ert-deftest esh-cmd-test/if-else-statement () | 181 | (ert-deftest esh-cmd-test/if-else-statement () |
| 163 | "Test invocation of an if/else statement." | 182 | "Test invocation of an if/else statement." |
| 183 | (with-temp-eshell | ||
| 184 | (let ((eshell-test-value t)) | ||
| 185 | (eshell-command-result-p "if $eshell-test-value {echo yes} {echo no}" | ||
| 186 | "yes\n")) | ||
| 187 | (let ((eshell-test-value nil)) | ||
| 188 | (eshell-command-result-p "if $eshell-test-value {echo yes} {echo no}" | ||
| 189 | "no\n")))) | ||
| 190 | |||
| 191 | (ert-deftest esh-cmd-test/if-else-statement-ext-cmd () | ||
| 192 | "Test invocation of an if/else statement using an external command." | ||
| 164 | (skip-unless (executable-find "[")) | 193 | (skip-unless (executable-find "[")) |
| 165 | (with-temp-eshell | 194 | (with-temp-eshell |
| 166 | (eshell-command-result-p "if {[ foo = foo ]} {echo yes} {echo no}" | 195 | (eshell-command-result-p "if {[ foo = foo ]} {echo yes} {echo no}" |
| @@ -170,15 +199,26 @@ e.g. \"{(+ 1 2)} 3\" => 3" | |||
| 170 | 199 | ||
| 171 | (ert-deftest esh-cmd-test/unless-statement () | 200 | (ert-deftest esh-cmd-test/unless-statement () |
| 172 | "Test invocation of an unless statement." | 201 | "Test invocation of an unless statement." |
| 173 | (skip-unless (executable-find "[")) | ||
| 174 | (with-temp-eshell | 202 | (with-temp-eshell |
| 175 | (eshell-command-result-p "unless {[ foo = foo ]} {echo no}" | 203 | (let ((eshell-test-value t)) |
| 176 | "\\`\\'") | 204 | (eshell-command-result-p "unless $eshell-test-value {echo no}" |
| 177 | (eshell-command-result-p "unless {[ foo = bar ]} {echo no}" | 205 | "\\`\\'")) |
| 178 | "no\n"))) | 206 | (let ((eshell-test-value nil)) |
| 207 | (eshell-command-result-p "unless $eshell-test-value {echo no}" | ||
| 208 | "no\n")))) | ||
| 179 | 209 | ||
| 180 | (ert-deftest esh-cmd-test/unless-else-statement () | 210 | (ert-deftest esh-cmd-test/unless-else-statement () |
| 181 | "Test invocation of an unless/else statement." | 211 | "Test invocation of an unless/else statement." |
| 212 | (with-temp-eshell | ||
| 213 | (let ((eshell-test-value t)) | ||
| 214 | (eshell-command-result-p "unless $eshell-test-value {echo no} {echo yes}" | ||
| 215 | "yes\n")) | ||
| 216 | (let ((eshell-test-value nil)) | ||
| 217 | (eshell-command-result-p "unless $eshell-test-value {echo no} {echo yes}" | ||
| 218 | "no\n")))) | ||
| 219 | |||
| 220 | (ert-deftest esh-cmd-test/unless-else-statement-ext-cmd () | ||
| 221 | "Test invocation of an unless/else statement using an external command." | ||
| 182 | (skip-unless (executable-find "[")) | 222 | (skip-unless (executable-find "[")) |
| 183 | (with-temp-eshell | 223 | (with-temp-eshell |
| 184 | (eshell-command-result-p "unless {[ foo = foo ]} {echo no} {echo yes}" | 224 | (eshell-command-result-p "unless {[ foo = foo ]} {echo no} {echo yes}" |