test-ob-tangle.el 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ;;; test-ob-tangle.el --- tests for ob-tangle.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. ;;; Comments:
  16. ;; Template test file for Org-mode tests
  17. ;;; Code:
  18. ;; TODO
  19. ;; (ert-deftest ob-tangle/noweb-on-tangle ()
  20. ;; "Noweb header arguments tangle correctly.
  21. ;; - yes expand on both export and tangle
  22. ;; - no expand on neither export or tangle
  23. ;; - tangle expand on only tangle not export"
  24. ;; (let ((target-file (make-temp-file "ob-tangle-test-")))
  25. ;; (org-test-at-id "eb1f6498-5bd9-45e0-9c56-50717053e7b7"
  26. ;; (org-narrow-to-subtree)
  27. ;; (org-babel-tangle target-file))
  28. ;; (let ((tang (with-temp-buffer
  29. ;; (insert-file-contents target-file)
  30. ;; (buffer-string))))
  31. ;; (flet ((exp-p (arg)
  32. ;; (and
  33. ;; (string-match
  34. ;; (format "noweb-%s-start\\([^\000]*\\)noweb-%s-end" arg arg)
  35. ;; tang)
  36. ;; (string-match "expanded" (match-string 1 tang)))))
  37. ;; (should (exp-p "yes"))
  38. ;; (should-not (exp-p "no"))
  39. ;; (should (exp-p "tangle"))))))
  40. (ert-deftest ob-tangle/no-excessive-id-insertion-on-tangle ()
  41. "Don't add IDs to headings without tangling code blocks."
  42. (org-test-at-id "ef06fd7f-012b-4fde-87a2-2ae91504ea7e"
  43. (org-babel-next-src-block)
  44. (org-narrow-to-subtree)
  45. (org-babel-tangle)
  46. (should (null (org-id-get)))))
  47. (ert-deftest ob-tangle/continued-code-blocks-w-noweb-ref ()
  48. "Test that the :noweb-ref header argument is used correctly."
  49. (org-test-at-id "54d68d4b-1544-4745-85ab-4f03b3cbd8a0"
  50. (let ((tangled
  51. "df|sed '1d'|awk '{print $5 \" \" $6}'|sort -n |tail -1|awk '{print $2}'"))
  52. (org-narrow-to-subtree)
  53. (org-babel-tangle)
  54. (with-temp-buffer
  55. (insert-file-contents "babel.sh")
  56. (goto-char (point-min))
  57. (should (re-search-forward (regexp-quote tangled) nil t)))
  58. (delete-file "babel.sh"))))
  59. (ert-deftest ob-tangle/expand-headers-as-noweb-references ()
  60. "Test that references to headers are expanded during noweb expansion."
  61. (org-test-at-id "2409e8ba-7b5f-4678-8888-e48aa02d8cb4"
  62. (org-babel-next-src-block 2)
  63. (let ((expanded (org-babel-expand-noweb-references)))
  64. (should (string-match (regexp-quote "simple") expanded))
  65. (should (string-match (regexp-quote "length 14") expanded)))))
  66. (ert-deftest ob-tangle/comment-links-at-left-margin ()
  67. "Test commenting of links at left margin."
  68. (should
  69. (string-match
  70. (regexp-quote "# [[http://orgmode.org][Org mode]]")
  71. (org-test-with-temp-text-in-file
  72. "[[http://orgmode.org][Org mode]]
  73. #+header: :comments org :tangle \"test-ob-tangle.sh\"
  74. #+begin_src sh
  75. echo 1
  76. #+end_src"
  77. (unwind-protect
  78. (progn (org-babel-tangle)
  79. (with-temp-buffer (insert-file-contents "test-ob-tangle.sh")
  80. (buffer-string)))
  81. (delete-file "test-ob-tangle.sh"))))))
  82. (provide 'test-ob-tangle)
  83. ;;; test-ob-tangle.el ends here