diff options
Diffstat (limited to 'test/lisp/eshell/eshell-tests-helpers.el')
-rw-r--r-- | test/lisp/eshell/eshell-tests-helpers.el | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/test/lisp/eshell/eshell-tests-helpers.el b/test/lisp/eshell/eshell-tests-helpers.el index 4c833c96e7e..652146fefcc 100644 --- a/test/lisp/eshell/eshell-tests-helpers.el +++ b/test/lisp/eshell/eshell-tests-helpers.el @@ -33,9 +33,9 @@ (defvar eshell-history-file-name nil) (defvar eshell-last-dir-ring-file-name nil) -(defvar eshell-test--max-subprocess-time 5 - "The maximum amount of time to wait for a subprocess to finish, in seconds. -See `eshell-wait-for-subprocess'.") +(defvar eshell-test--max-wait-time 5 + "The maximum amount of time to wait for a condition to resolve, in seconds. +See `eshell-wait-for'.") (defun eshell-tests-remote-accessible-p () "Return if a test involving remote files can proceed. @@ -54,6 +54,13 @@ beginning of the test file." (let* (;; We want no history file, so prevent Eshell from falling ;; back on $HISTFILE. (process-environment (cons "HISTFILE" process-environment)) + ;; Enable process debug instrumentation. We may be able + ;; to remove this eventually once we're confident that + ;; all the process bugs have been worked out. (At that + ;; point, we can just enable this selectively when + ;; needed.) See also `eshell-test-command-result' + ;; below. + (eshell-debug-command (cons 'process eshell-debug-command)) (eshell-history-file-name nil) (eshell-last-dir-ring-file-name nil) (eshell-buffer (eshell t))) @@ -73,19 +80,35 @@ BUFNAME will be set to the name of the temporary buffer." (let ((,bufname (buffer-name))) ,@body))) +(defun eshell-wait-for (predicate &optional message) + "Wait until PREDICATE returns non-nil. +If this takes longer than `eshell-test--max-wait-time', raise an +error. MESSAGE is an optional message to use if this times out." + (let ((start (current-time)) + (message (or message "timed out waiting for condition"))) + (while (not (funcall predicate)) + (when (> (float-time (time-since start)) + eshell-test--max-wait-time) + (error message)) + (sit-for 0.1)))) + (defun eshell-wait-for-subprocess (&optional all) "Wait until there is no interactive subprocess running in Eshell. If ALL is non-nil, wait until there are no Eshell subprocesses at all running. -If this takes longer than `eshell-test--max-subprocess-time', +If this takes longer than `eshell-test--max-wait-time', raise an error." - (let ((start (current-time))) - (while (if all eshell-process-list (eshell-interactive-process-p)) - (when (> (float-time (time-since start)) - eshell-test--max-subprocess-time) - (error "timed out waiting for subprocess(es)")) - (sit-for 0.1)))) + (eshell-wait-for + (lambda () + (not (if all eshell-process-list (eshell-interactive-process-p)))))) + +(defun eshell-get-debug-logs () + "Get debug command logs for displaying on test failures." + (when (get-buffer eshell-debug-command-buffer) + (let ((separator (make-string 40 ?-))) + (with-current-buffer eshell-debug-command-buffer + (string-replace "\f" separator (buffer-string)))))) (defun eshell-insert-command (command &optional func) "Insert a COMMAND at the end of the buffer. @@ -126,17 +149,21 @@ FUNC is the function to call after inserting the text (see If IGNORE-ERRORS is non-nil, ignore any errors signaled when inserting the command." - (let ((debug-on-error (and (not ignore-errors) debug-on-error))) - (eshell-insert-command command func)) - (eshell-wait-for-subprocess) - (should (eshell-match-output regexp))) + (ert-info (#'eshell-get-debug-logs :prefix "Command logs: ") + (let ((debug-on-error (and (not ignore-errors) debug-on-error))) + (eshell-insert-command command func)) + (eshell-wait-for-subprocess) + (should (eshell-match-output regexp)))) (defvar eshell-history-file-name) (defun eshell-test-command-result (command) "Like `eshell-command-result', but not using HOME." (ert-with-temp-directory eshell-directory-name - (let ((eshell-history-file-name nil)) + (let ((eshell-history-file-name nil) + ;; Enable process debug instrumentation. See + ;; `with-temp-eshell' above. + (eshell-debug-command (cons 'process eshell-debug-command))) (eshell-command-result command)))) (defun eshell-command-result--equal (_command actual expected) @@ -155,10 +182,11 @@ inserting the command." (defun eshell-command-result-equal (command result) "Execute COMMAND non-interactively and compare it to RESULT." - (should (eshell-command-result--equal - command - (eshell-test-command-result command) - result))) + (ert-info (#'eshell-get-debug-logs :prefix "Command logs: ") + (should (eshell-command-result--equal + command + (eshell-test-command-result command) + result)))) (provide 'eshell-tests-helpers) |