本文介绍了使用cmake如何从ctest获取详细输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CMake建立我的项目。我已经添加了一个单元测试二进制,它使用boost单元测试框架。这一个二进制包含所有的单元测试。我添加了由CTest运行的二进制文件:

I'm using CMake to build my project. I have added a unit test binary which is using boost unit testing framework. This one binary contains all of the unit tests. I've added that binary to be run by CTest:

ADD_EXECUTABLE( tftest test-main.cpp )
ENABLE_TESTING()
ADD_TEST( UnitTests tftest)

但Visual Studio中的构建输出仅显示运行ctest的结果:

but the build output in Visual Studio only shows the result of running ctest:

      Start 1: UnitTests
  1/1 Test #1: UnitTests ................***Failed    0.05 sec

  0% tests passed, 1 tests failed out of 1

这不是很有帮助,因为我看不到哪个测试失败。如果我从命令行手动运行ctest --verbose,我得到boost单元测试的输出,告诉实际失败的:

This is not very helpful because I can't see which test failed. If I run ctest manually from the command line with --verbose I get the output from boost unit test which tells what actually failed:

1: Test command: tftest.exe
1: Test timeout computed to be: 9.99988e+006
1: Running 4 test cases...
1: test-main.cpp(20): error in "sanity_check3": check 1 == 2 failed
1:
1: *** 1 failure detected in test suite "Master Test Suite"
1/1 Test #1: UnitTests ................***Failed    0.00 sec

那么,我需要改变在CMakeLists.txt有ctest运行--verbose在任何时候?有没有更好的方法使用boost单元测试与cmake / ctest?

So, what do I need to change in the CMakeLists.txt to have ctest run with --verbose at all times? Is there a better way to use boost unit tests with cmake/ctest?

推荐答案

可以设置环境变量,每当测试失败时,它将显示测试程序的任何输出。使用Makefile和命令行执行此操作的一种方法如下:

You can set the environment variable CTEST_OUTPUT_ON_FAILURE, which will show you any output from the test program whenever the test fails. One way to do this when using Makefiles and the command line would be as follows:

env CTEST_OUTPUT_ON_FAILURE=1 make check

显示了如何在Visual Studio中设置环境变量。

This SO question and answer shows how to set environment variables in Visual Studio.

这篇关于使用cmake如何从ctest获取详细输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 05:17