LinuxCommandLibrary

ctest

Run and test software built with CMake

TLDR

Run all tests defined in the CMake project, executing 4 [j]obs at a time in parallel

$ ctest [[-j|--parallel]] [4] --output-on-failure
copy

List available tests
$ ctest [[-N|--show-only]]
copy

Run a single test based on its name, or filter on a regular expression
$ ctest --output-on-failure [[-R|--tests-regex]] '^[test_name]$'
copy

SYNOPSIS

ctest [options]

PARAMETERS

--build-config
    Set the build configuration to test (e.g., Debug, Release).

-C
    Alias for --build-config.

--output-on-failure
    Display the output of failed tests.

-O
    Alias for --output-on-failure

-j
    Run tests in parallel using the specified number of jobs.

--parallel
    Alias for -j.

--verbose
    Enable verbose output.

-V
    Alias for --verbose.

--test-listing-file
    Write the list of tests to the file

--help
    Display help information.

--version
    Display version information.

-N
    Do not execute tests. Display a list of tests instead

DESCRIPTION

ctest is the CMake test driver program. It is used to run tests defined by CMake's add_test() command.
ctest can execute tests individually or in parallel, and it supports various testing frameworks and methodologies.
It provides detailed reporting on test results, including pass/fail status, execution time, and output logs. ctest can be used for regression testing, continuous integration, and general software testing purposes. It's an essential tool in CMake-based projects for ensuring code quality and stability.
It's primarily used from the command line but is often integrated into build scripts or CI/CD pipelines.

CAVEATS

ctest requires a CMake-generated build directory containing test definitions. The build directory must be set up correctly before running ctest.

TEST SELECTION

ctest provides different options for selecting and running a subset of tests instead of running all defined tests. Tests can be selected based on their name, index, or regular expression.

RETURN VALUE

ctest returns 0 if all tests pass, and a non-zero value if any tests fail.

HISTORY

ctest was developed as part of the CMake build system to provide a standardized way to run and report on tests within CMake projects. Its evolution has been closely tied to the development of CMake itself, adding features such as parallel test execution, advanced reporting, and integration with various CI systems.

SEE ALSO

cmake(1), make(1)

Copied to clipboard