ctest: --max-width not respected if shorter than the test with the longest name
According to the docs (https://cmake.org/cmake/help/latest/manual/ctest.1.html#cmdoption-ctest-max-width), the --max-width
parameter is supposed to "set the max width for a test name to output". Apparently this is only the case if the specified width is wider than the test with the widest name.
In the docs it looks like the behavior on how cmake detects width of test names have changed from a default fixed value to automatically finding the longest test, and it seems like this option was originally only meant to increase the width in order to avoid clipping.
However, I have a test named theWidthOfThisTestIs22
which is 22 characters wide. If i set the --max-width 10
I would expect ctest to output the name of the test as theWidthOf
. However, this is not the case and I get the original name of the test.
Looked quickly at the code and it seems like the Source/CTest/cmCTestHandler.cxx
is updating/overriding the value specified on the command line when ComputeTestList()
or ComputeTestListsForRerunFailed()
is called. Both of those functions call UpdateMaxTestNameWidth()
, which is overwriting the value that was supplied on the command line.
Expected behavior.
If --max-width
is not specified, ctest
should set the max-width to the length of the longest test (this is what ctest
is doing today).
If --max-width
is specified on the command line, ctest
should not overwrite the value even for shorter or longer widths than the size of the longest test.
Here is a simple CMakeLists.txt
to reproduce the issue:
cmake_minimum_required(VERSION 3.23)
project(test)
enable_testing()
add_test(NAME theWidthOfThisTestIs22 COMMAND true)
Running cmake -B build && cd build
to configure, the output looks like this when running ctest
with different arguments for --max-width
Default, no value, then I get 30 as specified as the initial value (int MaxTestNameWidth = 30;
) in cmCTest.cxx
$ ctest
Test project /tmp/test/build
Start 1: theWidthOfThisTestIs22
1/1 Test #1: theWidthOfThisTestIs22 ........... Passed 0.00 sec
...
The longest test name in this configuration is 22 characters so using the default of 30 makes sense. Setting --max-width
to any value lower than or equal to 22 does not change the output:
$ ctest --max-width 22
Test project /tmp/test/build
Start 1: theWidthOfThisTestIs22
1/1 Test #1: theWidthOfThisTestIs22 ... Passed 0.00 sec
...
$ ctest --max-width 21
Test project /tmp/test/build
Start 1: theWidthOfThisTestIs22
1/1 Test #1: theWidthOfThisTestIs22 ... Passed 0.00 sec
...
$ ctest --max-width 5
Test project /tmp/test/build
Start 1: theWidthOfThisTestIs22
1/1 Test #1: theWidthOfThisTestIs22 ... Passed 0.00 sec
...
Setting --max-width
to any value greater than 22 increases the width to the expected value. E.g:
$ ctest --max-width 25
Test project /tmp/test/build
Start 1: theWidthOfThisTestIs22
1/1 Test #1: theWidthOfThisTestIs22 ...... Passed 0.00 sec
...
Adds an additional 3 dots (.
) as expected.