Forrest logo
back to the ctest tool

ctest:tldr:25e10

ctest: Run a single test based on its name, or filter on a regular expression.
$ ctest --output-on-failure -R '^${test_name}$'
try on your machine

The command "ctest --output-on-failure -R '^${test_name}$'" is used to run a specific test case and display its output only when it fails.

Here is a breakdown of the different components of the command:

  • "ctest": It is a command-line tool for running tests in CMake-based projects.

  • "--output-on-failure": This option ensures that the output of a test case is displayed on the console only when it fails. If a test case passes successfully, its output will not be shown.

  • "-R '^${test_name}$'": This option is used to specify a regular expression pattern for matching the test case(s) to be executed. In this case, the pattern is '^${test_name}$', where:

    • '^': indicates the start of the input string.
    • '${test_name}': represents a variable that holds the name of the test case to be run. The value of this variable will be substituted in place of '${test_name}' at runtime.
    • '$': indicates the end of the input string.

So, when you run this command, it will run the test case(s) whose name matches the provided regular expression pattern and display their output only if they fail. The value of the 'test_name' variable should be specified appropriately to match the desired test case.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the ctest tool