本文介绍了将 ctest 命令替换为“ctest --output-on-failure";永久用于 CMakeLists.txt 中的特定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现通用的 ctest 命令没有提供关于测试的太多信息,所以我想添加 ctest --output-on-failure 但不有用户担心标志.我希望他们只是 cmakemake 项目并运行 ctest,它应该运行 ctest with --output-on-失败 标志.是否可以在 CMakeLists.txt 中做到这一点?

I have found that generic ctest command doesn't give much information about the tests, so I would like to add ctest --output-on-failure but not have the users to worry about the flag. I want them just to cmake, make the project and run ctest and it should run ctest with the --output-on-failure flag. Is it possible to do that in CMakeLists.txt?

env CTEST_OUTPUT_ON_FAILURE=1 make test 的输出

 4/13 Test  #4: TEST_SSSP ........................***Failed  Required regular expression not found.Regex=[CORRECT
]  0.00 sec
Loading Matrix-market coordinate-formatted graph ...
Input graph file /home/muhammad/gunrock/dataset/small/chesapeake.mtx does not exis

set_property(TEST TestName PROPERTY ENVIRONMENT "CTEST_OUTPUT_ON_FAILURE=1") 的输出

 4/13 Test  #4: TEST_SSSP ........................***Failed  Required regular expression not found.Regex=[CORRECT
]  0.00 sec

set_property 中的标志不起作用.

推荐答案

在 CMake 3.17 发行说明,有一个新变量 CMAKE_CTEST_ARGUMENTS 您可以设置为将任何命令行参数传递给 CTest,包括 --output-on-failure.在您的特定情况下,您现在可以简单地将其添加到您的 CMakeLists.txt 中:

In CMake 3.17 release notes, there's a new variable CMAKE_CTEST_ARGUMENTS that you can set to pass any command-line arguments to CTest, including --output-on-failure. In your specific case, you can now simply add this to your CMakeLists.txt:

list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")

这篇关于将 ctest 命令替换为“ctest --output-on-failure";永久用于 CMakeLists.txt 中的特定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 16:14