Early on in the development of the Harlan compiler, my collaborators and I realized we were spending a lot of time writing compilers that translate Scheme-like languages into C or C++. A lot of this code should be common between projects, so we decided to factor some of this code into the Elegant Weapons project. Elegant Weapons even had a trivial test suite. Unfortunately, because the primary consumer of Elegant Weapons was Harlan, the design was still far to specific to Harlan. As we realized when Nada Amin submitted a fix for the Elegant Weapons tests, we weren’t even running our own tests anymore. Clearly we needed to do something better if Elegant Weapons were truly going to be a project worthy of existing on its own.

Lately I’ve seen a lot of GitHub repositories that include an image like this in their Readme:

It turns out this is from a free service called Travis CI, which makes it easy to integrate continuous integration with GitHub projects. Basically, this means you can define a set of tests that run every time you push a commit to GitHub, and you’ll be notified if something breaks.

Scheme was not one of the languages with first class support, but fortunately we can make it work. Here’s how.

Travis CI gives a lot of flexibility with the scripts you can run on their servers. Thus, we will pretend that we are a C project, and that our build process installs Petite Chez Scheme. Once that’s done, we run a small wrapper script which launches our Scheme test suite.

First, we need a script to install Petite. You can find our script here, but I’ve included the contents below.

#!/bin/bash

tar xzf pcsv8.4-a6le.tar.gz

cd csv8.4/custom

./configure
make
sudo make install


Notice that we can use sudo within our script. This is because Travis CI gives you your very own virtual machine and allows passwordless sudo. Once your tests are done, the VM is destroyed and your next build will happen on an entirely new instance.

Next, lets assume our test suite is called run-tests.scm. We can then create a simple wrapper script to execute these. Be sure to mark it as executable before you check it in.

#!/bin/bash

/usr/bin/petite --libdirs lib --script run-tests.scm


Some of the parameters will be specific to your project. For example, the Elegant Weapons code lives in the lib subdirectory, so we are sure to add this to the compiler’s load path.

Finally, with all the necessary pieces, we can create the .travis.yml file that will actually enable our project with Travis CI:

language: c

compiler:
- gcc

install: ./travis/install-petite.sh
script: ./run-tests


Once you add this file to your repository, push it to GitHub, create your Travis CI account and enable Travis CI for your repository, you should have your tests automatically running.

Obviously, these instructions have been unique to Petite Chez Scheme. It should not take too much trouble to adapt these to your Scheme implementation of choice. In the future, I hope to learn how to automatically run the tests on a variety of Scheme implementations to help keep us honest as far as portability is concerned.