From fd968125e88ec5925c7ea741834ed9f6cae87bd9 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 15 Apr 2024 22:50:47 +0200 Subject: [PATCH] :rotating_light: fix warning --- tests/src/unit-diagnostics.cpp | 5 +++++ tests/src/unit-element_access2.cpp | 5 +++++ tests/src/unit-udt_macro.cpp | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/tests/src/unit-diagnostics.cpp b/tests/src/unit-diagnostics.cpp index 483f96e73..c84a32fc8 100644 --- a/tests/src/unit-diagnostics.cpp +++ b/tests/src/unit-diagnostics.cpp @@ -39,7 +39,12 @@ TEST_CASE("Better diagnostics") { json j; j["object"]["object"] = true; + +#if defined(JSON_HAS_CPP_17) CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key not found (key is an rvalue and cannot be shown)", json::out_of_range); +#else + CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key 'not_found' not found", json::out_of_range); +#endif } SECTION("array index out of range") diff --git a/tests/src/unit-element_access2.cpp b/tests/src/unit-element_access2.cpp index ae6ba955e..0ef66bab7 100644 --- a/tests/src/unit-element_access2.cpp +++ b/tests/src/unit-element_access2.cpp @@ -69,8 +69,13 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j SECTION("access outside bounds") { +#if defined(JSON_HAS_CPP_17) CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); +#else + CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); + CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&); +#endif #ifdef JSON_HAS_CPP_17 CHECK_THROWS_WITH_AS(j.at(std::string_view("foo")), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&); diff --git a/tests/src/unit-udt_macro.cpp b/tests/src/unit-udt_macro.cpp index 310fe068e..db5131552 100644 --- a/tests/src/unit-udt_macro.cpp +++ b/tests/src/unit-udt_macro.cpp @@ -341,7 +341,11 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU // check exception in case of missing field json j = json(p1); j.erase("age"); +#if defined(JSON_HAS_CPP_17) CHECK_THROWS_WITH_AS(j.get(), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", json::out_of_range); +#else + CHECK_THROWS_WITH_AS(j.get(), "[json.exception.out_of_range.403] key 'age' not found", json::out_of_range); +#endif } }