From f855d257df26a0b640b0bfff6d24ed74cdab3ca4 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 29 Sep 2026 03:30:39 +0200 Subject: [PATCH] Fix CI: keep raw strings with backslashes out of test macros for MSVC MSVC stringizes the arguments of doctest's CHECK() so that a raw string literal becomes an ordinary one, and then reported the "\q" in the new alt_string recovery test as warning C4129, an error with /WX. The input is now a variable. The same pattern with "\u0000" in the parser's recovery test is replaced by a JSON value built from a std::string. Signed-off-by: Niels Lohmann --- tests/src/unit-alt-string.cpp | 4 +++- tests/src/unit-class_parser.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-alt-string.cpp b/tests/src/unit-alt-string.cpp index 43e400702..98a13a13f 100644 --- a/tests/src/unit-alt-string.cpp +++ b/tests/src/unit-alt-string.cpp @@ -395,7 +395,9 @@ TEST_CASE("alternative string type") alt_json j; recovering_parser sax(j); - CHECK(!alt_json::sax_parse(R"([1., "a\qb", tru, {"k" 2}])", &sax)); + // not inside CHECK(): MSVC reads the escape in a stringized raw string + const std::string input = R"([1., "a\qb", tru, {"k" 2}])"; + CHECK(!alt_json::sax_parse(input, &sax)); CHECK(sax.errors == 4); CHECK(j.dump() == R"([1,"aqb",null,{"k":2}])"); diff --git a/tests/src/unit-class_parser.cpp b/tests/src/unit-class_parser.cpp index 16840d93d..d9e3886de 100644 --- a/tests/src/unit-class_parser.cpp +++ b/tests/src/unit-class_parser.cpp @@ -3268,7 +3268,7 @@ TEST_CASE("parser error recovery (#3989)") const auto in_string = parse_recovering(std::string("[\"a\0b\"]", 7)); CHECK(in_string.balanced); #ifdef JSON_TEST_STRICT_NUL_HANDLING_ENABLED - CHECK(in_string.value == json::parse(R"(["a\u0000b"])")); + CHECK(in_string.value == json::array({std::string("a\0b", 3)})); #else CHECK(in_string.value == json::parse(R"(["a"])")); #endif