在检查测试用例中使用文件
我需要使用一个文件来进行使用 Check 编写的测试。我最初对路径进行了硬编码,效果很好。但是,当代码在源目录之外构建时,这不起作用。我想出了以下有点有效的解决方案。 (然后我在路径名前添加了 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])
不幸的是,make distcheck
再次失败。我可以发布特定的路径布局和结构,但我想知道在所有这些情况下是否有一种“简单”的方法来引用源目录中的文件。谢谢!
更新:我尝试使用绝对路径,但当我尝试更新 configure.ac$abs_top_srcdir
代码>.任何关于为什么会这样的想法将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现问题是在配置时未设置
$top_srcdir
。相反,我在测试Makefile.am
中将-DTESTS_DIR="\"$(top_srcdir)/tests/\""
添加到AM_CFLAGS
中,并且还将包含测试文件的所有目录添加到EXTRA_DIST
中。I discovered that the problem was that
$top_srcdir
is not set at configure time. Instead, I added-DTESTS_DIR="\"$(top_srcdir)/tests/\""
toAM_CFLAGS
in my testsMakefile.am
and also added all directories containing test files toEXTRA_DIST
.