summaryrefslogtreecommitdiff
path: root/test/lisp/eshell/eshell-tests.el
diff options
context:
space:
mode:
Diffstat (limited to 'test/lisp/eshell/eshell-tests.el')
-rw-r--r--test/lisp/eshell/eshell-tests.el93
1 files changed, 60 insertions, 33 deletions
diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el
index fbff51a8873..390f75cfbb9 100644
--- a/test/lisp/eshell/eshell-tests.el
+++ b/test/lisp/eshell/eshell-tests.el
@@ -34,6 +34,8 @@
(file-name-directory (or load-file-name
default-directory))))
+(defvar eshell-test-value nil)
+
;;; Tests:
(ert-deftest eshell-test/pipe-headproc ()
@@ -129,17 +131,12 @@ This test uses a pipeline for the command."
"Test that `eshell-command' works for background commands."
(skip-unless (executable-find "echo"))
(ert-with-temp-directory eshell-directory-name
- (let ((eshell-history-file-name nil))
- ;; XXX: We can't write to the current buffer here, since
- ;; `eshell-command' will produce an invalid command in that
- ;; case. Just make sure the command runs and produces an output
- ;; buffer.
- (eshell-command "*echo hi &")
- (with-current-buffer "*Eshell Async Command Output*"
- (while (get-buffer-process (current-buffer))
- (accept-process-output))
- (goto-char (point-min))
- (should (looking-at "\\[echo\\(\\.exe\\)?\\(<[0-9]+>\\)?\\]"))))))
+ (let ((orig-processes (process-list))
+ (eshell-history-file-name nil))
+ (with-temp-buffer
+ (eshell-command "*echo hi &" t)
+ (eshell-wait-for (lambda () (equal (process-list) orig-processes)))
+ (should (equal (buffer-string) "hi\n"))))))
(ert-deftest eshell-test/eshell-command/background-pipeline ()
"Test that `eshell-command' works for background commands.
@@ -147,14 +144,12 @@ This test uses a pipeline for the command."
(skip-unless (and (executable-find "echo")
(executable-find "cat")))
(ert-with-temp-directory eshell-directory-name
- (let ((eshell-history-file-name nil))
- ;; XXX: As above, we can't write to the current buffer here.
- (eshell-command "*echo hi | *cat &")
- (with-current-buffer "*Eshell Async Command Output*"
- (while (get-buffer-process (current-buffer))
- (accept-process-output))
- (goto-char (point-min))
- (should (looking-at "\\[cat\\(\\.exe\\)?\\(<[0-9]+>\\)?\\]"))))))
+ (let ((orig-processes (copy-tree (process-list)))
+ (eshell-history-file-name nil))
+ (with-temp-buffer
+ (eshell-command "*echo hi | *cat &" t)
+ (eshell-wait-for (lambda () (equal (process-list) orig-processes)))
+ (should (equal (buffer-string) "hi\n"))))))
(ert-deftest eshell-test/command-running-p ()
"Modeline should show no command running"
@@ -168,27 +163,28 @@ This test uses a pipeline for the command."
(with-temp-eshell
(eshell-insert-command "echo $(+ 1 (- 4 3)) \"alpha beta\" file" 'ignore)
(let ((here (point)) begin valid)
- (eshell-bol)
+ (beginning-of-line)
(setq begin (point))
(eshell-forward-argument 4)
(setq valid (= here (point)))
(eshell-backward-argument 4)
(prog1
(and valid (= begin (point)))
- (eshell-bol)
+ (beginning-of-line)
(delete-region (point) (point-max))))))
(ert-deftest eshell-test/queue-input ()
- "Test queuing command input"
+ "Test queuing command input.
+This should let the current command finish, then automatically
+insert the queued one at the next prompt, and finally run it."
(with-temp-eshell
- (eshell-insert-command "sleep 2")
- (eshell-insert-command "echo alpha" 'eshell-queue-input)
- (let ((count 10))
- (while (and eshell-current-command
- (> count 0))
- (sit-for 1)
- (setq count (1- count))))
- (should (eshell-match-output "alpha\n"))))
+ (eshell-insert-command "sleep 1; echo slept")
+ (eshell-insert-command "echo alpha" #'eshell-queue-input)
+ (let ((start (marker-position (eshell-beginning-of-output))))
+ (eshell-wait-for (lambda () (not eshell-current-command)))
+ (should (string-match "^slept\n.*echo alpha\nalpha\n$"
+ (buffer-substring-no-properties
+ start (eshell-end-of-output)))))))
(ert-deftest eshell-test/flush-output ()
"Test flushing of previous output"
@@ -198,12 +194,43 @@ This test uses a pipeline for the command."
(should (eshell-match-output
(concat "^" (regexp-quote "*** output flushed ***\n") "$")))))
-(ert-deftest eshell-test/run-old-command ()
- "Re-run an old command"
+(ert-deftest eshell-test/get-old-input ()
+ "Test that we can get the input of a previous command."
(with-temp-eshell
(eshell-insert-command "echo alpha")
(goto-char eshell-last-input-start)
- (string= (eshell-get-old-input) "echo alpha")))
+ (should (string= (eshell-get-old-input) "echo alpha"))
+ ;; Make sure that `eshell-get-old-input' works even if the point is
+ ;; inside the prompt.
+ (let ((inhibit-field-text-motion t))
+ (beginning-of-line))
+ (should (string= (eshell-get-old-input) "echo alpha"))))
+
+(ert-deftest eshell-test/get-old-input/rerun-command ()
+ "Test that we can rerun an old command when point is on it."
+ (with-temp-eshell
+ (let ((eshell-test-value "first"))
+ (eshell-match-command-output "echo $eshell-test-value" "first"))
+ ;; Go to the previous prompt.
+ (forward-line -2)
+ (let ((inhibit-field-text-motion t))
+ (end-of-line))
+ ;; Rerun the command, but with a different variable value.
+ (let ((eshell-test-value "second"))
+ (eshell-send-input))
+ (eshell-match-output "second")))
+
+(ert-deftest eshell-test/get-old-input/run-output ()
+ "Test that we can run a line of output as a command when point is on it."
+ (with-temp-eshell
+ (eshell-match-command-output "echo \"echo there\"" "echo there")
+ ;; Go to the output, and insert "hello" after "echo".
+ (forward-line -1)
+ (forward-word)
+ (insert " hello")
+ ;; Run the line as a command.
+ (eshell-send-input)
+ (eshell-match-output "(\"hello\" \"there\")")))
(provide 'eshell-tests)