Explorar o código

ob-sh: no longer fails on empty results

* lisp/ob-sh.el (org-babel-sh-evaluate): no longer assumes that
  results are non-nil
Eric Schulte %!s(int64=14) %!d(string=hai) anos
pai
achega
c9b017632e
Modificáronse 2 ficheiros con 12 adicións e 6 borrados
  1. 7 6
      lisp/ob-sh.el
  2. 5 0
      testing/lisp/test-ob-sh.el

+ 7 - 6
lisp/ob-sh.el

@@ -152,12 +152,13 @@ If RESULT-TYPE equals 'output then return a list of the outputs
 of the statements in BODY, if RESULT-TYPE equals 'value then
 return the value of the last statement in BODY."
   ((lambda (results)
-     (if (or (member "scalar" result-params)
-	     (member "output" result-params))
-	 results
-       (let ((tmp-file (org-babel-temp-file "sh-")))
-	 (with-temp-file tmp-file (insert results))
-	 (org-babel-import-elisp-from-file tmp-file))))
+     (when results
+       (if (or (member "scalar" result-params)
+	       (member "output" result-params))
+	   results
+	 (let ((tmp-file (org-babel-temp-file "sh-")))
+	   (with-temp-file tmp-file (insert results))
+	   (org-babel-import-elisp-from-file tmp-file)))))
    (if (not session)
        (org-babel-eval org-babel-sh-command (org-babel-trim body))
      (mapconcat

+ 5 - 0
testing/lisp/test-ob-sh.el

@@ -29,6 +29,11 @@ unless the body of the tangled block does."
   (should (string-match "^[\n\r][\t ]*[\n\r]"
 			(org-babel-expand-body:sh "\n\necho 2" '()))))
 
+(ert-deftest test-ob-sh/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))))
+
 (provide 'test-ob-sh)
 
 ;;; test-ob-sh.el ends here