test-ob-clojure.el 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ;;; test-ob-clojure.el -*- lexical-binding: t; -*-
  2. ;; Copyright (c) 2018-2022 Free Software Foundation, Inc.
  3. ;; Authors: stardiviner
  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 <https://www.gnu.org/licenses/>.
  15. ;;; Comments:
  16. ;; Org tests for ob-clojure.el live here
  17. ;;; Code:
  18. (org-test-for-executable "cider")
  19. (unless (featurep 'cider)
  20. (signal 'missing-test-dependency "CIDER"))
  21. (unless (featurep 'ob-clojure)
  22. (signal 'missing-test-dependency "Support for Clojure code blocks"))
  23. (ert-deftest ob-clojure/simple-session ()
  24. (org-test-with-temp-text
  25. "#+begin_src clojure :session
  26. (print \"hello, world\")
  27. #+end_src
  28. "
  29. (should (string= "hello, world" (org-babel-execute-src-block)))))
  30. (ert-deftest ob-clojure/initiate-session ()
  31. (org-test-with-temp-text
  32. "#+begin_src clojure :session :var a=1 :results output
  33. (print \"hello, world\")
  34. #+end_src
  35. #+begin_src clojure :session :results output
  36. (print a)
  37. #+end_src"
  38. (goto-char (point-min))
  39. (org-babel-switch-to-session)
  40. (sleep-for 2)
  41. (org-babel-execute-maybe)
  42. (org-babel-next-src-block)
  43. (goto-char (org-babel-result-end))
  44. (forward-line 2)
  45. (should (string=
  46. ": 1"
  47. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
  48. (ert-deftest ob-clojure/initiate-session-with-var ()
  49. (org-test-with-temp-text
  50. "#+begin_src clojure :session :var a=1 :results output
  51. (print a)
  52. #+end_src"
  53. (org-babel-next-src-block)
  54. (org-babel-initiate-session)
  55. (sleep-for 2)
  56. (org-babel-execute-maybe)
  57. (goto-char (org-babel-result-end))
  58. (forward-line 2)
  59. (should (string=
  60. ": 1"
  61. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
  62. (ert-deftest ob-clojure/tangle-without-ns ()
  63. (org-test-with-temp-text
  64. "#+begin_src clojure :tangle /tmp/test.clj
  65. (print 1)
  66. #+end_src"
  67. (org-babel-next-src-block)
  68. (org-babel-tangle)
  69. (should
  70. (string=
  71. "(print 1)
  72. "
  73. (with-temp-buffer
  74. (insert-file-contents "/tmp/test.clj")
  75. (buffer-substring-no-properties (point-min) (point-max)))))))
  76. (provide 'test-ob-clojure)
  77. ;;; test-ob-clojure.el ends here