mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
CTest: Support --max-width shorter than longest test name
Fixes: #24101
This commit is contained in:
@@ -374,8 +374,9 @@ void cmCTestMemCheckHandler::GenerateCTestXML(cmXMLWriter& xml)
|
||||
}
|
||||
xml.EndElement(); // Results
|
||||
if (memoryErrors > 0) {
|
||||
int const maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
|
||||
std::string outname = result.Name + " ";
|
||||
size_t const maxTestNameWidth = std::max<size_t>(
|
||||
this->CTest->GetMaxTestNameWidth(), result.Name.size());
|
||||
outname.resize(maxTestNameWidth + 4, '.');
|
||||
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
||||
cc + 1 << "/" << total << " MemCheck: #"
|
||||
|
||||
@@ -261,7 +261,8 @@ cmCTestRunTest::EndTestResult cmCTestRunTest::EndTest(size_t completed,
|
||||
// If the test did not pass, reprint test name and error
|
||||
std::string output = this->GetTestPrefix(completed, total);
|
||||
std::string testName = this->TestProperties->Name;
|
||||
int const maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
|
||||
size_t const maxTestNameWidth =
|
||||
std::max<size_t>(this->CTest->GetMaxTestNameWidth(), testName.size());
|
||||
testName.resize(maxTestNameWidth + 4, '.');
|
||||
|
||||
output += testName;
|
||||
@@ -1041,8 +1042,9 @@ void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total)
|
||||
<< indexStr.str();
|
||||
outputStream << " ";
|
||||
|
||||
int const maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
|
||||
std::string outname = this->TestProperties->Name + " ";
|
||||
size_t const maxTestNameWidth =
|
||||
std::max<size_t>(this->CTest->GetMaxTestNameWidth(), outname.size() - 1);
|
||||
outname.resize(maxTestNameWidth + 4, '.');
|
||||
outputStream << outname;
|
||||
|
||||
|
||||
@@ -1351,15 +1351,15 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
|
||||
|
||||
void cmCTestTestHandler::UpdateMaxTestNameWidth()
|
||||
{
|
||||
std::string::size_type max = this->CTest->GetMaxTestNameWidth();
|
||||
std::string::size_type max = this->CTest->GetLongestTestNameWidth();
|
||||
for (cmCTestTestProperties& p : this->TestList) {
|
||||
if (max < p.Name.size()) {
|
||||
max = p.Name.size();
|
||||
}
|
||||
}
|
||||
if (static_cast<std::string::size_type>(
|
||||
this->CTest->GetMaxTestNameWidth()) != max) {
|
||||
this->CTest->SetMaxTestNameWidth(static_cast<int>(max));
|
||||
this->CTest->GetLongestTestNameWidth()) != max) {
|
||||
this->CTest->SetLongestTestNameWidth(static_cast<int>(max));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-6
@@ -161,7 +161,10 @@ struct cmCTest::Private
|
||||
std::chrono::steady_clock::now();
|
||||
cmDuration TimeLimit = cmCTest::MaxDuration();
|
||||
|
||||
int MaxTestNameWidth = 30;
|
||||
// Longest width of all test names (does not take any override into account).
|
||||
int LongestTestNameWidth = 30;
|
||||
// Override from the command line or profile for the maximum width.
|
||||
cm::optional<int> MaxTestNameWidthOverride;
|
||||
|
||||
cm::optional<size_t> ParallelLevel = 1;
|
||||
bool ParallelLevelSetInCli = false;
|
||||
@@ -1721,7 +1724,8 @@ bool cmCTest::SetArgsFromPreset(cmCMakePresetsArgs const& args)
|
||||
expandedPreset->Output->SubprojectSummary.value_or(true);
|
||||
|
||||
if (expandedPreset->Output->MaxTestNameWidth) {
|
||||
this->Impl->MaxTestNameWidth = *expandedPreset->Output->MaxTestNameWidth;
|
||||
this->Impl->MaxTestNameWidthOverride =
|
||||
expandedPreset->Output->MaxTestNameWidth;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1969,7 +1973,7 @@ int cmCTest::Run(std::vector<std::string> const& args)
|
||||
return true;
|
||||
};
|
||||
auto const dashW = [this](std::string const& width) -> bool {
|
||||
this->Impl->MaxTestNameWidth = atoi(width.c_str());
|
||||
this->Impl->MaxTestNameWidthOverride = atoi(width.c_str());
|
||||
return true;
|
||||
};
|
||||
auto const dashA = [this, &processSteps](std::string const& notes) -> bool {
|
||||
@@ -3150,12 +3154,18 @@ bool cmCTest::ShouldPrintLabels() const
|
||||
|
||||
int cmCTest::GetMaxTestNameWidth() const
|
||||
{
|
||||
return this->Impl->MaxTestNameWidth;
|
||||
return this->Impl->MaxTestNameWidthOverride.value_or(
|
||||
this->Impl->LongestTestNameWidth);
|
||||
}
|
||||
|
||||
void cmCTest::SetMaxTestNameWidth(int w)
|
||||
int cmCTest::GetLongestTestNameWidth() const
|
||||
{
|
||||
this->Impl->MaxTestNameWidth = w;
|
||||
return this->Impl->LongestTestNameWidth;
|
||||
}
|
||||
|
||||
void cmCTest::SetLongestTestNameWidth(int w)
|
||||
{
|
||||
this->Impl->LongestTestNameWidth = w;
|
||||
}
|
||||
|
||||
void cmCTest::SetProduceXML(bool v)
|
||||
|
||||
+5
-2
@@ -204,9 +204,12 @@ public:
|
||||
|
||||
cm::optional<unsigned int> GetRandomSeed() const;
|
||||
|
||||
/** The max output width */
|
||||
/** The max output width with overrides taken into account */
|
||||
int GetMaxTestNameWidth() const;
|
||||
void SetMaxTestNameWidth(int w);
|
||||
|
||||
/** The maximum width of all test names */
|
||||
int GetLongestTestNameWidth() const;
|
||||
void SetLongestTestNameWidth(int w);
|
||||
|
||||
/**
|
||||
* Run a single executable command and put the stdout and stderr
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
^Test project [^
|
||||
]*/Tests/RunCMake/CTestCommandLine/TestMaxWidthLong
|
||||
Start 1: test1
|
||||
1/3 Test #1: test1 \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
Start 2: test2
|
||||
2/3 Test #2: test2 \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
Start 3: TestNameIsLongerThanTheDefault30CharactersSoTheMaxWidthIncreases
|
||||
3/3 Test #3: TestNameIsLongerThanTheDefault30CharactersSoTheMaxWidthIncreases \.\.\. Passed +[0-9\.]+ sec
|
||||
+
|
||||
100% tests passed out of 3
|
||||
+
|
||||
Total Test time \(real\) = +[0-9\.]+ sec
|
||||
@@ -0,0 +1,12 @@
|
||||
^Test project [^
|
||||
]*/Tests/RunCMake/CTestCommandLine/TestMaxWidthLong
|
||||
Start 1: test1
|
||||
1/3 Test #1: test1 \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
Start 2: test2
|
||||
2/3 Test #2: test2 \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
Start 3: TestNameIsLongerThanTheDefault30CharactersSoTheMaxWidthIncreases
|
||||
3/3 Test #3: TestNameIsLongerThanTheDefault30CharactersSoTheMaxWidthIncreases \.\.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
+
|
||||
100% tests passed out of 3
|
||||
+
|
||||
Total Test time \(real\) = +[0-9\.]+ sec
|
||||
@@ -0,0 +1,12 @@
|
||||
^Test project [^
|
||||
]*/Tests/RunCMake/CTestCommandLine/TestMaxWidthLong
|
||||
Start 1: test1
|
||||
1/3 Test #1: test1 \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
Start 2: test2
|
||||
2/3 Test #2: test2 \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
Start 3: TestNameIsLongerThanTheDefault30CharactersSoTheMaxWidthIncreases
|
||||
3/3 Test #3: TestNameIsLongerThanTheDefault30CharactersSoTheMaxWidthIncreases \.\.\. Passed +[0-9\.]+ sec
|
||||
+
|
||||
100% tests passed out of 3
|
||||
+
|
||||
Total Test time \(real\) = +[0-9\.]+ sec
|
||||
@@ -0,0 +1,12 @@
|
||||
^Test project [^
|
||||
]*/Tests/RunCMake/CTestCommandLine/TestMaxWidthShort
|
||||
Start 1: test1
|
||||
1/3 Test #1: test1 \.\.\. Passed +[0-9\.]+ sec
|
||||
Start 2: test2
|
||||
2/3 Test #2: test2 \.\.\. Passed +[0-9\.]+ sec
|
||||
Start 3: test3
|
||||
3/3 Test #3: test3 \.\.\. Passed +[0-9\.]+ sec
|
||||
+
|
||||
100% tests passed out of 3
|
||||
+
|
||||
Total Test time \(real\) = +[0-9\.]+ sec
|
||||
@@ -0,0 +1,12 @@
|
||||
^Test project [^
|
||||
]*/Tests/RunCMake/CTestCommandLine/TestMaxWidthShort
|
||||
Start 1: test1
|
||||
1/3 Test #1: test1 \.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
Start 2: test2
|
||||
2/3 Test #2: test2 \.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
Start 3: test3
|
||||
3/3 Test #3: test3 \.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
+
|
||||
100% tests passed out of 3
|
||||
+
|
||||
Total Test time \(real\) = +[0-9\.]+ sec
|
||||
@@ -0,0 +1,12 @@
|
||||
^Test project [^
|
||||
]*/Tests/RunCMake/CTestCommandLine/TestMaxWidthShort
|
||||
Start 1: test1
|
||||
1/3 Test #1: test1 \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
Start 2: test2
|
||||
2/3 Test #2: test2 \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
Start 3: test3
|
||||
3/3 Test #3: test3 \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. Passed +[0-9\.]+ sec
|
||||
+
|
||||
100% tests passed out of 3
|
||||
+
|
||||
Total Test time \(real\) = +[0-9\.]+ sec
|
||||
@@ -1129,3 +1129,36 @@ block()
|
||||
-D CTEST_SUBMIT_PARTS=BadPart
|
||||
)
|
||||
endblock()
|
||||
|
||||
# Test the --max-width/-W flag.
|
||||
function(run_TestMaxWidth name kind lastName args)
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/TestMaxWidth${kind})
|
||||
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(test1 \"${CMAKE_COMMAND}\" -E echo test)
|
||||
add_test(test2 \"${CMAKE_COMMAND}\" -E echo test)
|
||||
add_test(${lastName} \"${CMAKE_COMMAND}\" -E echo test)
|
||||
")
|
||||
run_cmake_command(${name} ${CMAKE_CTEST_COMMAND} ${args})
|
||||
endfunction()
|
||||
|
||||
function(run_TestMaxWidthShort name width)
|
||||
run_TestMaxWidth(${name} Short test3 "${width}")
|
||||
endfunction()
|
||||
function(run_TestMaxWidthLong name width)
|
||||
run_TestMaxWidth(
|
||||
${name}
|
||||
Long
|
||||
TestNameIsLongerThanTheDefault30CharactersSoTheMaxWidthIncreases
|
||||
"${width}"
|
||||
)
|
||||
endfunction()
|
||||
|
||||
run_TestMaxWidthShort(MaxWidthShortUnset "")
|
||||
run_TestMaxWidthShort(MaxWidthShort10 "--max-width 10")
|
||||
run_TestMaxWidthShort(MaxWidthShort0 "--max-width 0")
|
||||
run_TestMaxWidthLong(MaxWidthLongUnset "")
|
||||
run_TestMaxWidthLong(MaxWidthLong70 "-W 70")
|
||||
run_TestMaxWidthLong(MaxWidthLong30 "-W 30")
|
||||
|
||||
Reference in New Issue
Block a user