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?
AM_CPPFLAGS+=-DSRCDIR=$(srcdir)
)$(builddir)/filereader $(srcdir)/data/file1.bin
)cp $(srcdir)/data/file1.bin $(builddir)/data/file1.bin
? how would a proper make-rule look like??)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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With