test-ob-lob.el 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. ;;; test-ob-lob.el --- test for ob-lob.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. ;;; Tests
  16. (org-babel-lob-ingest
  17. (expand-file-name
  18. "library-of-babel.org"
  19. (expand-file-name
  20. "doc"
  21. (expand-file-name
  22. ".."
  23. (expand-file-name
  24. ".."
  25. (file-name-directory
  26. (or load-file-name buffer-file-name)))))))
  27. (ert-deftest test-ob-lob/ingest ()
  28. "Test the ingestion of an org-mode file."
  29. (should (< 0 (org-babel-lob-ingest
  30. (expand-file-name "babel.org" org-test-example-dir)))))
  31. (ert-deftest test-ob-lob/call-with-header-arguments ()
  32. "Test the evaluation of a library of babel #+call: line."
  33. (org-test-at-id "fab7e291-fde6-45fc-bf6e-a485b8bca2f0"
  34. (move-beginning-of-line 1)
  35. (forward-line 6)
  36. (message (buffer-substring (point-at-bol) (point-at-eol)))
  37. (should (string= "testing" (org-babel-lob-execute
  38. (org-babel-lob-get-info))))
  39. (forward-line 1)
  40. (should (string= "testing" (caar (org-babel-lob-execute
  41. (org-babel-lob-get-info)))))
  42. (forward-line 1)
  43. (should (string= "testing" (org-babel-lob-execute
  44. (org-babel-lob-get-info))))
  45. (forward-line 1)
  46. (should (string= "testing" (caar (org-babel-lob-execute
  47. (org-babel-lob-get-info)))))
  48. (forward-line 1)
  49. (should (string= "testing" (org-babel-lob-execute
  50. (org-babel-lob-get-info))))
  51. (forward-line 1)
  52. (should (string= "testing" (caar (org-babel-lob-execute
  53. (org-babel-lob-get-info)))))
  54. (forward-line 1) (beginning-of-line) (forward-char 27)
  55. (should (string= "testing" (org-babel-lob-execute
  56. (org-babel-lob-get-info))))
  57. (forward-line 1) (beginning-of-line) (forward-char 27)
  58. (should (string= "testing" (caar (org-babel-lob-execute
  59. (org-babel-lob-get-info)))))
  60. (forward-line 1) (beginning-of-line)
  61. (should (= 4 (org-babel-lob-execute (org-babel-lob-get-info))))
  62. (forward-line 1)
  63. (should (string= "testing" (org-babel-lob-execute
  64. (org-babel-lob-get-info))))
  65. (forward-line 1)
  66. (should (string= "123" (org-babel-lob-execute (org-babel-lob-get-info))))))
  67. (ert-deftest test-ob-lob/export-lob-lines ()
  68. "Test the export of a variety of library babel call lines."
  69. (org-test-at-id "72ddeed3-2d17-4c7f-8192-a575d535d3fc"
  70. (org-narrow-to-subtree)
  71. (let ((buf (current-buffer))
  72. (string (buffer-string)))
  73. (with-temp-buffer
  74. (org-mode)
  75. (insert string)
  76. (org-babel-exp-process-buffer buf)
  77. (message (buffer-string))
  78. (goto-char (point-min))
  79. (should (re-search-forward "^: 0" nil t))
  80. (should (re-search-forward "call =2= stuck" nil t))
  81. (should (re-search-forward
  82. "exported =call_double(it=2)= because" nil t))
  83. (should (re-search-forward "^=6= because" nil t))
  84. (should (re-search-forward "results 8 should" nil t))
  85. (should (re-search-forward "following 2\\*5==10= should" nil t))))))
  86. (ert-deftest test-ob-lob/do-not-eval-lob-lines-in-example-blocks-on-export ()
  87. (require 'ox)
  88. (org-test-with-temp-text-in-file "
  89. for export
  90. #+begin_example
  91. #+call: rubbish()
  92. #+end_example"
  93. (should (progn (org-export-execute-babel-code) t))))
  94. (ert-deftest test-ob-lob/caching-call-line ()
  95. (let ((temporary-value-for-test 0))
  96. (org-test-with-temp-text "
  97. #+name: call-line-caching-example
  98. #+begin_src emacs-lisp :var bar=\"baz\"
  99. (setq temporary-value-for-test (+ 1 temporary-value-for-test))
  100. #+end_src
  101. #+call: call-line-caching-example(\"qux\") :cache yes
  102. "
  103. (goto-char (point-max)) (forward-line -1)
  104. ;; first execution should flip value to t
  105. (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) 1))
  106. ;; if cached, second evaluation will retain the t value
  107. ;;
  108. ;; Note: This instance tests for equality with "1". We would
  109. ;; prefer if the cached result returned was actually 1, however
  110. ;; this is not the current behavior so this test is encoding
  111. ;; undesired behavior (because the current goal is simply to see
  112. ;; that caching is used on call lines).
  113. ;;
  114. (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) "1")))))
  115. (ert-deftest test-ob-lob/named-caching-call-line ()
  116. (let ((temporary-value-for-test 0))
  117. (org-test-with-temp-text "
  118. #+name: call-line-caching-example
  119. #+begin_src emacs-lisp :var bar=\"baz\"
  120. (setq temporary-value-for-test (+ 1 temporary-value-for-test))
  121. #+end_src
  122. #+name: call-line-caching-called
  123. #+call: call-line-caching-example(\"qux\") :cache yes
  124. "
  125. (goto-char (point-max)) (forward-line -1)
  126. ;; first execution should flip value to t
  127. (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) 1))
  128. ;; if cached, second evaluation will retain the t value
  129. ;;
  130. ;; Note: This instance tests for equality with "1". We would
  131. ;; prefer if the cached result returned was actually 1, however
  132. ;; this is not the current behavior so this test is encoding
  133. ;; undesired behavior (because the current goal is simply to see
  134. ;; that caching is used on call lines).
  135. ;;
  136. (should (equal (org-babel-lob-execute (org-babel-lob-get-info)) "1")))))
  137. (provide 'test-ob-lob)
  138. ;;; test-ob-lob.el ends here