From 942b8affbe781452faa788d8fed303d6d3218463 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 1 Jan 2022 14:16:52 +0100 Subject: [PATCH] :construction: move to Catch2 --- test/CMakeLists.txt | 4 +- test/src/unit-assert_macro.cpp | 2 +- test/src/unit-cbor.cpp | 44 +++++----- test/src/unit-class_parser.cpp | 16 ++-- test/src/unit-conversions.cpp | 142 +++++++++++++++++++-------------- test/src/unit-diagnostics.cpp | 21 +++-- test/src/unit-json_pointer.cpp | 6 +- test/src/unit-modifiers.cpp | 6 +- test/src/unit-msgpack.cpp | 2 +- test/src/unit-regression1.cpp | 2 +- test/src/unit-regression2.cpp | 3 +- test/src/unit-ubjson.cpp | 25 +++--- test/src/unit-udt_macro.cpp | 3 +- 13 files changed, 156 insertions(+), 120 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 05f749394..ba99837a6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -95,7 +95,7 @@ foreach(file ${files}) ) else() add_test(NAME "${testcase}_cpp17" - COMMAND ${testcase}_cpp17 ${DOCTEST_TEST_FILTER} --no-skip + COMMAND ${testcase}_cpp17 ${DOCTEST_TEST_FILTER} "*" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) endif() @@ -110,7 +110,7 @@ foreach(file ${files}) ) else() add_test(NAME "${testcase}" - COMMAND ${testcase} ${DOCTEST_TEST_FILTER} --no-skip + COMMAND ${testcase} ${DOCTEST_TEST_FILTER} "*" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) endif() diff --git a/test/src/unit-assert_macro.cpp b/test/src/unit-assert_macro.cpp index 06f2860d2..57550f794 100644 --- a/test/src/unit-assert_macro.cpp +++ b/test/src/unit-assert_macro.cpp @@ -61,7 +61,7 @@ TEST_CASE("JSON_ASSERT(x)") CHECK_THROWS_WITH(json(it, j.end()), "[json.exception.invalid_iterator.201] iterators are not compatible"); // check that assertion actually happened - CHECK(assert_counter == 1); + CHECK(assert_counter == 2); } } #endif diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index 2a6e2e86d..0baac4d16 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -450,7 +450,7 @@ TEST_CASE("CBOR") { for (size_t i = 24; i <= 255; ++i) { - CAPTURE(i) + CAPTURE(i); // create JSON value with integer number json j = -1; @@ -521,7 +521,7 @@ TEST_CASE("CBOR") 65536u, 77777u, 1048576u }) { - CAPTURE(i) + CAPTURE(i); // create JSON value with integer number json j = -1; @@ -648,7 +648,7 @@ TEST_CASE("CBOR") { for (size_t i = 0; i <= 23; ++i) { - CAPTURE(i) + CAPTURE(i); // create JSON value with unsigned integer number json j = i; @@ -711,7 +711,7 @@ TEST_CASE("CBOR") { for (size_t i = 256; i <= 65535; ++i) { - CAPTURE(i) + CAPTURE(i); // create JSON value with unsigned integer number json j = i; @@ -1097,7 +1097,7 @@ TEST_CASE("CBOR") { for (size_t N = 0; N <= 0x17; ++N) { - CAPTURE(N) + CAPTURE(N); // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); @@ -1131,7 +1131,7 @@ TEST_CASE("CBOR") { for (size_t N = 24; N <= 255; ++N) { - CAPTURE(N) + CAPTURE(N); // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); @@ -1166,7 +1166,7 @@ TEST_CASE("CBOR") 256u, 999u, 1025u, 3333u, 2048u, 65535u }) { - CAPTURE(N) + CAPTURE(N); // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); @@ -1199,7 +1199,7 @@ TEST_CASE("CBOR") 65536u, 77777u, 1048576u }) { - CAPTURE(N) + CAPTURE(N); // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); @@ -1446,7 +1446,7 @@ TEST_CASE("CBOR") { for (size_t N = 0; N <= 0x17; ++N) { - CAPTURE(N) + CAPTURE(N); // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); @@ -1480,7 +1480,7 @@ TEST_CASE("CBOR") { for (size_t N = 24; N <= 255; ++N) { - CAPTURE(N) + CAPTURE(N); // create JSON value with string containing of N * 'x' const auto s = std::vector(N, 'x'); @@ -1515,7 +1515,7 @@ TEST_CASE("CBOR") 256u, 999u, 1025u, 3333u, 2048u, 65535u }) { - CAPTURE(N) + CAPTURE(N); // create JSON value with string containing of N * 'x' const auto s = std::vector(N, 'x'); @@ -1548,7 +1548,7 @@ TEST_CASE("CBOR") 65536u, 77777u, 1048576u }) { - CAPTURE(N) + CAPTURE(N); // create JSON value with string containing of N * 'x' const auto s = std::vector(N, 'x'); @@ -1582,7 +1582,7 @@ TEST_CASE("CBOR") auto j = json::from_cbor(input); CHECK(j.is_binary()); auto k = json::binary({0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x99}); - CAPTURE(j.dump(0, ' ', false, json::error_handler_t::strict)) + CAPTURE(j.dump(0, ' ', false, json::error_handler_t::strict)); CHECK(j == k); } @@ -1989,7 +1989,7 @@ TEST_CASE("CBOR regressions") TEST_DATA_DIRECTORY "/cbor_regression/test21" }) { - CAPTURE(filename) + CAPTURE(filename); try { @@ -2023,7 +2023,7 @@ TEST_CASE("CBOR regressions") } #endif -TEST_CASE("CBOR roundtrips" * doctest::skip()) +TEST_CASE("CBOR roundtrips", "[.]") { SECTION("input from flynn") { @@ -2190,10 +2190,10 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json" }) { - CAPTURE(filename) + CAPTURE(filename); { - INFO_WITH_TEMP(filename + ": std::vector"); + CAPTURE(filename + ": std::vector"); // parse JSON file std::ifstream f_json(filename); json j1 = json::parse(f_json); @@ -2208,7 +2208,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) } { - INFO_WITH_TEMP(filename + ": std::ifstream"); + CAPTURE(filename + ": std::ifstream"); // parse JSON file std::ifstream f_json(filename); json j1 = json::parse(f_json); @@ -2223,7 +2223,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) } { - INFO_WITH_TEMP(filename + ": uint8_t* and size"); + CAPTURE(filename + ": uint8_t* and size"); // parse JSON file std::ifstream f_json(filename); json j1 = json::parse(f_json); @@ -2238,7 +2238,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) } { - INFO_WITH_TEMP(filename + ": output to output adapters"); + CAPTURE(filename + ": output to output adapters"); // parse JSON file std::ifstream f_json(filename); json j1 = json::parse(f_json); @@ -2249,7 +2249,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) if (exclude_packed.count(filename) == 0u) { { - INFO_WITH_TEMP(filename + ": output adapters: std::vector"); + CAPTURE(filename + ": output adapters: std::vector"); std::vector vec; json::to_cbor(j1, vec); CHECK(vec == packed); @@ -2319,7 +2319,7 @@ TEST_CASE("all CBOR first bytes") { // check that parse_error.112 is only thrown if the // first byte is in the unsupported set - INFO_WITH_TEMP(e.what()); + CAPTURE(e.what()); if (unsupported.find(byte) != unsupported.end()) { CHECK(e.id == 112); diff --git a/test/src/unit-class_parser.cpp b/test/src/unit-class_parser.cpp index c1ce9ccc4..176229587 100644 --- a/test/src/unit-class_parser.cpp +++ b/test/src/unit-class_parser.cpp @@ -1173,7 +1173,7 @@ TEST_CASE("parser class") if (c > 0x1f) { CHECK_THROWS_WITH(parser_helper(s), - "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast(c)) + "'"); + "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast(c)) + "'"); } break; } @@ -1249,7 +1249,7 @@ TEST_CASE("parser class") if (c > 0x1f) { CHECK_THROWS_WITH(parser_helper(s1), - "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'"); + "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'"); } CAPTURE(s2); @@ -1258,7 +1258,7 @@ TEST_CASE("parser class") if (c > 0x1f) { CHECK_THROWS_WITH(parser_helper(s2), - "[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'"); + "[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'"); } CAPTURE(s3); @@ -1267,7 +1267,7 @@ TEST_CASE("parser class") if (c > 0x1f) { CHECK_THROWS_WITH(parser_helper(s3), - "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'"); + "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'"); } CAPTURE(s4); @@ -1276,7 +1276,7 @@ TEST_CASE("parser class") if (c > 0x1f) { CHECK_THROWS_WITH(parser_helper(s4), - "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'"); + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'"); } } } @@ -1827,7 +1827,9 @@ TEST_CASE("parser class") SECTION("error messages for comments") { json _; - CHECK_THROWS_WITH_AS(_ = json::parse("/a", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid comment; expecting '/' or '*' after '/'; last read: '/a'", json::parse_error); - CHECK_THROWS_WITH_AS(_ = json::parse("/*", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid comment; missing closing '*/'; last read: '/*'", json::parse_error); + CHECK_THROWS_WITH(_ = json::parse("/a", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid comment; expecting '/' or '*' after '/'; last read: '/a'"); + CHECK_THROWS_AS(_ = json::parse("/a", nullptr, true, true), json::parse_error); + CHECK_THROWS_WITH(_ = json::parse("/*", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid comment; missing closing '*/'; last read: '/*'"); + CHECK_THROWS_AS(_ = json::parse("/*", nullptr, true, true), json::parse_error); } } diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index b4f1f7b08..0482931a8 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -1310,69 +1310,89 @@ TEST_CASE("value conversion") const json j_string_const(json::value_t::string); const json j_boolean_const(json::value_t::boolean); - CHECK_THROWS_WITH_AS(j_null.get(), - "[json.exception.type_error.302] type must be binary, but is null", - json::type_error); - CHECK_THROWS_WITH_AS(j_object.get(), - "[json.exception.type_error.302] type must be binary, but is object", - json::type_error); - CHECK_THROWS_WITH_AS(j_array.get(), - "[json.exception.type_error.302] type must be binary, but is array", - json::type_error); - CHECK_THROWS_WITH_AS(j_string.get(), - "[json.exception.type_error.302] type must be binary, but is string", - json::type_error); - CHECK_THROWS_WITH_AS(j_boolean.get(), - "[json.exception.type_error.302] type must be binary, but is boolean", - json::type_error); + CHECK_THROWS_WITH(j_null.get(), + "[json.exception.type_error.302] type must be binary, but is null"); + CHECK_THROWS_AS(j_null.get(), + json::type_error); + CHECK_THROWS_WITH(j_object.get(), + "[json.exception.type_error.302] type must be binary, but is object"); + CHECK_THROWS_AS(j_object.get(), + json::type_error); + CHECK_THROWS_WITH(j_array.get(), + "[json.exception.type_error.302] type must be binary, but is array"); + CHECK_THROWS_AS(j_array.get(), + json::type_error); + CHECK_THROWS_WITH(j_string.get(), + "[json.exception.type_error.302] type must be binary, but is string"); + CHECK_THROWS_AS(j_string.get(), + json::type_error); + CHECK_THROWS_WITH(j_boolean.get(), + "[json.exception.type_error.302] type must be binary, but is boolean"); + CHECK_THROWS_AS(j_boolean.get(), + json::type_error); - CHECK_THROWS_WITH_AS(j_null_const.get(), - "[json.exception.type_error.302] type must be binary, but is null", - json::type_error); - CHECK_THROWS_WITH_AS(j_object_const.get(), - "[json.exception.type_error.302] type must be binary, but is object", - json::type_error); - CHECK_THROWS_WITH_AS(j_array_const.get(), - "[json.exception.type_error.302] type must be binary, but is array", - json::type_error); - CHECK_THROWS_WITH_AS(j_string_const.get(), - "[json.exception.type_error.302] type must be binary, but is string", - json::type_error); - CHECK_THROWS_WITH_AS(j_boolean_const.get(), - "[json.exception.type_error.302] type must be binary, but is boolean", - json::type_error); + CHECK_THROWS_WITH(j_null_const.get(), + "[json.exception.type_error.302] type must be binary, but is null"); + CHECK_THROWS_AS(j_null_const.get(), + json::type_error); + CHECK_THROWS_WITH(j_object_const.get(), + "[json.exception.type_error.302] type must be binary, but is object"); + CHECK_THROWS_AS(j_object_const.get(), + json::type_error); + CHECK_THROWS_WITH(j_array_const.get(), + "[json.exception.type_error.302] type must be binary, but is array"); + CHECK_THROWS_AS(j_array_const.get(), + json::type_error); + CHECK_THROWS_WITH(j_string_const.get(), + "[json.exception.type_error.302] type must be binary, but is string"); + CHECK_THROWS_AS(j_string_const.get(), + json::type_error); + CHECK_THROWS_WITH(j_boolean_const.get(), + "[json.exception.type_error.302] type must be binary, but is boolean"); + CHECK_THROWS_AS(j_boolean_const.get(), + json::type_error); - CHECK_THROWS_WITH_AS(j_null.get_binary(), - "[json.exception.type_error.302] type must be binary, but is null", - json::type_error); - CHECK_THROWS_WITH_AS(j_object.get_binary(), - "[json.exception.type_error.302] type must be binary, but is object", - json::type_error); - CHECK_THROWS_WITH_AS(j_array.get_binary(), - "[json.exception.type_error.302] type must be binary, but is array", - json::type_error); - CHECK_THROWS_WITH_AS(j_string.get_binary(), - "[json.exception.type_error.302] type must be binary, but is string", - json::type_error); - CHECK_THROWS_WITH_AS(j_boolean.get_binary(), - "[json.exception.type_error.302] type must be binary, but is boolean", - json::type_error); + CHECK_THROWS_WITH(j_null.get_binary(), + "[json.exception.type_error.302] type must be binary, but is null"); + CHECK_THROWS_AS(j_null.get_binary(), + json::type_error); + CHECK_THROWS_WITH(j_object.get_binary(), + "[json.exception.type_error.302] type must be binary, but is object"); + CHECK_THROWS_AS(j_object.get_binary(), + json::type_error); + CHECK_THROWS_WITH(j_array.get_binary(), + "[json.exception.type_error.302] type must be binary, but is array"); + CHECK_THROWS_AS(j_array.get_binary(), + json::type_error); + CHECK_THROWS_WITH(j_string.get_binary(), + "[json.exception.type_error.302] type must be binary, but is string"); + CHECK_THROWS_AS(j_string.get_binary(), + json::type_error); + CHECK_THROWS_WITH(j_boolean.get_binary(), + "[json.exception.type_error.302] type must be binary, but is boolean"); + CHECK_THROWS_AS(j_boolean.get_binary(), + json::type_error); - CHECK_THROWS_WITH_AS(j_null_const.get_binary(), - "[json.exception.type_error.302] type must be binary, but is null", - json::type_error); - CHECK_THROWS_WITH_AS(j_object_const.get_binary(), - "[json.exception.type_error.302] type must be binary, but is object", - json::type_error); - CHECK_THROWS_WITH_AS(j_array_const.get_binary(), - "[json.exception.type_error.302] type must be binary, but is array", - json::type_error); - CHECK_THROWS_WITH_AS(j_string_const.get_binary(), - "[json.exception.type_error.302] type must be binary, but is string", - json::type_error); - CHECK_THROWS_WITH_AS(j_boolean_const.get_binary(), - "[json.exception.type_error.302] type must be binary, but is boolean", - json::type_error); + CHECK_THROWS_WITH(j_null_const.get_binary(), + "[json.exception.type_error.302] type must be binary, but is null"); + CHECK_THROWS_AS(j_null_const.get_binary(), + json::type_error); + CHECK_THROWS_WITH(j_object_const.get_binary(), + "[json.exception.type_error.302] type must be binary, but is object"); + CHECK_THROWS_AS(j_object_const.get_binary(), + json::type_error); + CHECK_THROWS_WITH(j_array_const.get_binary(), + "[json.exception.type_error.302] type must be binary, but is array"); + CHECK_THROWS_AS(j_array_const.get_binary(), + json::type_error); + CHECK_THROWS_WITH(j_string_const.get_binary(), + "[json.exception.type_error.302] type must be binary, but is string"); + CHECK_THROWS_AS(j_string_const.get_binary(), + json::type_error); + CHECK_THROWS_WITH(j_boolean_const.get_binary(), + "[json.exception.type_error.302] type must be binary, but is boolean"); + CHECK_THROWS_AS(j_boolean_const.get_binary(), + json::type_error); } } @@ -1717,4 +1737,4 @@ TEST_CASE("JSON to enum mapping") #undef JSON_HAS_CPP_14 #endif -DOCTEST_CLANG_SUPPRESS_WARNING_POP +//DOCTEST_CLANG_SUPPRESS_WARNING_POP diff --git a/test/src/unit-diagnostics.cpp b/test/src/unit-diagnostics.cpp index 3a81479bb..96e9a0a90 100644 --- a/test/src/unit-diagnostics.cpp +++ b/test/src/unit-diagnostics.cpp @@ -110,8 +110,10 @@ TEST_CASE("Better diagnostics") json j = {{"foo", "bar"}}; json k = {{"bla", 1}}; - CHECK_THROWS_WITH_AS(j.update(k["bla"].begin(), k["bla"].end()), "[json.exception.type_error.312] (/bla) cannot use update() with number", json::type_error); - CHECK_THROWS_WITH_AS(j.update(k["bla"]), "[json.exception.type_error.312] (/bla) cannot use update() with number", json::type_error); + CHECK_THROWS_WITH(j.update(k["bla"].begin(), k["bla"].end()), "[json.exception.type_error.312] (/bla) cannot use update() with number"); + CHECK_THROWS_AS(j.update(k["bla"].begin(), k["bla"].end()), json::type_error); + CHECK_THROWS_WITH(j.update(k["bla"]), "[json.exception.type_error.312] (/bla) cannot use update() with number"); + CHECK_THROWS_AS(j.update(k["bla"]), json::type_error); } } @@ -119,15 +121,18 @@ TEST_CASE("Regression tests for extended diagnostics") { SECTION("Regression test for https://github.com/nlohmann/json/pull/2562#pullrequestreview-574858448") { - CHECK_THROWS_WITH_AS(json({"0", "0"})[1].get(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error); - CHECK_THROWS_WITH_AS(json({"0", "1"})[1].get(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error); + CHECK_THROWS_WITH(json({"0", "0"})[1].get(), "[json.exception.type_error.302] (/1) type must be number, but is string"); + CHECK_THROWS_AS(json({"0", "0"})[1].get(), json::type_error); + CHECK_THROWS_WITH(json({"0", "1"})[1].get(), "[json.exception.type_error.302] (/1) type must be number, but is string"); + CHECK_THROWS_AS(json({"0", "1"})[1].get(), json::type_error); } SECTION("Regression test for https://github.com/nlohmann/json/pull/2562/files/380a613f2b5d32425021129cd1f371ddcfd54ddf#r563259793") { json j; j["/foo"] = {1, 2, 3}; - CHECK_THROWS_WITH_AS(j.unflatten(), "[json.exception.type_error.315] (/~1foo) values in object must be primitive", json::type_error); + CHECK_THROWS_WITH(j.unflatten(), "[json.exception.type_error.315] (/~1foo) values in object must be primitive"); + CHECK_THROWS_AS(j.unflatten(), json::type_error); } SECTION("Regression test for issue #2838 - Assertion failure when inserting into arrays with JSON_DIAGNOSTICS set") @@ -220,7 +225,8 @@ TEST_CASE("Regression tests for extended diagnostics") // Must call operator[] on const element, otherwise m_parent gets updated. auto const& constJ = j; - CHECK_THROWS_WITH_AS(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number", json::type_error); + CHECK_THROWS_WITH(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number"); + CHECK_THROWS_AS(constJ["one"].at(0), json::type_error); } // void update(const_iterator first, const_iterator last) @@ -236,7 +242,8 @@ TEST_CASE("Regression tests for extended diagnostics") // Must call operator[] on const element, otherwise m_parent gets updated. auto const& constJ = j; - CHECK_THROWS_WITH_AS(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number", json::type_error); + CHECK_THROWS_WITH(constJ["one"].at(0), "[json.exception.type_error.304] (/one) cannot use at() with number"); + CHECK_THROWS_AS(constJ["one"].at(0), json::type_error); } // Code from #3007 triggering unwanted assertion without fix to update(). diff --git a/test/src/unit-json_pointer.cpp b/test/src/unit-json_pointer.cpp index 24fe1f81b..7a30eeb3a 100644 --- a/test/src/unit-json_pointer.cpp +++ b/test/src/unit-json_pointer.cpp @@ -359,8 +359,8 @@ TEST_CASE("JSON pointers") } // on some machines, the check below is not constant - DOCTEST_MSVC_SUPPRESS_WARNING_PUSH - DOCTEST_MSVC_SUPPRESS_WARNING(4127) + //DOCTEST_MSVC_SUPPRESS_WARNING_PUSH + //DOCTEST_MSVC_SUPPRESS_WARNING(4127) if (sizeof(typename json::size_type) < sizeof(unsigned long long)) { @@ -375,7 +375,7 @@ TEST_CASE("JSON pointers") CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str()); } - DOCTEST_MSVC_SUPPRESS_WARNING_POP + //DOCTEST_MSVC_SUPPRESS_WARNING_POP CHECK_THROWS_AS(j.at("/one"_json_pointer) = 1, json::parse_error); CHECK_THROWS_WITH(j.at("/one"_json_pointer) = 1, diff --git a/test/src/unit-modifiers.cpp b/test/src/unit-modifiers.cpp index 119f4ec65..03899d5d3 100644 --- a/test/src/unit-modifiers.cpp +++ b/test/src/unit-modifiers.cpp @@ -1025,8 +1025,10 @@ TEST_CASE("modifiers") json::binary_t s1 = {{1, 2, 3, 4}}; std::vector s2 = {{5, 6, 7, 8}}; - CHECK_THROWS_WITH_AS(j.swap(s1), "[json.exception.type_error.310] cannot use swap() with number", json::type_error); - CHECK_THROWS_WITH_AS(j.swap(s2), "[json.exception.type_error.310] cannot use swap() with number", json::type_error); + CHECK_THROWS_WITH(j.swap(s1), "[json.exception.type_error.310] cannot use swap() with number"); + CHECK_THROWS_AS(j.swap(s1), json::type_error); + CHECK_THROWS_WITH(j.swap(s2), "[json.exception.type_error.310] cannot use swap() with number"); + CHECK_THROWS_AS(j.swap(s2), json::type_error); } } } diff --git a/test/src/unit-msgpack.cpp b/test/src/unit-msgpack.cpp index 367504fdd..b37d679f8 100644 --- a/test/src/unit-msgpack.cpp +++ b/test/src/unit-msgpack.cpp @@ -1642,7 +1642,7 @@ TEST_CASE("single MessagePack roundtrip") } } -TEST_CASE("MessagePack roundtrips" * doctest::skip()) +TEST_CASE("MessagePack roundtrips", "[.]") { SECTION("input from msgpack-python") { diff --git a/test/src/unit-regression1.cpp b/test/src/unit-regression1.cpp index c49661b86..915fcdba0 100644 --- a/test/src/unit-regression1.cpp +++ b/test/src/unit-regression1.cpp @@ -1588,7 +1588,7 @@ TEST_CASE("regression tests, exceptions dependent") json j; s >> j; s >> j; - CHECK_THROWS_AS(s >> j, json::parse_error const); + CHECK_THROWS_AS(s >> j, json::parse_error); CHECK(s.eof()); } } diff --git a/test/src/unit-regression2.cpp b/test/src/unit-regression2.cpp index 368d04f9f..d487260ba 100644 --- a/test/src/unit-regression2.cpp +++ b/test/src/unit-regression2.cpp @@ -807,7 +807,8 @@ TEST_CASE("regression tests 2") const auto j_path = j.get(); CHECK(j_path == text_path); - CHECK_THROWS_WITH_AS(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number", json::type_error); + CHECK_THROWS_WITH(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number"); + CHECK_THROWS_AS(nlohmann::detail::std_fs::path(json(1)), json::type_error); } #endif diff --git a/test/src/unit-ubjson.cpp b/test/src/unit-ubjson.cpp index 3a0e96cf6..32ea6de6a 100644 --- a/test/src/unit-ubjson.cpp +++ b/test/src/unit-ubjson.cpp @@ -807,11 +807,14 @@ TEST_CASE("UBJSON") json _; std::vector vec2 = {'H', 'i', 2, '1', 'A', '3'}; - CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vec2), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A", json::parse_error); + CHECK_THROWS_WITH(_ = json::from_ubjson(vec2), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A"); + CHECK_THROWS_AS(_ = json::from_ubjson(vec2), json::parse_error); std::vector vec3 = {'H', 'i', 2, '1', '.'}; - CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vec3), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1.", json::parse_error); + CHECK_THROWS_WITH(_ = json::from_ubjson(vec3), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1."); + CHECK_THROWS_AS(_ = json::from_ubjson(vec3), json::parse_error); std::vector vec4 = {'H', 2, '1', '0'}; - CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vec4), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x02", json::parse_error); + CHECK_THROWS_WITH(_ = json::from_ubjson(vec4), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x02"); + CHECK_THROWS_AS(_ = json::from_ubjson(vec4), json::parse_error); } SECTION("serialization") @@ -2428,7 +2431,7 @@ TEST_CASE("all UBJSON first bytes") for (auto i = 0; i < 256; ++i) { const auto byte = static_cast(i); - CAPTURE(byte) + CAPTURE(byte); try { @@ -2438,7 +2441,7 @@ TEST_CASE("all UBJSON first bytes") { // check that parse_error.112 is only thrown if the // first byte is not in the supported set - INFO_WITH_TEMP(e.what()); + CAPTURE(e.what()); if (supported.find(byte) == supported.end()) { CHECK(e.id == 112); @@ -2452,7 +2455,7 @@ TEST_CASE("all UBJSON first bytes") } #endif -TEST_CASE("UBJSON roundtrips" * doctest::skip()) +TEST_CASE("UBJSON roundtrips", "[.]") { SECTION("input from self-generated UBJSON files") { @@ -2505,7 +2508,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip()) CAPTURE(filename); { - INFO_WITH_TEMP(filename + ": std::vector"); + CAPTURE(filename + ": std::vector"); // parse JSON file std::ifstream f_json(filename); json j1 = json::parse(f_json); @@ -2520,7 +2523,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip()) } { - INFO_WITH_TEMP(filename + ": std::ifstream"); + CAPTURE(filename + ": std::ifstream"); // parse JSON file std::ifstream f_json(filename); json j1 = json::parse(f_json); @@ -2535,7 +2538,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip()) } { - INFO_WITH_TEMP(filename + ": uint8_t* and size"); + CAPTURE(filename + ": uint8_t* and size"); // parse JSON file std::ifstream f_json(filename); json j1 = json::parse(f_json); @@ -2550,7 +2553,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip()) } { - INFO_WITH_TEMP(filename + ": output to output adapters"); + CAPTURE(filename + ": output to output adapters"); // parse JSON file std::ifstream f_json(filename); json j1 = json::parse(f_json); @@ -2559,7 +2562,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip()) auto packed = utils::read_binary_file(filename + ".ubjson"); { - INFO_WITH_TEMP(filename + ": output adapters: std::vector"); + CAPTURE(filename + ": output adapters: std::vector"); std::vector vec; json::to_ubjson(j1, vec); CHECK(vec == packed); diff --git a/test/src/unit-udt_macro.cpp b/test/src/unit-udt_macro.cpp index 95ebdbabf..dc38de55d 100644 --- a/test/src/unit-udt_macro.cpp +++ b/test/src/unit-udt_macro.cpp @@ -253,7 +253,8 @@ TEMPLATE_TEST_CASE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU // check exception in case of missing field json j = json(p1); j.erase("age"); - CHECK_THROWS_WITH_AS(j.get(), "[json.exception.out_of_range.403] key 'age' not found", json::out_of_range); + CHECK_THROWS_WITH(j.get(), "[json.exception.out_of_range.403] key 'age' not found"); + CHECK_THROWS_AS(j.get(), json::out_of_range); } }