使用CMake,如何从CTest获得详细输出? [英] Using CMake, how do I get verbose output from CTest?

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

问题描述

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

I'm using CMake to build my project. I have added a unit test binary which is using the 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

这不是很有帮助,因为我看不到哪个测试失败。如果我使用-verbose 从命令行手动运行ctest,我将获得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 a 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以-详细

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?

推荐答案

您可以设置环境变量 CTEST_OUTPUT_ON_FAILURE ,它将在测试失败时向您显示测试程序的任何输出。使用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 Stack Overflow question and answer shows how to set environment variables in Visual Studio.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆