From 0661de58d845f537d070979f9b49dd05800a141e Mon Sep 17 00:00:00 2001 From: friendlyanon Date: Fri, 30 Dec 2022 15:11:17 +0100 Subject: ctest(1): Add CTEST_NO_TESTS_ACTION env var This environment variable provides a default value for the --no-tests= command line argument. --- Help/envvar/CTEST_NO_TESTS_ACTION.rst | 14 ++++++++++++++ Help/manual/cmake-env-variables.7.rst | 1 + Help/manual/ctest.1.rst | 5 +++++ Help/release/dev/ctest-no-tests-action-env-var.rst | 7 +++++++ Source/cmCTest.cxx | 20 ++++++++++++++++++++ Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake | 8 ++++++++ .../CTestCommandLine/no-tests_env_bad-result.txt | 1 + .../CTestCommandLine/no-tests_env_bad-stderr.txt | 1 + .../no-tests_env_bad_with_cli_error-result.txt | 1 + .../no-tests_env_bad_with_cli_error-stderr.txt | 1 + .../no-tests_env_empty_legacy-stderr.txt | 1 + .../CTestCommandLine/no-tests_env_error-result.txt | 1 + .../CTestCommandLine/no-tests_env_error-stderr.txt | 1 + Tests/RunCMake/RunCTest.cmake | 1 + 14 files changed, 63 insertions(+) create mode 100644 Help/envvar/CTEST_NO_TESTS_ACTION.rst create mode 100644 Help/release/dev/ctest-no-tests-action-env-var.rst create mode 100644 Tests/RunCMake/CTestCommandLine/no-tests_env_bad-result.txt create mode 100644 Tests/RunCMake/CTestCommandLine/no-tests_env_bad-stderr.txt create mode 100644 Tests/RunCMake/CTestCommandLine/no-tests_env_bad_with_cli_error-result.txt create mode 100644 Tests/RunCMake/CTestCommandLine/no-tests_env_bad_with_cli_error-stderr.txt create mode 100644 Tests/RunCMake/CTestCommandLine/no-tests_env_empty_legacy-stderr.txt create mode 100644 Tests/RunCMake/CTestCommandLine/no-tests_env_error-result.txt create mode 100644 Tests/RunCMake/CTestCommandLine/no-tests_env_error-stderr.txt diff --git a/Help/envvar/CTEST_NO_TESTS_ACTION.rst b/Help/envvar/CTEST_NO_TESTS_ACTION.rst new file mode 100644 index 0000000..2bc86dc --- /dev/null +++ b/Help/envvar/CTEST_NO_TESTS_ACTION.rst @@ -0,0 +1,14 @@ +CTEST_NO_TESTS_ACTION +--------------------- + +.. versionadded:: 3.26 + +.. include:: ENV_VAR.txt + +Environment variable that controls how :manual:`ctest ` handles +cases when there are no tests to run. Possible values are: ``error``, +``ignore``, empty or unset. + +The :option:`--no-tests=\ ` option to +:manual:`ctest ` overrides this environment variable if both +are given. diff --git a/Help/manual/cmake-env-variables.7.rst b/Help/manual/cmake-env-variables.7.rst index 50fcf75..4c29b80 100644 --- a/Help/manual/cmake-env-variables.7.rst +++ b/Help/manual/cmake-env-variables.7.rst @@ -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 diff --git a/Help/manual/ctest.1.rst b/Help/manual/ctest.1.rst index 30a9eae..5e82faa 100644 --- a/Help/manual/ctest.1.rst +++ b/Help/manual/ctest.1.rst @@ -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 ========= diff --git a/Help/release/dev/ctest-no-tests-action-env-var.rst b/Help/release/dev/ctest-no-tests-action-env-var.rst new file mode 100644 index 0000000..8679977 --- /dev/null +++ b/Help/release/dev/ctest-no-tests-action-env-var.rst @@ -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=\ ` command line + argument of :manual:`ctest(1)`. diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index f60a1e9..41c05e2 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -217,6 +217,7 @@ struct cmCTest::Private std::map 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& 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 && diff --git a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake index 8c35fe5..bda260a 100644 --- a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake @@ -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}\") diff --git a/Tests/RunCMake/CTestCommandLine/no-tests_env_bad-result.txt b/Tests/RunCMake/CTestCommandLine/no-tests_env_bad-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/no-tests_env_bad-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CTestCommandLine/no-tests_env_bad-stderr.txt b/Tests/RunCMake/CTestCommandLine/no-tests_env_bad-stderr.txt new file mode 100644 index 0000000..97187e6 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/no-tests_env_bad-stderr.txt @@ -0,0 +1 @@ +^Unknown value for CTEST_NO_TESTS_ACTION: 'bad'$ diff --git a/Tests/RunCMake/CTestCommandLine/no-tests_env_bad_with_cli_error-result.txt b/Tests/RunCMake/CTestCommandLine/no-tests_env_bad_with_cli_error-result.txt new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/no-tests_env_bad_with_cli_error-result.txt @@ -0,0 +1 @@ +8 diff --git a/Tests/RunCMake/CTestCommandLine/no-tests_env_bad_with_cli_error-stderr.txt b/Tests/RunCMake/CTestCommandLine/no-tests_env_bad_with_cli_error-stderr.txt new file mode 100644 index 0000000..eafba1c --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/no-tests_env_bad_with_cli_error-stderr.txt @@ -0,0 +1 @@ +No tests were found!!! diff --git a/Tests/RunCMake/CTestCommandLine/no-tests_env_empty_legacy-stderr.txt b/Tests/RunCMake/CTestCommandLine/no-tests_env_empty_legacy-stderr.txt new file mode 100644 index 0000000..a7c4b11 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/no-tests_env_empty_legacy-stderr.txt @@ -0,0 +1 @@ +^No tests were found!!!$ diff --git a/Tests/RunCMake/CTestCommandLine/no-tests_env_error-result.txt b/Tests/RunCMake/CTestCommandLine/no-tests_env_error-result.txt new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/no-tests_env_error-result.txt @@ -0,0 +1 @@ +8 diff --git a/Tests/RunCMake/CTestCommandLine/no-tests_env_error-stderr.txt b/Tests/RunCMake/CTestCommandLine/no-tests_env_error-stderr.txt new file mode 100644 index 0000000..eafba1c --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/no-tests_env_error-stderr.txt @@ -0,0 +1 @@ +No tests were found!!! diff --git a/Tests/RunCMake/RunCTest.cmake b/Tests/RunCMake/RunCTest.cmake index 86f5b3a..d46f6ad 100644 --- a/Tests/RunCMake/RunCTest.cmake +++ b/Tests/RunCMake/RunCTest.cmake @@ -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 -- cgit v0.12