Repository navigation
ENH: Add GoogleTests covering ITK exception classes - #6956
hjmjohnson merged 1 commit into
Conversation
[Low impact] This test-only change appears safe to merge.
|
ebad435 to
f62b3ff
Compare
|
Niels has reviewed this PR. Philosophically, I am in favor. I prefer to skip reviewing it in detail. |
Sorry, @dzenanz, I did not review all 500+ added lines of code so far. I just did some cherry-picking on low hanging fruit. Although I do agree philosophically 😸 |
b05d135 to
0418064
Compare
0418064 to
7e99108
Compare
| EXPECT_EQ(std::as_const(defaultConstructed).GetDataObject(), nullptr); | ||
|
|
||
| const std::string printedWithoutDataObject = PrintToString(defaultConstructed); | ||
| EXPECT_TRUE(Contains(printedWithoutDataObject, "itk::" + expectedName)); |
There was a problem hiding this comment.
As a future improvement, I think it would be nice if we could use GoogleTest Matchers like HasSubstr, instead of using our own local Contains helper function:
EXPECT_THAT(printedWithoutDataObject, HasSubstr("itk::" + expectedName));
But for now, EXPECT_TRUE(Contains(... is fine to me. 👍
There was a problem hiding this comment.
Agreed that matchers would be nicer. They need googlemock, though, and ITK neither vendors it nor builds it: UpdateFromUpstream.sh imports only googletest/, BUILD_GMOCK is forced OFF, and the drivers link only GTest::gtest. So I am keeping Contains here and treating matchers as out of scope until a larger investigation of using gMock in ITK is done: its benefit to the tests, the cost of vendoring it, and the system-GoogleTest builds. I will bring that to Discourse before proposing a change.
N-Dekker
left a comment
There was a problem hiding this comment.
Thanks Hans! Approved 👍
Exception-class behavior was tested mostly as a side effect of filter tests printing the exceptions they caught; DataObjectError::Print, for example, was reached only through three filter test drivers. These tests exercise each exception class directly (construction, accessors, Print, copy and move, and use through a base-class reference), so a test that only checks a throw does not need to print the exception for coverage. Covers the Common exceptions (including DataObjectError and InvalidRequestedRegionError with and without a data object), the image and mesh IO exceptions, and the SampleToHistogramFilter exceptions. IOMeshBase gets its first GoogleTest driver.
7e99108 to
324ca0c
Compare
Adds GoogleTests that exercise ITK's exception classes directly, so a test of a filter that throws only needs to check the throw, not print the exception for coverage. Run alone, the exception tests cover 100% of the exception-class lines (196 of 196), up from 71% today.
What is covered
Core/Common/test/itkCommonExceptionsGTest.cxxMemoryAllocationError,RangeError,InvalidArgumentError,IncompatibleOperandsError,DerefError,ProcessAborted,DataObjectError,InvalidRequestedRegionErrorIO/ImageBase/test/itkImageIOExceptionsGTest.cxxImageFileReaderException,ImageFileWriterException,ImageSeriesWriterExceptionIO/MeshBase/test/itkMeshIOExceptionsGTest.cxxMeshFileReaderException,MeshFileWriterExceptionNumerics/Statistics/test/itkSampleToHistogramFilterExceptionsGTest.cxxitkDeclareExceptionMacroexceptions initkSampleToHistogramFilter.hEach class is checked for its name, construction (default and with file, line, description, and location),
Printoutput, copy and move, and use through a base-class reference. Throwability is checked at compile time (static_asserton the base class and on non-throwing copy), not by throwing in the test.DataObjectErrorandInvalidRequestedRegionErrorare printed both without a data object ("(None)") and with an image attached, which also checks that the image'sPrintSelfoutput appears.IOMeshBasegets its first GoogleTest driver.Why
Most exception-class code was covered as a side effect of filter tests printing the exceptions they caught.
DataObjectError::Print, for example, was reached only through the ImageCompare, ImageCompose, and ImageGrid test drivers. Tests dedicated to the exceptions keep that coverage when filter tests use plainEXPECT_THROW.Verification
LLVM source-based coverage build (macOS, Apple clang) of ITKCommon, ITKIOImageBase, ITKIOMeshBase, and ITKStatistics; only
ExceptionObject.*, the four new suites, anditkExceptionObjectTestrun:mainAll GoogleTests in the four drivers pass under CTest, and the build has no warnings.
pre-commit run --all-filespasses.AI assistance
An AI coding assistant wrote the tests and ran the coverage measurement under the author's direction.