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

查看:57
本文介绍了使用 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 始终使用 --verbose 运行?有没有更好的方法在 CMake/CTest 中使用 Boost 单元测试?

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

这个Stack Overflow 问答 展示了如何在 Visual Studio 中设置环境变量.

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

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

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