From 3ab8cc00303ce090557097276047965ac3a7eef1 Mon Sep 17 00:00:00 2001 From: Jared Duffey Date: Fri, 14 Aug 2026 09:41:17 -0400 Subject: [PATCH 1/3] Changed test macros to copy result - Wrapped inside do while block for formatting - Now check that the argument to the macros is actually a Result Signed-off-by: Jared Duffey --- .../simplnx/UnitTest/UnitTestCommon.hpp | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp b/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp index 9cd2106644..5b5618cbc0 100644 --- a/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp +++ b/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp @@ -40,6 +40,15 @@ namespace fs = std::filesystem; using namespace nx::core; +namespace nx::core +{ +// Concept that checks if T is an instance of Result +template +concept IsResult = requires(T x) { + { Result{x} } -> std::same_as; +}; +} // namespace nx::core + #define SIMPLNX_RESULT_CATCH_PRINT(result) \ for(const auto& warning : (result).warnings()) \ { \ @@ -54,12 +63,20 @@ using namespace nx::core; } #define SIMPLNX_RESULT_REQUIRE_VALID(result) \ - SIMPLNX_RESULT_CATCH_PRINT(result); \ - REQUIRE((result).valid()); + do \ + { \ + const IsResult auto NX_TEST_RESULT = (result); \ + SIMPLNX_RESULT_CATCH_PRINT(NX_TEST_RESULT); \ + REQUIRE(NX_TEST_RESULT.valid()); \ + } while(false); #define SIMPLNX_RESULT_REQUIRE_INVALID(result) \ - SIMPLNX_RESULT_CATCH_PRINT(result); \ - REQUIRE((result).invalid()); + do \ + { \ + const IsResult auto NX_TEST_RESULT = (result); \ + SIMPLNX_RESULT_CATCH_PRINT(NX_TEST_RESULT); \ + REQUIRE(NX_TEST_RESULT.invalid()); \ + } while(false); namespace nx::core { From 54524b2948dca6bc7c11b02c0a9b9fb8e6472666 Mon Sep 17 00:00:00 2001 From: Jared Duffey Date: Fri, 21 Aug 2026 16:45:34 -0400 Subject: [PATCH 2/3] Switched to only allowing lvalues in SIMPLNX_RESULT_REQUIRE macros Signed-off-by: Jared Duffey --- .../simplnx/UnitTest/UnitTestCommon.hpp | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp b/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp index 5b5618cbc0..7a73d41a84 100644 --- a/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp +++ b/test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp @@ -42,13 +42,15 @@ using namespace nx::core; namespace nx::core { -// Concept that checks if T is an instance of Result +template +inline constexpr bool IsResult_v = false; + template -concept IsResult = requires(T x) { - { Result{x} } -> std::same_as; -}; +inline constexpr bool IsResult_v> = true; } // namespace nx::core +#define NX_IS_LVALUE_RESULT(value) (IsResult_v> && std::is_lvalue_reference_v) + #define SIMPLNX_RESULT_CATCH_PRINT(result) \ for(const auto& warning : (result).warnings()) \ { \ @@ -65,17 +67,17 @@ concept IsResult = requires(T x) { #define SIMPLNX_RESULT_REQUIRE_VALID(result) \ do \ { \ - const IsResult auto NX_TEST_RESULT = (result); \ - SIMPLNX_RESULT_CATCH_PRINT(NX_TEST_RESULT); \ - REQUIRE(NX_TEST_RESULT.valid()); \ + static_assert(NX_IS_LVALUE_RESULT(result), "SIMPLNX_RESULT_REQUIRE_VALID requires an lvalue Result"); \ + SIMPLNX_RESULT_CATCH_PRINT(result); \ + REQUIRE((result).valid()); \ } while(false); #define SIMPLNX_RESULT_REQUIRE_INVALID(result) \ do \ { \ - const IsResult auto NX_TEST_RESULT = (result); \ - SIMPLNX_RESULT_CATCH_PRINT(NX_TEST_RESULT); \ - REQUIRE(NX_TEST_RESULT.invalid()); \ + static_assert(NX_IS_LVALUE_RESULT(result), "SIMPLNX_RESULT_REQUIRE_INVALID requires an lvalue Result"); \ + SIMPLNX_RESULT_CATCH_PRINT(result); \ + REQUIRE((result).invalid()); \ } while(false); namespace nx::core From 07d7f5d1b88f245669dd9cfe4c2d467ffad35185 Mon Sep 17 00:00:00 2001 From: Jared Duffey Date: Tue, 25 Aug 2026 13:47:22 -0400 Subject: [PATCH 3/3] Fixed filter tests Signed-off-by: Jared Duffey --- src/Plugins/ITKImageProcessing/test/ITKImageWriterTest.cpp | 6 ++++-- .../SimplnxCore/test/KeepRemoveRankedFeaturesTest.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Plugins/ITKImageProcessing/test/ITKImageWriterTest.cpp b/src/Plugins/ITKImageProcessing/test/ITKImageWriterTest.cpp index 896e8225e5..56f51b17e3 100644 --- a/src/Plugins/ITKImageProcessing/test/ITKImageWriterTest.cpp +++ b/src/Plugins/ITKImageProcessing/test/ITKImageWriterTest.cpp @@ -385,8 +385,10 @@ TEST_CASE("ITKImageProcessing::ITKImageWriterFilter: RGBA Image Output", "[ITKIm args.insertOrAssign(ITKImageWriterFilter::k_TotalIndexDigits_Key, std::make_any(3)); args.insertOrAssign(ITKImageWriterFilter::k_LeadingDigitCharacter_Key, std::make_any("0")); - SIMPLNX_RESULT_REQUIRE_VALID(filter.preflight(dataStructure, args).outputActions); - SIMPLNX_RESULT_REQUIRE_VALID(filter.execute(dataStructure, args).result); + auto preflightResult = filter.preflight(dataStructure, args).outputActions; + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult); + auto executeResult = filter.execute(dataStructure, args).result; + SIMPLNX_RESULT_REQUIRE_VALID(executeResult); using ImageType = itk::Image, 2>; auto reader = itk::ImageFileReader::New(); diff --git a/src/Plugins/SimplnxCore/test/KeepRemoveRankedFeaturesTest.cpp b/src/Plugins/SimplnxCore/test/KeepRemoveRankedFeaturesTest.cpp index d55c058dae..86fbe0d3cb 100644 --- a/src/Plugins/SimplnxCore/test/KeepRemoveRankedFeaturesTest.cpp +++ b/src/Plugins/SimplnxCore/test/KeepRemoveRankedFeaturesTest.cpp @@ -497,9 +497,11 @@ TEST_CASE("SimplnxCore::KeepRemoveRankedFeaturesFilter: Invariants", "[SimplnxCo // Keeping 2 gives {1, 4}; keeping 3 gives {1, 4, 3}. Compare cell-wise: every cell surviving // under k=2 must also survive under k=3. DataStructure smallDs = BuildFiveFeatureData(); - SIMPLNX_RESULT_REQUIRE_VALID(filter.execute(smallDs, MakeArgs(0ULL, 0ULL, 2ULL)).result); + auto smallDsResult = filter.execute(smallDs, MakeArgs(0ULL, 0ULL, 2ULL)).result; + SIMPLNX_RESULT_REQUIRE_VALID(smallDsResult); DataStructure largeDs = BuildFiveFeatureData(); - SIMPLNX_RESULT_REQUIRE_VALID(filter.execute(largeDs, MakeArgs(0ULL, 0ULL, 3ULL)).result); + auto largeDsResult = filter.execute(largeDs, MakeArgs(0ULL, 0ULL, 3ULL)).result; + SIMPLNX_RESULT_REQUIRE_VALID(largeDsResult); const std::vector smallIds = ReadFeatureIds(smallDs); const std::vector largeIds = ReadFeatureIds(largeDs);