diff options
author | Jim Porter <jporterbugs@gmail.com> | 2022-08-13 20:31:11 -0700 |
---|---|---|
committer | Jim Porter <jporterbugs@gmail.com> | 2022-08-15 20:40:27 -0700 |
commit | 07b8fb197a3057a3419be0335236547e4d7a326b (patch) | |
tree | 52b631c5f3cc6370223e1d9f7920b7b3af37f197 /test/lisp/eshell/eshell-tests-helpers.el | |
parent | 1973d4ac1b613bdd6c70e1ef2bac97b538fbb2ed (diff) | |
download | emacs-07b8fb197a3057a3419be0335236547e4d7a326b.tar.gz emacs-07b8fb197a3057a3419be0335236547e4d7a326b.tar.bz2 emacs-07b8fb197a3057a3419be0335236547e4d7a326b.zip |
Provide ERT explainer for 'eshell-match-command-output'
This was formerly named 'eshell-command-result-p', but "result" isn't
quite the right terminology, since this function specifically tested
the output of a command, not its Lisp result (as
'eshell-command-result' would return).
* test/lisp/eshell/eshell-tests-helpers.el (eshell-insert-command):
Provide a more-complete docstring.
(eshell-match-result): Rename to...
(eshell-match-output): ... this.
(eshell-match-output--explainer): New function.
(eshell-command-result-p): Rename to...
(eshell-match-command-output): ... this.
* test/lisp/eshell/em-alias-tests.el
* test/lisp/eshell/em-dirs-tests.el
* test/lisp/eshell/em-extpipe-tests.el
* test/lisp/eshell/em-script-tests.el
* test/lisp/eshell/esh-cmd-tests.el
* test/lisp/eshell/esh-proc-tests.el
* test/lisp/eshell/esh-var-tests.el
* test/lisp/eshell/eshell-tests-helpers.el
* test/lisp/eshell/eshell-tests.el: Use 'eshell-match-command-output'.
Diffstat (limited to 'test/lisp/eshell/eshell-tests-helpers.el')
-rw-r--r-- | test/lisp/eshell/eshell-tests-helpers.el | 38 |
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) |