Doctest.el or testing your pure Elisp functions in your docstring
A little time ago I have submitted code-compass to melpa (hopefully it gets approved soon). That gave me the opportunity to discover my reviewer repositories and I found a super cool little Emacs package: doctest.el.
This lets you write (and run) a test in your symbols documentation strings.
For instance, you can define a function like this:
(defun my-add (a b) " >> (my-add 1 1) => 2" (+ a b))
and when you use doctest-here
on the >>
(or just doctest-defun
),
you would have your assertion evaluated.
I liked it so much that I roughly patched a few shortcomings:
- make it work for symbols defined in buffers that are not saved to a file
- support multiple lines for input and output in assertion
You can find my fork here, if you like it and look for those improvements.
Happy testing!