README 4.5 KB

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