ctest(1): Add CTEST_NO_TESTS_ACTION env var

This environment variable provides a default value for the
--no-tests=<action> command line argument.
This commit is contained in:
friendlyanon 2022-12-30 15:11:17 +01:00
parent bb52a1781a
commit 0661de58d8
14 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,14 @@
CTEST_NO_TESTS_ACTION
---------------------
.. versionadded:: 3.26
.. include:: ENV_VAR.txt
Environment variable that controls how :manual:`ctest <ctest(1)>` handles
cases when there are no tests to run. Possible values are: ``error``,
``ignore``, empty or unset.
The :option:`--no-tests=\<action\> <ctest --no-tests>` option to
:manual:`ctest <ctest(1)>` overrides this environment variable if both
are given.

View File

@ -92,6 +92,7 @@ Environment Variables for CTest
/envvar/CMAKE_CONFIG_TYPE
/envvar/CTEST_INTERACTIVE_DEBUG_MODE
/envvar/CTEST_NO_TESTS_ACTION
/envvar/CTEST_OUTPUT_ON_FAILURE
/envvar/CTEST_PARALLEL_LEVEL
/envvar/CTEST_PROGRESS_OUTPUT

View File

@ -435,6 +435,11 @@ Run Tests
unifies the behavior of CTest by either returning an error code if no tests
were found or by ignoring it.
.. versionadded:: 3.26
This option can also be set by setting the :envvar:`CTEST_NO_TESTS_ACTION`
environment variable.
View Help
=========

View File

@ -0,0 +1,7 @@
ctest-no-tests-action-env-var
-----------------------------
* The :envvar:`CTEST_NO_TESTS_ACTION` environment variable was added to
provide a default value for the
:option:`--no-tests=\<action\> <ctest --no-tests>` command line
argument of :manual:`ctest(1)`.

View File

@ -217,6 +217,7 @@ struct cmCTest::Private
std::map<std::string, std::string> Definitions;
cmCTest::NoTests NoTestsMode = cmCTest::NoTests::Legacy;
bool NoTestsModeSetInCli = false;
};
struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag)
@ -2132,6 +2133,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
} else {
this->Impl->NoTestsMode = cmCTest::NoTests::Ignore;
}
this->Impl->NoTestsModeSetInCli = true;
}
// options that control what tests are run
@ -2774,6 +2776,24 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output)
}
}
// handle CTEST_NO_TESTS_ACTION environment variable
if (!this->Impl->NoTestsModeSetInCli) {
std::string action;
if (cmSystemTools::GetEnv("CTEST_NO_TESTS_ACTION", action) &&
!action.empty()) {
if (action == "error"_s) {
this->Impl->NoTestsMode = cmCTest::NoTests::Error;
} else if (action == "ignore"_s) {
this->Impl->NoTestsMode = cmCTest::NoTests::Ignore;
} else {
cmCTestLog(this, ERROR_MESSAGE,
"Unknown value for CTEST_NO_TESTS_ACTION: '" << action
<< '\'');
return 1;
}
}
}
// TestProgressOutput only supported if console supports it and not logging
// to a file
this->Impl->TestProgressOutput = this->Impl->TestProgressOutput &&

View File

@ -389,6 +389,14 @@ function(run_NoTests)
run_cmake_command(no-tests_error ${CMAKE_CTEST_COMMAND} --no-tests=error)
run_cmake_command(no-tests_bad ${CMAKE_CTEST_COMMAND} --no-tests=bad)
run_cmake_command(no-tests_legacy ${CMAKE_CTEST_COMMAND})
run_cmake_command(no-tests_env_ignore ${CMAKE_COMMAND} -E env CTEST_NO_TESTS_ACTION=ignore ${CMAKE_CTEST_COMMAND})
run_cmake_command(no-tests_env_error ${CMAKE_COMMAND} -E env CTEST_NO_TESTS_ACTION=error ${CMAKE_CTEST_COMMAND})
run_cmake_command(no-tests_env_bad ${CMAKE_COMMAND} -E env CTEST_NO_TESTS_ACTION=bad ${CMAKE_CTEST_COMMAND})
run_cmake_command(no-tests_env_empty_legacy ${CMAKE_COMMAND} -E env CTEST_NO_TESTS_ACTION= ${CMAKE_CTEST_COMMAND})
run_cmake_command(no-tests_env_bad_with_cli_error ${CMAKE_COMMAND} -E env CTEST_NO_TESTS_ACTION=bad ${CMAKE_CTEST_COMMAND} --no-tests=error)
file(WRITE "${RunCMake_TEST_BINARY_DIR}/NoTestsScript.cmake" "
set(CTEST_COMMAND \"${CMAKE_CTEST_COMMAND}\")
set(CTEST_SOURCE_DIRECTORY \"${RunCMake_SOURCE_DIR}\")

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
^Unknown value for CTEST_NO_TESTS_ACTION: 'bad'$

View File

@ -0,0 +1 @@
No tests were found!!!

View File

@ -0,0 +1 @@
^No tests were found!!!$

View File

@ -0,0 +1 @@
8

View File

@ -0,0 +1 @@
No tests were found!!!

View File

@ -3,6 +3,7 @@ include(RunCMake)
# Isolate our ctest runs from external environment.
unset(ENV{CTEST_PARALLEL_LEVEL})
unset(ENV{CTEST_OUTPUT_ON_FAILURE})
unset(ENV{CTEST_NO_TESTS_ACTION})
function(run_ctest CASE_NAME)
configure_file(${RunCMake_SOURCE_DIR}/test.cmake.in