:
Unit testing with a clean interface
I have long been a supporter of introducing some version of
test-early or test-first design into my intro programming courses, but I
didn't find the unit testing ecosystem of C++ especially conducive to
intro students' needs. So I wrote a new framework, called Unci (UNit testing
with a Clean Interface---not the cleanest acronym but it does make for an
attractive logo!).
Here's some of what Unci has to offer the intro student:
- No boilerplate code! Everything the programmer types has a
readily-understood semantic significance.
- No manual registration of each new unit test! Type the test in,
that's it.
- Simplified, Unci-specific syntax for the unit-testing-related
things. (There are five or so special keywords.)
- And Unci-generated error messages, meaningful to the intro
student, for errors they make in the Unci syntax. (No more
indecipherable macro fails!)
- Free-form C++ code for everything else. (You would probably
expect this from any good testing framework, but I want to be clear that
I didn't strip that away in the name of "simplicity" or whatever.)
- And C++-compiler-generated error messages, correctly keyed to
source code line numbers, for errors in their C++ code: they'll get
the same error message on a (say) misspelled function name that they'd
get for the same error in any other file.
From the student's perspective, a ".u file" is a different kind of
file that they can compile, just as they can compile a ".cpp file".
Under the hood, the Unci source file is translated (i.e. compiled) into
a valid C++ file, and compiled against the cppunit library. (At some
point in the future, I hope to make it more standalone, but the cppunit
dependence is invisible to the student.)
Runnable programs
The Unci system includes the following executables:
- unci-translate
- This is the core executable; it reads, from stdin or from a given
filename, a file presumed to be in Unci format, and it produces, on
stdout, a C++ source file suitable for compilation with a
C++11-compliant compiler. This executable should normally be wrapped in
some sort of script.
- uncic
- This script gets a filename ending in .u, does some lightweight
error checking, and calls unci-translate and g++ to create a .o file
suitable for linking the cppunit library and whatever is being tested.
This command is sort of the moral equivalent of "g++ -c". If you have
your students using Makefiles or some other build system, this script
would probably be the one you'd use (by writing a rule that uses it to
generate .o files from .u files).
- compile
- This script is a somewhat more fully-featured shell script that can
be your students' one-stop shop for compiling code if they're using the
command-line compiler commands. It can be used in place of "g++",
making .cpp and .u files both effectively first-class "source code
files" as far as the students are concerned. (It supports the "-c"
option if they want to be producing .o files, and also: passes all other
options to g++; prints "Success!" rather than succeeding silently;
prevents them compiling .h files accidentally; turns on debugging (-g);
turns on warnings; prints only the first error message to prevent
spamming with hundreds of lines of error messages. Most of that has
nothing to do with Unci but is useful for the same intro audiences that
Unci targets.)
Other inclusions
A few other files come in handy if you're in a command-line
development environment:
- Vim support:
-
- ftdetect-unci.vim
- To be dropped into a ftdetect/ directory inside ~/.vim or $VIM:
Recognises .u as the extension for filetype unci
- ftplugin-unci.vim
- To be dropped into a ftplugin/ directory inside ~/.vim or $VIM:
Tells Vim to basically treat this like a C++ file
- syntax-unci.vim
- To be dropped into a syntax/ directory inside ~/.vim or $VIM:
Tells Vim how to interpret the Unci syntax (keywords, etc)
- Enscript support:
-
- unci.st
- To be added to enscript's hl/ directory (possibly inside
/usr/share/enscript/) to make the bolding
and such work for .u files. (As with vim syntax, mostly follows
existing C++ rules, with a few tweaks.) Also requires addidion
of the line
/\.u$/ unci;
to the namerules
section of enscript.st
Presentations
System requirements and download
Currently, this is squarely targeted at a linux-y environment, and
if you want to rebuild it on your system, you'll need make, flex, and a
willingness to tinker (or email me, and I can try to help). Once built,
you'll need to be able to copy an executable and two scripts to
/usr/local/bin or the equivalent, and have a compiler that
handles C++11 code. (The scripts are written assuming g++ but are
trivially tweakable to use clang++, or probably others.) Also, for now,
the cppunit library has to be installed (sorry).
If you download it, drop me an email and I'll update you when I get
my act together and update it.