From 886296b6e32082791f1f83911e171c5de3d29d4c Mon Sep 17 00:00:00 2001 From: Jared Duffey Date: Fri, 14 Aug 2026 09:41:17 -0400 Subject: [PATCH] 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 {