aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavide Masserut2023-08-29 22:33:48 +0200
committerJim Porter2023-09-02 15:40:04 -0700
commit3d08d0dd80a02419f8301b63bb5663710f4f8ee2 (patch)
treead7a0223d01f0c183926c52c6fe27bd2bff1f6fd /test
parent6ae2b74ed20f7c96384ed67981405212d7e2bea2 (diff)
downloademacs-3d08d0dd80a02419f8301b63bb5663710f4f8ee2.tar.gz
emacs-3d08d0dd80a02419f8301b63bb5663710f4f8ee2.zip
Display the exit code if the last command failed in Eshell
* lisp/eshell/esh-io.el (eshell-last-command-status): Make buffer-local. * lisp/eshell/em-prompt.el (eshell-prompt-function): Insert the exit code if last command failed. * test/lisp/eshell/em-prompt-tests.el (em-prompt-test/after-failure): New test. (em-prompt-test/next-previous-prompt-1) (em-prompt-test/forward-backward-matching-input-1): Add a failing command to tests. * doc/misc/eshell.texi (Invocation): Document change. * etc/NEWS: Announce change (bug#65604).
Diffstat (limited to 'test')
-rw-r--r--test/lisp/eshell/em-prompt-tests.el44
1 files changed, 34 insertions, 10 deletions
diff --git a/test/lisp/eshell/em-prompt-tests.el b/test/lisp/eshell/em-prompt-tests.el
index f6a63ac0db5..46e74e64983 100644
--- a/test/lisp/eshell/em-prompt-tests.el
+++ b/test/lisp/eshell/em-prompt-tests.el
@@ -85,20 +85,41 @@ This tests the case when `eshell-highlight-prompt' is nil."
85 (apply #'propertize "hello\n" 85 (apply #'propertize "hello\n"
86 eshell-command-output-properties))))))) 86 eshell-command-output-properties)))))))
87 87
88(ert-deftest em-prompt-test/after-failure ()
89 "Check that current prompt shows the exit code of the last failed command."
90 (with-temp-eshell
91 (let ((debug-on-error nil))
92 (eshell-insert-command "(zerop \"foo\")"))
93 (let ((current-prompt (field-string (1- (point)))))
94 (should (equal-including-properties
95 current-prompt
96 (propertize
97 (concat (directory-file-name default-directory)
98 (unless (eshell-exit-success-p)
99 (format " [%d]" eshell-last-command-status))
100 (if (= (file-user-uid) 0) " # " " $ "))
101 'read-only t
102 'field 'prompt
103 'font-lock-face 'eshell-prompt
104 'front-sticky '(read-only field font-lock-face)
105 'rear-nonsticky '(read-only field font-lock-face)))))))
106
88(defun em-prompt-test/next-previous-prompt-1 () 107(defun em-prompt-test/next-previous-prompt-1 ()
89 "Helper for checking forward/backward navigation of old prompts." 108 "Helper for checking forward/backward navigation of old prompts."
90 (with-temp-eshell 109 (with-temp-eshell
91 (eshell-insert-command "echo one") 110 (eshell-insert-command "echo one")
92 (eshell-insert-command "echo two") 111 (eshell-insert-command "echo two")
93 (eshell-insert-command "echo three") 112 (eshell-insert-command "echo three")
113 (let ((debug-on-error nil)) ; A failed command.
114 (eshell-insert-command "(zerop \"foo\")"))
94 (insert "echo fou") ; A partially-entered command. 115 (insert "echo fou") ; A partially-entered command.
95 (ert-info ("Go back one prompt") 116 (ert-info ("Go back one prompt")
96 (eshell-previous-prompt) 117 (eshell-previous-prompt)
97 (should (equal (point) (field-beginning))) 118 (should (equal (point) (field-beginning)))
98 (should (equal (field-string) "echo three\n"))) 119 (should (equal (field-string) "(zerop \"foo\")\n")))
99 (ert-info ("Go back two prompts, starting from the end of the input") 120 (ert-info ("Go back three prompts, starting from the end of the input")
100 (end-of-line) 121 (end-of-line)
101 (eshell-previous-prompt 2) 122 (eshell-previous-prompt 3)
102 (should (equal (point) (field-beginning))) 123 (should (equal (point) (field-beginning)))
103 (should (equal (field-string) "echo one\n"))) 124 (should (equal (field-string) "echo one\n")))
104 (ert-info ("Go to the current prompt, starting from the end of the input") 125 (ert-info ("Go to the current prompt, starting from the end of the input")
@@ -110,20 +131,20 @@ This tests the case when `eshell-highlight-prompt' is nil."
110 (eshell-next-prompt) 131 (eshell-next-prompt)
111 (should (equal (point) (field-beginning))) 132 (should (equal (point) (field-beginning)))
112 (should (equal (field-string) "echo two\n"))) 133 (should (equal (field-string) "echo two\n")))
113 (ert-info ("Go forward two prompts") 134 (ert-info ("Go forward three prompts")
114 (eshell-next-prompt 2) 135 (eshell-next-prompt 3)
115 (should (equal (point) (field-beginning))) 136 (should (equal (point) (field-beginning)))
116 (should (equal (field-string) "echo fou"))) 137 (should (equal (field-string) "echo fou")))
117 (ert-info ("Go back one prompt, starting from the beginning of the line") 138 (ert-info ("Go back one prompt, starting from the beginning of the line")
118 (forward-line 0) 139 (forward-line 0)
119 (eshell-previous-prompt 1) 140 (eshell-previous-prompt 1)
120 (should (equal (point) (field-beginning))) 141 (should (equal (point) (field-beginning)))
121 (should (equal (field-string) "echo three\n"))) 142 (should (equal (field-string) "(zerop \"foo\")\n")))
122 (ert-info ("Go back one prompt, starting from the previous prompt's output") 143 (ert-info ("Go back one prompt, starting from the previous prompt's output")
123 (forward-line -1) 144 (forward-line -1)
124 (eshell-previous-prompt 1) 145 (eshell-previous-prompt 1)
125 (should (equal (point) (field-beginning))) 146 (should (equal (point) (field-beginning)))
126 (should (equal (field-string) "echo two\n"))))) 147 (should (equal (field-string) "echo three\n")))))
127 148
128(ert-deftest em-prompt-test/next-previous-prompt () 149(ert-deftest em-prompt-test/next-previous-prompt ()
129 "Check that navigating forward/backward through old prompts works correctly." 150 "Check that navigating forward/backward through old prompts works correctly."
@@ -141,17 +162,20 @@ This tests the case when `eshell-highlight-prompt' is nil."
141 (eshell-insert-command "printnl something else") 162 (eshell-insert-command "printnl something else")
142 (eshell-insert-command "echo two") 163 (eshell-insert-command "echo two")
143 (eshell-insert-command "echo three") 164 (eshell-insert-command "echo three")
165 (let ((debug-on-error nil)) ; A failed command.
166 (eshell-insert-command "(zerop \"foo\")"))
144 (insert "echo fou") ; A partially-entered command. 167 (insert "echo fou") ; A partially-entered command.
145 (ert-info ("Go back one prompt") 168 (ert-info ("Search for \"echo\", back one prompt")
146 (eshell-backward-matching-input "echo" 1) 169 (eshell-backward-matching-input "echo" 1)
147 (should (equal (point) (field-beginning))) 170 (should (equal (point) (field-beginning)))
148 (should (equal (field-string) "echo three\n"))) 171 (should (equal (field-string) "echo three\n")))
149 (ert-info ("Go back two prompts, starting from the end of this line") 172 (ert-info ((concat "Search for \"echo\", back two prompts, "
173 "starting from the end of this line"))
150 (end-of-line) 174 (end-of-line)
151 (eshell-backward-matching-input "echo" 2) 175 (eshell-backward-matching-input "echo" 2)
152 (should (equal (point) (field-beginning))) 176 (should (equal (point) (field-beginning)))
153 (should (equal (field-string) "echo one\n"))) 177 (should (equal (field-string) "echo one\n")))
154 (ert-info ("Go forward three prompts") 178 (ert-info ("Search for \"echo\", forward three prompts")
155 (eshell-forward-matching-input "echo" 3) 179 (eshell-forward-matching-input "echo" 3)
156 (should (equal (point) (field-beginning))) 180 (should (equal (point) (field-beginning)))
157 (should (equal (field-string) "echo fou"))))) 181 (should (equal (field-string) "echo fou")))))