automake: automatically run unit tests
Asked Answered
S

1

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?

Spaniard answered 18/4, 2015 at 9:37 Comment(0)
C
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.

Chinn answered 18/4, 2015 at 10:27 Comment(6)
From gnu.org/software/automake/manual/html_node/…: "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."Ab
To which file should I add the line? Id did not work for both test/Makefile.am and Makefile.am. Does the position matter?Spaniard
@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.Chinn
Still, it compiles (as before) but does not run it automatically :-/Spaniard
@Paddre, I missed that target is called prog_test, but the executable name is prog. Try TESTS = prog.Chinn
@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 :-)Spaniard

© 2022 - 2024 — McMap. All rights reserved.