Learn how to test your Emacs Lisp exercises on Exercism
Elisp tests are run using ERT, an Emacs Lisp library for regression/unit testing. Tests can be run several ways.
To run the tests interactively from within Emacs:
M-x eval-buffer RET
M-x ert RET test-name RET
M-x ert RET t RETNote that this will run all tests currently loaded into Emacs!
M-x eval-buffer RETbefore testing whenever you've made changes
To only execute the tests in the current buffer you can add this to your
(defun my-eval-and-run-all-tests-in-buffer () "Delete all loaded tests from the runtime, evaluate the current buffer and run all loaded tests with ert." (interactive) (ert-delete-all-tests) (eval-buffer) (ert 't))
After restarting Emacs:
M-x my-eval-and-run-all-tests-in-buffer RET
Interactive testing is great while you're working on an exercise, but batch mode testing is preferable for when you want to check that an exercise is ready for submission.
To run run all tests from the terminal, in batch mode, execute
emacs -batch -l ert -l *-test.el -f ert-run-tests-batch-and-exit
The above command is a bit unwieldy, so if you like:
#!/usr/bin/env sh emacs -batch -l ert -l $1 -f ert-run-tests-batch-and-exit
chmod +x ert-run
You should be able to simply call
ert-run *-test.el and run the tests
in batch mode.
Other options can be found in the docs,
C-h i m ert RET.
Since Emacs is, itself, an elisp interpreter, your working code is always in its
native execution environment. You can evaluate any form by pressing
C-x e at
the end of the form, or a selection with
M-x eval-region or the whole buffer
M-x eval-buffer. This can be extremely useful for quickly debugging your
Since both your code and tests are valid elisp, it is suggested to work with your exercise code in a buffer pane side-by side with its test, like so:
Split the frame vertically with
C-x 3, switch to the new window with
and open the file with
C-x C-f /path/to/file.