>From 77f70d788631c57823ab18fe7ae1b58f2583b400 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Fri, 20 Apr 2018 15:45:06 +0100 Subject: [PATCH 1/2] Fix failing test for bug#30280 * test/lisp/simple-tests.el (simple-tests-async-shell-command-30280): Fix failing test. --- test/lisp/simple-tests.el | 59 ++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el index 7a10df2058..678d9b9385 100644 --- a/test/lisp/simple-tests.el +++ b/test/lisp/simple-tests.el @@ -521,30 +521,51 @@ simple-test-undo-with-switched-buffer (do-auto-fill) (should (string-equal (buffer-string) "foo bar")))) + +;;; Shell command. + (ert-deftest simple-tests-async-shell-command-30280 () "Test for https://debbugs.gnu.org/30280 ." - :expected-result :failed (let* ((async-shell-command-buffer 'new-buffer) (async-shell-command-display-buffer nil) - (str "*Async Shell Command*") - (buffers-name - (cl-loop repeat 2 - collect (buffer-name - (generate-new-buffer str)))) + (base "name") + (first (buffer-name (generate-new-buffer base))) + (second (generate-new-buffer-name base)) + ;; `save-window-excursion' doesn't restore frame configurations. + (pop-up-frames nil) (inhibit-message t)) - (mapc #'kill-buffer buffers-name) - (async-shell-command - (format "%s -Q -batch -eval '(progn (sleep-for 3600) (message \"foo\"))'" - invocation-name)) - (async-shell-command - (format "%s -Q -batch -eval '(progn (sleep-for 1) (message \"bar\"))'" - invocation-name)) - (let ((buffers (mapcar #'get-buffer buffers-name)) - (processes (mapcar #'get-buffer-process buffers-name))) - (unwind-protect - (should (memq (cadr buffers) (mapcar #'window-buffer (window-list)))) - (mapc #'delete-process processes) - (mapc #'kill-buffer buffers))))) + ;; Let `shell-command' create the buffer as needed. + (kill-buffer first) + (unwind-protect + (save-window-excursion + ;; One command has no output, the other does. + ;; Removing the -eval argument also yields no output, but + ;; then both commands exit simultaneously when + ;; `accept-process-output' is called on the second command. + (dolist (form '("(sleep-for 8)" "(message \"\")")) + (async-shell-command (format "%s -Q -batch -eval '%s'" + invocation-name form) + first)) + ;; First command should neither have nor display output. + (let* ((buffer (get-buffer first)) + (process (get-buffer-process buffer))) + (should (buffer-live-p buffer)) + (should process) + (should (zerop (buffer-size buffer))) + (should (not (get-buffer-window buffer)))) + ;; Second command should both have and display output. + (let* ((buffer (get-buffer second)) + (process (get-buffer-process buffer))) + (should (buffer-live-p buffer)) + (should process) + (should (accept-process-output process 4 nil t)) + (should (> (buffer-size buffer) 0)) + (should (get-buffer-window buffer)))) + (dolist (name (list first second)) + (let* ((buffer (get-buffer name)) + (process (and buffer (get-buffer-process buffer)))) + (when process (delete-process process)) + (when buffer (kill-buffer buffer))))))) (provide 'simple-test) ;;; simple-test.el ends here -- 2.17.0