[英]Using files in Check test cases
I need to use a file for one of my tests written using Check . 我需要为使用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
) (然后,我在路径名前加上
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
. 不幸的是,这对于
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
. 更新:我尝试使用绝对路径,但是当我尝试更新
configure.ac
的定义时,似乎没有设置$abs_top_srcdir
。 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. 我发现问题是在配置时未设置
$top_srcdir
。 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
. 相反,我在测试
Makefile.am
-DTESTS_DIR="\\"$(top_srcdir)/tests/\\""
到AM_CFLAGS
中,并且还将所有包含测试文件的目录添加到EXTRA_DIST
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.