From 3a5f3fedecc3bde2acb70ac89ffbbbe89e41b4ff Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 5 Sep 2026 21:32:58 +0200 Subject: [PATCH] Guard patch_inplace() partial-application test against JSON_NOEXCEPTION The "distinguishing contract vs patch(): partial application on failure" test relies on doc.patch_inplace(patch) actually throwing so the partially-applied state can be observed right after the throw point. Under ci_test_noexceptions, JSON_THROW() calls std::abort() instead of throwing, and doctest's --no-throw test filter (which that CI job passes) makes CHECK_THROWS_AS() a no-op that never even evaluates its expression -- so patch_inplace() is never called and the follow-up assertions fail against the untouched original document. Guard the whole SECTION with #if !defined(JSON_NOEXCEPTION), following the same convention already used elsewhere in the test suite (e.g. unit-class_parser.cpp) for exception-dependent tests. Signed-off-by: Niels Lohmann --- tests/src/unit-json_patch.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/src/unit-json_patch.cpp b/tests/src/unit-json_patch.cpp index d7c8a2f15..56fc1faf4 100644 --- a/tests/src/unit-json_patch.cpp +++ b/tests/src/unit-json_patch.cpp @@ -703,6 +703,16 @@ TEST_CASE("JSON patch") CHECK(doc == expected); } + // this test relies on the "test" operation actually throwing so the + // partial-application state can be observed right after the throw + // point; under JSON_NOEXCEPTION, JSON_THROW() calls std::abort() + // instead (there is no C++ exception to throw), and doctest's + // CHECK_THROWS_AS() is compiled out to a no-op that never even + // invokes the given expression (see doctest's "--no-throw" test + // filter, which ci_test_noexceptions passes) -- so patch()/ + // patch_inplace() would never be called at all and the follow-up + // state assertions below would fail against the untouched original +#if !defined(JSON_NOEXCEPTION) SECTION("distinguishing contract vs patch(): partial application on failure") { // Unlike patch(), which is all-or-nothing because it applies the @@ -747,6 +757,7 @@ TEST_CASE("JSON patch") CHECK(doc.at("baz") == "boo"); CHECK(doc.at("foo") == "bar"); } +#endif // !defined(JSON_NOEXCEPTION) } SECTION("errors")