README 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. How to run one test:
  63. Use this as a demo example of a failing test
  64. #+BEGIN_SRC emacs-lisp
  65. (ert-deftest test-org/org-link-escape-ascii-character-demo-of-fail ()
  66. (should (string= "%5B" ;; expecting %5B is right
  67. (org-link-escape "[")))
  68. (should (string= "%5C" ;; expecting %5C is wrong, %5D right
  69. (org-link-escape "]"))))
  70. #+END_SRC
  71. or evaluate the ert-deftest form of the test you want to run. Then
  72. "M-x ert RET test-org/org-link-escape-ascii-character-demo-of-fail RET"
  73. When not visible yet switch to the ERT results buffer named
  74. "\*ert\*". When a test failed the ERT results buffer shows the
  75. details of the first "should" that failed. See
  76. (info "(ert)Running Tests Interactively") on how to re-run, start
  77. the debugger etc.
  78. How to run all tests of a single test file:
  79. "M-x ert-delete-all-tests RET", confirm. Open the file
  80. ./lisp/test-*.el, "M-x eval-buffer RET", "M-x ert RET t RET"
  81. Consider to set pp-escape-newlines nil before running the test when
  82. looking at "should" in the ERT results buffer. Especially when
  83. using "l" to look at passed test results and possibly missing an
  84. appropriate setting of pp-escape-newlines made only temporarily for
  85. the running time of the test as e. g. tests using
  86. org-test-table-target-expect-tblfm do.
  87. * Troubleshooting
  88. - If the value of the =org-babel-no-eval-on-ctrl-c-ctrl-c= is non-nil
  89. then it will result in some test failure, as there are tests which
  90. rely on this behavior.