From 40566a5d0c0ef4d30961915bac7875d078adb58e Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 22 Jan 2022 18:54:55 -0700 Subject: [PATCH v6 2/3] Rework eshell-match-result for testing asynchronous commands When using eshell-match-result via eshell-command-result-p to examine the output of asynchronous Eshell commands, a newly emitted prompt is included in the text against which the regexp is matched. This makes it awkward to match against the whole output; for example, to check whether it is empty. Rework the function to exclude the prompt. * test/lisp/eshell/eshell-tests-helpers.el (eshell-match-result): Exclude any newly emitted prompt from the text against which the regexp is matched. Additionally, the function no longer moves point. * test/lisp/eshell/eshell-tests.el (eshell-test/flush-output): Update and simplify test given how eshell-match-result no longer moves point. --- test/lisp/eshell/eshell-tests-helpers.el | 9 +++++---- test/lisp/eshell/eshell-tests.el | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/lisp/eshell/eshell-tests-helpers.el b/test/lisp/eshell/eshell-tests-helpers.el index 0930f82284..77f5313d57 100644 --- a/test/lisp/eshell/eshell-tests-helpers.el +++ b/test/lisp/eshell/eshell-tests-helpers.el @@ -66,10 +66,11 @@ eshell-insert-command (funcall (or func 'eshell-send-input))) (defun eshell-match-result (regexp) - "Check that text after `eshell-last-input-end' matches REGEXP." - (goto-char eshell-last-input-end) - (should (string-match-p regexp (buffer-substring-no-properties - (point) (point-max))))) + "Check that output of last command matches REGEXP." + (should + (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." diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index 6aeefdfde2..542815df80 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -232,9 +232,8 @@ eshell-test/flush-output (with-temp-eshell (eshell-insert-command "echo alpha") (eshell-kill-output) - (eshell-match-result (regexp-quote "*** output flushed ***\n")) - (should (forward-line)) - (should (= (point) eshell-last-output-start)))) + (eshell-match-result + (concat "^" (regexp-quote "*** output flushed ***\n") "$")))) (ert-deftest eshell-test/run-old-command () "Re-run an old command" -- 2.30.2