CMake:为ctest设置一个环境变量(否则自动从ctest / make测试输出测试失败) [英] CMake: setting an environmental variable for ctest (or otherwise getting failed test output from ctest/make test automatically)
问题描述
我希望ctest默认显示失败的测试输出。也就是说,我想运行:
$ make all test
,并查看失败测试的任何输出,而无需 cat Testing / Temporary / LastTest.log
。
看来,有两种方法可以这样做:
(1)设置 CTEST_OUTPUT_ON_FAILURE
环境变量:
$ CTEST_OUTPUT_ON_FAILURE = 1使所有测试
$#或CTEST_OUTPUT_ON_FAILURE = 1 ctest
(2)指定 - 输出失败
标记到 ctest
调用:
$ ctest - output-on-failure
有没有办法编写一个CMakeLists.txt文件, ctests转储失败的测试输出默认情况下,在正常的使所有测试调用没有诉诸在会话中导出全局环境变量或诉诸自定义目标,如 make check
(如 here )?
我知道 SET_TESTS_PROPERTIES()
命令,但尝试如下:
项目(testenv CXX)
ENABLE_TESTING()
ADD_EXECUTABLE(hello hello.cpp)
ADD_TEST( testhello hello)
#以下设置运行测试
#progoram'hello'的shell的环境变量,而不是运行ctest的shell
SET_TESTS_PROPERTIES (testhello
属性环境CTEST_OUTPUT_ON_FAILURE = 1)
,实验表明环境变量在shell中设置测试程序被执行,但不在ctest中执行的shell中。
内置测试
目标无法修改,但您可以添加自定义 che ck
目标,它调用 ctest
与 - 输出失败
开关以下方式:
if(CMAKE_CONFIGURATION_TYPES)
add_custom_target(检查COMMAND $ {CMAKE_CTEST_COMMAND}
--force -new-ctest-process - output-on-failure
--build-config$&CONFIGURATION>)
else()
add_custom_target(检查命令$ {CMAKE_CTEST_COMMAND}
--force-new-ctest-process - output-on-failure)
endif()
为单一构建类型和多配置构建,自定义目标必须设置不同。在后一种情况下,活动构建配置必须使用 - build-config
ctest 调用>标志。默认情况下, - force-new-ctest-process
由内置的测试
目标使用。 p>
I want ctest to show me the failed tests output by default. That is, I want to run:
$ make all test
and see any output of failed tests without having to cat Testing/Temporary/LastTest.log
.
It appears that there are two ways of doing this:
(1) Setting the CTEST_OUTPUT_ON_FAILURE
environmental variable:
$ CTEST_OUTPUT_ON_FAILURE=1 make all test
$ # or CTEST_OUTPUT_ON_FAILURE=1 ctest
(2) Specifying the --output-on-failure
flag to the ctest
invocation:
$ ctest --output-on-failure
Is there a way to write a CMakeLists.txt file such that ctests dumps failed tests output by default on a normal "make all test" invocation WITHOUT resorting to exporting the environmental variable globally in the session or resorting to a custom target like make check
(as described here)?
I am aware of the SET_TESTS_PROPERTIES()
command, but trying it out like this:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(testenv CXX)
ENABLE_TESTING()
ADD_EXECUTABLE(hello hello.cpp)
ADD_TEST(testhello hello)
# Following sets the environment variable for the shell in which the test
# progoram 'hello' is run, but not the shell in which ctest is run
SET_TESTS_PROPERTIES(testhello
PROPERTIES ENVIRONMENT "CTEST_OUTPUT_ON_FAILURE=1")
and experimenting shows that the environmental variable is set in the shell that the test program is executed in, but not in the shell that ctest is executed in.
The built-in test
target cannot be modified, but you can add a custom check
target which invokes ctest
with the --output-on-failure
switch in the following way:
if (CMAKE_CONFIGURATION_TYPES)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure
--build-config "$<CONFIGURATION>")
else()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure)
endif()
The custom target has to be set up differently for single build type and multi-configuration builds. In the latter case, the active build configuration has to be passed on to the ctest
invocation using the --build-config
flag. The --force-new-ctest-process
is used by the built-in test
target by default.
这篇关于CMake:为ctest设置一个环境变量(否则自动从ctest / make测试输出测试失败)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!