Like it!

Join us on Facebook!

Like it!

Let Automake build and run your test cases

Add easy support for testing your program.

Automake is able to build and run your test suites without tearing your mind apart. The key point is to add a couple of special variables inside the glorious and set up the rest properly.

Say you have a project organized as follows:

... [many others Autotools files here] ...

where src/ contains the actual source code and test/ the test suite. I want Make to build the tests from the latter folder (possibly including the needed files from src/) and run the suites, alerting me if anything goes wrong. Please note that I'm using non-recursive Automake.

Open your and define the special variable TESTS, which is basically the name of the executable (or script or program) that Make will run in order to do the testing. Say you have an app called Funky, I would call the test program as funky_test. For example:

TESTS = funky_test

You can actually define multiple test programs, but I will stick to one for the sake of simplicity. Next, add check_PROGRAMS: another variable that will define programs that are compiled when someone runs the test suite. For example:

check_PROGRAMS = funky_test

That was pretty obvious. The last step: list all the source files needed within the variable [your_program]_SOURCES. So in our example it would be:

funky_test_SOURCES = test/ src/ src/

Here I'm including the main source file with the actual test suite (test/ and other classes from the src/ folder, needed by the test itself (src/ and src/

Finally: build and run your tests with make check. Enjoy!

Thomas on September 30, 2018 at 12:46
Erreur, ce n'est pas "funky_test_PROGRAMS = " mais "funky_test_SOURCES ="
Triangles on October 05, 2018 at 10:39
You're right Thomas. Error fixed, merci beaucoup!
lemon on February 19, 2019 at 20:07
thanks for this!