From 90432170552a6e922d48d51138b2062aa11e5575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= Date: Wed, 26 Oct 2022 13:35:26 +0200 Subject: [PATCH] WIP test-ob-shell: Add tests for some recent changes --- testing/lisp/test-ob-shell.el | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index 4c00faa49..8cd967343 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -170,6 +170,66 @@ ob-comint.el, which was not previously tested." "#+BEGIN_SRC sh :results table\necho 'I \"want\" it all'\n#+END_SRC" (org-babel-execute-src-block))))) +;;; Standard output + +(ert-deftest ob-shell/standard-output-after-failure () + "Test standard output after exiting with a non-zero code." + (should (= 1 + (org-babel-execute:sh + "echo 1; exit 2" nil)))) + +;;; Error output + +(ert-deftest ob-shell/error-output-after-success () + "Test that error output shows in the error buffer after exiting +with a zero code." + (should + (string= "1 +[ Babel evaluation exited with code 2 ]" + (progn (org-babel-eval-wipe-error-buffer) + (org-babel-execute:sh + "echo 1 >&2" nil) + (with-current-buffer org-babel-error-buffer-name + (buffer-string)))))) + +(ert-deftest ob-shell/error-output-after-failure () + "Test that error output shows in the error buffer, alongside the +exit code, after exiting with a non-zero code." + (should + (string= "1 +[ Babel evaluation exited with code 2 ]" + (progn (org-babel-eval-wipe-error-buffer) + (org-babel-execute:sh + "echo 1 >&2; exit 2" nil) + (with-current-buffer org-babel-error-buffer-name + (buffer-string)))))) + +;;; Exit codes + +(ert-deftest ob-shell/exit-code () + "Test that the exit code shows in the error buffer after exiting +with a non-zero return code." + (should + (string= "[ Babel evaluation exited with code 1 ]" + (progn (org-babel-eval-wipe-error-buffer) + (org-babel-execute:sh + "exit 1" nil) + (with-current-buffer org-babel-error-buffer-name + (buffer-string)))))) + +(ert-deftest ob-shell/exit-codes () + "Test that multiple exit codes show in the error buffer after +exiting with a non-zero return code more than once." + (should + (string= "[ Babel evaluation exited with code 1 ] +[ Babel evaluation exited with code 2 ]" + (progn (org-babel-eval-wipe-error-buffer) + (org-babel-execute:sh + "exit 1" nil) + (org-babel-execute:sh + "exit 2" nil) + (with-current-buffer org-babel-error-buffer-name + (buffer-string)))))) (provide 'test-ob-shell) -- 2.38.1