Skip to content

BUG: Fail Statistics tests when Update() throws, then convert to GoogleTest - #7048

Open
hjmjohnson wants to merge 20 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-statistics-swallowed-exceptions
Open

hjmjohnson wants to merge 20 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-statistics-swallowed-exceptions

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Ten Statistics tests caught an exception from Update(), printed it, and carried on, so a failing filter went unnoticed and the checks that followed read output that was never produced. For each test, one BUG: commit makes the catch fail the test, and the next commit converts the fixed test to GoogleTest (ASSERT_NO_THROW).

Test Sites fixed
itkCovarianceSampleFilterTest 1
itkCovarianceSampleFilterTest2 3
itkMeanSampleFilterTest 1
itkMeanSampleFilterTest2 1
itkMeanSampleFilterTest3 1
itkWeightedMeanSampleFilterTest 4
itkWeightedCovarianceSampleFilterTest 1 (its message also called the exception "expected")
itkWeightedCovarianceSampleFilterTest2 1 (same)
itkStandardDeviationPerComponentSampleFilterTest 1
itkSubsampleTest3 2
Testing

macOS arm64, conda clang, Release, ITK_BUILD_DEFAULT_MODULES=OFF, Module_ITKStatistics=ON. Every one of the 20 commits builds both Statistics drivers with 0 warnings and passes the affected legacy and GoogleTest tests. Each fixed legacy test passes, which confirms that none of these Update() calls throws today. pre-commit run --all-files passes.

Every Statistics GoogleTest, the existing ones and these ten, was also scanned for try/catch blocks and error branches that cannot fail the test; none remain.

The conversions use ASSERT_NO_THROW rather than EXPECT_NO_THROW because each Update() is followed by checks on the filter's output.

How these were found

A review of the staged no-argument GoogleTest conversions (gtest-staging-C) found that the conversions copied these swallowing catch blocks faithfully. As with #7046, the fix goes to each legacy test first and the conversion follows. itkCovarianceSampleFilterTest3 has the same defect; it is fixed separately in #7049 because #7046 converts it.

AI assistance (Claude Code) was used to find the defects and draft the changes; they were reviewed and tested locally.

@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Numerics Issues affecting the Numerics module labels Oct 31, 2026
@hjmjohnson
hjmjohnson marked this pull request as ready for review October 31, 2026 18:19
@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: plus

[Low impact] The changes affect how a bounded set of Statistics tests report results.

The exception fixes look sound, but the numbered conversions must use distinct GoogleTest suites before merging.

Findings

  1. P2 Test files share suite names ▶

Summary

Converts ten Statistics tests to GoogleTest and makes unexpected Update() exceptions stop each test before it reads output.

  • Statistics tests now stop when a required filter update throws.

Reviews (1) · Last reviewed commit: "ENH: Convert itkSubsampleTest3 to Google..." · Reviewed by Greptile

The catch block printed the exception and let the test continue, so
a failing Update() went unnoticed and the checks that follow ran on
output that was never produced.
The catch block printed the exception and let the test continue, so
a failing Update() went unnoticed and the checks that follow ran on
output that was never produced.
@hjmjohnson
hjmjohnson force-pushed the bug-statistics-swallowed-exceptions branch from ded447c to 6680dd6 Compare October 31, 2026 23:23
The catch block printed the exception and let the test continue, so
a failing Update() went unnoticed and the checks that follow ran on
output that was never produced.
The catch block printed the exception and let the test continue, so
a failing Update() went unnoticed and the checks that follow ran on
output that was never produced.
The catch block printed the exception and let the test continue, so
a failing Update() went unnoticed and the checks that follow ran on
output that was never produced.
The catch block printed the exception and let the test continue, so
a failing Update() went unnoticed and the checks that follow ran on
output that was never produced.
The catch block printed the exception and let the test continue, so
a failing Update() went unnoticed and the checks that follow ran on
output that was never produced. Its message also wrongly called the exception expected.
The catch block printed the exception and let the test continue, so
a failing Update() went unnoticed and the checks that follow ran on
output that was never produced. Its message also wrongly called the exception expected.
…) throws

The catch block printed the exception and let the test continue, so
a failing Update() went unnoticed and the checks that follow ran on
output that was never produced.
The catch block printed the exception and let the test continue, so
a failing Update() went unnoticed and the checks that follow ran on
output that was never produced.
@hjmjohnson
hjmjohnson force-pushed the bug-statistics-swallowed-exceptions branch from 6680dd6 to 483d119 Compare November 1, 2026 00:53
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request Nov 1, 2026
# Conflicts:
#	Modules/Numerics/Statistics/test/CMakeLists.txt
@hjmjohnson
hjmjohnson requested a review from dzenanz November 1, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Numerics Issues affecting the Numerics module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant