Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CMake, how do I get verbose output from CTest?

Tags:

cmake

ctest

People also ask

What is CMake CTest?

CTest provides a command-line signature to configure (i.e. run cmake on), build, and/or execute a test: ctest --build-and-test <path-to-source> <path-to-build> --build-generator <generator> [<options>...]

Is CTest part of CMake?

CTest is an executable that comes with CMake; it handles running the tests for the project. While CTest works well with CMake, you do not have to use CMake in order to use CTest.

What is CTest command?

DESCRIPTION. The "ctest" executable is the CMake test driver program. CMake-generated build trees created for projects that use the ENABLE_TESTING and ADD_TEST commands have testing support. This program will run the tests and report results.


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

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


You could call ctest directly, after cmaking and making your project.

ctest --verbose

  1. You can check the Testing/Temporary subfolder. It is automatically created after running make test. This folder contains two files: LastTest.log and LastTestsFailed.log. LastTest.log contains desired output for run tests. LastTestFailed.log contains names of failed tests. So you can check them manually after executing make test.

  2. The second way is to get ctest to show you the content of log files after running tests:

    1. place in build dir (from which you run make test) file CTestCustom.ctest (you can do it with configure file command, for example) with following contents

      CTEST_CUSTOM_POST_TEST("cat Testing/Temporary/LastTest.log")

Instead of cat you may use whatever Windows cmd command that does similar things.

  1. run make test again and get profit!

additional info about customizing ctest you can find here. Just step to "Customizing cmake" section. Good luck!


There is a very simple solution (which for some reason is difficult to find via Google Search):

ctest --output-on-failure

If you use CMake with Visual Studio's open folder function you can add the

"ctestCommandArgs": "--output-on-failure"

setting to your build configuration.


I had to add "check" target by myself. "make tests" does nothing by some reason. So what I did (as was suggest somewhere on stackoverflow) - I added this target manually. To get verbose output I just wrote it like:

add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)