Search code examples
unit-testingemacselispert

Why does ERT say my test is aborted?


I'm trying out writing some elisp for the first time. I'd like to be able to run unit tests on it.

I have a buffer with the following in it:

(ert-deftest addition-test ()
  (should (= (+ 1 2) 4)))

And I ran M-x eval-buffer to install the ert-deftest definition into my emacs. When I run M-x ert RET t RET, I see:

Selector: t
Passed: 0
Failed: 0
Total:  0/1

Started at:   2015-11-16 00:27:46-0800
Aborted.
Aborted at:   2015-11-16 00:27:46-0800

A

A addition-test
    aborted

And I see the message "Test failed: ...." in the minibuffer at the bottom of the screen. Why is the failure reported there rather in the ERT buffer?

EDIT:

It appears that the "aborted" message occurs after a failing test is hit, then any remaining tests aren't run. Example:

(ert-deftest test1 ()
  (should 1))

(ert-deftest test2 ()
  (should nil))

(ert-deftest test3 ()
  (should 1))

M-x eval-buffer RET M-x ert RET opens up a buffer named *ert* that says:

Selector: t
Passed: 1
Failed: 0
Total:  1/3

Started at:   2015-11-16 02:06:57-0800
Aborted.
Aborted at:   2015-11-16 02:06:57-0800

.A-

A test2
    aborted

And in *Messages* I see:

Aborted: Ran 3 tests, 1 results were as expected
ert-fail: Test failed: ((should nil) :form nil :value nil)

If I go in the *ert* and press d over test2, I get the following in *Messages*:

Running test test2...ABORTED
ert-fail: Test failed: ((should nil) :form nil :value nil)

I can convince it to run test3 if I hit enter on the - in .A-, expand test3, then hit d on it. That looks like:

Selector: t
Passed: 2
Failed: 0
Total:  2/3

Started at:   2015-11-16 02:08:40-0800
Aborted.
Aborted at:   2015-11-16 02:08:40-0800

.A.

A test2
    aborted

. test3
    passed

In terms of getting a backtrace, hitting b over test2 gives me:

ert-results-pop-to-backtrace-for-test-at-point: cl-etypecase failed: [cl-struct-ert-test-aborted-with-non-local-exit  (((should nil) :form nil :value nil))], (ert-test-passed ert-test-result-with-condition)

I don't understand the output of the backtrace at all. This behavior doesn't seem to match what the ERT documentation says so I'm really puzzled. What's going on here?


Solution

  • The code you have posted works in a clean Emacs started with emacs -Q. Most likely, it is caused by some library that has been loaded somehow.