5

I am maintaining an autoconf package and wanted to integrate automatic testing. I use the Boost Unit Test Framework for my unit tests and was able to sucessfully integrate it into the package.

That is it can be compiled via make check, but is is not run (although I read that make check both compiles and runs the tests). As result, I have to run it manually after building the tests which is cumbersome.

Makefile.am in the test folder looks like this:

check_PROGRAMS = prog_test
prog_test_SOURCES = test_main.cpp ../src/class1.cpp class1_test.cpp class2.cpp ../src/class2_test.cpp ../src/class3.cpp ../src/class4.cpp
prog_test_LDADD = $(BOOST_FILESYSTEM_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_UNIT_TEST_FRAMEWORK_LIB)

Makefile.am in the root folder:

SUBDIRS = src test
dist_doc_DATA = README
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4

Running test/prog yields the output:

Running 4 test cases...

*** No errors detected

(I don't think you need the contents of my test cases in order to answer my question, so I omitted them for now)

So how can I make automake run my tests every time I run make check?

Paddre
  • 798
  • 1
  • 9
  • 19

1 Answers1

10

At least one way of doing this involves setting TESTS variable. Here's what documentation on automake says about it:

If the special variable TESTS is defined, its value is taken to be a list of programs or scripts to run in order to do the testing.

So adding the line

TESTS = $(check_PROGRAMS)

should instruct it to run the tests on make check.

xaizek
  • 5,098
  • 1
  • 34
  • 60
  • 3
    From https://www.gnu.org/software/automake/manual/html_node/Scripts_002dbased-Testsuites.html#index-TESTS: "Programs listed in check_PROGRAMS (and check_LIBRARIES, check_LTLIBRARIES...) are only built during make check, not during make all. You should list there any program needed by your tests that does not need to be built by make all. Note that check_PROGRAMS are not automatically added to TESTS because check_PROGRAMS usually lists programs used by the tests, not the tests themselves. Of course you can set TESTS = $(check_PROGRAMS) if all your programs are test cases." – William Pursell Apr 18 '15 at 10:39
  • To which file should I add the line? Id did not work for both `test/Makefile.am` and `Makefile.am`. Does the position matter? – Paddre Apr 18 '15 at 10:56
  • @Paddre, position doesn't really matter, add the line to `test/Makefile.am`, root makefile will invoke it. Make sure that `Makefile.in` and `Makefile` are regenerated after the changes, an easy way might be to run `make distclean`. – xaizek Apr 18 '15 at 11:28
  • Still, it compiles (as before) but does not run it automatically :-/ – Paddre Apr 18 '15 at 11:43
  • @Paddre, I missed that target is called `prog_test`, but the executable name is `prog`. Try `TESTS = prog`. – xaizek Apr 18 '15 at 11:49
  • @xaizek: It was a typo (wrote `TEST` instead of `TESTS` -.-). After doing `automake --add-missing` (which installed the test-driver program), it worked fine (with `TESTS = $(check_PROGRAMS)`). Thank you very much :-) – Paddre Apr 18 '15 at 12:27