diff options
| author | Jim Porter | 2022-08-14 13:48:22 -0700 |
|---|---|---|
| committer | Jim Porter | 2022-08-15 20:40:27 -0700 |
| commit | cf873c1a090b95746cf2f2a9a24a5e4bd7cc2cd6 (patch) | |
| tree | 5e8c9eb3498242e5f6fe208fdcb6b01dda0f47a4 | |
| parent | c1f1be4b73072440518f02356998cf58ba127ebd (diff) | |
| download | emacs-cf873c1a090b95746cf2f2a9a24a5e4bd7cc2cd6.tar.gz emacs-cf873c1a090b95746cf2f2a9a24a5e4bd7cc2cd6.zip | |
Fix non-interactive use of conditionals in Eshell
* lisp/eshell/esh-cmd.el (eshell-rewrite-if-command): Fix misplaced
't' symbol; it should be passed to 'eshell-invokify-arg'.
(eshell-do-eval): Pass 'synchronous-p' to recursive calls in some
missing cases.
* test/lisp/eshell/esh-cmd-tests.el (esh-cmd-test/if-statement,
(esh-cmd-test/if-else-statement)
(esh-cmd-test/if-else-statement-lisp-form)
(esh-cmd-test/if-else-statement-lisp-form-2)
(esh-cmd-test/if-else-statement-ext-cmd)
(esh-cmd-test/unless-statement)
(esh-cmd-test/unless-else-statement)
(esh-cmd-test/unless-else-statement-lisp-form)
(esh-cmd-test/unless-else-statement-ext-cmd): Use
'eshell-command-result-equal'.
| -rw-r--r-- | lisp/eshell/esh-cmd.el | 7 | ||||
| -rw-r--r-- | test/lisp/eshell/esh-cmd-tests.el | 119 |
2 files changed, 59 insertions, 67 deletions
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index 62c95056fd2..2f77f3f4974 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el | |||
| @@ -607,7 +607,7 @@ must be implemented via rewriting, rather than as a function." | |||
| 607 | t)) | 607 | t)) |
| 608 | (if (= (length terms) 4) | 608 | (if (= (length terms) 4) |
| 609 | `(eshell-protect | 609 | `(eshell-protect |
| 610 | ,(eshell-invokify-arg (car (last terms)))) t)))) | 610 | ,(eshell-invokify-arg (car (last terms)) t)))))) |
| 611 | 611 | ||
| 612 | (defvar eshell-last-command-result) ;Defined in esh-io.el. | 612 | (defvar eshell-last-command-result) ;Defined in esh-io.el. |
| 613 | 613 | ||
| @@ -1122,7 +1122,7 @@ be finished later after the completion of an asynchronous subprocess." | |||
| 1122 | (setcar eshell-test-body nil)) | 1122 | (setcar eshell-test-body nil)) |
| 1123 | (unless (car eshell-test-body) | 1123 | (unless (car eshell-test-body) |
| 1124 | (setcar eshell-test-body (copy-tree (car args)))) | 1124 | (setcar eshell-test-body (copy-tree (car args)))) |
| 1125 | (while (cadr (eshell-do-eval (car eshell-test-body))) | 1125 | (while (cadr (eshell-do-eval (car eshell-test-body) synchronous-p)) |
| 1126 | (setcar eshell-command-body | 1126 | (setcar eshell-command-body |
| 1127 | (if (cddr args) | 1127 | (if (cddr args) |
| 1128 | `(progn ,@(copy-tree (cdr args))) | 1128 | `(progn ,@(copy-tree (cdr args))) |
| @@ -1142,7 +1142,8 @@ be finished later after the completion of an asynchronous subprocess." | |||
| 1142 | (setcar eshell-test-body (copy-tree (car args)))) | 1142 | (setcar eshell-test-body (copy-tree (car args)))) |
| 1143 | (setcar eshell-command-body | 1143 | (setcar eshell-command-body |
| 1144 | (copy-tree | 1144 | (copy-tree |
| 1145 | (if (cadr (eshell-do-eval (car eshell-test-body))) | 1145 | (if (cadr (eshell-do-eval (car eshell-test-body) |
| 1146 | synchronous-p)) | ||
| 1146 | (cadr args) | 1147 | (cadr args) |
| 1147 | (car (cddr args))))) | 1148 | (car (cddr args))))) |
| 1148 | (eshell-do-eval (car eshell-command-body) synchronous-p)) | 1149 | (eshell-do-eval (car eshell-command-body) synchronous-p)) |
diff --git a/test/lisp/eshell/esh-cmd-tests.el b/test/lisp/eshell/esh-cmd-tests.el index c5d780a399d..3a582965d62 100644 --- a/test/lisp/eshell/esh-cmd-tests.el +++ b/test/lisp/eshell/esh-cmd-tests.el | |||
| @@ -188,97 +188,88 @@ e.g. \"{(+ 1 2)} 3\" => 3" | |||
| 188 | 188 | ||
| 189 | (ert-deftest esh-cmd-test/if-statement () | 189 | (ert-deftest esh-cmd-test/if-statement () |
| 190 | "Test invocation of an if statement." | 190 | "Test invocation of an if statement." |
| 191 | (with-temp-eshell | 191 | (let ((eshell-test-value t)) |
| 192 | (let ((eshell-test-value t)) | 192 | (eshell-command-result-equal "if $eshell-test-value {echo yes}" |
| 193 | (eshell-match-command-output "if $eshell-test-value {echo yes}" | 193 | "yes")) |
| 194 | "yes\n")) | 194 | (let ((eshell-test-value nil)) |
| 195 | (let ((eshell-test-value nil)) | 195 | (eshell-command-result-equal "if $eshell-test-value {echo yes}" |
| 196 | (eshell-match-command-output "if $eshell-test-value {echo yes}" | 196 | nil))) |
| 197 | "\\`\\'")))) | ||
| 198 | 197 | ||
| 199 | (ert-deftest esh-cmd-test/if-else-statement () | 198 | (ert-deftest esh-cmd-test/if-else-statement () |
| 200 | "Test invocation of an if/else statement." | 199 | "Test invocation of an if/else statement." |
| 201 | (with-temp-eshell | 200 | (let ((eshell-test-value t)) |
| 202 | (let ((eshell-test-value t)) | 201 | (eshell-command-result-equal "if $eshell-test-value {echo yes} {echo no}" |
| 203 | (eshell-match-command-output "if $eshell-test-value {echo yes} {echo no}" | 202 | "yes")) |
| 204 | "yes\n")) | 203 | (let ((eshell-test-value nil)) |
| 205 | (let ((eshell-test-value nil)) | 204 | (eshell-command-result-equal "if $eshell-test-value {echo yes} {echo no}" |
| 206 | (eshell-match-command-output "if $eshell-test-value {echo yes} {echo no}" | 205 | "no"))) |
| 207 | "no\n")))) | ||
| 208 | 206 | ||
| 209 | (ert-deftest esh-cmd-test/if-else-statement-lisp-form () | 207 | (ert-deftest esh-cmd-test/if-else-statement-lisp-form () |
| 210 | "Test invocation of an if/else statement using a Lisp form." | 208 | "Test invocation of an if/else statement using a Lisp form." |
| 211 | (with-temp-eshell | 209 | (eshell-command-result-equal "if (zerop 0) {echo yes} {echo no}" |
| 212 | (eshell-match-command-output "if (zerop 0) {echo yes} {echo no}" | 210 | "yes") |
| 213 | "yes\n") | 211 | (eshell-command-result-equal "if (zerop 1) {echo yes} {echo no}" |
| 214 | (eshell-match-command-output "if (zerop 1) {echo yes} {echo no}" | 212 | "no") |
| 215 | "no\n") | 213 | (let ((debug-on-error nil)) |
| 216 | (let ((debug-on-error nil)) | 214 | (eshell-command-result-equal "if (zerop \"foo\") {echo yes} {echo no}" |
| 217 | (eshell-match-command-output "if (zerop \"foo\") {echo yes} {echo no}" | 215 | "no"))) |
| 218 | "no\n")))) | ||
| 219 | 216 | ||
| 220 | (ert-deftest esh-cmd-test/if-else-statement-lisp-form-2 () | 217 | (ert-deftest esh-cmd-test/if-else-statement-lisp-form-2 () |
| 221 | "Test invocation of an if/else statement using a Lisp form. | 218 | "Test invocation of an if/else statement using a Lisp form. |
| 222 | This tests when `eshell-lisp-form-nil-is-failure' is nil." | 219 | This tests when `eshell-lisp-form-nil-is-failure' is nil." |
| 223 | (let ((eshell-lisp-form-nil-is-failure nil)) | 220 | (let ((eshell-lisp-form-nil-is-failure nil)) |
| 224 | (with-temp-eshell | 221 | (eshell-command-result-equal "if (zerop 0) {echo yes} {echo no}" |
| 225 | (eshell-match-command-output "if (zerop 0) {echo yes} {echo no}" | 222 | "yes") |
| 226 | "yes\n") | 223 | (eshell-command-result-equal "if (zerop 1) {echo yes} {echo no}" |
| 227 | (eshell-match-command-output "if (zerop 1) {echo yes} {echo no}" | 224 | "yes") |
| 228 | "yes\n") | 225 | (let ((debug-on-error nil)) |
| 229 | (let ((debug-on-error nil)) | 226 | (eshell-command-result-equal "if (zerop \"foo\") {echo yes} {echo no}" |
| 230 | (eshell-match-command-output "if (zerop \"foo\") {echo yes} {echo no}" | 227 | "no")))) |
| 231 | "no\n"))))) | ||
| 232 | 228 | ||
| 233 | (ert-deftest esh-cmd-test/if-else-statement-ext-cmd () | 229 | (ert-deftest esh-cmd-test/if-else-statement-ext-cmd () |
| 234 | "Test invocation of an if/else statement using an external command." | 230 | "Test invocation of an if/else statement using an external command." |
| 235 | (skip-unless (executable-find "[")) | 231 | (skip-unless (executable-find "[")) |
| 236 | (with-temp-eshell | 232 | (eshell-command-result-equal "if {[ foo = foo ]} {echo yes} {echo no}" |
| 237 | (eshell-match-command-output "if {[ foo = foo ]} {echo yes} {echo no}" | 233 | "yes") |
| 238 | "yes\n") | 234 | (eshell-command-result-equal "if {[ foo = bar ]} {echo yes} {echo no}" |
| 239 | (eshell-match-command-output "if {[ foo = bar ]} {echo yes} {echo no}" | 235 | "no")) |
| 240 | "no\n"))) | ||
| 241 | 236 | ||
| 242 | (ert-deftest esh-cmd-test/unless-statement () | 237 | (ert-deftest esh-cmd-test/unless-statement () |
| 243 | "Test invocation of an unless statement." | 238 | "Test invocation of an unless statement." |
| 244 | (with-temp-eshell | 239 | (let ((eshell-test-value t)) |
| 245 | (let ((eshell-test-value t)) | 240 | (eshell-command-result-equal "unless $eshell-test-value {echo no}" |
| 246 | (eshell-match-command-output "unless $eshell-test-value {echo no}" | 241 | nil)) |
| 247 | "\\`\\'")) | 242 | (let ((eshell-test-value nil)) |
| 248 | (let ((eshell-test-value nil)) | 243 | (eshell-command-result-equal "unless $eshell-test-value {echo no}" |
| 249 | (eshell-match-command-output "unless $eshell-test-value {echo no}" | 244 | "no"))) |
| 250 | "no\n")))) | ||
| 251 | 245 | ||
| 252 | (ert-deftest esh-cmd-test/unless-else-statement () | 246 | (ert-deftest esh-cmd-test/unless-else-statement () |
| 253 | "Test invocation of an unless/else statement." | 247 | "Test invocation of an unless/else statement." |
| 254 | (with-temp-eshell | 248 | (let ((eshell-test-value t)) |
| 255 | (let ((eshell-test-value t)) | 249 | (eshell-command-result-equal |
| 256 | (eshell-match-command-output | 250 | "unless $eshell-test-value {echo no} {echo yes}" |
| 257 | "unless $eshell-test-value {echo no} {echo yes}" | 251 | "yes")) |
| 258 | "yes\n")) | 252 | (let ((eshell-test-value nil)) |
| 259 | (let ((eshell-test-value nil)) | 253 | (eshell-command-result-equal |
| 260 | (eshell-match-command-output | 254 | "unless $eshell-test-value {echo no} {echo yes}" |
| 261 | "unless $eshell-test-value {echo no} {echo yes}" | 255 | "no"))) |
| 262 | "no\n")))) | ||
| 263 | 256 | ||
| 264 | (ert-deftest esh-cmd-test/unless-else-statement-lisp-form () | 257 | (ert-deftest esh-cmd-test/unless-else-statement-lisp-form () |
| 265 | "Test invocation of an unless/else statement using a Lisp form." | 258 | "Test invocation of an unless/else statement using a Lisp form." |
| 266 | (with-temp-eshell | 259 | (eshell-command-result-equal "unless (zerop 0) {echo no} {echo yes}" |
| 267 | (eshell-match-command-output "unless (zerop 0) {echo no} {echo yes}" | 260 | "yes") |
| 268 | "yes\n") | 261 | (eshell-command-result-equal "unless (zerop 1) {echo no} {echo yes}" |
| 269 | (eshell-match-command-output "unless (zerop 1) {echo no} {echo yes}" | 262 | "no") |
| 270 | "no\n") | 263 | (let ((debug-on-error nil)) |
| 271 | (let ((debug-on-error nil)) | 264 | (eshell-command-result-equal "unless (zerop \"foo\") {echo no} {echo yes}" |
| 272 | (eshell-match-command-output "unless (zerop \"foo\") {echo no} {echo yes}" | 265 | "no"))) |
| 273 | "no\n")))) | ||
| 274 | 266 | ||
| 275 | (ert-deftest esh-cmd-test/unless-else-statement-ext-cmd () | 267 | (ert-deftest esh-cmd-test/unless-else-statement-ext-cmd () |
| 276 | "Test invocation of an unless/else statement using an external command." | 268 | "Test invocation of an unless/else statement using an external command." |
| 277 | (skip-unless (executable-find "[")) | 269 | (skip-unless (executable-find "[")) |
| 278 | (with-temp-eshell | 270 | (eshell-command-result-equal "unless {[ foo = foo ]} {echo no} {echo yes}" |
| 279 | (eshell-match-command-output "unless {[ foo = foo ]} {echo no} {echo yes}" | 271 | "yes") |
| 280 | "yes\n") | 272 | (eshell-command-result-equal "unless {[ foo = bar ]} {echo no} {echo yes}" |
| 281 | (eshell-match-command-output "unless {[ foo = bar ]} {echo no} {echo yes}" | 273 | "no")) |
| 282 | "no\n"))) | ||
| 283 | 274 | ||
| 284 | ;; esh-cmd-tests.el ends here | 275 | ;; esh-cmd-tests.el ends here |