Skip to content

BUG: Fail metric tests whose expected exception is not thrown, then convert to GoogleTest - #7052

Merged
hjmjohnson merged 4 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-metric-expected-exceptions
Nov 2, 2026
Merged

hjmjohnson merged 4 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-metric-expected-exceptions

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Two Registration metric tests tried to cause an exception, but when nothing was thrown they printed the metric value and still passed. For each test, one BUG: commit makes the check fail, and the next commit converts the fixed test to GoogleTest (EXPECT_THROW).

Test Checks fixed
itkMutualInformationMetricTest 2 (fixed-image standard deviation too small; null fixed image)
itkKullbackLeiblerCompareHistogramImageToImageMetricTest 1 (null fixed image)
Testing

macOS arm64, conda clang, Release, ITK_BUILD_DEFAULT_MODULES=OFF, Module_ITKRegistrationCommon=ON. Every one of the 4 commits builds both RegistrationCommon drivers with 0 warnings and passes the two tests. Each fixed legacy test passes, which confirms that all three calls do throw, including the standard-deviation case (the KullbackLeibler test has that block commented out). pre-commit run --all-files passes.

EXPECT_THROW keeps both original statements, Initialize() and GetValue(), since either may be the one that throws.

How these were found

Same review as #7046, extended to the rest of the tree. The staged conversions on gtest-staging-C copied these blocks faithfully.

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:Registration Issues affecting the Registration module labels Oct 31, 2026
@hjmjohnson
hjmjohnson marked this pull request as ready for review October 31, 2026 18:23
@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Low impact] The PR changes how two Registration Common tests report their results.

The PR appears safe to merge, with a non-blocking improvement to make the small-deviation exception check repeatable.

Findings

  1. P2 Exception check uses changing samples ▶

Summary

Converts two registration metric tests to GoogleTest and makes three missing-exception cases fail.

  • The Mutual Information test fails when an expected exception is missing.
  • The Kullback-Leibler test fails when its null-image exception is missing.

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

The checks that an exception is thrown printed a value when nothing
was thrown but did not fail the test.
@hjmjohnson
hjmjohnson force-pushed the bug-metric-expected-exceptions branch from ad4a138 to 81fa904 Compare October 31, 2026 23:23
…hrown

The check that an exception is thrown printed a value when nothing
was thrown but did not fail the test.
Converts itkKullbackLeiblerCompareHistogramImageToImageMetricTest.
@hjmjohnson
hjmjohnson force-pushed the bug-metric-expected-exceptions branch from 81fa904 to 1824982 Compare November 1, 2026 00:52
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request Nov 1, 2026
@hjmjohnson
hjmjohnson requested a review from dzenanz November 1, 2026 16:52
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request Nov 1, 2026
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request Nov 2, 2026
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request Nov 2, 2026

@dzenanz dzenanz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good on a glance.

@hjmjohnson
hjmjohnson merged commit 4c4444f into InsightSoftwareConsortium:main Nov 2, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Registration Issues affecting the Registration 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.

2 participants