2 #+TITLE: Org-mode Testing
3 #+PROPERTY: results silent
7 The only dependency is [[http://www.emacswiki.org/emacs/ErtTestLibrary][ERT]] the Emacs testing library which ships with
8 Emacs24. If you are running an older version of Emacs and don't
9 already have ERT installed it can be installed from its old [[https://github.com/ohler/ert][git
12 * Non-interactive batch testing from the command line
14 The simplest way to run the Org-mode test suite is from the command
15 line with the following invocation. Note that the paths below are
16 relative to the base of the Org-mode directory.
18 Also note that many of the current tests uses babel evaluation...
20 #+BEGIN_SRC sh :dir (expand-file-name "..")
21 # For Emacs earlier than 24, add -L /path/to/ert
23 -L lisp/ -L testing/ -L testing/lisp -l lisp/org.el \
24 -l lisp/org-id.el -l testing/org-test.el \
25 --eval "(progn (org-reload) (setq org-confirm-babel-evaluate nil) \
26 (org-babel-do-load-languages 'org-babel-load-languages \
27 '((emacs-lisp . t) (shell . t) (org . t))))" \
28 -f org-test-run-batch-tests
31 The options in the above command are explained below.
33 | -Q | ignores any personal configuration ensuring a vanilla Emacs instance is used |
34 | --batch | runs Emacs in "batch" mode with no gui and termination after execution |
35 | -l | loads Org-mode and the org mode test suite defined in testing/org-test.el |
36 | --eval | reloads Org-mode and allows evaluation of code blocks by the tests |
37 | -f | actually runs the tests using the `org-test-run-batch-tests' function |
39 * Interactive testing from within Emacs
41 To run the Org-mode test suite from a current Emacs instance simply
42 load and run the test suite with the following commands.
44 1) First load the test suite.
45 #+BEGIN_SRC emacs-lisp :var here=(buffer-file-name)
46 (add-to-list 'load-path (file-name-directory here))
50 2) Load required Babel languages
51 #+BEGIN_SRC emacs-lisp
52 (org-babel-do-load-languages
53 'org-babel-load-languages
55 (mapc (lambda (lang) (add-to-list 'org-babel-load-languages (cons lang t)))
56 '(emacs-lisp shell org))
57 org-babel-load-languages))
60 3) Then run the test suite. Babel evaluation confirmation is disabled
61 and ~C-c C-c~ is enabled while running the tests.
62 #+BEGIN_SRC emacs-lisp
63 (let (org-babel-no-eval-on-ctrl-c-ctrl-c
64 org-confirm-babel-evaluate)
65 (org-test-run-all-tests))
68 When a test fails, run it interactively and investigate the problem
69 in the ERT results buffer.
72 Use this as a demo example of a failing test
73 #+BEGIN_SRC emacs-lisp
74 (ert-deftest test-org/org-link-escape-ascii-character-demo-of-fail ()
75 (should (string= "%5B" ;; expecting %5B is right
76 (org-link-escape "[")))
77 (should (string= "%5C" ;; expecting %5C is wrong, %5D right
78 (org-link-escape "]"))))
80 or evaluate the ert-deftest form of the test you want to run. Then
81 "M-x ert RET test-org/org-link-escape-ascii-character-demo-of-fail RET"
82 When not visible yet switch to the ERT results buffer named
83 "\*ert\*". When a test failed the ERT results buffer shows the
84 details of the first "should" that failed. See
85 (info "(ert)Running Tests Interactively") on how to re-run, start
88 How to run all tests of a single test file:
89 "M-x ert-delete-all-tests RET", confirm. Open the file
90 ./lisp/test-*.el, "M-x eval-buffer RET", "M-x ert RET t RET"
92 Consider to set pp-escape-newlines nil before running the test when
93 looking at "should" in the ERT results buffer. Especially when
94 using "l" to look at passed test results and possibly missing an
95 appropriate setting of pp-escape-newlines made only temporarily for
96 the running time of the test as e. g. tests using
97 org-test-table-target-expect-tblfm do.
101 - If the value of the =org-babel-no-eval-on-ctrl-c-ctrl-c= is non-nil
102 then it will result in some test failure, as there are tests which
103 rely on this behavior.