Using files in Check test cases
I need to use a file for one of my tests written using Check. I initially hardcoded the path, which worked fine. However, this didn't work when the code is built outside of the source directory. I came up with the following solution which somewhat works. (I then prefix pathnames with TESTS_DIR
)
# Set correct directory for test files
AS_IF([test "x$srcdir" = x.],
[TESTS_DIR=""],
[TESTS_DIR="$srcdir/tests/"])
AC_DEFINE_UNQUOTED([TESTS_DIR], ["$TESTS_DIR"]开发者_开发问答, [directory for test files])
Unfortunately, this fails again for make distcheck
. I could post specific path layouts and structures, but I'm wondering if there's an "easy" way to refer to files in the source directory in all these cases. Thanks!
UPDATE: I've tried to use absolute paths, but it seems $abs_top_srcdir
isn't set when I tried to update the define in configure.ac
. Any thoughts as to why that is would be appreciated.
I discovered that the problem was that $top_srcdir
is not set at configure time. Instead, I added -DTESTS_DIR="\"$(top_srcdir)/tests/\""
to AM_CFLAGS
in my tests Makefile.am
and also added all directories containing test files to EXTRA_DIST
.
精彩评论