Forráskód Böngészése

ob-shell: Fix handling list variables

* lisp/ob-shell.el (org-babel--variable-assignments:bash): Do not
  error when value is a list.

* testing/lisp/test-ob-shell.el (ob-shell/simple-list): New test.

Reported-by: Keith Amidon <camalot@picnicpark.org>
<http://permalink.gmane.org/gmane.emacs.orgmode/113920>
Nicolas Goaziou 7 éve
szülő
commit
b8df40eccc
2 módosított fájl, 21 hozzáadás és 5 törlés
  1. 7 5
      lisp/ob-shell.el
  2. 14 0
      testing/lisp/test-ob-shell.el

+ 7 - 5
lisp/ob-shell.el

@@ -140,11 +140,13 @@ This function is called by `org-babel-execute-src-block'."
 
 (defun org-babel--variable-assignments:bash (varname values &optional sep hline)
   "Represents the parameters as useful Bash shell variables."
-  (if (listp values)
-      (if (and (listp (car values)) (= 1 (length (car values))))
-	  (org-babel--variable-assignments:bash_array varname values sep hline)
-	(org-babel--variable-assignments:bash_assoc varname values sep hline))
-    (org-babel--variable-assignments:sh-generic varname values sep hline)))
+  (pcase values
+    (`((,_ ,_ . ,_) . ,_)		;two-dimensional array
+     (org-babel--variable-assignments:bash_assoc varname values sep hline))
+    (`(,_ . ,_)				;simple list
+     (org-babel--variable-assignments:bash_array varname values sep hline))
+    (_					;scalar value
+     (org-babel--variable-assignments:sh-generic varname values sep hline))))
 
 (defun org-babel-variable-assignments:shell (params)
   "Return list of shell statements assigning the block's variables."

+ 14 - 0
testing/lisp/test-ob-shell.el

@@ -86,6 +86,20 @@ ob-comint.el, which was not previously tested."
     (org-babel-next-src-block 2)
     (should (equal "20 cm" (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
+   (= 2
+      (org-test-with-temp-text
+	  "#+BEGIN_SRC bash :var l='(1 2)\necho ${l[1]}\n#+END_SRC"
+	(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 :var l='(1 2)\necho ${l}\n#+END_SRC"
+	    (org-babel-execute-src-block)))))
 
 (provide 'test-ob-shell)