129 Commits
Author SHA1 Message Date
Taylor Braun-JonesandTyler Yankee 5cced02b9d CTest: Repeat test fixtures with the tests that require them
When ctest repeats tests with its --repeat option, it repeats each test
on its own.  A fixture's setup and cleanup tests therefore run all of
their repetitions back to back, and the tests they bracket repeat inside
a single setup/cleanup pair:

  setup -> setup -> test -> test -> cleanup -> cleanup

Add a FIXTURE_REPEAT_MODE test property to select how a fixture behaves
when its tests are repeated:

* AROUND_ALL_REPEATS: the fixture runs once, around all repetitions of
  the tests requiring it.
* AROUND_EACH_REPEAT: the fixture and the tests requiring it repeat
  together, so every repetition gets a fresh setup and its own cleanup.
* EACH_TEST_SEPARATELY: every test repeats on its own, as before.

The property describes the fixture rather than the test carrying it, so
setting it on any one of a fixture's setup or cleanup tests is enough.

In AROUND_EACH_REPEAT mode the tests of a fixture form a repeat group that
ctest re-queues as a whole once every test in it has finished.  The --repeat
condition then applies to the group the way it applies to an individual
test: until-fail repeats while the whole group passes, until-pass repeats
while any of it does not, and after-timeout repeats while any of it times
out.  Fixtures that share a test repeat together, so a test requiring two of
them still runs once per repetition.

A group is recorded the way a repeating test is: only once it stops
repeating, and with the results of its last repetition.  A group that
until-pass makes pass therefore reports a pass rather than the failure that
made it repeat, a test that DEPENDS on one of the group's tests waits for
the last repetition rather than the first, and `ctest -F` resumes an
interrupted group by running it again from the beginning.

Fixtures that repeat together have to agree on the mode: a test cannot
repeat with one fixture but not with another it takes part in, and a fixture
whose setup and cleanup tests disagree has no coherent behavior.  Report an
error and run nothing in those cases rather than pick an order in which a
test repeats after a fixture it requires has been cleaned up.

Add policy CMP0224 to select AROUND_EACH_REPEAT as the default for fixtures
whose setup and cleanup tests choose no mode themselves.  Record the mode
the policy chose in the generated test file under its own
_CMAKE_DEFAULT_FIXTURE_REPEAT_MODE keyword, so that ctest reads a mode
rather than the policy settings behind it, and so that a mode requested on
one of a fixture's tests wins over the default recorded for its siblings.
Only NEW needs recording: with nothing recorded, ctest already uses the
behavior of CMake 4.4 and below.  Fixtures are common, and the choice of
mode matters only to those who run ctest --repeat, so warn about the unset
policy only when the CMAKE_POLICY_WARNING_CMP0224 variable asks for it.

discover_tests() and gtest_discover_tests() create their tests while ctest
runs or at build time, too late for the policy to reach them, so carry the
setting in effect at their call sites through to the tests they create.

Report the repetition a grouped test belongs to in the "(run N/M)" suffix
of its "Start" line, as ctest already does for a test repeating on its own.

Co-authored-by: Tyler Yankee <tyler.yankee@kitware.com>
Fixes: #21438
2026-09-18 08:29:28 -04:00
Brad King ab46a992e5 Merge topic 'ctest-dashboard-preset-env'
27f28db197 Help: Clarify CTEST_NO_TESTS_ACTION support and interaction
a235560e53 Help: Clarify interaction between CTest parallelism toggles
f745dd11ab ctest: Respect test envvars set by CTEST_PRESET
277236a99a cmCTestTestCommand: Factor out preset resolution
81b46d87ba cmCTest: Factor out environment variable handling
4e81913645 Tests: Fix unset(ENV{...}) typos

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12495
2026-09-18 07:59:56 -04:00
Tyler Yankee f745dd11ab ctest: Respect test envvars set by CTEST_PRESET
Note the special attention given to support CTest environment variables
from inside a test preset's `environment` field.

Fixes: #28079
2026-09-16 09:34:43 -04:00
Tyler Yankee 4e81913645 Tests: Fix unset(ENV{...}) typos 2026-09-16 08:51:36 -04:00
Tyler Yankee ec138e6f8e ctest: Add CLI argument spell checking
Use Levenshtein distance to track when the user may have made a typo in
an argument to `ctest`.
2026-09-11 08:23:32 -04:00
Nerixyz 865d6bf223 CTest: Support --max-width shorter than longest test name
Fixes: #24101
2026-09-07 18:21:35 +02:00
Maxime HaselbauerandTyler Yankee 135c7aa1f1 ctest: Add test rerun index "(run XX/YY)" to output
This makes the output more user friendly when using CTest's repeat
options (`until-fail`, `until-pass` `after-timeout`).

Closes: #28039
Co-authored-by: Tyler Yankee <tyler.yankee@kitware.com>
2026-08-21 09:11:52 -04:00
Arha Gatram 572e4b5d2a ctest: Add --show-only=json-v1-raw option
This option changes the JSON value field for test properties to use the
unparsed string value.

Fixes: #27958
2026-08-03 09:36:11 -07:00
Tyler Yankee 4eda69be82 Tests: Centralize JSON schema validation
As the number of areas in CMake for which we've provided JSON schemas
has expanded, testing infrastructure has mostly been copy-pasted across
the relevant test suites. Unify it to a single reusable validator
script and CMake helper.
2026-07-24 09:55:23 -04:00
Brad King 40089c5db6 Merge topic 'ctest-configure-avoid-unused-cli-warning'
72eac83626 ctest: Avoid unused-cli warning when propagating SITE/BUILDNAME

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12299
2026-07-21 15:15:30 -04:00
Zack Galbreath 72eac83626 ctest: Avoid unused-cli warning when propagating SITE/BUILDNAME
Commit 433721b7a7 (ctest: Pass CTEST_SITE/CTEST_BUILD_NAME to configure
step, 2026-06-15) updated ctest_configure() to pass `-DSITE=...` and
`-DBUILDNAME=...` to the configure command whenever CTEST_SITE or
CTEST_BUILD_NAME are set. Projects that don't include the CTest module never
reference these cache variables, causing CMake to report an unused-cli warning.

Use `-C <initial-cache>` instead of `-D` to seed SITE/BUILDNAME. Cache entries
set using `-C` are not tracked by CMake's unused-cli diagnostic, so projects
using the CTest module still get DartConfiguration.tcl populated correctly,
while projects that never reference SITE/BUILDNAME no longer see the warning.

Fixes: #27953
2026-07-20 13:21:00 -04:00
Brad King 9d55e56259 Merge topic 'ctest-junit-exit-error'
0d320cb496 ctest: Exit nonzero when write to output JUnit or XML fails

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12282
2026-07-20 09:56:03 -04:00
Tyler Yankee 0d320cb496 ctest: Exit nonzero when write to output JUnit or XML fails
`ProcessHandler` can return -1, 0, or 1, and the latter is used in this
particular case.

Fixes: #27949
2026-07-15 15:56:03 -04:00
Brad King 28ce1b8bc3 Merge topic 'test-out-of-date'
e11b5827c3 ctest: Add --out-of-date option for running out of date tests

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12180
2026-07-01 09:45:18 -04:00
Martin Duffy e11b5827c3 ctest: Add --out-of-date option for running out of date tests
Add an --out-of-date option to ctest which runs only those tests with
recorded build dependencies whose timestamps are newer than the timestamp
at which the test last finished.

Fixes: #27614
2026-06-30 11:31:35 -04:00
Brad King d781e3b477 Tests: Update https-is-disabled error message for curl 8.21 2026-06-30 10:32:54 -04:00
Zack Galbreath 433721b7a7 ctest: Pass CTEST_SITE/CTEST_BUILD_NAME to configure step
When performing the configure step in dashboard client mode, propagate
`CTEST_SITE` and `CTEST_BUILD_NAME` as the `SITE` and `BUILDNAME`
respective cache variables.

This causes the values recorded in `DartConfiguration.tcl` to match those
specified by the user, allowing subsequent ctest calls to reuse them
automatically.
2026-06-15 10:56:11 -04:00
Zack Galbreath 3b6247a148 ctest: Honor preset binaryDir for initial configuration
Prior to this commit, ctest would sometimes use the current working directory
as its binary directory rather than honoring `binaryDir` from a configure
preset. This would occur when using ctest in dashboard client mode to perform
an initial configuration with a preset.

  `ctest --source-dir=<dir> -T Configure -D CTEST_PRESET=<preset>`

An explicit `--build-dir` still takes precedence over the preset's `binaryDir`.
2026-06-13 08:50:33 -04:00
Zack Galbreath a798a84b22 ctest: add new variable CTEST_SUBMIT_PARTS
This new variable allows dashboard client users to specify what parts
to submit.
2026-06-03 10:45:42 -04:00
Zack Galbreath 9a0010eef2 ctest: add --source-dir argument to enable initial configure
Add the --source-dir argument to ctest to allow it to perform an initial
configuration step for an empty binary directory when operating in
dashboard client mode.
2026-06-01 14:11:46 -04:00
Zack Galbreath 2e214f0a5b ctest: allow CTest Script variables to be set via the command-line
Allow CTEST_* variables to be defined on the command-line when using
`ctest -T`.

Fixes: #27788
2026-05-14 11:37:57 -04:00
Brad King 5494697ed1 Tests: Add case for llvm-cov usage by ctest command line modes
Follow up commit a7780d1b9c (ctest: Add a `CoverageTool` setting to
enable integration with `llvm-cov`, 2026-04-15).

Issue: #26932
2026-05-11 11:32:15 -04:00
Brad King 61cba092a2 Tests: Update expected DNS resolution error message for curl 8.20
The word "host" is no longer included.
2026-04-29 14:17:22 -04:00
scivision d0100b4060 ctest: Avoid printing failed if nothing failed
Fixes: #27607
2026-04-14 15:56:49 -04:00
Mickaël Germain b3980bf703 ctest: Add support for forwarding arguments to tests via --
Add support for `ctest [options] -- <args>` to forward extra arguments
to every executed test's command line. Arguments after `--` are appended
after each test's own arguments in the order given.

This enables passing options to test frameworks like Google Test or
doctest without needing per-test ARGS properties:

    ctest -R my_test -- --gtest_filter=SomeTest.Case
    ctest --verbose -- --success

An error is raised if `--` is combined with `--build-and-test`, `-S`,
or `-D`/`-T`/`-M` modes, which have their own argument forwarding.
A bare `--` with no following arguments is silently ignored.

Fixes: #20470
2026-03-13 16:21:02 -07:00
Sebastian Sura 3e89f5ae83 ctest: Disable pre- and post-processing during --show-only
Do not run the custom pre-/post- test tasks when instructed to only show
the tests that would be executed.  Otherwise it's impossible to reliably
parse the output of this as is will be contaminated by all output
produced by the pre-/post-scripts!

Fixes: #23254
2026-03-03 16:57:05 -05:00
Sertonix 8dbb7f65f9 ctest: Exit 1 when argc == 1 and no input file exists
Fixes: #26759
2026-03-02 12:20:08 -05:00
Brad King 8f848dbc1f Tests/RunCMake/CTestCommandLine: Add case for ctest --rerun-failed
Remove the old `CTestTestRerunFailed` test.
2025-12-08 15:16:51 -05:00
AJIOB 5de7a09e77 Tests/RunCMake: Match dots more precisely, part 3 2025-10-20 14:45:24 -04:00
AJIOB 06ccd15457 Tests/RunCMake: Match xxx.cmake file name more precisely 2025-10-16 17:42:12 +03:00
Brad King 8f166fa51e ci: Add jobs to perform coverage with BullseyeCoverage on Linux 2025-10-05 07:04:03 -04:00
Brad King d84e4dd621 Merge topic 'ctest-T-test-timeout'
9dc3edbba8 ctest: Restore default test timeout for command-line `-T Test` step
8745e6308e ctest: Restore default of no time limit for command-line `-T Test` step

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11094
2025-08-20 10:01:02 -04:00
Brad King 9dc3edbba8 ctest: Restore default test timeout for command-line -T Test step
In commit 774fcbe49c (CTest: Base command line mode on top of scripting
commands, 2024-10-05, v4.0.0-rc1~653^2) the implementation of this step
was converted to use `ctest_test` internally.  That command has its own
default test timeout of 600s if the ctest "TimeOut" configuration value
is not set.  If "TimeOut" is not set then default it to our previous
command-line mode default test timeout.

Fixes: #27139
2025-08-18 14:30:56 -04:00
Craig Scott 2e7bca5f05 ctest: Add JSON schema for --show-only=json-v1 output
Add schema validation to the existing test case for --show-only=json-v1 too.

Fixes: #26980
2025-06-10 07:12:31 +10:00
Brad King bf5661bb25 Merge topic 'test-ctest-regression'
6bc5b467a9 Tests: Fix RunCMake.CTestCommandLine under ctest -T Coverage

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !10699
2025-04-23 08:43:05 -04:00
Brad King 6bc5b467a9 Tests: Fix RunCMake.CTestCommandLine under ctest -T Coverage
Update commit 712cb8cb14 (ctest: Restore support for -T Test without
dashboard configuration, 2025-03-06, v4.0.0-rc4~11^2) to avoid
conflating coverage of CMake itself with the coverage mode of ctest
being tested.
2025-04-22 11:25:24 -04:00
Daniel GoldbergandBrad King d3455f38de ctest: Add option to specify the --schedule-random seed
When `--schedule-random` is used in automated CI jobs, failures may
occur due to test order.  We now log the seed.  Provide a way for
developers to re-run the same order by specifying the seed.

Fixes: #26760
Co-authored-by: Brad King <brad.king@kitware.com>
2025-03-18 14:17:59 -04:00
Daniel PfeiferandBrad King 712cb8cb14 ctest: Restore support for -T Test without dashboard configuration
Since commit 774fcbe49c (CTest: Base command line mode on top of
scripting commands, 2024-10-05, v4.0.0-rc1~653^2) we drive dashboard
client steps through `cmCTestHandlerCommand::ExecuteHandlerCommand`
instead of calling `ProcessHandler` directly.  This requires the
`BuildDirectory` to be known to establish a work directory.

Fixes: #26743
Co-authored-by: Brad King <brad.king@kitware.com>
2025-03-06 09:43:22 -05:00
Brad King 7b041f7fe8 ctest: Print GENERATED_RESOURCE_SPEC_FILE property in show-only output
This was missed in commit c8c1dd0d95 (CTest: Add ability to dynamically
generate resource spec file, 2023-07-20, v3.28.0-rc1~233^2).
2024-11-25 14:18:07 -05:00
Brad King 733808150b ctest: Print custom timeout signal properties in show-only output
This was missed in commit 54c5654f7d (ctest: Optionally terminate tests
with a custom signal on timeout, 2023-05-11, v3.27.0-rc1~18^2).
2024-11-25 14:17:34 -05:00
Brad King 57587b3863 Tests/RunCMake/CTestCommandLine: Fix python string literal syntax 2024-11-25 12:15:29 -05:00
Daniel Pfeifer 281e9039cb cmWorkingDirectory: Unify error messages 2024-10-18 15:04:07 -04:00
Daniel Pfeifer 774fcbe49c CTest: Base command line mode on top of scripting commands
Make sure that all CMake variables that are translated into
CTest options in `cmCTest*Command` implementations are translated
from CTest options into CMake variables before the functions are
called.  This back-and-forth translation should be temporary.
It is a necessary prerequisite for refactoring `cmCTest*Handler`
implementations to operate on CMake variables directly rather
than CTest options.
2024-10-12 06:42:02 -04:00
Daniel Pfeifer 5115c01e1f CTestCommandLine tests: Make sure to test successful run
Add a DartConfiguration.tcl file in two places, so that testing the
generated Text.xml file does not depend on output in stderr.
2024-10-09 18:48:52 +02:00
Brad King f4aa34daa7 Tests/RunCMake: Update cmake_minimum_required versions to 3.10
For policy-specific tests, use the version before the policy was
introduced.  Otherwise, use 3.10 where possible.
2024-10-03 11:52:22 -04:00
Brad King 8f6092fc20 Tests: Move ctest --print-labels case into RunCMake.CTestCommandLine 2024-07-24 10:07:35 -04:00
Wim Colgate 49e9f817de ctest: Display test labels in failure summary
In a complex test environment, there may be a desire to add a test
property label to indicate context. Here is one such example:

    set_property(TEST mygoofytest PROPERTY LABELS might-fail-on-config-change)

Upon looking at the failed test summary, one can quickly decide whether
the failure might be expected or not.

    198 - mygoofytest (Failed)                might-fail-on-config-change
2024-07-17 13:56:01 -04:00
castro-ma c971212703 ctest: Allow --test-dir override when using presets
Fixes: #23982
2024-04-24 16:45:29 -04:00
Martin Duffy 96dbf6c34a ctest: Cleanup for invalid argument handling
Backs out unrelated change and changes error message to 'Unknown argument'
2024-04-17 15:44:56 -04:00
Brad King c2949dbdf8 Merge topic 'ctest-invalid-arg'
304396d13c ctest: Show error on invalid ctest arguments
06cb978c1b Tests: Fix ctest flag typo in RunCMake.GoogleTest

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Acked-by: scivision <michael@scivision.dev>
Merge-request: !9383
2024-04-05 11:55:47 -04:00