org-mode/testing/README.org
Bastien Guerry ecd0562c5f Fix the master branch.
I started from the 78ec8e commit then cherry-picked and squashed
commits that have been done in master since then, except the bad
commits that overwrote the tree (in master) with the tree in maint.

This commit also bumps the version number to 7.8.06.

The only "fix" that was made between 78ec8e and the previous commit
is e0072f which has been reported to break stuff.
2012-03-19 22:01:29 +01:00

4.2 KiB

Org-mode Testing

The following instructions describe how to get started using the Org-mode test framework.

To run the tests interactively

  1. Install the jump.el testing dependency which is included as a git submodule in the org-mode repository. To do so run the following git submodule commands from inside the base of the Org-mode directory (or just execute the following code block).

      cd ..
      git submodule init
      git submodule update
  2. Load the org-test.el file

      (load-file "org-test.el")
  3. The org-test-jump command is now bound to M-C-j in all emacs-lisp files. Call this command from any file in the lisp/ directory of the org-mode repository to jump to the related test file in the testing/ directory. Call this functions with a prefix argument, and the corresponding test file will be stubbed out if it doesn't already exist.
  4. Ingest the library-of-babel.org file since some tests require this.

      (org-babel-lob-ingest "../contrib/babel/library-of-babel.org")
  5. Review the ERT documentation
  6. A number of org-mode-specific functions and macros are provided in org-test.el see the ;;; Functions for Writing Tests subsection of that file. Some of these functions make use of example org-mode files located in the examples/ directory.
  7. Functions for loading and running the Org-mode tests are provided in the ;;; Load and Run Tests subsection, the most important of which are

    • org-test-load which loads the entire Org-mode test suite
    • org-test-current-defun which runs all tests for the current function around point (should be called from inside of an Org-mode elisp file)
    • org-test-run-all-tests which runs the entire Org-mode test suite
    • also note that the ert command can also be used to run tests
  8. Load and run all tests

      (load-file "org-test.el")
      (org-babel-lob-ingest "../contrib/babel/library-of-babel.org")
      (org-test-load)
      (org-test-run-all-tests)

To run the tests in batch mode

First tangle this file out to your desktop.

  ;; add to the load path
  (add-to-list 'load-path (concat org-dir "/lisp/"))
  (add-to-list 'load-path (concat org-dir "/lisp/testing/"))
  (add-to-list 'load-path (concat org-dir "/lisp/testing/ert/"))
  
  ;; load Org-mode
  (require 'org)
  
  ;; setup the ID locations used in tests
  (require 'org-id)
  (org-id-update-id-locations
   (list (concat org-dir "/testing/examples/babel.org")
         (concat org-dir "/testing/examples/ob-C-test.org")
         (concat org-dir "/testing/examples/normal.org")
         (concat org-dir "/testing/examples/ob-awk-test.org")
         (concat org-dir "/testing/examples/ob-octave.org")
         (concat org-dir "/testing/examples/ob-fortran-test.org")
         (concat org-dir "/testing/examples/ob-maxima-test.org")
         (concat org-dir "/testing/examples/link-in-heading.org")
         (concat org-dir "/testing/examples/links.org")))
  
  ;; ensure that the latest Org-mode is loaded
  (org-reload)
  
  ;; load the test suite
  (load-file (concat org-dir "/testing/org-test.el"))
  
  ;; configure Babel
  (org-babel-lob-ingest (concat org-dir "/contrib/babel/library-of-babel.org"))
  (org-babel-do-load-languages
   'org-babel-load-languages
   '((emacs-lisp . t)
     (sh . t)))
  (setq org-confirm-babel-evaluate nil)
  
  ;; run the test suite
  (org-test-run-all-tests)
  
  ;; print the results
  (with-current-buffer "*ert*"
    (print (buffer-string)))

Then run the test suite with the following command which could use any version of Emacs.

  emacs --batch -Q -l ~/Desktop/run-org-tests.el