README 3.8 KB

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