ctest: Exit 1 when argc == 1 and no input file exists

Fixes: #26759
This commit is contained in:
Sertonix
2026-03-02 12:20:08 -05:00
committed by Brad King
parent fa7c993ef9
commit 8dbb7f65f9
7 changed files with 23 additions and 4 deletions
+3
View File
@@ -54,6 +54,9 @@ in the following cases:
* An error occurs, such as failure to process invalid arguments.
* .. versionadded:: 4.4
No arguments are given and no ``CTestTestfile.cmake`` exists.
* The :option:`--no-tests=error <ctest --no-tests>` argument is given and no
tests are executed, e.g., when ``CTestTestfile.cmake`` defines no tests,
or when the given arguments exclude all tests.
+5
View File
@@ -0,0 +1,5 @@
ctest-error-exit
----------------
* :manual:`ctest(1)` now exits with non-zero if invoked with no
arguments and no test input file exists.
+6 -4
View File
@@ -209,12 +209,13 @@ int main(int argc, char const* const* argv)
return 1;
}
bool const haveTestfile = cmSystemTools::FileExists("CTestTestfile.cmake") ||
cmSystemTools::FileExists("DartTestfile.txt");
// If there is a testing input file, check for documentation options
// only if there are actually arguments. We want running without
// arguments to run tests.
if (argc > 1 ||
!(cmSystemTools::FileExists("CTestTestfile.cmake") ||
cmSystemTools::FileExists("DartTestfile.txt"))) {
if (argc > 1 || !haveTestfile) {
if (argc == 1) {
std::cerr << "*********************************\n"
"No test configuration file found!\n"
@@ -228,7 +229,8 @@ int main(int argc, char const* const* argv)
doc.SetSection("Name", cmDocumentationName);
doc.SetSection("Usage", cmDocumentationUsage);
doc.PrependSection("Options", cmDocumentationOptions);
return !doc.PrintRequestedDocumentation(std::cout);
return !doc.PrintRequestedDocumentation(std::cout) ||
(argc == 1 && !haveTestfile);
}
}
@@ -424,6 +424,8 @@ add_test(test2 \"${CMAKE_COMMAND}\" -E echo \"not running\")
endfunction()
run_stop_on_failure()
run_cmake_command(usage ${CMAKE_CTEST_COMMAND})
function(run_TestAffinity)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/TestAffinity)
set(RunCMake_TEST_NO_CLEAN 1)
@@ -0,0 +1 @@
1
@@ -0,0 +1,3 @@
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
No test configuration file found!
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
@@ -0,0 +1,3 @@
Usage
ctest \[options\]