test-ob-shell.el 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ;;; test-ob-shell.el
  2. ;; Copyright (c) 2010-2014 Eric Schulte
  3. ;; Authors: Eric Schulte
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Comment:
  16. ;; Template test file for Org-mode tests
  17. ;;; Code:
  18. (org-test-for-executable "sh")
  19. (unless (featurep 'ob-shell)
  20. (signal 'missing-test-dependency "Support for Shell code blocks"))
  21. (ert-deftest test-ob-shell/dont-insert-spaces-on-expanded-bodies ()
  22. "Expanded shell bodies should not start with a blank line
  23. unless the body of the tangled block does."
  24. (should-not (string-match "^[\n\r][\t ]*[\n\r]"
  25. (org-babel-expand-body:generic "echo 2" '())))
  26. (should (string-match "^[\n\r][\t ]*[\n\r]"
  27. (org-babel-expand-body:generic "\n\necho 2" '()))))
  28. (ert-deftest test-ob-shell/dont-error-on-empty-results ()
  29. "Was throwing an elisp error when shell blocks threw errors and
  30. returned empty results."
  31. (should (null (org-babel-execute:sh "ls NoSuchFileOrDirectory.txt" nil))))
  32. (ert-deftest test-ob-shell/session ()
  33. "This also tests `org-babel-comint-with-output' in
  34. ob-comint.el, which was not previously tested."
  35. (let ((res (org-babel-execute:sh "echo 1; echo 2" '((:session . "yes")))))
  36. (should res)
  37. (should (listp res))))
  38. ; A list of tests using the samples in ob-shell-test.org
  39. (ert-deftest ob-shell/generic-uses-no-arrays ()
  40. "No arrays for generic"
  41. (org-test-at-id "0ba56632-8dc1-405c-a083-c204bae477cf"
  42. (org-babel-next-src-block)
  43. (should (equal "one two three" (org-babel-execute-src-block)))))
  44. (ert-deftest ob-shell/bash-uses-arrays ()
  45. "Bash arrays"
  46. (org-test-at-id "0ba56632-8dc1-405c-a083-c204bae477cf"
  47. (org-babel-next-src-block 2)
  48. (should (equal "one" (org-babel-execute-src-block)))))
  49. (ert-deftest ob-shell/generic-uses-no-assoc-arrays ()
  50. "No associative arrays for generic"
  51. (org-test-at-id "bec1a5b0-4619-4450-a8c0-2a746b44bf8d"
  52. (org-babel-next-src-block)
  53. (should (equal "first one second two third three"
  54. (org-babel-execute-src-block)))))
  55. (ert-deftest ob-shell/bash-uses-assoc-arrays ()
  56. "Bash associative arrays"
  57. (org-test-at-id "bec1a5b0-4619-4450-a8c0-2a746b44bf8d"
  58. (org-babel-next-src-block 2)
  59. (should (equal "two" (org-babel-execute-src-block)))))
  60. (ert-deftest ob-shell/generic-uses-no-assoc-arrays ()
  61. "No associative arrays for generic"
  62. (org-test-at-id "82320a48-3409-49d7-85c9-5de1c6d3ff87"
  63. (org-babel-next-src-block)
  64. (should (equal "bread 2 kg spaghetti 20 cm milk 50 dl"
  65. (org-babel-execute-src-block)))))
  66. (ert-deftest ob-shell/bash-uses-assoc-arrays ()
  67. "Bash associative arrays as strings for the row"
  68. (org-test-at-id "82320a48-3409-49d7-85c9-5de1c6d3ff87"
  69. (org-babel-next-src-block 2)
  70. (should (equal "20 cm" (org-babel-execute-src-block)))))
  71. (provide 'test-ob-shell)
  72. ;;; test-ob-shell.el ends here