Generating The Test Driver

Building an efficient and extendable testsuite is an essential part of the project.

Hooking your testsuite to the build system

The build system should allow you to run tests from it. To do this you will need to add a rule to the which is located in the tests folder.


In the makefile check-local is an automake directive that allows you to add steps to the check rule defined in the at the root of the project. The doc of automake for this part is here.

You are free to implement your test suite in the technology you prefer.


The commands that are run in the check-local rule only run after the unit tests so if the unit tests fail the check-local rule will not be run.

Hooking your unit tests to the build system

Unit tests are already given in the given code. They allow you to unit test certain parts of TC, and are notably used in lib/misc.

You can easily add them for that you just have to add a C++ file which contains the different tests, then add them in a make file.

By convention on TC the unit tests are next to the tested features. For example in lib/misc the tests for the Symbol class are defined in Unit tests can be registered in the build system thanks to the check_PROGRAMS variable.

check_PROGRAMS += %D%/test-symbol

This registers as a unit test program. The variable check_PROGRAMS and a global variable that contains all the files compiled as test files. It is defined in, the build system root.

Here is an example of C++ test code.

using misc::symbol;

int main()
  const symbol toto1("toto");
  const symbol toto2("toto");
  const symbol titi1("titi");

  // Checking symbol.
  //<< Testing set size.
  assertion(symbol::object_map_size() == 2);
  assertion(toto1.get() == "toto");
Maintaining multiple builds using autotools

Unless your whole test infrastructure is embedded in a single file (which is not a good idea), we advise you to generate any script used to run your tests so that they can be run from a directory other than the source directory where they reside. This is especially useful to maintain several builds (e.g. with different compilers or compiler flags) in parallel (see the section on VPATH Builds in Automake’s manual) and when running make distcheck (see the section on Checking the Distribution), as source and build directories are distinct in these circumstances.

The simplest way to generate a script is to rely on configure. For instance, the following line in generates a script tests/testsuite from the input tests/, while performing variables substitutions (in particular srcdir and similar variables):

AC_CONFIG_FILES([tests/testsuite], [chmod a=rx tests/testsuite])

The template file tests/ can then leverage this information to find data in the source directory. E.g., if tests are located in the tests/ subdirectory of the top source directory, the beginning of tests/ might look like this:

#! /bin/sh
# configure_input

# Where the tests can be found.

# ...

Another strategy to generate scripts is to use make, as suggested by Autoconf’s manual (see the section on Installation Directory Variables).