umläute
umläute

Reputation: 31284

how to make autotools tests read files?

my autotools project has a couple of unit-tests. one of these tests (filereader) needs to read a file (data/test1.bin)

Here's my filesystem layout: - libfoo/tests/filereader.c - libfoo/tests/data/test1.bin

and my libfoo/tests/Makefile.am:

AUTOMAKE_OPTIONS = foreign
AM_CPPFLAGS = -I$(top_srcdir)/foo
LDADD = $(top_builddir)/src/libfoo.la

EXTRA_DIST = data/file1.bin

TESTS = filereader
check_PROGRAMS= filereader
filereader_SOURCES = filereader.c

this works great, as long as i do in-tree builds. However, when running the test-suite out-of-tree (e.g. make distcheck), the filereader test cannot find the input file anymore.

This is obviously because only the source tree contains the input file, but not the build tree.

i wonder what is the canonical way to fix this problem?

Upvotes: 5

Views: 570

Answers (2)

Edward Hartnett
Edward Hartnett

Reputation: 961

There is a way to do this with autoconf. From the netcdf-c configure.ac:

##
# Some files need to exist in build directories
# that do not correspond to their source directory, or
# the test program makes an assumption about where files
# live.  AC_CONFIG_LINKS provides a mechanism to link/copy files
# if an out-of-source build is happening.
##

AC_CONFIG_LINKS([nc_test4/ref_hdf5_compat1.nc:nc_test4/ref_hdf5_compat1.nc])
AC_CONFIG_LINKS([nc_test4/ref_hdf5_compat2.nc:nc_test4/ref_hdf5_compat2.nc])
AC_CONFIG_LINKS([nc_test4/ref_hdf5_compat3.nc:nc_test4/ref_hdf5_compat3.nc])

AC_CONFIG_LINKS([nc_test4/ref_chunked.hdf4:nc_test4/ref_chunked.hdf4])
AC_CONFIG_LINKS([nc_test4/ref_contiguous.hdf4:nc_test4/ref_contiguous.hdf4])

Upvotes: 0

Diego Elio Pettenò
Diego Elio Pettenò

Reputation: 3240

Canonically, the solution would be to define the path to your file into the unittest, so the first option you laid out. The second one is also possible but it requires using an in-between driver script.

I would suggest avoiding the third one, but if you do want to go down that route, use $(LN_S) rather than cp; this way you reduce the I/O load of the test.

Upvotes: 2

Related Questions