3

The CxxTest documentation has an example of a Makefile that generates and runs unit tests. How do I do the same for automake (Makefile.am)?

Peter Tseng
  • 13,613
  • 4
  • 67
  • 57

1 Answers1

2

I did this by creating this Makefile.am in a tests directory, where all the test code was:

check_PROGRAMS = tests

EXTRA_tests_SOURCES  = test_example1.hpp
EXTRA_tests_SOURCES += test_example2.hpp

tests_SOURCES = runner-autogen.cpp

BUILT_SOURCES = runner-autogen.cpp
MAINTAINERCLEANFILES = runner-autogen.cpp

runner-autogen.cpp: $(EXTRA_tests_SOURCES)
    /path/to/cxxtest/bin/cxxtestgen --runner=ErrorPrinter -o $@ $<

What this does is compile runner-autogen.cpp into the test program (called tests) and runs it with make check. If any of the listed .hpp files change, it will run cxxtestgen to recreate runner-autogen.cpp.

Because runner-autogen.cpp is listed as a source file, it will be included in the release archive by make dist, so the user won't need cxxtest present unless they modify one of the .hpp files.

Malvineous
  • 25,144
  • 16
  • 116
  • 151