Make distcheck and tests that need input files

I recently converted my build system to automake / autoconf. In my project, I have several unit tests that need input files in the directory from where they run. When I run make distcheck and it tries to build VPATH, these tests fail because they apparently do not run from the directory where the input files are. I was wondering if there is any quick fix for this. For example, can I somehow tell the system not to run these tests on make distcheck (but still run them on make check)? Or in cd to the directory where the files are located before running the tests?

+6
source share
2 answers

I had the same problem and used a solution similar to William. My Makefile.am looks something like this:

EXTRA_DIST = testdata/test1.dat AM_CPPFLAGS = -DDATADIR=\"$(srcdir)/\" 

Then, in my unittest, I use the DATADIR define:

 string path = DATADIR "/testdata/test1.dat" 

This works with make check and make distcheck .

+7
source

A typical solution is to write tests so that they look in the source directory for data files. For example, you can refer to $srcdir in a test or convert test to test.in and refer to @ srcdir@ .

If your tests are all in the source directory, you can run all the tests in this directory by setting TESTS_ENVIRONMENT in Makefile.am:

 TESTS_ENVIRONMENT = cd $(srcdir) && 

This will fail if some of your tests are created by configure and therefore will live only in the build directory, in which case you can selectively cd with something like:

  TESTS_ENVIRONMENT = { test $${tst} = mytest && cd $(srcdir); true; } && 

Trying to use TESTS_ENVIRONMENT, as it is fragile at best, and it would be better to write tests so that they look in the source directory for the data files.

+4
source

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


All Articles