Has it really almost been a week? Well, it's been a good week for hacks.
ElUnit is
a unit testing framework for Emacs Lisp designed to allow
Test-Driven development. I believe it to be pretty much at release
quality, though a few more convenience macros (assert-equal, for
instance) remain to be written. You define suites of tests using
the defsuite
macro:
(defsuite my-test-suite (two-plus-two "Test that 2 + 2 = 4" (assert (equal 4 (+ 2 2)))) (another-test (assert (equal 0 (- 2 2)))) (bad-math "This test should fail!" (assert (equal 5 (+ 2 2)))) (another-test "duplicate should overwrite original" (assert (equal 3 (length (elunit-suite 'my-test-suite)))))) (add-hook 'my-test-suite-teardown-hook (lambda () (message "teardown hook")))
M-x elunit gets you some nicely formatted reports:
Loaded suite: my-test-suite
.F.
1) Failure: bad-math [/home/phil/.emacs.d/elunit-test.el: 13]
This test should fail!
Result: (cl-assertion-failed (equal 5 (+ 2 2)))
3 tests total, 1 failures in 0 seconds.
How many times do I have to tell you that two plus two is four? Anyway, I'm pretty happy with the results, especially considering I was able to keep it at about 90 LOC. Give it a shot, and if you've got anything to say, pipe up on the wiki discussion.
Grab it straight out of my Trac.
๛