Skip to content

BUG: Propagate test helper status and mark the helpers [[nodiscard]] - #6704

Merged
hjmjohnson merged 3 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix-propagate-helper-status
Jul 27, 2026
Merged

BUG: Propagate test helper status and mark the helpers [[nodiscard]]#6704
hjmjohnson merged 3 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix-propagate-helper-status

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Jul 25, 2026

Copy link
Copy Markdown
Member

Test helpers that return EXIT_SUCCESS/EXIT_FAILURE are now [[nodiscard]], so a caller that drops the status no longer compiles. That plus the six original call-site fixes turns 13 explicit failure returns and 31 ITK_TEST_* assertions back into real assertions, and exposed a wrong superclass assertion that only MSVC evaluates.

The defect
switch (std::stoi(argv[1]))
{
  case 2:
    PerformBSplineExpImageRegistration<2>(argc, argv);   // return value ignored
    break;
  ...
}
return EXIT_SUCCESS;

The helpers do run — each one's argument-count guard matches its registered CMake invocation — so the defect is latent: the assertions execute but their verdict is discarded.

File Swallowed inside the helper
itkLabelOverlapMeasuresImageFilterTest.cxx 6 return EXIT_FAILURE
itkBSplineExponentialImageRegistrationTest.cxx 2 + 2 ITK_TEST_*
itkBSplineImageRegistrationTest.cxx 2 + 2
itkExponentialImageRegistrationTest.cxx 3 + 7
itkTimeVaryingBSplineVelocityFieldImageRegistrationTest.cxx 13 ITK_TEST_*
itkTimeVaryingVelocityFieldImageRegistrationTest.cxx 7 ITK_TEST_*
Commit 2: the Windows failure this unmasked

itkLabelOverlapMeasuresImageFilterTest's helper asserts

ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, LabelOverlapMeasuresImageFilter, ImageToImageFilter);

but the filter derives from ImageSink (itkLabelOverlapMeasuresImageFilter.h:43), and the enclosing test asserts ImageSink correctly 140 lines later.

The assertion is compiler-dependent. itkTestingMacros.h:54-83 defines two variants: under __GNUC__ the macro only prints the class name, while everywhere else it also compares Superclass::GetNameOfClass() and returns EXIT_FAILURE on mismatch. GCC and Clang both define __GNUC__, so only MSVC evaluates the check — and only once commit 1 stopped discarding the helper's status did that reach the test result. Pixi-Cxx (windows-2022) was the sole red check before this fix.

Commit 3: [[nodiscard]] across the test tree

290 declarations in 211 files. Selection is mechanical: a file-scope, non-entry-point function returning int whose body contains EXIT_SUCCESS or EXIT_FAILURE.

The attribute goes on every declaration, not only the definition. [[nodiscard]] governs calls that follow the declaration carrying it, so a bare forward declaration leaves earlier call sites unchecked — annotating the 14 forward declarations is what exposed the CoherenceEnhancingDiffusionTest site below.

Deliberately not annotated:

  • 38 int-returning helpers whose return is a value, not a status (lookup in itkExceptionObjectTest, the dynamic_castDownCast* family, the test*Spline helpers). Annotating these would only force (void) casts at legitimate discard sites.
  • TestKernelTransform, which uses a bare 0/1 convention and needs a semantics change first — handled separately.
  • itkSyNImageRegistrationTest and itkBSplineSyNImageRegistrationTest, whose discarded call sites are fixed by BUG: Make the SyN registration tests actually run a registration #6703. Annotating them without that PR's argc fix makes itkBSplineSyNImageRegistrationTest fail. They can be annotated once BUG: Make the SyN registration tests actually run a registration #6703 lands.

The attribute exposed 30 discarded call sites in 8 tests, all fixed here:

File Sites
itkCentralDifferenceImageFunctionOnVectorSpeedTest.cxx 10
itkObjectToObjectMultiMetricv4RegistrationTest.cxx 5
itkDiscreteGaussianImageFilterTest2.cxx 4
itkSLICImageFilterTest.cxx 4
itkFFTDiscreteGaussianImageFilterTest.cxx 2
itkFancyStringTest.cxx 2
itkMeanSquaresImageToImageMetricv4OnVectorTest2.cxx 2
CoherenceEnhancingDiffusionTest.cxx 1

Where a helper is called several times in one scope the status accumulates with testStatus |= (the existing idiom in itkColorTableTest.cxx); plain = is used only where the branches are mutually exclusive.

Three of these were invisible to a source-level audit: in itkFancyStringTest and CoherenceEnhancingDiffusionTest the discard happens inside ITK_TRY_EXPECT_NO_EXCEPTION(...), where the call is not lexically a statement. The compiler sees it after expansion; a grep does not.

Test plan

Release, Ninja, AppleClang, macOS arm64, in a build tree configured against this branch alone (Module_ITKReview=ON added so no annotated file goes uncompiled).

  • Full build of 8452 targets plus incremental passes: zero -Wunused-result diagnostics, zero errors, no new warnings.
  • ctest -j8: 100% passed, 0 failed out of 6207.
  • pre-commit run --all-files exits 0.

Not exercised locally: the annotated files under Video/BridgeOpenCV, Video/BridgeVXL and the GPU modules, which need OpenCV / VXL / OpenCL. Every helper and call site in those 20 files was inspected by hand and all consume their return value. CI covers the compile.

@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration module area:Core Issues affecting the Core module area:IO Issues affecting the IO module area:Segmentation Issues affecting the Segmentation module area:Video Issues affecting the Video module area:Numerics Issues affecting the Numerics module labels Jul 25, 2026
@hjmjohnson hjmjohnson changed the title BUG: Propagate helper status in six registration and overlap tests BUG: Propagate test helper status and mark the helpers [[nodiscard]] Jul 25, 2026
@hjmjohnson
hjmjohnson marked this pull request as ready for review July 25, 2026 16:25
@greptile-apps

This comment was marked as resolved.

@hjmjohnson
hjmjohnson force-pushed the fix-propagate-helper-status branch from b15c9d8 to 81a7a0e Compare July 25, 2026 16:55
Each of these tests dispatches to a templated helper selected by image
dimension and discards the helper's return value, then returns
EXIT_SUCCESS unconditionally. The tests therefore pass even when the
helper reports failure, silencing 13 explicit failure returns and 31
ITK_TEST_* assertions.

Capture the helper's status and return it.
The helper asserts a superclass of ImageToImageFilter, but the filter
derives from ImageSink. MSVC evaluates the superclass check, so the
helper returns EXIT_FAILURE on Windows.
Test sources define file-scope helpers returning EXIT_SUCCESS or
EXIT_FAILURE, and a caller that drops the value turns every assertion
inside the helper into a no-op. Marking the helpers [[nodiscard]] makes
the compiler reject that.

Annotate the 290 declarations of such helpers and propagate the status
at the 30 call sites the attribute exposes, in eight tests spanning
image functions, smoothing, diffusion, XML, metrics and superpixel
segmentation.

The attribute goes on every declaration, not just the definition: it
only governs calls that follow the declaration carrying it, so a bare
forward declaration leaves earlier call sites unchecked.

Helpers whose int return is a value rather than a status are left
unannotated, as are the few using a bare 0/1 convention.
@hjmjohnson
hjmjohnson force-pushed the fix-propagate-helper-status branch from 81a7a0e to 021999f Compare July 25, 2026 17:41
@hjmjohnson

Copy link
Copy Markdown
Member Author

@greptileai review

@hjmjohnson
hjmjohnson requested a review from dzenanz July 27, 2026 12:04
@hjmjohnson
hjmjohnson merged commit c01976d into InsightSoftwareConsortium:main Jul 27, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Numerics Issues affecting the Numerics module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module area:Video Issues affecting the Video module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances 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