ert-publish-test.el 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. (add-to-list 'load-path (expand-file-name "tools"))
  2. (require 'ert)
  3. (defun org-export-as-html-test-fixture (file body)
  4. "Export the example.org buffer to html, then run the tests in
  5. body passing in the org-buffer and the html-buffer as arguments"
  6. (unwind-protect
  7. (let* ((org-buffer (save-excursion (find-file file)
  8. (buffer-name)))
  9. (html-buffer "*Org HTML Export*"))
  10. ;; setup
  11. (set-buffer org-buffer)
  12. (call-interactively 'org-export-as-html-to-buffer)
  13. (save-excursion
  14. ;; run the tests
  15. (eval (list body org-buffer html-buffer))))
  16. (progn
  17. ;; clean up
  18. (kill-buffer "*Org HTML Export*")
  19. (kill-buffer file))))
  20. (defun org-test-search-map-all-org-html-links (buffer body)
  21. "for each org link in BUFFER call BODY passing the link-url and
  22. link-text as arguments."
  23. (save-excursion
  24. (set-buffer buffer)
  25. (goto-char (point-min))
  26. (while (re-search-forward "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]" nil t)
  27. (eval (list body (match-string 1) (replace-regexp-in-string "[\r\n]" " " (match-string 3)))))))
  28. ;; this actually defines the test to be run by ert
  29. (ert-deftest org-test-export-as-html ()
  30. (org-export-as-html-test-fixture
  31. "example.org"
  32. (lambda (org-buffer html-buffer)
  33. (org-test-search-map-all-org-html-links
  34. org-buffer
  35. (lambda (link-url link-text)
  36. (save-excursion
  37. (message (format "%s as %s" link-url link-text))
  38. (set-buffer html-buffer)
  39. (goto-char (point-min))
  40. (search-forward link-text)
  41. (re-search-backward "<a href=\"\\(.*\\)\"" nil t)
  42. (should (string= (match-string 1)
  43. link-url))))))))
  44. ;; this runs the ert test
  45. (ert-run-tests-interactively "^org-test-export-" " *org export tests*")