diff options
author | Brad King <brad.king@kitware.com> | 2021-06-10 12:19:50 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-06-10 12:20:18 (GMT) |
commit | cf85c6bf85398213d965a41f81b604142456bd23 (patch) | |
tree | e2839b851e32fd0ad491116cc7d2fd9ea1c34a00 | |
parent | 49c165450f05a125f7e7b81e9eb0c7ba4a3b595a (diff) | |
parent | 02f1271bdf810107ad5d3c0cffb74b472d706054 (diff) | |
download | CMake-cf85c6bf85398213d965a41f81b604142456bd23.zip CMake-cf85c6bf85398213d965a41f81b604142456bd23.tar.gz CMake-cf85c6bf85398213d965a41f81b604142456bd23.tar.bz2 |
Merge topic 'ctest_custom_details'
02f1271bdf ctest: allow test output to override the 'details' field
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6204
-rw-r--r-- | Help/command/ctest_test.rst | 11 | ||||
-rw-r--r-- | Source/CTest/cmCTestRunTest.cxx | 16 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.cxx | 10 | ||||
-rw-r--r-- | Source/CTest/cmCTestTestHandler.h | 2 | ||||
-rw-r--r-- | Tests/RunCMake/ctest_test/RunCMakeTest.cmake | 12 | ||||
-rw-r--r-- | Tests/RunCMake/ctest_test/TestCompletionStatus-check.cmake | 16 |
6 files changed, 66 insertions, 1 deletions
diff --git a/Help/command/ctest_test.rst b/Help/command/ctest_test.rst index 65555a6..2153c90 100644 --- a/Help/command/ctest_test.rst +++ b/Help/command/ctest_test.rst @@ -259,3 +259,14 @@ The following example demonstrates how to upload non-image files to CDash. If the name of the file to upload is known at configure time, you can use the :prop_test:`ATTACHED_FILES` or :prop_test:`ATTACHED_FILES_ON_FAIL` test properties instead. + +Custom Details +"""""""""""""" + +The following example demonstrates how to specify a custom value for the +``Test Details`` field displayed on CDash. + +.. code-block:: c++ + + std::cout << + "<CTestDetails>My Custom Details Value</CTestDetails>" << std::endl; diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 5a6c775..a892113 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -40,6 +40,22 @@ void cmCTestRunTest::CheckOutput(std::string const& line) { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->GetIndex() << ": " << line << std::endl); + + // Check for special CTest XML tags in this line of output. + // If any are found, this line is excluded from ProcessOutput. + if (!line.empty() && line.find("<CTest") != std::string::npos) { + if (this->TestHandler->CustomCompletionStatusRegex.find(line)) { + this->TestResult.CustomCompletionStatus = + this->TestHandler->CustomCompletionStatusRegex.match(1); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + this->GetIndex() << ": " + << "Test Details changed to '" + << this->TestResult.CustomCompletionStatus + << "'" << std::endl); + return; + } + } + this->ProcessOutput += line; this->ProcessOutput += "\n"; diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index fd38f39..730ec0f 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -308,6 +308,10 @@ cmCTestTestHandler::cmCTestTestHandler() // regex to detect each individual <DartMeasurement>...</DartMeasurement> this->DartStuff1.compile( "(<DartMeasurement[^<]*</DartMeasurement[a-zA-Z]*>)"); + + // regex to detect <CTestDetails>...</CTestDetails> + this->CustomCompletionStatusRegex.compile( + "<CTestDetails>(.*)</CTestDetails>"); } void cmCTestTestHandler::Initialize() @@ -1460,7 +1464,11 @@ void cmCTestTestHandler::GenerateDartOutput(cmXMLWriter& xml) xml.StartElement("NamedMeasurement"); xml.Attribute("type", "text/string"); xml.Attribute("name", "Completion Status"); - xml.Element("Value", result.CompletionStatus); + if (result.CustomCompletionStatus.empty()) { + xml.Element("Value", result.CompletionStatus); + } else { + xml.Element("Value", result.CustomCompletionStatus); + } xml.EndElement(); // NamedMeasurement xml.StartElement("NamedMeasurement"); diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 9f5b3da..bd51738 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -175,6 +175,7 @@ public: std::string ExceptionStatus; bool CompressOutput; std::string CompletionStatus; + std::string CustomCompletionStatus; std::string Output; std::string DartString; int TestCount; @@ -358,6 +359,7 @@ private: ListOfTests TestList; size_t TotalNumberOfTests; cmsys::RegularExpression DartStuff; + cmsys::RegularExpression CustomCompletionStatusRegex; std::ostream* LogFile; diff --git a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake index 76a63f0..f07a12b 100644 --- a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake +++ b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake @@ -169,3 +169,15 @@ add_test( run_ctest(TestMeasurements) endfunction() run_measurements() + +# Verify that test output can override the Completion Status. +function(run_completion_status) + set(CASE_CMAKELISTS_SUFFIX_CODE [[ +add_test( + NAME custom_details + COMMAND ${CMAKE_COMMAND} -E + echo test output\n<CTestDetails>CustomDetails</CTestDetails>\nmore output) + ]]) + run_ctest(TestCompletionStatus) +endfunction() +run_completion_status() diff --git a/Tests/RunCMake/ctest_test/TestCompletionStatus-check.cmake b/Tests/RunCMake/ctest_test/TestCompletionStatus-check.cmake new file mode 100644 index 0000000..10de2ed --- /dev/null +++ b/Tests/RunCMake/ctest_test/TestCompletionStatus-check.cmake @@ -0,0 +1,16 @@ +file(READ "${RunCMake_TEST_BINARY_DIR}/Testing/TAG" _tag) +string(REGEX REPLACE "^([^\n]*)\n.*$" "\\1" _date "${_tag}") +file(READ "${RunCMake_TEST_BINARY_DIR}/Testing/${_date}/Test.xml" _test_contents) + +# Check custom completion status. +if(NOT _test_contents MATCHES [[<Value>CustomDetails</Value>]]) + string(APPEND RunCMake_TEST_FAILED + "Could not find expected <Value>CustomDetails</Value> in Test.xml") +endif() +# Check test output. +if(NOT _test_contents MATCHES "test output") + string(APPEND RunCMake_TEST_FAILED "Could not find expected string 'test output' in Test.xml") +endif() +if(NOT _test_contents MATCHES "more output") + string(APPEND RunCMake_TEST_FAILED "Could not find expected string 'more output' in Test.xml") +endif() |