From f7a41a2ee68d180cf97af5561a1696e95b8ba953 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 26 Sep 2026 07:46:59 +0200 Subject: [PATCH] Fix the BON8 CI failures of the bulk-read tests - skip the contiguous-versus-stream tests of BON8 strings and BSON keys when exceptions are disabled: they catch the parse errors of invalid input, and without exceptions the library aborts instead - use static_cast for the int64 test value (google-readability-casting) Signed-off-by: Niels Lohmann --- tests/src/unit-bon8.cpp | 5 ++++- tests/src/unit-bson.cpp | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/src/unit-bon8.cpp b/tests/src/unit-bon8.cpp index 40a59a973..3866180ba 100644 --- a/tests/src/unit-bon8.cpp +++ b/tests/src/unit-bon8.cpp @@ -222,7 +222,7 @@ TEST_CASE("BON8") SECTION("signed values are read back as unsigned when not negative") { - const json j = json::from_bon8(json::to_bon8(json(std::int64_t(1000)))); + const json j = json::from_bon8(json::to_bon8(json(static_cast(1000)))); CHECK(j.is_number_unsigned()); CHECK(j == 1000); } @@ -645,6 +645,8 @@ TEST_CASE("BON8") } } +// the test catches the exceptions of invalid input +#if !defined(JSON_NOEXCEPTION) TEST_CASE("BON8 strings from contiguous and stream input") { // contiguous input copies the valid UTF-8 of a string in bulk, a stream @@ -700,6 +702,7 @@ TEST_CASE("BON8 strings from contiguous and stream input") CHECK_THROWS_WITH_AS(_ = json::from_bon8(inputs[7]), "[json.exception.parse_error.110] parse error at byte 23: syntax error while parsing BON8 string: unexpected end of input", json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_bon8(inputs[9]), "[json.exception.parse_error.110] parse error at byte 22: syntax error while parsing BON8 value: expected end of input; last byte: 0x91", json::parse_error&); } +#endif // use this testcase outside [hide] to run it with Valgrind TEST_CASE("BON8 nesting does not consume the call stack") diff --git a/tests/src/unit-bson.cpp b/tests/src/unit-bson.cpp index ec6240388..6db36e887 100644 --- a/tests/src/unit-bson.cpp +++ b/tests/src/unit-bson.cpp @@ -1066,6 +1066,8 @@ TEST_CASE("Incomplete BSON Input") } } +// the test catches the exceptions of invalid input +#if !defined(JSON_NOEXCEPTION) TEST_CASE("BSON keys from contiguous and stream input") { // contiguous input reads a key up to its \x00-byte in one step, a stream @@ -1101,6 +1103,7 @@ TEST_CASE("BSON keys from contiguous and stream input") CHECK(from_vector == from_stream); } } +#endif TEST_CASE("Negative size of binary value") {