Unit tests using Automake

I am working on a project with other people in a team using GNU autotools. In the project, we use unit test for each non-trivial C ++ class. I found out that there is support for unit testing. For this, I use this structure:

./ + tests/ + Makefile.am + classA_test.cc .... + classB_test.cc + src/ + lib/ + Makefile.am 

The problem arises because my main Makefile.am uses subdir-objects options - note that I am not using a recursive make file for the source files. I cannot export my variables - such as AM_CPPFLAGS-- to another Makefile. So far I have done this using:

  $ make check 

but I keep getting problems for paths and parameters when I do

  $ make distcheck 

So my questions are: what is the standard way to deal with unit tests?

EDIT:

I did this while I remove subdir objects from /Makefile.am tests. Now it raises some warnings, but compiles. However, this does not seem to be suitable for solving unit tests.

+5
source share
1 answer

After some research, I came up with a suitable way to handle unit tests and Automake:

Following the previous pattern:

 ./ + tests/ + Makefile.am + classA_test.cc .... + classB_test.cc + src/ + lib/ + Makefile.am 

Makefile.am will be the main root, this one calls the makefile in the test directory

 $ cat Makefile.am SUBDIRS = . tests # (Super Important) note the "." before tests, # it means it will be executed first .... $ cat test/Makefile.am AM_CXXFLAGS = ... AM_LDFLAGS = -L @ top_srcdir@ /lib #If needed LDADD = -llibraryfortests #If needed TESTS = test1 .. testN test1_SOURCES = test1.cc ../src/somewhere/classtotest.cc testN_SOURCES = ... $ cat configure.ac AM_INIT_AUTOMAKE([subdir-objects]) AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([tests/Makefile]) ... 

Now if you want to run tests

 $ sh ../pathto/configure $ make check 

In addition, dist [check] should work

 $ make distcheck ... make[3]: Entering directory `/home/vicente/test/tests' PASS: settings ============================================================================ Testsuite summary for Pepinos 00.13.15 ============================================================================ # TOTAL: 1 # PASS: 1 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ make[3]: Leaving directory `/home/vicente/test/tests' ... 

So, to answer another question?

Q. I cannot export my variables - such as AM_CPPFLAGS-- to another Makefile.

a. True, but I can always declare a variable in configure.ac and AC_SUBT to make it visible to another Makefile.am

Sources: fooobar.com/questions/944043 / ...

+1
source

Source: https://habr.com/ru/post/944026/


All Articles