📚 node [[testing my org export customisations with ert]]

Testing my org-export customisations with ERT

https://emacs.stackexchange.com/questions/50676/testing-emacs-lisp-code-involving-org-mode

First, for sanity, get a basic test working.

(ert-deftest test-simple-sanity-check ()
  (should (string= "yo" "yo")))

Then a basic org-related test working.

#+beginsrc emacs-lisp ; https://emacs.stackexchange.com/questions/50676/testing-emacs-lisp-code-involving-org-mode (defun promote-next-heading () (org-next-visible-heading 1) (org-metaright))

(ert-deftest test-simple-org-sanity-check () (should (string= (with-temp-buffer (org-mode) (insert "

test heading

") (goto-char (point-min)) (promote-next-heading) (buffer-string)) "

test heading

"))) #+endsrc

Next up is to test org-export-to-buffer. I'll start with the ascii backend.

(ert-deftest test-simple-export-to-buffer ()
  (should
   (string=
    (with-temp-buffer
      (org-mode)
      (insert "#+TITLE: Title\n")
      (insert "* Test heading")
      (setq org-export-with-author nil)  ; Turn off author name
      (setq org-export-with-toc nil)     ; Turn off table of contents
      (org-export-to-buffer 'ascii (current-buffer))
      (buffer-string))
    "                                _______\n\n                                 TITLE\n                                _______\n\n\n1 Test heading\n==============\n" 
    )))

Hmm. I think it'll be better to test against an expected file output though.

The official org tests should be a good reference https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/testing/lisp

📖 stoas
⥱ context