summaryrefslogtreecommitdiff
path: root/test/lisp/eshell/eshell-tests-helpers.el
diff options
context:
space:
mode:
Diffstat (limited to 'test/lisp/eshell/eshell-tests-helpers.el')
-rw-r--r--test/lisp/eshell/eshell-tests-helpers.el38
1 files changed, 25 insertions, 13 deletions
diff --git a/test/lisp/eshell/eshell-tests-helpers.el b/test/lisp/eshell/eshell-tests-helpers.el
index 4ad76ca6978..778087bd755 100644
--- a/test/lisp/eshell/eshell-tests-helpers.el
+++ b/test/lisp/eshell/eshell-tests-helpers.el
@@ -65,24 +65,36 @@ raise an error."
(error "timed out waiting for subprocess(es)"))
(sit-for 0.1))))
-(defun eshell-insert-command (text &optional func)
- "Insert a command at the end of the buffer."
+(defun eshell-insert-command (command &optional func)
+ "Insert a COMMAND at the end of the buffer.
+After inserting, call FUNC. If FUNC is nil, instead call
+`eshell-send-input'."
(goto-char eshell-last-output-end)
- (insert-and-inherit text)
+ (insert-and-inherit command)
(funcall (or func 'eshell-send-input)))
-(defun eshell-match-result (regexp)
- "Check that output of last command matches REGEXP."
- (should
- (string-match-p
+(defun eshell-match-output (regexp)
+ "Test whether the output of the last command matches REGEXP."
+ (string-match-p
regexp (buffer-substring-no-properties
- (eshell-beginning-of-output) (eshell-end-of-output)))))
-
-(defun eshell-command-result-p (text regexp &optional func)
- "Insert a command at the end of the buffer."
- (eshell-insert-command text func)
+ (eshell-beginning-of-output) (eshell-end-of-output))))
+
+(defun eshell-match-output--explainer (regexp)
+ "Explain the result of `eshell-match-output'."
+ `(mismatched-output
+ (command ,(buffer-substring-no-properties
+ eshell-last-input-start eshell-last-input-end))
+ (output ,(buffer-substring-no-properties
+ (eshell-beginning-of-output) (eshell-end-of-output)))
+ (regexp ,regexp)))
+
+(put 'eshell-match-output 'ert-explainer #'eshell-match-output--explainer)
+
+(defun eshell-match-command-output (command regexp &optional func)
+ "Insert a COMMAND at the end of the buffer and match the output with REGEXP."
+ (eshell-insert-command command func)
(eshell-wait-for-subprocess)
- (eshell-match-result regexp))
+ (should (eshell-match-output regexp)))
(defvar eshell-history-file-name)