Vladimir Sedach

Have Emacs - Will Hack

March 21, 2018

Unobtrusive live coding unit tests with assert

The Fall 2017 edition of ;login:, the USENIX magazine, had a column by David Beazley describing Aur Saraf's PyCon Israel 2017 live coding performance of a brainfuck interpreter. Saraf's technique basically looks like:

(defun foo (x)
  (+ 1 x))

(assert (eql (foo 1) 2))
(assert (eql (foo 2) 3))

The code and tests live in the same file, so any time you eval-buffer or equivalent, the asserts are evaluated.

This is a neat technique for live coding scenarios, such as programming interviews.