test-ob-R.el 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ;;; test-ob-R.el --- tests for ob-R.el
  2. ;; Copyright (c) 2011-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. ;;; Code:
  16. (org-test-for-executable "R")
  17. (unless (featurep 'ess)
  18. (signal 'missing-test-dependency "ESS"))
  19. (unless (featurep 'ob-R)
  20. (signal 'missing-test-dependency "Support for R code blocks"))
  21. (ert-deftest test-ob-R/simple-session ()
  22. (let (ess-ask-for-ess-directory ess-history-file)
  23. (org-test-with-temp-text
  24. "#+begin_src R :session R\n paste(\"Yep!\")\n#+end_src\n"
  25. (should (string= "Yep!" (org-babel-execute-src-block))))))
  26. (ert-deftest test-ob-R/colnames-yes-header-argument ()
  27. (org-test-with-temp-text "#+name: eg
  28. | col |
  29. |-----|
  30. | a |
  31. | b |
  32. #+header: :colnames yes
  33. #+header: :var x = eg
  34. #+begin_src R
  35. x
  36. #+end_src"
  37. (org-babel-next-src-block)
  38. (should (equal '(("col") hline ("a") ("b"))
  39. (org-babel-execute-src-block)))))
  40. (ert-deftest test-ob-R/colnames-nil-header-argument ()
  41. (org-test-with-temp-text "#+name: eg
  42. | col |
  43. |-----|
  44. | a |
  45. | b |
  46. #+header: :colnames nil
  47. #+header: :var x = eg
  48. #+begin_src R
  49. x
  50. #+end_src"
  51. (org-babel-next-src-block)
  52. (should (equal '(("col") hline ("a") ("b"))
  53. (org-babel-execute-src-block)))))
  54. (ert-deftest test-ob-R/colnames-no-header-argument ()
  55. (org-test-with-temp-text "#+name: eg
  56. | col |
  57. |-----|
  58. | a |
  59. | b |
  60. #+header: :colnames no
  61. #+header: :var x = eg
  62. #+begin_src R
  63. x
  64. #+end_src"
  65. (org-babel-next-src-block)
  66. (should (equal '(("col") ("a") ("b"))
  67. (org-babel-execute-src-block)))))
  68. (ert-deftest test-ob-R/results-file ()
  69. (let (ess-ask-for-ess-directory ess-history-file)
  70. (org-test-with-temp-text
  71. "#+NAME: TESTSRC
  72. #+BEGIN_SRC R :results file
  73. a <- file.path(\"junk\", \"test.org\")
  74. a
  75. #+END_SRC"
  76. (goto-char (point-min)) (org-babel-execute-maybe)
  77. (org-babel-goto-named-result "TESTSRC") (forward-line 1)
  78. (should (string= "[[file:junk/test.org]]"
  79. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  80. (goto-char (point-min)) (forward-line 1)
  81. (insert "#+header: :session\n")
  82. (goto-char (point-min)) (org-babel-execute-maybe)
  83. (org-babel-goto-named-result "TESTSRC") (forward-line 1)
  84. (should (string= "[[file:junk/test.org]]"
  85. (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))))
  86. (provide 'test-ob-R)
  87. ;;; test-ob-R.el ends here