Lee Hambley
Lee Hambley

Reputation: 6370

Running Nested Tests with CTest

I have a small, but non-trivial project, which for architectural reasons is built as three separete projects, they are inter-dependent, so unless I'm particularly focused, or improving test-coverage having spotted a hole, it makes sense for me to work from the proejct root.

The layout is as such:

/CMakeLists.txt
/build/
/src/command-line-application/
/src/command-line-application/CMakeLists.txt
/src/command-line-application/build/
/src/command-line-application/src/
/src/command-line-application/tests/
/src/command-line-application/include/
/src/vlc-plugin/
/src/vlc-plugin/src/
/src/libmyproject/
/src/libmyproject/CMakeLists.txt
/src/libmyproject/build/
/src/libmyproject/src/
/src/libmyproject/tests/
/src/libmyproject/include/
/src/libmyotherproject/
/src/libmyotherproject/CMakeLists.txt
/src/libmyotherproject/build/
/src/libmyotherproject/src/
/src/libmyotherproject/tests/
/src/libmyotherproject/include/

A word on the architecture, libmyproject is the real meat of my application, it's built this way because a CLI is a horrible way to ship code to end-users, as a library, it is also used from C# and Objective-C applications. (and all that works as expected)

The libmyotherproject is some platform specific support code, not directly connected to libmyproject, it has a few unit tests.

The vlc-plugin isn't important here, except to show that not everything in /src/*/ has unit tests.

My workflow is typically to hack on the CLI app until something useful crops up, and then refactor it into the library, and make sure it's portable.

When I'm working in /src/*/build/, typically running cmake ../ && make && ctest --output-on-failure, everything works.

When I'm working in /build, and run cmake, the individual components are built correctly (using add_subdirectories()) from CMake, but CTest does not recursively find the tests.

The documentation for CTest is a little unhelpful in what you should do:

USAGE
         ctest [options]

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.

I would have expected since the ADD_TEST() calls live in /src/libmyotherproject/tests/CMakeLists.txt, that they would be run? (They are at least compiled when I run cmake from /build/)

I hope I have been able to provide enough informaton, thank you.

Upvotes: 4

Views: 1439

Answers (1)

DLRdave
DLRdave

Reputation: 14250

Put

include(CTest)

in your top level CMakeLists.txt file before you make any add_subdirectory calls.

That will call enable_testing for you, and also set things up if you ever want to run a ctest dashboard script on the project to send results to a CDash server.

Upvotes: 5

Related Questions