gpt4 book ai didi

cmake - 仅在 ctest 中运行时测试可执行文件失败

转载 作者:行者123 更新时间:2023-12-01 10:37:05 25 4
gpt4 key购买 nike

当我使用 ctest 接口(interface)进行 cmake ( add_test(...) ),并运行 make 目标 make test ,我的几个测试失败了。当我直接从二进制构建文件夹的命令行运行每个测试时,它们都可以工作。

我可以用什么来调试这个?

最佳答案

要调试,可以先运行ctest直接代替make test .

然后您可以添加 -V ctest 的选项获得详细的输出。

第三个neat trick from a cmake developer是让 ctest 启动一个 xterm shell。所以添加

add_test(run_xterm xterm)

在最后的 CMakeLists.txt 文件中。然后运行 ​​ make test它会打开一个xterm。然后看看你是否可以通过从 xterm 运行它来复制失败的测试。如果确实失败了,请检查您的环境(即从 xterm 运行 env > xterm.env,然后从正常 session 中再次运行 env > regular.env 并比较输出)。

我发现我的测试是为了寻找通过二进制 cmake 输出文件夹顶部的相对路径传递的外部文件(即您键入 make test 的那个)。但是,当您通过 ctest 运行测试时,当前工作目录是该特定子目录的二进制文件夹,并且测试失败。

换句话说:

这有效
test/mytest

但这没有用
cd test; ./mytest

我必须修复单元测试以使用它需要的配置文件的绝对路径,而不是像 ../../../testvector/foo.txt 这样的路径.

关于cmake - 仅在 ctest 中运行时测试可执行文件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36189438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com