mirror of
https://github.com/nlohmann/json.git
synced 2026-09-07 08:47:57 +00:00
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 <mail@nlohmann.me>
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user