File: ert.el.html

ERT is a tool for automated testing in Emacs Lisp. Its main features are facilities for defining and running test cases and reporting the results as well as for debugging test failures interactively.

The main entry points are ert-deftest, which is similar to defun but defines a test, and ert-run-tests-interactively, which runs tests and offers an interactive interface for inspecting results and debugging. There is also ert-run-tests-batch-and-exit for non-interactive use.

The body of ert-deftest forms resembles a function body, but the additional operators should, should-not, should-error, skip-when and skip-unless are available. should is similar to cl's assert, but signals a different error when its condition is violated that is caught and processed by ERT. In addition, it analyzes its argument form and records information that helps debugging (cl-assert tries to do something similar when its second argument SHOW-ARGS is true, but should is more sophisticated). For information on should-not and should-error, see their docstrings. The skip-when and skip-unless forms skip the test immediately, which is useful for checking the test environment (like availability of features, external binaries, etc).

See ERT's Info manual (ert) Top as well as the docstrings for more details. To see some examples of tests written in ERT, see the test suite distributed with the Emacs source distribution (in the "test" directory).

Defined variables (22)

ert--find-test-regexpThe regexp the ‘find-function’ mechanisms use for finding test definitions.
ert--infosThe stack of ‘ert-info’ infos that currently apply.
ert--running-testsList of tests that are currently in execution.
ert--selector-historyList of recent test selectors read from terminal.
ert--test-buffersTable of all test buffers. Keys are the buffer objects, values are t.
ert-batch-backtrace-line-lengthTarget length for lines in ERT batch backtraces.
ert-batch-backtrace-right-marginThe maximum line length for printing backtraces in ‘ert-run-tests-batch’.
ert-batch-print-length‘print-length’ setting used in ‘ert-run-tests-batch’.
ert-batch-print-level‘print-level’ setting used in ‘ert-run-tests-batch’.
ert-debug-on-errorNon-nil means enter debugger when a test fails or terminates with an error.
ert-load-file-nameThe name of the loaded ERT test file, a string.
ert-quietNon-nil makes ERT only print important information in batch mode.
ert-results-mode-abbrev-tableAbbrev table for ‘ert-results-mode’.
ert-results-mode-hookHook run after entering ‘ert-results-mode’.
ert-results-mode-mapKeymap for ‘ert-results-mode’.
ert-results-mode-menuMenu for ‘ert-results-mode’.
ert-results-mode-syntax-tableSyntax table for ‘ert-results-mode’.
ert-simple-view-mode-abbrev-tableAbbrev table for ‘ert-simple-view-mode’.
ert-simple-view-mode-hookHook run after entering ‘ert-simple-view-mode’.
ert-simple-view-mode-mapKeymap for ‘ert-simple-view-mode’.
ert-simple-view-mode-syntax-tableSyntax table for ‘ert-simple-view-mode’.
ert-test-run-redisplay-interval-secsHow many seconds ERT should wait between redisplays while running tests.

Defined functions (314)

copy-ert--ewoc-entry(ARG)
copy-ert--stats(ARG)
copy-ert--test-execution-info(ARG)
copy-ert-test(ARG)
copy-ert-test-aborted-with-non-local-exit(ARG)
copy-ert-test-failed(ARG)
copy-ert-test-passed(ARG)
copy-ert-test-quit(ARG)
copy-ert-test-result(ARG)
copy-ert-test-result-with-condition(ARG)
copy-ert-test-skipped(ARG)
ert(SELECTOR)
ert--abbreviate-string(S LEN SUFFIXP)
ert--activate-font-lock-keywords()
ert--button-action-position()
ert--call-with-test-buffer(ERT--BASE-NAME ERT--THUNK)
ert--erts-specifications(END)
ert--ewoc-entry-expanded-p(ert--ewoc-entry-expanded-p X)
ert--ewoc-entry-expanded-p--inliner(INLINE--FORM X)
ert--ewoc-entry-extended-printer-limits-p(ert--ewoc-entry-extended-printer-limits-p X)
ert--ewoc-entry-extended-printer-limits-p--inliner(INLINE--FORM X)
ert--ewoc-entry-hidden-p(ert--ewoc-entry-hidden-p X)
ert--ewoc-entry-hidden-p--inliner(INLINE--FORM X)
ert--ewoc-entry-p(X)
ert--ewoc-entry-p--inliner(INLINE--FORM X)
ert--ewoc-entry-test(ert--ewoc-entry-test X)
ert--ewoc-entry-test--inliner(INLINE--FORM X)
ert--ewoc-position(EWOC NODE)
ert--expand-should(WHOLE FORM INNER-EXPANDER)
ert--expand-should-1(WHOLE FORM INNER-EXPANDER)
ert--explain-equal(A B)
ert--explain-equal-including-properties(A B)
ert--explain-equal-including-properties-rec(A B)
ert--explain-equal-rec(A B)
ert--explain-format-atom(X)
ert--explain-string-equal(A B)
ert--explain-time-equal-p(A B)
ert--force-message-log-buffer-truncation()
ert--format-test-buffer-name(BASE-NAME)
ert--format-time-iso8601(TIME)
ert--get-explainer(FN-NAME)
ert--insert-backtrace-header(NAME)
ert--insert-human-readable-selector(SELECTOR)
ert--insert-infos(RESULT)
ert--make-stats(TESTS SELECTOR)
ert--make-xrefs-region(BEGIN END)
ert--parse-keys-and-body(KEYS-AND-BODY)
ert--plist-difference-explanation(A B)
ert--pp-with-indentation-and-newline(OBJECT)
ert--print-test-for-ewoc(ENTRY)
ert--remove-from-list
ert--results-expand-collapse-button-action(BUTTON)
ert--results-font-lock-function(ENABLEDP)
ert--results-format-expected-unexpected(EXPECTED UNEXPECTED)
ert--results-move(NODE EWOC-FN ERROR-MESSAGE)
ert--results-progress-bar-button-action(BUTTON)
ert--results-progress-bar-button-help-echo(WINDOW OBJECT POS)
ert--results-test-at-point-allow-redefinition()
ert--results-test-at-point-no-redefinition(&optional ERROR)
ert--results-test-node-at-point()
ert--results-test-node-or-null-at-point()
ert--results-update-after-test-redefinition(POS NEW-TEST)
ert--results-update-ewoc-hf(EWOC STATS)
ert--results-update-stats-display(EWOC STATS)
ert--results-update-stats-display-maybe(EWOC STATS)
ert--run-test-debugger(INFO CONDITION DEBUGFUN)
ert--run-test-internal(TEST-EXECUTION-INFO)
ert--setup-results-buffer(STATS LISTENER)
ert--should-error-handle-error(FORM-DESCRIPTION-FN CONDITION TYPE EXCLUDE-SUBTYPES)
ert--signal-should-execution(FORM-DESCRIPTION)
ert--significant-plist-keys(PLIST)
ert--skip-unless(FORM)
ert--skip-when(FORM)
ert--special-operator-p(THING)
ert--stats-aborted-p(ert--stats-aborted-p X)
ert--stats-aborted-p--inliner(INLINE--FORM X)
ert--stats-current-test(ert--stats-current-test X)
ert--stats-current-test--inliner(INLINE--FORM X)
ert--stats-end-time(ert--stats-end-time X)
ert--stats-end-time--inliner(INLINE--FORM X)
ert--stats-failed-expected(ert--stats-failed-expected X)
ert--stats-failed-expected--inliner(INLINE--FORM X)
ert--stats-failed-unexpected(ert--stats-failed-unexpected X)
ert--stats-failed-unexpected--inliner(INLINE--FORM X)
ert--stats-next-redisplay(ert--stats-next-redisplay X)
ert--stats-next-redisplay--inliner(INLINE--FORM X)
ert--stats-p(X)
ert--stats-p--inliner(INLINE--FORM X)
ert--stats-passed-expected(ert--stats-passed-expected X)
ert--stats-passed-expected--inliner(INLINE--FORM X)
ert--stats-passed-unexpected(ert--stats-passed-unexpected X)
ert--stats-passed-unexpected--inliner(INLINE--FORM X)
ert--stats-selector(ert--stats-selector X)
ert--stats-selector--inliner(INLINE--FORM X)
ert--stats-set-test-and-result(STATS POS TEST RESULT)
ert--stats-skipped(ert--stats-skipped X)
ert--stats-skipped--inliner(INLINE--FORM X)
ert--stats-start-time(ert--stats-start-time X)
ert--stats-start-time--inliner(INLINE--FORM X)
ert--stats-test-end-times(ert--stats-test-end-times X)
ert--stats-test-end-times--inliner(INLINE--FORM X)
ert--stats-test-key(TEST)
ert--stats-test-map(ert--stats-test-map X)
ert--stats-test-map--inliner(INLINE--FORM X)
ert--stats-test-pos(STATS TEST)
ert--stats-test-results(ert--stats-test-results X)
ert--stats-test-results--inliner(INLINE--FORM X)
ert--stats-test-start-times(ert--stats-test-start-times X)
ert--stats-test-start-times--inliner(INLINE--FORM X)
ert--stats-tests(ert--stats-tests X)
ert--stats-tests--inliner(INLINE--FORM X)
ert--string-first-line(S)
ert--test-buffer-button-action(BUTTON)
ert--test-execution-info-ert-debug-on-error(ert--test-execution-info-ert-debug-on-error X)
ert--test-execution-info-ert-debug-on-error--inliner(INLINE--FORM X)
ert--test-execution-info-exit-continuation(ert--test-execution-info-exit-continuation X)
ert--test-execution-info-exit-continuation--inliner(INLINE--FORM X)
ert--test-execution-info-p(X)
ert--test-execution-info-p--inliner(INLINE--FORM X)
ert--test-execution-info-result(ert--test-execution-info-result X)
ert--test-execution-info-result--inliner(INLINE--FORM X)
ert--test-execution-info-test(ert--test-execution-info-test X)
ert--test-execution-info-test--inliner(INLINE--FORM X)
ert--test-name-button-action(BUTTON)
ert--tests-running-mode-line-indicator()
ert--text-button(STRING &rest PROPERTIES)
ert--unload-function()
ert-call-with-buffer-renamed(BUFFER-NAME THUNK)
ert-char-for-test-result(RESULT EXPECTEDP)
ert-deftest(NAME () [DOCSTRING] [:expected-result RESULT-TYPE] [:tags '(TAG...)] BODY...)
ert-delete-all-tests()
ert-delete-test(TEST-NAME)
ert-describe-test(TEST-OR-TEST-NAME)
ert-equal-including-properties(O1 O2)
ert-face-for-stats(STATS)
ert-face-for-test-result(EXPECTEDP)
ert-fail(DATA)
ert-find-test-other-window(TEST-NAME)
ert-get-test(SYMBOL)
ert-info
ert-insert-test-name-button(TEST-NAME)
ert-kill-all-test-buffers()
ert-make-test-unbound(SYMBOL)
ert-pass()
ert-read-test-name(PROMPT &optional DEFAULT HISTORY ADD-DEFAULT-TO-PROMPT)
ert-read-test-name-at-point(PROMPT)
ert-reason-for-test-result(RESULT)
ert-results-describe-test-at-point()
ert-results-find-test-at-point-other-window()
ert-results-jump-between-summary-and-result()
ert-results-mode()
ert-results-mode-menu(ARG1)
ert-results-next-test()
ert-results-pop-to-backtrace-for-test-at-point()
ert-results-pop-to-messages-for-test-at-point()
ert-results-pop-to-should-forms-for-test-at-point()
ert-results-pop-to-timings()
ert-results-previous-test()
ert-results-rerun-all-tests()
ert-results-rerun-test-at-point()
ert-results-rerun-test-at-point-debugging-errors()
ert-results-toggle-printer-limits-for-test-at-point()
ert-run-or-rerun-test(STATS TEST LISTENER)
ert-run-test(ERT-TEST)
ert-run-tests(SELECTOR LISTENER &optional INTERACTIVELY)
ert-run-tests-batch(&optional SELECTOR)
ert-run-tests-batch-and-exit(&optional SELECTOR)
ert-run-tests-interactively(SELECTOR)
ert-running-test()
ert-select-tests(SELECTOR UNIVERSE)
ert-set-test(SYMBOL DEFINITION)
ert-simple-view-mode()
ert-skip(DATA)
ert-stats-completed(STATS)
ert-stats-completed-expected(STATS)
ert-stats-completed-unexpected(STATS)
ert-stats-skipped(STATS)
ert-stats-total(STATS)
ert-string-for-test-result(RESULT EXPECTEDP)
ert-summarize-tests-batch-and-exit(&optional HIGH)
ert-test--erts-test(GEN-SPECS FILE)
ert-test-aborted-with-non-local-exit-duration(ert-test-aborted-with-non-local-exit-duration X)
ert-test-aborted-with-non-local-exit-duration--inliner(INLINE--FORM X)
ert-test-aborted-with-non-local-exit-messages(ert-test-aborted-with-non-local-exit-messages X)
ert-test-aborted-with-non-local-exit-messages--inliner(INLINE--FORM X)
ert-test-aborted-with-non-local-exit-p(X)
ert-test-aborted-with-non-local-exit-p--inliner(INLINE--FORM X)
ert-test-aborted-with-non-local-exit-should-forms(ert-test-aborted-with-non-local-exit-should-forms X)
ert-test-aborted-with-non-local-exit-should-forms--inliner(INLINE--FORM X)
ert-test-at-point()
ert-test-body(ert-test-body X)
ert-test-body--inliner(INLINE--FORM X)
ert-test-boundp(SYMBOL)
ert-test-documentation(ert-test-documentation X)
ert-test-documentation--inliner(INLINE--FORM X)
ert-test-erts-file(FILE &optional TRANSFORM)
ert-test-expected-result-type(ert-test-expected-result-type X)
ert-test-expected-result-type--inliner(INLINE--FORM X)
ert-test-failed-backtrace(ert-test-failed-backtrace X)
ert-test-failed-backtrace--inliner(INLINE--FORM X)
ert-test-failed-condition(ert-test-failed-condition X)
ert-test-failed-condition--inliner(INLINE--FORM X)
ert-test-failed-duration(ert-test-failed-duration X)
ert-test-failed-duration--inliner(INLINE--FORM X)
ert-test-failed-infos(ert-test-failed-infos X)
ert-test-failed-infos--inliner(INLINE--FORM X)
ert-test-failed-messages(ert-test-failed-messages X)
ert-test-failed-messages--inliner(INLINE--FORM X)
ert-test-failed-p(X)
ert-test-failed-p--inliner(INLINE--FORM X)
ert-test-failed-should-forms(ert-test-failed-should-forms X)
ert-test-failed-should-forms--inliner(INLINE--FORM X)
ert-test-file-name(ert-test-file-name X)
ert-test-file-name--inliner(INLINE--FORM X)
ert-test-location(TEST)
ert-test-most-recent-result(ert-test-most-recent-result X)
ert-test-most-recent-result--inliner(INLINE--FORM X)
ert-test-name(ert-test-name X)
ert-test-name--inliner(INLINE--FORM X)
ert-test-p(X)
ert-test-p--inliner(INLINE--FORM X)
ert-test-passed-duration(ert-test-passed-duration X)
ert-test-passed-duration--inliner(INLINE--FORM X)
ert-test-passed-messages(ert-test-passed-messages X)
ert-test-passed-messages--inliner(INLINE--FORM X)
ert-test-passed-p(X)
ert-test-passed-p--inliner(INLINE--FORM X)
ert-test-passed-should-forms(ert-test-passed-should-forms X)
ert-test-passed-should-forms--inliner(INLINE--FORM X)
ert-test-quit-backtrace(ert-test-quit-backtrace X)
ert-test-quit-backtrace--inliner(INLINE--FORM X)
ert-test-quit-condition(ert-test-quit-condition X)
ert-test-quit-condition--inliner(INLINE--FORM X)
ert-test-quit-duration(ert-test-quit-duration X)
ert-test-quit-duration--inliner(INLINE--FORM X)
ert-test-quit-infos(ert-test-quit-infos X)
ert-test-quit-infos--inliner(INLINE--FORM X)
ert-test-quit-messages(ert-test-quit-messages X)
ert-test-quit-messages--inliner(INLINE--FORM X)
ert-test-quit-p(X)
ert-test-quit-p--inliner(INLINE--FORM X)
ert-test-quit-should-forms(ert-test-quit-should-forms X)
ert-test-quit-should-forms--inliner(INLINE--FORM X)
ert-test-result-duration(ert-test-result-duration X)
ert-test-result-duration--inliner(INLINE--FORM X)
ert-test-result-expected-p(TEST RESULT)
ert-test-result-messages(ert-test-result-messages X)
ert-test-result-messages--inliner(INLINE--FORM X)
ert-test-result-p(X)
ert-test-result-p--inliner(INLINE--FORM X)
ert-test-result-should-forms(ert-test-result-should-forms X)
ert-test-result-should-forms--inliner(INLINE--FORM X)
ert-test-result-type-p(RESULT RESULT-TYPE)
ert-test-result-with-condition-backtrace(ert-test-result-with-condition-backtrace X)
ert-test-result-with-condition-backtrace--inliner(INLINE--FORM X)
ert-test-result-with-condition-condition(ert-test-result-with-condition-condition X)
ert-test-result-with-condition-condition--inliner(INLINE--FORM X)
ert-test-result-with-condition-duration(ert-test-result-with-condition-duration X)
ert-test-result-with-condition-duration--inliner(INLINE--FORM X)
ert-test-result-with-condition-infos(ert-test-result-with-condition-infos X)
ert-test-result-with-condition-infos--inliner(INLINE--FORM X)
ert-test-result-with-condition-messages(ert-test-result-with-condition-messages X)
ert-test-result-with-condition-messages--inliner(INLINE--FORM X)
ert-test-result-with-condition-p(X)
ert-test-result-with-condition-p--inliner(INLINE--FORM X)
ert-test-result-with-condition-should-forms(ert-test-result-with-condition-should-forms X)
ert-test-result-with-condition-should-forms--inliner(INLINE--FORM X)
ert-test-skipped-backtrace(ert-test-skipped-backtrace X)
ert-test-skipped-backtrace--inliner(INLINE--FORM X)
ert-test-skipped-condition(ert-test-skipped-condition X)
ert-test-skipped-condition--inliner(INLINE--FORM X)
ert-test-skipped-duration(ert-test-skipped-duration X)
ert-test-skipped-duration--inliner(INLINE--FORM X)
ert-test-skipped-infos(ert-test-skipped-infos X)
ert-test-skipped-infos--inliner(INLINE--FORM X)
ert-test-skipped-messages(ert-test-skipped-messages X)
ert-test-skipped-messages--inliner(INLINE--FORM X)
ert-test-skipped-p(X)
ert-test-skipped-p--inliner(INLINE--FORM X)
ert-test-skipped-should-forms(ert-test-skipped-should-forms X)
ert-test-skipped-should-forms--inliner(INLINE--FORM X)
ert-test-tags(ert-test-tags X)
ert-test-tags--inliner(INLINE--FORM X)
ert-unload-function()
ert-with-buffer-renamed((BUFFER-NAME-FORM) &body BODY)
ert-with-buffer-selected(BUFFER-OR-NAME &body BODY)
ert-with-test-buffer((&key ((:name NAME-FORM) nil) ((:selected SELECT-FORM) nil)) &body BODY)
ert-write-junit-test-report(STATS)
ert-write-junit-test-summary-report(&rest LOGFILES)
make-ert--ewoc-entry
make-ert--ewoc-entry--cmacro
make-ert--stats
make-ert--stats--cmacro
make-ert--test-execution-info
make-ert--test-execution-info--cmacro
make-ert-test
make-ert-test--cmacro
make-ert-test-aborted-with-non-local-exit
make-ert-test-aborted-with-non-local-exit--cmacro
make-ert-test-failed
make-ert-test-failed--cmacro
make-ert-test-passed
make-ert-test-passed--cmacro
make-ert-test-quit
make-ert-test-quit--cmacro
make-ert-test-result
make-ert-test-result--cmacro
make-ert-test-result-with-condition
make-ert-test-result-with-condition--cmacro
make-ert-test-skipped
make-ert-test-skipped--cmacro
should(FORM)
should-error(FORM &rest KEYWORD-ARGS)
should-not(FORM)

Defined faces (2)

ert-test-result-expectedFace used for expected results in the ERT results buffer.
ert-test-result-unexpectedFace used for unexpected results in the ERT results buffer.