diff options
Diffstat (limited to 'test/lisp/eshell/eshell-tests.el')
| -rw-r--r-- | test/lisp/eshell/eshell-tests.el | 30 |
1 files changed, 30 insertions, 0 deletions
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)"))) |