Commit bae8e701 by Niels Lohmann

🔀 merge branch 'feature/noexceptions_2' into develop

parents 74cbd30c 87c5e32e
...@@ -71,6 +71,21 @@ matrix: ...@@ -71,6 +71,21 @@ matrix:
after_success: after_success:
- make cppcheck - make cppcheck
# no exceptions
- os: linux
compiler: gcc
env:
- COMPILER=g++-4.9
- SPECIAL=no_exceptions
- TEST_PATTERN=-e \"*\"
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: [g++-4.9, cppcheck]
before_script:
- CPPFLAGS="-DJSON_NOEXCEPTION" make
# Coveralls (http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/) # Coveralls (http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/)
- os: linux - os: linux
......
...@@ -75,7 +75,7 @@ test-%: src/unit-%.cpp ../src/json.hpp thirdparty/catch/catch.hpp ...@@ -75,7 +75,7 @@ test-%: src/unit-%.cpp ../src/json.hpp thirdparty/catch/catch.hpp
@echo "[CXXLD] $@" @echo "[CXXLD] $@"
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -DCATCH_CONFIG_MAIN $< -o $@ @$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -DCATCH_CONFIG_MAIN $< -o $@
TEST_PATTERN = "*" TEST_PATTERN ?= "*"
TEST_PREFIX = "" TEST_PREFIX = ""
check: $(TESTCASES) check: $(TESTCASES)
@cd .. ; for testcase in $(TESTCASES); do echo "Executing $$testcase..."; $(TEST_PREFIX)test/$$testcase $(TEST_PATTERN) || exit 1; done @cd .. ; for testcase in $(TESTCASES); do echo "Executing $$testcase..."; $(TEST_PREFIX)test/$$testcase $(TEST_PATTERN) || exit 1; done
......
...@@ -1187,7 +1187,7 @@ TEST_CASE("single CBOR roundtrip") ...@@ -1187,7 +1187,7 @@ TEST_CASE("single CBOR roundtrip")
} }
} }
TEST_CASE("CBOR regressions") TEST_CASE("CBOR regressions", "[!throws]")
{ {
SECTION("fuzz test results") SECTION("fuzz test results")
{ {
......
...@@ -298,25 +298,6 @@ TEST_CASE("element access 2") ...@@ -298,25 +298,6 @@ TEST_CASE("element access 2")
CHECK(j_const.value("/array"_json_pointer, json({10, 100})) == json({1, 2, 3})); CHECK(j_const.value("/array"_json_pointer, json({10, 100})) == json({1, 2, 3}));
} }
SECTION("access non-existing value")
{
CHECK(j.value("/not/existing"_json_pointer, 2) == 2);
CHECK(j.value("/not/existing"_json_pointer, 2u) == 2u);
CHECK(j.value("/not/existing"_json_pointer, false) == false);
CHECK(j.value("/not/existing"_json_pointer, "bar") == "bar");
CHECK(j.value("/not/existing"_json_pointer, 12.34) == Approx(12.34));
CHECK(j.value("/not/existing"_json_pointer, json({{"foo", "bar"}})) == json({{"foo", "bar"}}));
CHECK(j.value("/not/existing"_json_pointer, json({10, 100})) == json({10, 100}));
CHECK(j_const.value("/not/existing"_json_pointer, 2) == 2);
CHECK(j_const.value("/not/existing"_json_pointer, 2u) == 2u);
CHECK(j_const.value("/not/existing"_json_pointer, false) == false);
CHECK(j_const.value("/not/existing"_json_pointer, "bar") == "bar");
CHECK(j_const.value("/not/existing"_json_pointer, 12.34) == Approx(12.34));
CHECK(j_const.value("/not/existing"_json_pointer, json({{"foo", "bar"}})) == json({{"foo", "bar"}}));
CHECK(j_const.value("/not/existing"_json_pointer, json({10, 100})) == json({10, 100}));
}
SECTION("access on non-object type") SECTION("access on non-object type")
{ {
SECTION("null") SECTION("null")
...@@ -957,3 +938,37 @@ TEST_CASE("element access 2") ...@@ -957,3 +938,37 @@ TEST_CASE("element access 2")
} }
} }
} }
TEST_CASE("element access 2 (throwing tests)", "[!throws]")
{
SECTION("object")
{
json j = {{"integer", 1}, {"unsigned", 1u}, {"floating", 42.23}, {"null", nullptr}, {"string", "hello world"}, {"boolean", true}, {"object", json::object()}, {"array", {1, 2, 3}}};
const json j_const = j;
SECTION("access specified element with default value")
{
SECTION("given a JSON pointer")
{
SECTION("access non-existing value")
{
CHECK(j.value("/not/existing"_json_pointer, 2) == 2);
CHECK(j.value("/not/existing"_json_pointer, 2u) == 2u);
CHECK(j.value("/not/existing"_json_pointer, false) == false);
CHECK(j.value("/not/existing"_json_pointer, "bar") == "bar");
CHECK(j.value("/not/existing"_json_pointer, 12.34) == Approx(12.34));
CHECK(j.value("/not/existing"_json_pointer, json({{"foo", "bar"}})) == json({{"foo", "bar"}}));
CHECK(j.value("/not/existing"_json_pointer, json({10, 100})) == json({10, 100}));
CHECK(j_const.value("/not/existing"_json_pointer, 2) == 2);
CHECK(j_const.value("/not/existing"_json_pointer, 2u) == 2u);
CHECK(j_const.value("/not/existing"_json_pointer, false) == false);
CHECK(j_const.value("/not/existing"_json_pointer, "bar") == "bar");
CHECK(j_const.value("/not/existing"_json_pointer, 12.34) == Approx(12.34));
CHECK(j_const.value("/not/existing"_json_pointer, json({{"foo", "bar"}})) == json({{"foo", "bar"}}));
CHECK(j_const.value("/not/existing"_json_pointer, json({10, 100})) == json({10, 100}));
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment