From 79c58ea674c3a1946dd89d892239c9082e9dd65b Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 26 Sep 2018 11:05:22 -0400 Subject: [PATCH] Fix for building tests with GCC 4.8 --- README.md | 4 ++-- test/src/unit-regression.cpp | 28 +++++++++++++++++----------- test/src/unit-testsuites.cpp | 11 +++++++---- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 610e941cdd..957fffa184 100644 --- a/README.md +++ b/README.md @@ -843,7 +843,7 @@ json j_from_ubjson = json::from_ubjson(v_ubjson); Though it's 2018 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work: -- GCC 4.9 - 8.2 (and possibly later) +- GCC 4.8 - 8.2 (and possibly later) - Clang 3.4 - 6.1 (and possibly later) - Intel C++ Compiler 17.0.2 (and possibly later) - Microsoft Visual C++ 2015 / Build Tools 14.0.25123.0 (and possibly later) @@ -853,7 +853,7 @@ I would be happy to learn about other compilers/versions. Please note: -- GCC 4.8 has a bug [57824](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57824)): raw strings cannot be the arguments to macros. Don't use raw strings directly in macros with this compiler. +- GCC 4.8 has a bug [57824](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57824)): multiline raw strings cannot be the arguments to macros. Don't use multiline raw strings directly in macros with this compiler. - Android defaults to using very old compilers and C++ libraries. To fix this, add the following to your `Application.mk`. This will switch to the LLVM C++ library, the Clang compiler, and enable C++11 and other features disabled by default. ``` diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index 69c0cf29a4..c547864399 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -1427,20 +1427,26 @@ TEST_CASE("regression tests") } })"_json; - CHECK_THROWS_AS(model.patch(R"([{"op": "move", - "from": "/one/two/three", - "path": "/a/b/c"}])"_json), json::out_of_range&); - CHECK_THROWS_WITH(model.patch(R"([{"op": "move", - "from": "/one/two/three", - "path": "/a/b/c"}])"_json), + auto p1 = R"([{"op": "move", + "from": "/one/two/three", + "path": "/a/b/c"}])"_json; + CHECK_THROWS_AS(model.patch(p1), json::out_of_range&); + + auto p2 = R"([{"op": "move", + "from": "/one/two/three", + "path": "/a/b/c"}])"_json; + CHECK_THROWS_WITH(model.patch(p2), "[json.exception.out_of_range.403] key 'a' not found"); - CHECK_THROWS_AS(model.patch(R"([{"op": "copy", - "from": "/one/two/three", - "path": "/a/b/c"}])"_json), json::out_of_range&); - CHECK_THROWS_WITH(model.patch(R"([{"op": "copy", + auto p3 = R"([{"op": "copy", + "from": "/one/two/three", + "path": "/a/b/c"}])"_json; + CHECK_THROWS_AS(model.patch(p3), json::out_of_range&); + + auto p4 = R"([{"op": "copy", "from": "/one/two/three", - "path": "/a/b/c"}])"_json), + "path": "/a/b/c"}])"_json; + CHECK_THROWS_WITH(model.patch(p4), "[json.exception.out_of_range.403] key 'a' not found"); } diff --git a/test/src/unit-testsuites.cpp b/test/src/unit-testsuites.cpp index 237eb34ee6..908901ab31 100644 --- a/test/src/unit-testsuites.cpp +++ b/test/src/unit-testsuites.cpp @@ -405,7 +405,7 @@ TEST_CASE("RFC 7159 examples") SECTION("13 Examples") { { - CHECK_NOTHROW(json(R"( + auto json_contents = R"( { "Image": { "Width": 800, @@ -420,11 +420,13 @@ TEST_CASE("RFC 7159 examples") "IDs": [116, 943, 234, 38793] } } - )")); + )"; + + CHECK_NOTHROW(json(json_contents)); } { - CHECK_NOTHROW(json(R"( + auto json_contents = R"( [ { "precision": "zip", @@ -446,7 +448,8 @@ TEST_CASE("RFC 7159 examples") "Zip": "94085", "Country": "US" } - ])")); + ])"; + CHECK_NOTHROW(json(json_contents)); } CHECK(json::parse("\"Hello world!\"") == json("Hello world!"));