[gambit-list] Testing at compile-time

Bill Six billsix at gmail.com
Fri Jul 3 14:04:53 EDT 2015


Gambit community,

I was thinking about automated testing in general, and I thought to myself,
"why aren't automated tests collocated with the respective procedures under
test?"  So, using what I've learned from various emails from Marc over the
years [1] [2], I made a test framework [3] which collocates tests with
their definitions, executes the tests at compile-time only (well, Marc
calls it expansion-time); and should those tests fail, no executable nor
shared library is produced.  If they pass, the tests are not included in
the resulting executable.  I'm not aware of any other test framework in
existence which does this, but I think that the collocation is incredibly
helpful, and it helps to make programs in a "literate programming" style
[4].  It helps to answer questions like "What was the author intending when
he/she wrote this?" "How is this procedure intended to be used?", with no
need to jump around between files.

Attached is an implementation of this test framework in standard Gambit
syntax, or you could look at
https://github.com/billsix/bug/blob/master/src/main.bug.scm, which is
written in BUG scheme syntax (it's basically a pre-processed Gambit with
support for lambda literals: very informally ['foo] turns into (lambda ()
'foo), and [|x y z| (a x y z)] turns into (lambda (x y z) (a x y z)))

In creating this project, I also came to the realization that compilers can
also be interpreters capable of any computation, including I/O.  In my mind
this opens up a lot of possibilities beyond syntactic abstraction via
macros.  Besides the unit test suite, BUG automatically exports both
namespace declarations and macros definitions to files at compile time, for
use by projects which link to libbug.

Thanks for Gambit.

Bill

[1]
https://mercure.iro.umontreal.ca/pipermail/gambit-list/2006-May/000690.html
(by evaluating all procedures and macros at expansion time as part of the
test, it also solves the problem listed in referenced email)
[2]
https://mercure.iro.umontreal.ca/pipermail/gambit-list/2005-June/000305.html
[3] https://github.com/billsix/bug  It's not just a test framework, it's
Bill's Utilities for Gambit (BUG).  (currently only builds on Linux,
because I haven't ported the build process yet)
[4] https://en.wikipedia.org/wiki/Literate_programming
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20150703/dd230fcc/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.scm
Type: text/x-scheme
Size: 1354 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20150703/dd230fcc/attachment.bin>


More information about the Gambit-list mailing list