Automatically make unit tests
If you like hacking Scheme on Emacs and evaling expressions from buffers (just checking in the REPL to see if things look right), this little app is great for turning that into (kinda shabby) unit tests in a tests/run.scm file.
So if you have made a procedure called + that adds numbers, and you check it in the REPL by evaling
(+ 10 2 300)
and you think it looks right, this app'll turn that into a test that looks like this:
(unless (equal? 312 (+ 10 2 300)) (error "(+ 10 2 300)"))
Any pre-existing forms in a pre-existing tests/run.scm are kept, and duplicates across the two files are removed, but comments and such are lost, so be careful.
Either have a separate file in your source directory (this file does not need to be checked into VCS) or move things into such a file from whereever you have them, and then
make-tests /my/sloppy/old/repl-testing-file.scm
Also put any imports and defines that are needed to run the tests.
This will create
/my/sloppy/old/tests/run.scm
Look through it, edit it until you're happy etc. Again, re-running make-tests will clobber any formatting, commenting etc that you do in there, so be careful.
Additionally, it makes (clobbering, if it already exists) a file called /tmp/make-tests-examples.txt that contains things like:
(+ 10 2 300) ⇒ 312
Convenient to paste into any documentation you're writing.
For source code,
git clone https://idiomdrottning.org/make-tests