Merge branch 'maint'

This commit is contained in:
Nicolas Goaziou 2017-06-10 00:14:30 +02:00
commit 8ebfbc1d2a
2 changed files with 21 additions and 5 deletions

View File

@ -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."

View File

@ -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)