Repository navigation
Conversation
Various tests had their own `println(const char *)` implementation, which appear very similar to `std::puts`. (`std::puts` also adds a newline character at the end.)
| namespace | ||
| { | ||
| void | ||
| println(const char * c) |
There was a problem hiding this comment.
Actually we had four different (but very similar) implementations of println(const char *)! This one here was properly placed in an unnamed namespace. But the one in itkConstNeighborhoodIteratorTest.cxx was entirely global, and had external linkage. The one in itkNeighborhoodTest.cxx was declared static, while the one in itkHashTableGTest.cxx was declared inline!
| println("Testing std::unordered_set"); | ||
| std::puts("Testing std::unordered_set"); |
There was a problem hiding this comment.
Honestly I would rather not have such "unconditional" print statements in unit tests at all. (Not even by std::puts.) It produces distractive noise in the test output, IMO. So I would prefer to only see such informative output in case of a test failure. The GoogleTest macro SCOPED_TRACE(message) does so: it only produces output in case of a failure. Anyway, I think replacing print statements with SCOPED_TRACE calls is beyond the scope of this PR... 🤷
There was a problem hiding this comment.
Could be 😃 At least it's good to consider using the GoogleTest SCOPED_TRACE(message) macro, whenever it is useful 😃
There was a problem hiding this comment.
I think that SCOPED_TRACE should be used a lot more in GTests.
| void | ||
| println(const char * c) | ||
| { | ||
| std::cout << std::endl << c << std::endl; |
There was a problem hiding this comment.
Please note that this particular println implementation inserts two line breaks (one before and one after the message string), whereas the "global" println (implemented in itkConstNeighborhoodIteratorTest) only inserts a single line break, at the end:
ITK/Modules/Core/Common/test/itkConstNeighborhoodIteratorTest.cxx
Lines 24 to 27 in fc63666
I think this is an extra reason to remove them. It's too confusing to have multiple println implementations behaving differently.
However, this PR will effectively remove some line breaks from the test output. I hope that's OK!
Looking at https://open.cdash.org/tests/2833926099
[ RUN ] BoundaryCondition.ConstantBoundaryAtImageEdge
Creating some images
Initializing some images
Initializing smart neighborhood iterators
1327 1328 1329 0 0
This PR will remove the empty lines. and make it as in https://open.cdash.org/tests/2832303956
[ RUN ] BoundaryCondition.ConstantBoundaryAtImageEdge
Creating some images
Initializing some images
Initializing smart neighborhood iterators
1327 1328 1329 0 0
OK? To me it's fine.
[Low impact] The changes affect printed output from a bounded set of Core/Common tests. The PR appears safe to merge, with a non-blocking issue that splits two tests' diagnostic output. Findings
|
| itk::ConstNeighborhoodIterator<TestImageType>::RegionType reg = { idx, sz }; | ||
|
|
||
| println("Creating ConstNeighborhoodIterator"); | ||
| std::puts("Creating ConstNeighborhoodIterator"); |
There was a problem hiding this comment.
std::puts bypasses --redirectOutput, which both itkConstNeighborhoodIteratorTest and itkShapedNeighborhoodIteratorTest use. The driver redirects only std::cout.rdbuf(), so progress headings now go to stdout while iterator details go to the attached log file. This makes failure logs harder to follow. Keep these messages on std::cout, or update the driver to capture both output paths.
There was a problem hiding this comment.
OK, so it may not be such a good idea to use std::puts in this case. Addressed by:
There was a problem hiding this comment.
That's a good catch by greptile. I did not realize the redirect is not supported.
hjmjohnson
left a comment
There was a problem hiding this comment.
Given that redirect is not supported by std::puts, I think this should be superceeded by the other PR.
I also like your suggestion of only printing content when a failure occurs. I think inside gTest that the diagnostics should be minimal unless an error occurs.
@hjmjohnson Thanks Hans! I just encountered an extra motivation to minimize output on a successful pass, as https://open.cdash.org/tests/2835201106 says: I just wanted to see the output beyond the 1024 bytes boundary, to see the effect of removing
|
Various tests had their own
println(const char *)implementations, which appear very similar tostd::puts. (std::putsalso adds a newline character at the end.)