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
This commit is contained in:
Wim Colgate 2024-06-14 19:26:43 +00:00 committed by Brad King
parent 4a382aa8dd
commit 49e9f817de
5 changed files with 35 additions and 3 deletions

View File

@ -702,13 +702,23 @@ void cmCTestTestHandler::LogFailedTests(const std::vector<std::string>& failed,
if (this->GetTestStatus(ft) == "Not Run") {
testColor = cmCTest::Color::YELLOW;
}
std::string ft_name_and_status =
cmStrCat(ft.Name, " (", this->GetTestStatus(ft), ")");
std::string labels;
const cmCTestTestProperties& p = *ft.Properties;
if (!p.Labels.empty()) {
static size_t const maxLen = 50;
size_t const ns = ft_name_and_status.size() >= maxLen
? 1
: maxLen - ft_name_and_status.size();
labels = cmStrCat(std::string(ns, ' '), cmJoin(p.Labels, " "));
}
cmCTestLog(
this->CTest, HANDLER_OUTPUT,
"\t" << this->CTest->GetColorCode(testColor) << std::setw(3)
<< ft.TestCount << " - " << ft.Name << " ("
<< this->GetTestStatus(ft) << ")"
<< ft.TestCount << " - " << ft_name_and_status
<< this->CTest->GetColorCode(cmCTest::Color::CLEAR_COLOR)
<< std::endl);
<< labels << std::endl);
}
}
}

View File

@ -0,0 +1 @@
8

View File

@ -0,0 +1 @@
Errors while running CTest

View File

@ -0,0 +1,4 @@
The following tests FAILED:
[ ]+1 - ShortName \(Failed\) Label1 Label2
[ ]+2 - LongerName \(Failed\) Label3
[ ]+3 - Long_Test_Name_That_Is_Over_Fifty_Characters_In_Length \(Failed\) Label4

View File

@ -7,6 +7,22 @@ set(ENV{no_proxy} "$ENV{no_proxy},badhostname.invalid")
set(RunCMake_TEST_TIMEOUT 60)
block()
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/FailureLabels)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" "
add_test(ShortName \"${CMAKE_COMMAND}\" -E false)
set_tests_properties(ShortName PROPERTIES LABELS \"Label1;Label2\")
add_test(LongerName \"${CMAKE_COMMAND}\" -E false)
set_tests_properties(LongerName PROPERTIES LABELS \"Label3\")
add_test(Long_Test_Name_That_Is_Over_Fifty_Characters_In_Length \"${CMAKE_COMMAND}\" -E false)
set_tests_properties(Long_Test_Name_That_Is_Over_Fifty_Characters_In_Length PROPERTIES LABELS \"Label4\")
")
run_cmake_command(FailureLabels ${CMAKE_CTEST_COMMAND})
endblock()
run_cmake_command(repeat-opt-bad1
${CMAKE_CTEST_COMMAND} --repeat until-pass
)