README 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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) (shell . 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. * Trigger the tests with 'make'
  31. ** Recompile all
  32. Target ~test~ can be used to trigger a test run. The tests start
  33. after cleaning up and recompilation.
  34. #+BEGIN_SRC sh :dir (expand-file-name "..") :results silent
  35. make test
  36. #+END_SRC
  37. See ../mk/default.mk for details.
  38. ** Test dirty
  39. The 'dirty' targets are for recompiling without cleaning and
  40. rebuilding everything. This usually speeds up the recompilation
  41. considerably.
  42. The 'dirty' target is called test-dirty.
  43. #+BEGIN_SRC sh :dir (expand-file-name "..") :results silent
  44. make test-dirty
  45. #+END_SRC
  46. Note that the outcome may /not/ be in perfect shape.
  47. * Interactive testing from within Emacs
  48. To run the Org-mode test suite from a current Emacs instance simply
  49. load and run the test suite with the following commands.
  50. 1) First load the test suite.
  51. #+BEGIN_SRC emacs-lisp :var here=(buffer-file-name)
  52. (add-to-list 'load-path (file-name-directory here))
  53. (require 'org-test)
  54. #+END_SRC
  55. 2) Load required Babel languages
  56. #+BEGIN_SRC emacs-lisp
  57. (org-babel-do-load-languages
  58. 'org-babel-load-languages
  59. (and
  60. (mapc (lambda (lang) (add-to-list 'org-babel-load-languages (cons lang t)))
  61. '(emacs-lisp shell org))
  62. org-babel-load-languages))
  63. #+END_SRC
  64. 3) Then run the test suite. Babel evaluation confirmation is disabled
  65. and ~C-c C-c~ is enabled while running the tests.
  66. #+BEGIN_SRC emacs-lisp
  67. (let (org-babel-no-eval-on-ctrl-c-ctrl-c
  68. org-confirm-babel-evaluate)
  69. (org-test-run-all-tests))
  70. #+END_SRC
  71. When a test fails, run it interactively and investigate the problem
  72. in the ERT results buffer.
  73. To run one test: Use this as a demo example of a failing test
  74. #+BEGIN_SRC emacs-lisp
  75. (ert-deftest test-org/org-link-escape-ascii-character-demo-of-fail ()
  76. (should (string= "%5B" ; Expecting %5B is correct.
  77. (org-link-escape "[")))
  78. (should (string= "%5C" ; Expecting %5C is wrong, %5D correct.
  79. (org-link-escape "]"))))
  80. #+END_SRC
  81. or evaluate the ~ert-deftest form~ of the test you want to run.
  82. Then ~M-x ert RET
  83. test-org/org-link-escape-ascii-character-demo-of-fail RET~. When
  84. not visible yet switch to the ERT results buffer named ~*ert*~.
  85. When a test failed the ERT results buffer shows the details of the
  86. first ~should~ that failed. See ~(info "(ert)Running Tests
  87. Interactively")~ on how to re-run, start the debugger etc.
  88. To run several tests: ~M-x ert RET "<your regexp here>" RET~.
  89. To run all tests of a single test file: ~M-x ert-delete-all-tests
  90. RET~ and confirm. ~M-x load-file RET testing/lisp/<file>.el RET
  91. M-x ert RET t RET~.
  92. Consider to set
  93. #+BEGIN_SRC emacs-lisp
  94. (setq pp-escape-newlines nil)
  95. #+END_SRC
  96. before running the test when looking at ~should~ in the ERT results
  97. buffer. Especially when using ~l~ to look at passed test results
  98. and possibly missing an appropriate setting of ~pp-escape-newlines~
  99. made only temporarily for the running time of the test as
  100. e. g. tests using ~org-test-table-target-expect-tblfm~ do.
  101. * Troubleshooting
  102. - If the variable ~org-babel-no-eval-on-ctrl-c-ctrl-c~ is non-nil then
  103. it will result in some test failure, as there are tests which rely
  104. on this behavior.