Skip to content

Commit

Permalink
Do not colorize a deleted buffer
Browse files Browse the repository at this point in the history
Users should be able to manually kill the
*quickrun* buffer with no errors.

* quickrun.el (quickrun--make-sentinel):
Check if quickrun--buffer-name still alive before
call quickrun--apply-colorizing.
* test/test-quickrun.el (quickrun:user-manually-terminates-program):
Add test.
* sample/sample_endless_loop.bash:
Add sample file for the new test.
  • Loading branch information
Tino Calancha committed Mar 30, 2021
1 parent 57db985 commit 96d49f0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion quickrun.el
Expand Up @@ -1023,7 +1023,8 @@ if you set your own language configuration.")
(quickrun--exec rest-commands input orig-mode))
(t
(if (not is-success)
(if (eq quickrun-option-outputter #'quickrun--default-outputter)
(if (and (buffer-live-p quickrun--buffer-name)
(eq quickrun-option-outputter #'quickrun--default-outputter))
(quickrun--apply-colorizing input orig-mode)
(message "Failed: Exit Status=%d" exit-status))
(quickrun--apply-outputter outputter-func)
Expand Down
13 changes: 13 additions & 0 deletions sample/sample_endless_loop.bash
@@ -0,0 +1,13 @@
#!/bin/bash

function endlessLoop () {
local step=1
while true
do
printf "Endless loop step %d\n" $step
((step+=1))
sleep 1
done
}

endlessLoop
15 changes: 15 additions & 0 deletions test/test-quickrun.el
Expand Up @@ -77,4 +77,19 @@
(use-tempfile (quickrun--use-tempfile-p "hoge")))
(should-not use-tempfile)))

(ert-deftest quickrun:user-manually-terminates-program ()
"Users are able to manually terminate the program with no errors."
(with-current-buffer (find-file-noselect "sample/sample_endless_loop.bash")
(quickrun))
(sleep-for 1)
(condition-case err
(let ((buf (get-buffer "*quickrun*"))
(inhibit-message t))
(set-process-query-on-exit-flag (get-buffer-process buf) nil)
(kill-buffer buf)
(sleep-for 1)) ; Wait for the sentinel.
(wrong-type-argument
(quickrun--remove-temp-files)
(signal 'error "Cannot access a deleted buffer"))))

;;; test-quickrun.el ends here

0 comments on commit 96d49f0

Please sign in to comment.