Unit tests using Automake

谁说我不能喝 提交于 2019-12-30 09:44:08

问题


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

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

The problem comes since my main Makefile.am is using subdir-objects options --note that I am not using recursive makefile for the source files--, I cannot export my variables --such as, AM_CPPFLAGS-- to the other Makefile. So far I made it work using:

  $ make check      

but I keep getting problems for the paths and the options when I do

  $ make distcheck

So my questions is, how is the standard way to deal with unit tests?

EDIT:

I made it work as long as I remove the subdir-objects from the tests/Makefile.am. Now it throw some warnings but it compiles. Still it seems not to be an appropriate way to deal with unit tests


回答1:


After some research I came up with the appropiate way to deal with Unit tests and Automake:

Following the previous scheme:

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

The makefile.am in the root will be the main one, this one calls the makefile in the tests 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 the tests

$ sh ../pathto/configure 
$ make check 

As well 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 the other question?

Q. I cannot export my variables --such as, AM_CPPFLAGS-- to the other Makefile.

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

Sources: https://stackoverflow.com/a/29255889/2420872



来源:https://stackoverflow.com/questions/29251038/unit-tests-using-automake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!