emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Matt <matt@excalamus.com>
To: "Ihor Radchenko" <yantar92@posteo.net>
Cc: "emacs-orgmode" <emacs-orgmode@gnu.org>
Subject: Re: ob-shell intentions and paperwork (was Bash results broken?)
Date: Tue, 27 Dec 2022 15:48:32 -0500	[thread overview]
Message-ID: <18555580d75.d7b471f9370716.1497263973038999899@excalamus.com> (raw)
In-Reply-To: <1853354beb4.fce54d8d902653.6359367327256505471@excalamus.com>

[-- Attachment #1: Type: text/plain, Size: 855 bytes --]


 ---- On Wed, 21 Dec 2022 01:17:50 -0500  Matt  wrote --- 

 > Currently, though, I'm refactoring the ob-shell tests to remove dependency on ob-shell-test.org and to stop the suite from littering. 

Done.  Branched off bugfix, 12e10eb0d, and refactored test-ob-shell.el.  See attached patches.

The main changes spanning the patches are:

- tests are now standalone; they don't rely on ob-shell-test.org
- tests now share a common prefix, "test-ob-shell".  The entire suite runs with (ert "test-ob-shell")
- buffers and processes created during a test are killed when the test passes

 >  After that, I intend to incorporate the worg examples as tests.

This is probably a good place for me to pause and get feedback before writing more code. 

I just got the signed paperwork back from Craig and am waiting to be admitted to the Emacs group on Savannah.

[-- Attachment #2: 0001-test-ob-shell.el-Remove-mixed-tabs-and-spaces.patch --]
[-- Type: application/octet-stream, Size: 4889 bytes --]

From ecdb71afa00ca137b4faa737393cb027907a7f9f Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Tue, 20 Dec 2022 13:51:26 -0500
Subject: [PATCH 01/20] test-ob-shell.el: Remove mixed tabs and spaces

* test-ob-shell.el: Convert tabs to spaces.

Change made under the premise that one or the other is better than
both.
---
 testing/lisp/test-ob-shell.el | 58 +++++++++++++++++------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index b0d9beff4..816e93ac5 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -32,9 +32,9 @@
   "Expanded shell bodies should not start with a blank line
 unless the body of the tangled block does."
   (should-not (string-match "^[\n\r][\t ]*[\n\r]"
-			    (org-babel-expand-body:generic "echo 2" '())))
+                            (org-babel-expand-body:generic "echo 2" '())))
   (should (string-match "^[\n\r][\t ]*[\n\r]"
-			(org-babel-expand-body:generic "\n\necho 2" '()))))
+                        (org-babel-expand-body:generic "\n\necho 2" '()))))
 
 (ert-deftest test-ob-shell/dont-error-on-empty-results ()
   "Was throwing an elisp error when shell blocks threw errors and
@@ -49,8 +49,8 @@ ob-comint.el, which was not previously tested."
     (should (listp res)))
   ;; Test multi-line input.
   (let ((result (org-babel-execute:sh
-		 "if true \n then \n echo yes \n fi"
-		 '((:session . "yes")))))
+                 "if true \n then \n echo yes \n fi"
+                 '((:session . "yes")))))
     (should result)
     (should (string= "yes" result))))
 
@@ -71,47 +71,47 @@ ob-comint.el, which was not previously tested."
   "No associative arrays for generic"
   (should
    (equal "first one second two third three"
-	  (org-test-at-id
-	   "bec1a5b0-4619-4450-a8c0-2a746b44bf8d"
-	   (org-babel-next-src-block)
-	   (org-trim (org-babel-execute-src-block)))))
+          (org-test-at-id
+           "bec1a5b0-4619-4450-a8c0-2a746b44bf8d"
+           (org-babel-next-src-block)
+           (org-trim (org-babel-execute-src-block)))))
   (should
    (equal "bread 2 kg spaghetti 20 cm milk 50 dl"
-	  (org-test-at-id
-	   "82320a48-3409-49d7-85c9-5de1c6d3ff87"
-	   (org-babel-next-src-block)
-	   (org-trim (org-babel-execute-src-block))))))
+          (org-test-at-id
+           "82320a48-3409-49d7-85c9-5de1c6d3ff87"
+           (org-babel-next-src-block)
+           (org-trim (org-babel-execute-src-block))))))
 
 (ert-deftest ob-shell/bash-uses-assoc-arrays ()
   "Bash associative arrays"
   (should
    (equal "two"
-	  (org-test-at-id
-	   "bec1a5b0-4619-4450-a8c0-2a746b44bf8d"
-	   (org-babel-next-src-block 2)
-	   (org-trim (org-babel-execute-src-block)))))
+          (org-test-at-id
+           "bec1a5b0-4619-4450-a8c0-2a746b44bf8d"
+           (org-babel-next-src-block 2)
+           (org-trim (org-babel-execute-src-block)))))
   ;; Bash associative arrays as strings for the row.
   (should
    (equal "20 cm"
-	  (org-test-at-id
-	   "82320a48-3409-49d7-85c9-5de1c6d3ff87"
-	   (org-babel-next-src-block 2)
-	   (org-trim (org-babel-execute-src-block))))))
+          (org-test-at-id
+           "82320a48-3409-49d7-85c9-5de1c6d3ff87"
+           (org-babel-next-src-block 2)
+           (org-trim (org-babel-execute-src-block))))))
 
 (ert-deftest ob-shell/simple-list ()
   "Test list variables in shell."
   ;; With bash, a list is turned into an array.
   (should
    (equal "2"
-	  (org-test-with-temp-text
-	   "#+BEGIN_SRC bash :results output :var l='(1 2)\necho ${l[1]}\n#+END_SRC"
-	   (org-trim (org-babel-execute-src-block)))))
+          (org-test-with-temp-text
+           "#+BEGIN_SRC bash :results output :var l='(1 2)\necho ${l[1]}\n#+END_SRC"
+           (org-trim (org-babel-execute-src-block)))))
   ;; On sh, it is a string containing all values.
   (should
    (equal "1 2"
-	  (org-test-with-temp-text
-	   "#+BEGIN_SRC sh :results output :var l='(1 2)\necho ${l}\n#+END_SRC"
-	   (org-trim (org-babel-execute-src-block))))))
+          (org-test-with-temp-text
+           "#+BEGIN_SRC sh :results output :var l='(1 2)\necho ${l}\n#+END_SRC"
+           (org-trim (org-babel-execute-src-block))))))
 
 (ert-deftest ob-shell/remote-with-stdin-or-cmdline ()
   "Test :stdin and :cmdline with a remote directory."
@@ -166,9 +166,9 @@ ob-comint.el, which was not previously tested."
   "Test :results table."
   (should
    (equal '(("I \"want\" it all"))
-	  (org-test-with-temp-text
-	      "#+BEGIN_SRC sh :results table\necho 'I \"want\" it all'\n#+END_SRC"
-	    (org-babel-execute-src-block)))))
+          (org-test-with-temp-text
+              "#+BEGIN_SRC sh :results table\necho 'I \"want\" it all'\n#+END_SRC"
+            (org-babel-execute-src-block)))))
 
 (ert-deftest ob-shell/results-list ()
   "Test :results list."
-- 
2.38.1


[-- Attachment #3: 0002-test-ob-shell.el-Split-cases-into-two-tests.patch --]
[-- Type: application/octet-stream, Size: 1754 bytes --]

From 3f712ecc2302a16514d0ce4b2dbb98f0330bc8a2 Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Tue, 20 Dec 2022 13:53:44 -0500
Subject: [PATCH 02/20] test-ob-shell.el: Split cases into two tests

* testing/lisp/test-ob-shell.el
(test-ob-shell/dont-error-on-empty-results): Fix ambiguity in test
name, docstring, and function.  Explicitly test for empty results.
(test-ob-shell/dont-error-on-babel-error): Explicitly test for babel
error handling.  Previously tested implicitly.  On pass, remove
buffers created during test.

Two sources of errors exist: 1) empty results and 2) babel errors.
Original test checked both, despite its name specifing only the first
type.  Change splits original test into two according type of error.
---
 testing/lisp/test-ob-shell.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 816e93ac5..625dc64b9 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -37,9 +37,11 @@ unless the body of the tangled block does."
                         (org-babel-expand-body:generic "\n\necho 2" '()))))
 
 (ert-deftest test-ob-shell/dont-error-on-empty-results ()
-  "Was throwing an elisp error when shell blocks threw errors and
-returned empty results."
-  (should (null (org-babel-execute:sh "ls NoSuchFileOrDirectory.txt" nil))))
+  (should (null (org-babel-execute:sh nil nil))))
+
+(ert-deftest test-ob-shell/dont-error-on-babel-error ()
+  (if (should (null (org-babel-execute:sh "ls NoSuchFileOrDirectory.txt" nil)))
+      (kill-buffer "*Org-Babel Error Output*")))
 
 (ert-deftest test-ob-shell/session ()
   "This also tests `org-babel-comint-with-output' in
-- 
2.38.1


[-- Attachment #4: 0003-test-ob-shell.el-Refactor-test-ob-shell-session.patch --]
[-- Type: application/octet-stream, Size: 4652 bytes --]

From c64354854f6016cb0ad07c90f5e474c97cd790db Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Tue, 20 Dec 2022 15:22:38 -0500
Subject: [PATCH 03/20] test-ob-shell.el: Refactor test-ob-shell/session
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* testing/lisp/test-ob-shell.el (ob-shell/session): Split
`ob-shell/session' into
`test-ob-shell/session-single-return-returns-string' and
`test-ob-shell/session-multiple-returns-returns-list'.
(ob-shell/session): Rename comint from "yes" to test name[fn:1]. On
pass, kill process and remove process buffer.
* testing/lisp/test-ob-shell.el, lisp/ob-shell.el: Place notes
indicating need for future refactoring.

[fn:1] Session name is a string and not a variable (such as
`session-name').  This is because `org-babel-execute:sh' produces a
type error when the session name is defined with a variable.  The
source of the error appears to be the `params' symbol in
`org-babel-execute:sh'.  `params' does not evaluate as a variable as
expected–it evaluates as a symbol.  However, `org-babel-execute:sh' is
defined within a function factory which makes it difficult to debug.
Hard code the test name for now and refactor it later once
`org-babel-execute:sh` is refactored.
---
 lisp/ob-shell.el              |  2 ++
 testing/lisp/test-ob-shell.el | 36 ++++++++++++++++++++++-------------
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index d38d2d335..8da9aa738 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -68,6 +68,8 @@ alist element.")
 
 (defvar org-babel-prompt-command)
 
+;; TODO refactor into macro.  Currently violates (elisp) Coding
+;; Conventions and is hard to debug.
 (defun org-babel-shell-initialize ()
   "Define execution functions associated to shell names.
 This function has to be called whenever `org-babel-shell-names'
diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 625dc64b9..54b6d5a6f 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -29,8 +29,8 @@
   (signal 'missing-test-dependency "Support for Shell code blocks"))
 
 (ert-deftest test-ob-shell/dont-insert-spaces-on-expanded-bodies ()
-  "Expanded shell bodies should not start with a blank line
-unless the body of the tangled block does."
+  "Expanded shell bodies should not start with a blank line unless
+the body of the tangled block does."
   (should-not (string-match "^[\n\r][\t ]*[\n\r]"
                             (org-babel-expand-body:generic "echo 2" '())))
   (should (string-match "^[\n\r][\t ]*[\n\r]"
@@ -43,18 +43,28 @@ unless the body of the tangled block does."
   (if (should (null (org-babel-execute:sh "ls NoSuchFileOrDirectory.txt" nil)))
       (kill-buffer "*Org-Babel Error Output*")))
 
-(ert-deftest test-ob-shell/session ()
-  "This also tests `org-babel-comint-with-output' in
-ob-comint.el, which was not previously tested."
-  (let ((res (org-babel-execute:sh "echo 1; echo 2" '((:session . "yes")))))
-    (should res)
-    (should (listp res)))
-  ;; Test multi-line input.
-  (let ((result (org-babel-execute:sh
-                 "if true \n then \n echo yes \n fi"
-                 '((:session . "yes")))))
+;; TODO refactor session name into variable after refactoring
+;; org-babel-execute:sh.  See comment there.
+(ert-deftest test-ob-shell/session-single-return-returns-string ()
+  (let ((kill-buffer-query-functions nil)
+        (result (org-babel-execute:sh
+                 "echo test-ob-shell/session-evaluation-single-return-returns-string"
+                 '((:session . "test-ob-shell/session-evaluation-single-return-returns-string")))))
     (should result)
-    (should (string= "yes" result))))
+    (if (should (string= "test-ob-shell/session-evaluation-single-return-returns-string" result))
+        (kill-buffer "test-ob-shell/session-evaluation-single-return-returns-string"))))
+
+;; TODO refactor session name into variable after refactoring
+;; org-babel-execute:sh.  See comment there.
+(ert-deftest test-ob-shell/session-multiple-returns-returns-list ()
+  (let ((kill-buffer-query-functions nil)
+        (result (org-babel-execute:sh
+                 "echo 1; echo 2"
+                 '((:session . "test-ob-shell/session-multiple-returns-returns-list")))))
+    (should result)
+    (should (listp result))
+    (if (should (equal '((1) (2)) result))
+        (kill-buffer "test-ob-shell/session-multiple-returns-returns-list"))))
 
 ; A list of tests using the samples in ob-shell-test.org
 (ert-deftest ob-shell/generic-uses-no-arrays ()
-- 
2.38.1


[-- Attachment #5: 0004-test-ob-shell.el-Refactor-ob-shell-generic-uses-no-a.patch --]
[-- Type: application/octet-stream, Size: 2906 bytes --]

From 55caaf5c0fe4f2e9fe4b1c3cb1740ec2a6072c7b Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Tue, 20 Dec 2022 18:10:52 -0500
Subject: [PATCH 04/20] test-ob-shell.el: Refactor
 ob-shell/generic-uses-no-arrays

* testing/lisp/test-ob-shell.el: Define function
`test-ob-shell-multiline-string'.
(ob-shell/generic-uses-no-arrays): Rename test from
`ob-shell/generic-uses-no-arrays' to
`test-ob-shell/generic-uses-no-arrays'.
(ob-shell/generic-uses-no-arrays): Explain test in doc string.
(ob-shell/generic-uses-no-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
---
 testing/lisp/test-ob-shell.el | 41 +++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 54b6d5a6f..df32b8aa7 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -20,17 +20,32 @@
 
 ;;; Comment:
 
-;; Template test file for Org tests
-
-;;; Code:
+;;; Requirements:
 (org-test-for-executable "sh")
+
 (require 'ob-core)
+
 (unless (featurep 'ob-shell)
   (signal 'missing-test-dependency "Support for Shell code blocks"))
 
+;;; Code:
+(defun test-ob-shell-multiline-string (&rest strings)
+  "Join STRINGS with newlines.
+
+Each expression of STRINGS should evaluate to a string.
+
+    (test-ob-shell-multiline-string
+      \"first\"
+      (format \"second\")
+      (let ((last \"third\")) last))
+    ⇒ \"first\\nsecond\\nthird\"
+
+\(fn STRINGS)"
+  (string-join strings "\n"))
+
 (ert-deftest test-ob-shell/dont-insert-spaces-on-expanded-bodies ()
   "Expanded shell bodies should not start with a blank line unless
-the body of the tangled block does."
+the strings of the tangled block does."
   (should-not (string-match "^[\n\r][\t ]*[\n\r]"
                             (org-babel-expand-body:generic "echo 2" '())))
   (should (string-match "^[\n\r][\t ]*[\n\r]"
@@ -66,11 +81,19 @@ the body of the tangled block does."
     (if (should (equal '((1) (2)) result))
         (kill-buffer "test-ob-shell/session-multiple-returns-returns-list"))))
 
-; A list of tests using the samples in ob-shell-test.org
-(ert-deftest ob-shell/generic-uses-no-arrays ()
-  "No arrays for generic"
-  (org-test-at-id "0ba56632-8dc1-405c-a083-c204bae477cf"
-    (org-babel-next-src-block)
+(ert-deftest test-ob-shell/generic-uses-no-arrays ()
+  "Test generic serialization of array into a single string."
+  (org-test-with-temp-text
+      (test-ob-shell-multiline-string
+       "#+NAME: sample_array"
+       "| one   |"
+       "| two   |"
+       "| three |"
+       ""
+       "#+begin_src sh :exports results :results output :var array=sample_array"
+       "echo ${array}"
+       "<point>"
+       "#+end_src")
     (should (equal "one two three" (org-trim (org-babel-execute-src-block))))))
 
 (ert-deftest ob-shell/bash-uses-arrays ()
-- 
2.38.1


[-- Attachment #6: 0005-test-ob-shell.el-Refactor-ob-shell-bash-uses-arrays.patch --]
[-- Type: application/octet-stream, Size: 1856 bytes --]

From ebc48d2e7c3314d9669d212a237e319787974ab8 Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Tue, 20 Dec 2022 18:16:17 -0500
Subject: [PATCH 05/20] test-ob-shell.el: Refactor ob-shell/bash-uses-arrays

* test-ob-shell.el (ob-shell/bash-uses-arrays): Rename
`ob-shell/bash-uses-arrays' to `test-ob-shell/bash-uses-arrays'.
(ob-shell/bash-uses-arrays): Explain test in docstring.
(ob-shell/bash-uses-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
---
 testing/lisp/test-ob-shell.el | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index df32b8aa7..4c70c07fb 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -96,10 +96,23 @@ the strings of the tangled block does."
        "#+end_src")
     (should (equal "one two three" (org-trim (org-babel-execute-src-block))))))
 
-(ert-deftest ob-shell/bash-uses-arrays ()
-  "Bash arrays"
-  (org-test-at-id "0ba56632-8dc1-405c-a083-c204bae477cf"
-    (org-babel-next-src-block 2)
+(ert-deftest test-ob-shell/bash-uses-arrays ()
+  "Bash sees named array as a simple indexed array.
+
+In this test, we check that the returned value is indeed only the
+first item of the array, as opposed to the generic serialiation
+that will return all elements of the array as a single string."
+  (org-test-with-temp-text
+      (test-ob-shell-multiline-string
+       "#+NAME: sample_array"
+       "| one   |"
+       "| two   |"
+       "| three |"
+       ""
+       "#+begin_src bash :exports results :results output :var array=sample_array"
+       "echo ${array}"
+       "<point>"
+       "#+end_src")
     (should (equal "one" (org-trim (org-babel-execute-src-block))))))
 
 (ert-deftest ob-shell/generic-uses-no-assoc-arrays ()
-- 
2.38.1


[-- Attachment #7: 0006-test-ob-shell.el-Refactor-ob-shell-generic-uses-no-a.patch --]
[-- Type: application/octet-stream, Size: 3296 bytes --]

From 021a950bff733730be99a3a9a124c5e66de66b4e Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Tue, 20 Dec 2022 19:22:40 -0500
Subject: [PATCH 06/20] test-ob-shell.el: Refactor
 ob-shell/generic-uses-no-assoc-arrays

* test-ob-shell.el (ob-shell/generic-uses-no-assoc-arrays): Move
headlines and commentary from `testing/examples/ob-shell-test.org' to
docstring.
(ob-shell/generic-uses-no-assoc-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
(ob-shell/generic-uses-no-assoc-arrays): Split test based on simple
versus complex mapping cases,
`test-ob-shell/generic-uses-no-assoc-arrays-simple-map' and
`test-ob-shell/generic-uses-no-assoc-arrays-3-columns'.  Rename prefix
from "ob-shell" to "test-ob-shell".
---
 testing/lisp/test-ob-shell.el | 53 ++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 14 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 4c70c07fb..5c77b088b 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -115,20 +115,45 @@ that will return all elements of the array as a single string."
        "#+end_src")
     (should (equal "one" (org-trim (org-babel-execute-src-block))))))
 
-(ert-deftest ob-shell/generic-uses-no-assoc-arrays ()
-  "No associative arrays for generic"
-  (should
-   (equal "first one second two third three"
-          (org-test-at-id
-           "bec1a5b0-4619-4450-a8c0-2a746b44bf8d"
-           (org-babel-next-src-block)
-           (org-trim (org-babel-execute-src-block)))))
-  (should
-   (equal "bread 2 kg spaghetti 20 cm milk 50 dl"
-          (org-test-at-id
-           "82320a48-3409-49d7-85c9-5de1c6d3ff87"
-           (org-babel-next-src-block)
-           (org-trim (org-babel-execute-src-block))))))
+(ert-deftest test-ob-shell/generic-uses-no-assoc-arrays-simple-map ()
+  "Generic shell: no special handing for key-value mapping table
+
+No associative arrays for generic.  The shell will see all values
+as a single string."
+  (org-test-with-temp-text
+      (test-ob-shell-multiline-string
+       "#+NAME: sample_mapping_table"
+       "| first  | one   |"
+       "| second | two   |"
+       "| third  | three |"
+       ""
+       "#+begin_src sh :exports results :results output :var table=sample_mapping_table"
+       "echo ${table}"
+       "<point>"
+       "#+end_src")
+    (should
+     (equal "first one second two third three"
+            (org-trim (org-babel-execute-src-block))))))
+
+(ert-deftest test-ob-shell/generic-uses-no-assoc-arrays-3-columns ()
+  "Associative array tests (more than 2 columns)
+
+No associative arrays for generic.  The shell will see all values
+as a single string."
+  (org-test-with-temp-text
+      (test-ob-shell-multiline-string
+       "#+NAME: sample_big_table"
+       "| bread     |  2 | kg |"
+       "| spaghetti | 20 | cm |"
+       "| milk      | 50 | dl |"
+       ""
+       "#+begin_src sh :exports results :results output :var table=sample_big_table"
+       "echo ${table}"
+       "<point>"
+       "#+end_src")
+    (should
+     (equal "bread 2 kg spaghetti 20 cm milk 50 dl"
+            (org-trim (org-babel-execute-src-block))))))
 
 (ert-deftest ob-shell/bash-uses-assoc-arrays ()
   "Bash associative arrays"
-- 
2.38.1


[-- Attachment #8: 0007-test-ob-shell.el-Refactor-ob-shell-bash-uses-assoc-a.patch --]
[-- Type: application/octet-stream, Size: 3158 bytes --]

From 5b24aa18ec1fe8d60968d6530b2373d487bd8e9f Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Wed, 21 Dec 2022 00:45:44 -0500
Subject: [PATCH 07/20] test-ob-shell.el: Refactor
 ob-shell/bash-uses-assoc-arrays

* testing/lisp/test-ob-shell.el (ob-shell/bash-uses-assoc-arrays):
Split test cases into separate tests,
`test-ob-shell/bash-uses-assoc-arrays' and
`test-ob-shell/bash-uses-assoc-arrays-with-lists'.  Rename prefix from
"ob-shell" to "test-ob-shell".
(ob-shell/bash-uses-assoc-arrays): Move comments from
testing/examples/ob-shell-test.org to docstrings.
(ob-shell/bash-uses-assoc-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
---
 testing/lisp/test-ob-shell.el | 51 ++++++++++++++++++++++++++---------
 1 file changed, 38 insertions(+), 13 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 5c77b088b..a1cacdc16 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -155,21 +155,46 @@ as a single string."
      (equal "bread 2 kg spaghetti 20 cm milk 50 dl"
             (org-trim (org-babel-execute-src-block))))))
 
-(ert-deftest ob-shell/bash-uses-assoc-arrays ()
-  "Bash associative arrays"
-  (should
-   (equal "two"
-          (org-test-at-id
-           "bec1a5b0-4619-4450-a8c0-2a746b44bf8d"
-           (org-babel-next-src-block 2)
-           (org-trim (org-babel-execute-src-block)))))
-  ;; Bash associative arrays as strings for the row.
+(ert-deftest test-ob-shell/bash-uses-assoc-arrays ()
+  "Bash shell: support for associative arrays
+
+Bash will see a table that contains the first column as the
+'index' of the associative array, and the second column as the
+value. "
+  (org-test-with-temp-text
+      (test-ob-shell-multiline-string
+       "#+NAME: sample_mapping_table"
+       "| first  | one   |"
+       "| second | two   |"
+       "| third  | three |"
+       ""
+       "#+begin_src bash :exports :results output results :var table=sample_mapping_table"
+       "echo ${table[second]}"
+       "<point>"
+       "#+end_src")
+    (should
+     (equal "two"
+            (org-trim (org-babel-execute-src-block))))))
+
+(ert-deftest test-ob-shell/bash-uses-assoc-arrays-with-lists ()
+  "Bash shell: support for associative arrays with lists
+
+Bash will see an associative array that contains each row as a single
+string. Bash cannot handle lists in associative arrays."
+  (org-test-with-temp-text
+      (test-ob-shell-multiline-string
+       "#+NAME: sample_big_table"
+       "| bread     |  2 | kg |"
+       "| spaghetti | 20 | cm |"
+       "| milk      | 50 | dl |"
+       ""
+       "#+begin_src bash :exports results :results output :var table=sample_big_table"
+       "echo ${table[spaghetti]}"
+       "<point>"
+       "#+end_src")
   (should
    (equal "20 cm"
-          (org-test-at-id
-           "82320a48-3409-49d7-85c9-5de1c6d3ff87"
-           (org-babel-next-src-block 2)
-           (org-trim (org-babel-execute-src-block))))))
+          (org-trim (org-babel-execute-src-block))))))
 
 (ert-deftest ob-shell/simple-list ()
   "Test list variables in shell."
-- 
2.38.1


[-- Attachment #9: 0008-test-ob-shell.el-Refactor-ob-shell-simple-list.patch --]
[-- Type: application/octet-stream, Size: 2151 bytes --]

From c05e7eaace70589546083c84ae78369c613c532d Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Fri, 23 Dec 2022 21:16:42 -0500
Subject: [PATCH 08/20] test-ob-shell.el: Refactor ob-shell/simple-list

* test-ob-shell.el (ob-shell/simple-list): Change test name from
`ob-shell/simple-list' to `test-ob-shell/simple-list'.
(ob-shell/simple-list): Use `test-ob-shell-multiline-string' to write
source block on multiple lines.
---
 testing/lisp/test-ob-shell.el | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index a1cacdc16..085dc694d 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -196,20 +196,27 @@ string. Bash cannot handle lists in associative arrays."
    (equal "20 cm"
           (org-trim (org-babel-execute-src-block))))))
 
-(ert-deftest ob-shell/simple-list ()
-  "Test list variables in shell."
-  ;; With bash, a list is turned into an array.
+(ert-deftest test-ob-shell/simple-list ()
+  "Test list variables."
+  ;; bash: a list is turned into an array
   (should
    (equal "2"
           (org-test-with-temp-text
-           "#+BEGIN_SRC bash :results output :var l='(1 2)\necho ${l[1]}\n#+END_SRC"
+           (test-ob-shell-multiline-string
+            "#+BEGIN_SRC bash :results output :var l='(1 2)"
+            "echo ${l[1]}"
+            "#+END_SRC")
            (org-trim (org-babel-execute-src-block)))))
-  ;; On sh, it is a string containing all values.
+
+  ;; sh: a list is a string containing all values
   (should
    (equal "1 2"
           (org-test-with-temp-text
-           "#+BEGIN_SRC sh :results output :var l='(1 2)\necho ${l}\n#+END_SRC"
-           (org-trim (org-babel-execute-src-block))))))
+              (test-ob-shell-multiline-string
+               "#+BEGIN_SRC sh :results output :var l='(1 2)"
+               "echo ${l}"
+               "#+END_SRC")
+               (org-trim (org-babel-execute-src-block))))))
 
 (ert-deftest ob-shell/remote-with-stdin-or-cmdline ()
   "Test :stdin and :cmdline with a remote directory."
-- 
2.38.1


[-- Attachment #10: 0009-test-ob-shell.el-Refactor-ob-shell-remote-with-stdin.patch --]
[-- Type: application/octet-stream, Size: 1819 bytes --]

From 2178b926cd9b2a3ee01e6fc6d0282372f4ff72bd Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Fri, 23 Dec 2022 21:26:16 -0500
Subject: [PATCH 09/20] test-ob-shell.el: Refactor
 ob-shell/remote-with-stdin-or-cmdline

* test-ob-shell.el (ob-shell/remote-with-stdin-or-cmdline): Change
test name from `ob-shell/remote-with-stdin-or-cmdline' to
`test-ob-shell/remote-with-stdin-or-cmdline'.
(ob-shell/remote-with-stdin-or-cmdline): When test passes, kill buffer
created by test.
---
 testing/lisp/test-ob-shell.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 085dc694d..d32cc9002 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -218,7 +218,7 @@ string. Bash cannot handle lists in associative arrays."
                "#+END_SRC")
                (org-trim (org-babel-execute-src-block))))))
 
-(ert-deftest ob-shell/remote-with-stdin-or-cmdline ()
+(ert-deftest test-ob-shell/remote-with-stdin-or-cmdline ()
   "Test :stdin and :cmdline with a remote directory."
   ;; We assume `default-directory' is a local directory.
   (skip-unless (not (memq system-type '(ms-dos windows-nt))))
@@ -265,7 +265,8 @@ string. Bash cannot handle lists in associative arrays."
                            (org-trim (org-babel-execute-src-block))))
                  (expected (concat "ARGS: --verbose 23 71"
                                    "\nhello tramp from " (file-local-name default-directory))))
-            (should (equal result expected)))))))
+            (if (should (equal result expected))
+                (kill-matching-buffers (format "\\*tramp/mock\\s-%s\\*" system-name) t t)))))))
 
 (ert-deftest ob-shell/results-table ()
   "Test :results table."
-- 
2.38.1


[-- Attachment #11: 0010-test-ob-shell.el-Refactor-ob-shell-results-table.patch --]
[-- Type: application/octet-stream, Size: 1488 bytes --]

From 02f510153a252655da8fe11ab662f59bdf281a21 Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Fri, 23 Dec 2022 22:14:19 -0500
Subject: [PATCH 10/20] test-ob-shell.el: Refactor ob-shell/results-table

* test-ob-shell.el (ob-shell/results-table): Rename
`ob-shell/results-table' to `test-ob-shell/results-table'.
(ob-shell/results-table): Use `test-ob-shell-multiline-string' to
write source block on multiple lines.
---
 testing/lisp/test-ob-shell.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index d32cc9002..87a10eaa3 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -268,12 +268,15 @@ string. Bash cannot handle lists in associative arrays."
             (if (should (equal result expected))
                 (kill-matching-buffers (format "\\*tramp/mock\\s-%s\\*" system-name) t t)))))))
 
-(ert-deftest ob-shell/results-table ()
+(ert-deftest test-ob-shell/results-table ()
   "Test :results table."
   (should
    (equal '(("I \"want\" it all"))
           (org-test-with-temp-text
-              "#+BEGIN_SRC sh :results table\necho 'I \"want\" it all'\n#+END_SRC"
+              (test-ob-shell-multiline-string
+              "#+BEGIN_SRC sh :results table"
+              "echo 'I \"want\" it all'"
+              "#+END_SRC")
             (org-babel-execute-src-block)))))
 
 (ert-deftest ob-shell/results-list ()
-- 
2.38.1


[-- Attachment #12: 0011-test-ob-shell.el-Refactor-ob-shell-results-list.patch --]
[-- Type: application/octet-stream, Size: 1323 bytes --]

From eef3d9ade6171c5469a366e4dffee0c63c949458 Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Fri, 23 Dec 2022 22:34:12 -0500
Subject: [PATCH 11/20] test-ob-shell.el: Refactor ob-shell/results-list

* test-ob-shell.el (ob-shell/results-list): Rename
`ob-shell/results-list' to `test-ob-shell/results-list'.
(ob-shell/results-list): Use `test-ob-shell-multiline-string' to write
source block on multiple lines.
---
 testing/lisp/test-ob-shell.el | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 87a10eaa3..93f4c45af 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -279,10 +279,15 @@ string. Bash cannot handle lists in associative arrays."
               "#+END_SRC")
             (org-babel-execute-src-block)))))
 
-(ert-deftest ob-shell/results-list ()
+(ert-deftest test-ob-shell/results-list ()
   "Test :results list."
   (org-test-with-temp-text
-      "#+BEGIN_SRC sh :results list\necho 1\necho 2\necho 3\n#+END_SRC"
+      (test-ob-shell-multiline-string
+      "#+BEGIN_SRC sh :results list"
+      "echo 1"
+      "echo 2"
+      "echo 3"
+      "#+END_SRC")
     (should
      (equal '((1) (2) (3))
             (org-babel-execute-src-block)))
-- 
2.38.1


[-- Attachment #13: 0012-test-ob-shell.el-Refactor-ob-shell-standard-output-a.patch --]
[-- Type: application/octet-stream, Size: 1013 bytes --]

From 49378281e970d434d004c9e0ebc21f57dd0c3f56 Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Fri, 23 Dec 2022 22:36:51 -0500
Subject: [PATCH 12/20] test-ob-shell.el: Refactor
 ob-shell/standard-output-after-success

* test-ob-shell.el (ob-shell/standard-output-after-success): Rename
`ob-shell/standard-output-after-success' to
`test-ob-shell/standard-output-after-success'.
---
 testing/lisp/test-ob-shell.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 93f4c45af..a3b2e9ee0 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -300,7 +300,7 @@ string. Bash cannot handle lists in associative arrays."
 
 ;;; Standard output
 
-(ert-deftest ob-shell/standard-output-after-success ()
+(ert-deftest test-ob-shell/standard-output-after-success ()
   "Test standard output after exiting with a zero code."
   (should (= 1
              (org-babel-execute:sh
-- 
2.38.1


[-- Attachment #14: 0013-test-ob-shell.el-Refactor-ob-shell-standard-output-a.patch --]
[-- Type: application/octet-stream, Size: 1383 bytes --]

From ec9ae8226a895b1aecbb9037456b52649295563a Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Fri, 23 Dec 2022 22:38:00 -0500
Subject: [PATCH 13/20] test-ob-shell.el: Refactor
 ob-shell/standard-output-after-failure

* test-ob-shell.el (ob-shell/standard-output-after-failure): Rename
`ob-shell/standard-output-after-failure' to
`test-ob-shell/standard-output-after-failure'.
(ob-shell/standard-output-after-failure): On pass, kill buffer created
during test.
---
 testing/lisp/test-ob-shell.el | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index a3b2e9ee0..1742cf16f 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -306,11 +306,13 @@ string. Bash cannot handle lists in associative arrays."
              (org-babel-execute:sh
               "echo 1" nil))))
 
-(ert-deftest ob-shell/standard-output-after-failure ()
+(ert-deftest test-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))))
+  (if
+      (should (= 1
+                 (org-babel-execute:sh
+                  "echo 1; exit 2" nil)))
+      (kill-buffer "*Org-Babel Error Output*")))
 
 ;;; Standard error
 
-- 
2.38.1


[-- Attachment #15: 0014-test-ob-shell.el-Refactor-ob-shell-error-output-afte.patch --]
[-- Type: application/octet-stream, Size: 1087 bytes --]

From 0e643556f41e1a14b77d9973b2e1034fd5f22da8 Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Fri, 23 Dec 2022 22:39:11 -0500
Subject: [PATCH 14/20] test-ob-shell.el: Refactor
 ob-shell/error-output-after-success

* test-ob-shell.el (ob-shell/error-output-after-success): Rename
`ob-shell/error-output-after-success' to
`test-ob-shell/error-output-after-success'.
(ob-shell/error-output-after-success): On pass, kill buffer created by
test.
---
 testing/lisp/test-ob-shell.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 1742cf16f..9d0dea537 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -316,7 +316,7 @@ string. Bash cannot handle lists in associative arrays."
 
 ;;; Standard error
 
-(ert-deftest ob-shell/error-output-after-success ()
+(ert-deftest test-ob-shell/error-output-after-success ()
   "Test that standard error shows in the error buffer, alongside the
 exit code, after exiting with a zero code."
   (should
-- 
2.38.1


[-- Attachment #16: 0015-test-ob-shell.el-Refactor-ob-shell-error-output-afte.patch --]
[-- Type: application/octet-stream, Size: 2766 bytes --]

From 0b72f870ec8f079ab5f00d02f7768797e57a40b8 Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Fri, 23 Dec 2022 22:53:33 -0500
Subject: [PATCH 15/20] test-ob-shell.el: Refactor
 ob-shell/error-output-after-failure

* test-ob-shell.el (ob-shell/error-output-after-failure): Rename
`ob-shell/error-output-after-failure' to
`test-ob-shell/error-output-after-failure'.
(ob-shell/error-output-after-failure): On pass, kill buffer created by
test.
---
 testing/lisp/test-ob-shell.el | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 9d0dea537..9ba09908b 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -319,26 +319,30 @@ string. Bash cannot handle lists in associative arrays."
 (ert-deftest test-ob-shell/error-output-after-success ()
   "Test that standard error shows in the error buffer, alongside the
 exit code, after exiting with a zero code."
-  (should
-   (string= "1
+  (if
+      (should
+       (string= "1
 [ Babel evaluation exited with code 0 ]"
-            (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))))))
+                (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)))))
+      (kill-buffer "*Org-Babel Error Output*")))
 
-(ert-deftest ob-shell/error-output-after-failure ()
+(ert-deftest test-ob-shell/error-output-after-failure ()
   "Test that standard error shows in the error buffer, alongside the
 exit code, after exiting with a non-zero code."
-  (should
-   (string= "1
+  (if
+      (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))))))
+                (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)))))
+      (kill-buffer "*Org-Babel Error Output*")))
 
 (ert-deftest ob-shell/error-output-after-failure-multiple ()
   "Test that multiple standard error strings show in the error
-- 
2.38.1


[-- Attachment #17: 0016-test-ob-shell.el-Refactor-ob-shell-error-output-afte.patch --]
[-- Type: application/octet-stream, Size: 2163 bytes --]

From f2f56a6919d877e36d95ab33dce3b1fcd1e9bcf9 Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Fri, 23 Dec 2022 22:55:34 -0500
Subject: [PATCH 16/20] test-ob-shell.el: Refactor
 ob-shell/error-output-after-failure-multiple

* test-ob-shell.el (ob-shell/error-output-after-failure-multiple):
Rename `ob-shell/error-output-after-failure-multiple' to
`test-ob-shell/error-output-after-failure-multiple'.
(ob-shell/error-output-after-failure-multiple): On pass, kill buffer
created by test.
---
 testing/lisp/test-ob-shell.el | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 9ba09908b..fb58e70e1 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -344,21 +344,23 @@ exit code, after exiting with a non-zero code."
                          (buffer-string)))))
       (kill-buffer "*Org-Babel Error Output*")))
 
-(ert-deftest ob-shell/error-output-after-failure-multiple ()
+(ert-deftest test-ob-shell/error-output-after-failure-multiple ()
   "Test that multiple standard error strings show in the error
 buffer, alongside multiple exit codes."
-  (should
-   (string= "1
+  (if
+      (should
+       (string= "1
 [ Babel evaluation exited with code 2 ]
 3
 [ Babel evaluation exited with code 4 ]"
-            (progn (org-babel-eval-wipe-error-buffer)
-                   (org-babel-execute:sh
-                    "echo 1 >&2; exit 2" nil)
-                   (org-babel-execute:sh
-                    "echo 3 >&2; exit 4" nil)
-                   (with-current-buffer org-babel-error-buffer-name
-                     (buffer-string))))))
+                (progn (org-babel-eval-wipe-error-buffer)
+                       (org-babel-execute:sh
+                        "echo 1 >&2; exit 2" nil)
+                       (org-babel-execute:sh
+                        "echo 3 >&2; exit 4" nil)
+                       (with-current-buffer org-babel-error-buffer-name
+                         (buffer-string)))))
+      (kill-buffer "*Org-Babel Error Output*")))
 
 ;;; Exit codes
 
-- 
2.38.1


[-- Attachment #18: 0017-test-ob-shell.el-Refactor-ob-shell-exit-code.patch --]
[-- Type: application/octet-stream, Size: 1757 bytes --]

From a02faa555d218ff6c042eb6590b106deedd77ecb Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Fri, 23 Dec 2022 22:57:12 -0500
Subject: [PATCH 17/20] test-ob-shell.el: Refactor ob-shell/exit-code

* test-ob-shell.el (ob-shell/exit-code): Rename `ob-shell/exit-code'
to `test-ob-shell/exit-code'.
(ob-shell/exit-code): On pass, kill buffer created by test.
---
 testing/lisp/test-ob-shell.el | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index fb58e70e1..be9d1488d 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -364,16 +364,18 @@ buffer, alongside multiple exit codes."
 
 ;;; Exit codes
 
-(ert-deftest ob-shell/exit-code ()
+(ert-deftest test-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))))))
+  (if
+      (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)))))
+      (kill-buffer "*Org-Babel Error Output*")))
 
 (ert-deftest ob-shell/exit-code-multiple ()
   "Test that multiple exit codes show in the error buffer after
-- 
2.38.1


[-- Attachment #19: 0018-test-ob-shell.el-Refactor-ob-shell-exit-code-multipl.patch --]
[-- Type: application/octet-stream, Size: 2033 bytes --]

From b879fceda8e211bf4a0930474f36a8e48d935191 Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Fri, 23 Dec 2022 22:58:50 -0500
Subject: [PATCH 18/20] test-ob-shell.el: Refactor ob-shell/exit-code-multiple

* test-ob-shell.el (ob-shell/exit-code-multiple): Rename
`ob-shell/exit-code-multiple' to `test-ob-shell/exit-code-multiple'.
(ob-shell/exit-code-multiple): On pass, kill buffer created by test.
---
 testing/lisp/test-ob-shell.el | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index be9d1488d..e4a9849c6 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -377,19 +377,21 @@ with a non-zero return code."
                          (buffer-string)))))
       (kill-buffer "*Org-Babel Error Output*")))
 
-(ert-deftest ob-shell/exit-code-multiple ()
+(ert-deftest test-ob-shell/exit-code-multiple ()
   "Test that multiple exit codes show in the error buffer after
 exiting with a non-zero return code multiple times."
-  (should
-   (string= "[ Babel evaluation exited with code 1 ]
+  (if
+      (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))))))
+                (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)))))
+      (kill-buffer "*Org-Babel Error Output*")))
 
 (provide 'test-ob-shell)
 
-- 
2.38.1


[-- Attachment #20: 0019-ob-shell-test.org-Remove-ob-shell-test.org.patch --]
[-- Type: application/octet-stream, Size: 3138 bytes --]

From 07a74181f5cf0f90eaea3abd296a5cf7254b3454 Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Sat, 24 Dec 2022 11:29:06 -0500
Subject: [PATCH 19/20] ob-shell-test.org: Remove ob-shell-test.org

* testing/examples/ob-shell-test.org: Delete file

File was used by test-ob-shell.el to test ob-shell.el.  Tests have
been updated to use temporary buffers, rendering ob-shell-test.org
unnecessary.
---
 testing/examples/ob-shell-test.org | 88 ------------------------------
 1 file changed, 88 deletions(-)
 delete mode 100644 testing/examples/ob-shell-test.org

diff --git a/testing/examples/ob-shell-test.org b/testing/examples/ob-shell-test.org
deleted file mode 100644
index 2510f4f96..000000000
--- a/testing/examples/ob-shell-test.org
+++ /dev/null
@@ -1,88 +0,0 @@
-#+Title: a collection of examples for ob-shell tests
-#+OPTIONS: ^:nil
-
-* Sample data structures
-#+NAME: sample_array
-| one   |
-| two   |
-| three |
-
-#+NAME: sample_mapping_table
-| first  | one   |
-| second | two   |
-| third  | three |
-
-#+NAME: sample_big_table
-| bread     |  2 | kg |
-| spaghetti | 20 | cm |
-| milk      | 50 | dl |
-
-* Array tests
-  :PROPERTIES:
-  :ID:       0ba56632-8dc1-405c-a083-c204bae477cf
-  :END:
-** Generic shell: no arrays
-#+begin_src sh :exports results :results output :var array=sample_array
-echo ${array}
-#+end_src
-
-#+RESULTS:
-: one two three
-
-** Bash shell: support for arrays
-Bash will see a simple indexed array. In this test, we check that the
-returned value is indeed only the first item of the array, as opposed to
-the generic serialiation that will return all elements of the array as 
-a single string.
-#+begin_src bash :exports results :results output :var array=sample_array
-echo ${array}
-#+end_src
-
-#+RESULTS:
-: one
-
-* Associative array tests (simple map)
-  :PROPERTIES:
-  :ID:       bec1a5b0-4619-4450-a8c0-2a746b44bf8d
-  :END:
-** Generic shell: no special handing
-The shell will see all values as a single string.
-#+begin_src sh :exports results :results output :var table=sample_mapping_table
-echo ${table}
-#+end_src
-
-#+RESULTS:
-: first one second two third three
-
-** Bash shell: support for associative arrays
-Bash will see a table that contains the first column as the 'index'
-of the associative array, and the second column as the value.
-#+begin_src bash :exports :results output results :var table=sample_mapping_table
-echo ${table[second]}
-#+end_src
-
-#+RESULTS:
-: two
-
-* Associative array tests (more than 2 columns)
-  :PROPERTIES:
-  :ID:       82320a48-3409-49d7-85c9-5de1c6d3ff87
-  :END:
-** Generic shell: no special handing
-#+begin_src sh :exports results :results output :var table=sample_big_table
-echo ${table}
-#+end_src
-
-#+RESULTS:
-: bread 2 kg spaghetti 20 cm milk 50 dl
-   
-** Bash shell: support for associative arrays with lists
-Bash will see an associative array that contains each row as a single
-string. Bash cannot handle lists in associative arrays.
-#+begin_src bash :exports results :results output :var table=sample_big_table
-echo ${table[spaghetti]}
-#+end_src
-
-#+RESULTS:
-: 20 cm
-
-- 
2.38.1


[-- Attachment #21: 0020-test-ob-shell.el-Organize-tests.patch --]
[-- Type: application/octet-stream, Size: 2423 bytes --]

From 9f352bbbfc4b49d3acd690328a8e43ba134baa83 Mon Sep 17 00:00:00 2001
From: Matt Trzcinski <matt@excalamus.com>
Date: Sun, 25 Dec 2022 23:25:21 -0500
Subject: [PATCH 20/20] test-ob-shell.el: Organize tests

* testing/lisp/test-ob-shell.el:

  - Provide instructions for running tests
  - Require `org-test' explicitly
  - Group tests into sections
  - Insert `page-delimiter's between sections
---
 testing/lisp/test-ob-shell.el | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index e4a9849c6..08bf40553 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -18,17 +18,26 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
+\f
 ;;; Comment:
 
+;; To run tests, load this file and then call (ert "test-ob-shell").
+;; See README for other ways to run tests.
+
+\f
 ;;; Requirements:
-(org-test-for-executable "sh")
 
+(require 'org-test (expand-file-name "../org-test.el"))
 (require 'ob-core)
 
 (unless (featurep 'ob-shell)
   (signal 'missing-test-dependency "Support for Shell code blocks"))
 
+(org-test-for-executable "sh")
+
+\f
 ;;; Code:
+
 (defun test-ob-shell-multiline-string (&rest strings)
   "Join STRINGS with newlines.
 
@@ -43,6 +52,9 @@ Each expression of STRINGS should evaluate to a string.
 \(fn STRINGS)"
   (string-join strings "\n"))
 
+\f
+;;; Results
+
 (ert-deftest test-ob-shell/dont-insert-spaces-on-expanded-bodies ()
   "Expanded shell bodies should not start with a blank line unless
 the strings of the tangled block does."
@@ -298,6 +310,7 @@ string. Bash cannot handle lists in associative arrays."
       "- 1\n- 2\n- 3\n"
       (buffer-substring-no-properties (point) (point-max))))))
 
+\f
 ;;; Standard output
 
 (ert-deftest test-ob-shell/standard-output-after-success ()
@@ -314,6 +327,7 @@ string. Bash cannot handle lists in associative arrays."
                   "echo 1; exit 2" nil)))
       (kill-buffer "*Org-Babel Error Output*")))
 
+\f
 ;;; Standard error
 
 (ert-deftest test-ob-shell/error-output-after-success ()
@@ -362,6 +376,7 @@ buffer, alongside multiple exit codes."
                          (buffer-string)))))
       (kill-buffer "*Org-Babel Error Output*")))
 
+\f
 ;;; Exit codes
 
 (ert-deftest test-ob-shell/exit-code ()
-- 
2.38.1


  reply	other threads:[~2022-12-27 20:49 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-16 16:22 Bash results broken? Rudolf Adamkovič
2022-12-16 17:41 ` Ihor Radchenko
2022-12-18 11:19   ` Ihor Radchenko
2022-12-20  0:44     ` Rudolf Adamkovič
2022-12-20  3:40       ` Matt
2022-12-25 11:23         ` Ihor Radchenko
2022-12-26  2:25           ` Matt
2022-12-26  9:26             ` Ihor Radchenko
2022-12-21  6:17   ` ob-shell intentions and paperwork (was Bash results broken?) Matt
2022-12-27 20:48     ` Matt [this message]
2022-12-29 11:08       ` Ihor Radchenko
2022-12-29 14:20         ` Bastien Guerry
2022-12-30  5:34         ` Matt
2022-12-30  8:06           ` Bastien Guerry
2022-12-30 18:46           ` Matt
2022-12-31 14:31             ` Ihor Radchenko
2023-01-01 23:55               ` Matt
2023-01-02  9:47                 ` Ihor Radchenko
2023-01-02 16:40                   ` Matt
2023-01-03 10:50                     ` Ihor Radchenko
2023-01-03 13:00                       ` Matt
2023-01-05 10:31                         ` Ihor Radchenko
2023-01-05 11:21                           ` Bastien Guerry
2023-01-10  2:31                             ` Matt
2023-01-11 11:53                               ` Ihor Radchenko
2023-01-11 16:18                                 ` Matt
2023-01-11 17:02                                   ` Ihor Radchenko
2023-01-11 19:34                                     ` Matt
2023-01-12  8:26                                       ` Ihor Radchenko
2023-01-12 14:43                                     ` Max Nikulin
2023-01-13  9:36                                       ` Ihor Radchenko
2023-01-13 15:18                                         ` Matt
2023-01-13 15:23                                           ` Ihor Radchenko
2023-01-14  7:41                                             ` Max Nikulin
2023-01-14 10:35                                               ` Ihor Radchenko
2023-01-14 15:09                                                 ` cgit and merge commit Max Nikulin
2023-01-24 20:16                                                   ` Ihor Radchenko
2022-12-31 12:56           ` ob-shell intentions and paperwork (was Bash results broken?) Ihor Radchenko
2023-01-02  4:40             ` Refactor org-babel-shell-initialize? (was Re: ob-shell intentions and paperwork (was Bash results broken?)) Matt
2023-01-03  9:29               ` Ihor Radchenko
2023-01-05  8:32                 ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=18555580d75.d7b471f9370716.1497263973038999899@excalamus.com \
    --to=matt@excalamus.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).