summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-06-10 00:06:24 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-06-10 00:06:24 +0200
commitb8df40eccc6ce19455f2bdce50f6d6f3f913d544 (patch)
treef54b663095965af605bc8efa24d8115dbba075b1
parent7cd7b90dcb7ef87f1eb63d93ab725407e92f9979 (diff)
downloadorg-mode-b8df40eccc6ce19455f2bdce50f6d6f3f913d544.tar.gz
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>
-rw-r--r--lisp/ob-shell.el12
-rw-r--r--testing/lisp/test-ob-shell.el14
2 files changed, 21 insertions, 5 deletions
diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index 9c22af8..3787c26 100644
--- a/lisp/ob-shell.el
+++ b/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."
diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index ae2c290..61de9ac 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/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)