diff options
| author | Alan Mackenzie | 2022-01-22 11:02:50 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2022-01-22 11:02:50 +0000 |
| commit | 14d64a8adcc866deecd758b898e8ef2d836b354a (patch) | |
| tree | 83cff9669e266f8e283ccb8cd7518e909240f1e1 /test/lisp/eshell | |
| parent | bdd9b5b8a0d37dd09ee530c1dab3a44bee09e0f8 (diff) | |
| parent | ebe334cdc234de2897263aed4c05ac7088c11857 (diff) | |
| download | emacs-scratch/correct-warning-pos.tar.gz emacs-scratch/correct-warning-pos.zip | |
Merge branch 'master' into scratch/correct-warning-posscratch/correct-warning-pos
Diffstat (limited to 'test/lisp/eshell')
| -rw-r--r-- | test/lisp/eshell/esh-opt-tests.el | 86 | ||||
| -rw-r--r-- | test/lisp/eshell/eshell-tests.el | 30 |
2 files changed, 94 insertions, 22 deletions
diff --git a/test/lisp/eshell/esh-opt-tests.el b/test/lisp/eshell/esh-opt-tests.el index 255768635b1..b76ed8866df 100644 --- a/test/lisp/eshell/esh-opt-tests.el +++ b/test/lisp/eshell/esh-opt-tests.el | |||
| @@ -27,41 +27,63 @@ | |||
| 27 | (should | 27 | (should |
| 28 | (equal '(t) | 28 | (equal '(t) |
| 29 | (eshell--process-args | 29 | (eshell--process-args |
| 30 | "sudo" | 30 | "sudo" '("-a") |
| 31 | '("-a") | 31 | '((?a "all" nil show-all |
| 32 | '((?a "all" nil show-all ""))))) | 32 | "do not ignore entries starting with ."))))) |
| 33 | (should | ||
| 34 | (equal '(nil) | ||
| 35 | (eshell--process-args | ||
| 36 | "sudo" | ||
| 37 | '("-g") | ||
| 38 | '((?a "all" nil show-all ""))))) | ||
| 39 | (should | 33 | (should |
| 40 | (equal '("root" "world") | 34 | (equal '("root" "world") |
| 41 | (eshell--process-args | 35 | (eshell--process-args |
| 42 | "sudo" | 36 | "sudo" '("-u" "root" "world") |
| 43 | '("-u" "root" "world") | 37 | '((?u "user" t user |
| 44 | '((?u "user" t user "execute a command as another USER"))))) | 38 | "execute a command as another USER"))))) |
| 45 | (should | 39 | (should |
| 46 | (equal '(nil "emerge" "-uDN" "world") | 40 | (equal '(nil "emerge" "-uDN" "world") |
| 47 | (eshell--process-args | 41 | (eshell--process-args |
| 48 | "sudo" | 42 | "sudo" '("emerge" "-uDN" "world") |
| 49 | '("emerge" "-uDN" "world") | 43 | '((?u "user" t user |
| 50 | '((?u "user" t user "execute a command as another USER") | 44 | "execute a command as another USER") |
| 51 | :parse-leading-options-only)))) | 45 | :parse-leading-options-only)))) |
| 52 | (should | 46 | (should |
| 53 | (equal '("root" "emerge" "-uDN" "world") | 47 | (equal '("root" "emerge" "-uDN" "world") |
| 54 | (eshell--process-args | 48 | (eshell--process-args |
| 55 | "sudo" | 49 | "sudo" '("-u" "root" "emerge" "-uDN" "world") |
| 56 | '("-u" "root" "emerge" "-uDN" "world") | 50 | '((?u "user" t user |
| 57 | '((?u "user" t user "execute a command as another USER") | 51 | "execute a command as another USER") |
| 58 | :parse-leading-options-only)))) | 52 | :parse-leading-options-only)))) |
| 59 | (should | 53 | (should |
| 60 | (equal '("DN" "emerge" "world") | 54 | (equal '("DN" "emerge" "world") |
| 61 | (eshell--process-args | 55 | (eshell--process-args |
| 62 | "sudo" | 56 | "sudo" '("-u" "root" "emerge" "-uDN" "world") |
| 63 | '("-u" "root" "emerge" "-uDN" "world") | 57 | '((?u "user" t user |
| 64 | '((?u "user" t user "execute a command as another USER")))))) | 58 | "execute a command as another USER"))))) |
| 59 | |||
| 60 | ;; Test :external. | ||
| 61 | (cl-letf (((symbol-function 'eshell-search-path) #'ignore)) | ||
| 62 | (should | ||
| 63 | (equal '(nil "/some/path") | ||
| 64 | (eshell--process-args | ||
| 65 | "ls" '("/some/path") | ||
| 66 | '((?a "all" nil show-all | ||
| 67 | "do not ignore entries starting with .") | ||
| 68 | :external "ls"))))) | ||
| 69 | (cl-letf (((symbol-function 'eshell-search-path) #'identity)) | ||
| 70 | (should | ||
| 71 | (equal '(no-catch eshell-ext-command "ls") | ||
| 72 | (should-error | ||
| 73 | (eshell--process-args | ||
| 74 | "ls" '("-u" "/some/path") | ||
| 75 | '((?a "all" nil show-all | ||
| 76 | "do not ignore entries starting with .") | ||
| 77 | :external "ls")) | ||
| 78 | :type 'no-catch)))) | ||
| 79 | (cl-letf (((symbol-function 'eshell-search-path) #'ignore)) | ||
| 80 | (should-error | ||
| 81 | (eshell--process-args | ||
| 82 | "ls" '("-u" "/some/path") | ||
| 83 | '((?a "all" nil show-all | ||
| 84 | "do not ignore entries starting with .") | ||
| 85 | :external "ls")) | ||
| 86 | :type 'error))) | ||
| 65 | 87 | ||
| 66 | (ert-deftest test-eshell-eval-using-options () | 88 | (ert-deftest test-eshell-eval-using-options () |
| 67 | "Tests for `eshell-eval-using-options'." | 89 | "Tests for `eshell-eval-using-options'." |
| @@ -190,7 +212,27 @@ | |||
| 190 | '((?u "user" t user "execute a command as another USER") | 212 | '((?u "user" t user "execute a command as another USER") |
| 191 | :parse-leading-options-only) | 213 | :parse-leading-options-only) |
| 192 | (should (eq user nil)) | 214 | (should (eq user nil)) |
| 193 | (should (equal args '("emerge" "-uDN" "world"))))) | 215 | (should (equal args '("emerge" "-uDN" "world")))) |
| 216 | |||
| 217 | ;; Test unrecognized options. | ||
| 218 | (should-error | ||
| 219 | (eshell-eval-using-options | ||
| 220 | "ls" '("-u" "/some/path") | ||
| 221 | '((?a "all" nil show-all | ||
| 222 | "do not ignore entries starting with .")) | ||
| 223 | (ignore show-all))) | ||
| 224 | (should-error | ||
| 225 | (eshell-eval-using-options | ||
| 226 | "ls" '("-au" "/some/path") | ||
| 227 | '((?a "all" nil show-all | ||
| 228 | "do not ignore entries starting with .")) | ||
| 229 | (ignore show-all))) | ||
| 230 | (should-error | ||
| 231 | (eshell-eval-using-options | ||
| 232 | "ls" '("--unrecognized" "/some/path") | ||
| 233 | '((?a "all" nil show-all | ||
| 234 | "do not ignore entries starting with .")) | ||
| 235 | (ignore show-all)))) | ||
| 194 | 236 | ||
| 195 | (provide 'esh-opt-tests) | 237 | (provide 'esh-opt-tests) |
| 196 | 238 | ||
diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index aef14479078..1a7ab0ab06f 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el | |||
| @@ -30,6 +30,10 @@ | |||
| 30 | (require 'esh-mode) | 30 | (require 'esh-mode) |
| 31 | (require 'eshell) | 31 | (require 'eshell) |
| 32 | 32 | ||
| 33 | (defvar eshell-test--max-subprocess-time 5 | ||
| 34 | "The maximum amount of time to wait for a subprocess to finish, in seconds. | ||
| 35 | See `eshell-wait-for-subprocess'.") | ||
| 36 | |||
| 33 | (defmacro with-temp-eshell (&rest body) | 37 | (defmacro with-temp-eshell (&rest body) |
| 34 | "Evaluate BODY in a temporary Eshell buffer." | 38 | "Evaluate BODY in a temporary Eshell buffer." |
| 35 | `(ert-with-temp-directory eshell-directory-name | 39 | `(ert-with-temp-directory eshell-directory-name |
| @@ -44,6 +48,17 @@ | |||
| 44 | (let (kill-buffer-query-functions) | 48 | (let (kill-buffer-query-functions) |
| 45 | (kill-buffer eshell-buffer)))))) | 49 | (kill-buffer eshell-buffer)))))) |
| 46 | 50 | ||
| 51 | (defun eshell-wait-for-subprocess () | ||
| 52 | "Wait until there is no interactive subprocess running in Eshell. | ||
| 53 | If this takes longer than `eshell-test--max-subprocess-time', | ||
| 54 | raise an error." | ||
| 55 | (let ((start (current-time))) | ||
| 56 | (while (eshell-interactive-process) | ||
| 57 | (when (> (float-time (time-since start)) | ||
| 58 | eshell-test--max-subprocess-time) | ||
| 59 | (error "timed out waiting for subprocess")) | ||
| 60 | (sit-for 0.1)))) | ||
| 61 | |||
| 47 | (defun eshell-insert-command (text &optional func) | 62 | (defun eshell-insert-command (text &optional func) |
| 48 | "Insert a command at the end of the buffer." | 63 | "Insert a command at the end of the buffer." |
| 49 | (goto-char eshell-last-output-end) | 64 | (goto-char eshell-last-output-end) |
| @@ -59,6 +74,7 @@ | |||
| 59 | (defun eshell-command-result-p (text regexp &optional func) | 74 | (defun eshell-command-result-p (text regexp &optional func) |
| 60 | "Insert a command at the end of the buffer." | 75 | "Insert a command at the end of the buffer." |
| 61 | (eshell-insert-command text func) | 76 | (eshell-insert-command text func) |
| 77 | (eshell-wait-for-subprocess) | ||
| 62 | (eshell-match-result regexp)) | 78 | (eshell-match-result regexp)) |
| 63 | 79 | ||
| 64 | (defvar eshell-history-file-name) | 80 | (defvar eshell-history-file-name) |
| @@ -144,6 +160,20 @@ e.g. \"{(+ 1 2)} 3\" => 3" | |||
| 144 | "Interpolate and concat two Lisp forms" | 160 | "Interpolate and concat two Lisp forms" |
| 145 | (should (equal (eshell-test-command-result "+ $(+ 1 2)$(+ 1 2) 3") 36))) | 161 | (should (equal (eshell-test-command-result "+ $(+ 1 2)$(+ 1 2) 3") 36))) |
| 146 | 162 | ||
| 163 | (ert-deftest eshell-test/interp-cmd-external () | ||
| 164 | "Interpolate command result from external command" | ||
| 165 | (skip-unless (executable-find "echo")) | ||
| 166 | (with-temp-eshell | ||
| 167 | (eshell-command-result-p "echo ${*echo hi}" | ||
| 168 | "hi\n"))) | ||
| 169 | |||
| 170 | (ert-deftest eshell-test/interp-cmd-external-concat () | ||
| 171 | "Interpolate command result from external command with concatenation" | ||
| 172 | (skip-unless (executable-find "echo")) | ||
| 173 | (with-temp-eshell | ||
| 174 | (eshell-command-result-p "echo ${echo hi}-${*echo there}" | ||
| 175 | "hi-there\n"))) | ||
| 176 | |||
| 147 | (ert-deftest eshell-test/window-height () | 177 | (ert-deftest eshell-test/window-height () |
| 148 | "$LINES should equal (window-height)" | 178 | "$LINES should equal (window-height)" |
| 149 | (should (eshell-test-command-result "= $LINES (window-height)"))) | 179 | (should (eshell-test-command-result "= $LINES (window-height)"))) |