From 5bfb27c86550f14ee752a60bd21893dcc53ba2c7 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 8 May 2020 12:32:28 +0200 Subject: [PATCH 01/10] :rotating_light: fix some warnings --- cmake/download_test_data.cmake | 2 +- test/src/unit-noexcept.cpp | 18 ++++++------ test/src/unit-udt.cpp | 54 ++++++++++++++++------------------ 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/cmake/download_test_data.cmake b/cmake/download_test_data.cmake index e659da9d..c6dc135b 100644 --- a/cmake/download_test_data.cmake +++ b/cmake/download_test_data.cmake @@ -11,4 +11,4 @@ add_custom_target(download_test_data ) # create a header with the path to the downloaded test data -file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/json_test_data\"") +file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/json_test_data\"\n") diff --git a/test/src/unit-noexcept.cpp b/test/src/unit-noexcept.cpp index cf86e92d..8fbe9f91 100644 --- a/test/src/unit-noexcept.cpp +++ b/test/src/unit-noexcept.cpp @@ -46,20 +46,20 @@ void to_json(json&, pod) noexcept; void to_json(json&, pod_bis); void from_json(const json&, pod) noexcept; void from_json(const json&, pod_bis); -static json j; +static json* j; static_assert(noexcept(json{}), ""); -static_assert(noexcept(nlohmann::to_json(j, 2)), ""); -static_assert(noexcept(nlohmann::to_json(j, 2.5)), ""); -static_assert(noexcept(nlohmann::to_json(j, true)), ""); -static_assert(noexcept(nlohmann::to_json(j, test{})), ""); -static_assert(noexcept(nlohmann::to_json(j, pod{})), ""); -static_assert(not noexcept(nlohmann::to_json(j, pod_bis{})), ""); +static_assert(noexcept(nlohmann::to_json(*j, 2)), ""); +static_assert(noexcept(nlohmann::to_json(*j, 2.5)), ""); +static_assert(noexcept(nlohmann::to_json(*j, true)), ""); +static_assert(noexcept(nlohmann::to_json(*j, test{})), ""); +static_assert(noexcept(nlohmann::to_json(*j, pod{})), ""); +static_assert(not noexcept(nlohmann::to_json(*j, pod_bis{})), ""); static_assert(noexcept(json(2)), ""); static_assert(noexcept(json(test{})), ""); static_assert(noexcept(json(pod{})), ""); -static_assert(noexcept(j.get()), ""); -static_assert(not noexcept(j.get()), ""); +static_assert(noexcept(j->get()), ""); +static_assert(not noexcept(j->get()), ""); static_assert(noexcept(json(pod{})), ""); } diff --git a/test/src/unit-udt.cpp b/test/src/unit-udt.cpp index 86db2f23..b1da8c37 100644 --- a/test/src/unit-udt.cpp +++ b/test/src/unit-udt.cpp @@ -95,19 +95,19 @@ namespace udt { // templates because of the custom_json tests (see below) template -void to_json(BasicJsonType& j, age a) +static void to_json(BasicJsonType& j, age a) { j = a.m_val; } template -void to_json(BasicJsonType& j, const name& n) +static void to_json(BasicJsonType& j, const name& n) { j = n.m_val; } template -void to_json(BasicJsonType& j, country c) +static void to_json(BasicJsonType& j, country c) { switch (c) { @@ -124,54 +124,54 @@ void to_json(BasicJsonType& j, country c) } template -void to_json(BasicJsonType& j, const person& p) +static void to_json(BasicJsonType& j, const person& p) { j = BasicJsonType{{"age", p.m_age}, {"name", p.m_name}, {"country", p.m_country}}; } -void to_json(nlohmann::json& j, const address& a) +static void to_json(nlohmann::json& j, const address& a) { j = a.m_val; } -void to_json(nlohmann::json& j, const contact& c) +static void to_json(nlohmann::json& j, const contact& c) { j = json{{"person", c.m_person}, {"address", c.m_address}}; } -void to_json(nlohmann::json& j, const contact_book& cb) +static void to_json(nlohmann::json& j, const contact_book& cb) { j = json{{"name", cb.m_book_name}, {"contacts", cb.m_contacts}}; } // operators -bool operator==(age lhs, age rhs) +static bool operator==(age lhs, age rhs) { return lhs.m_val == rhs.m_val; } -bool operator==(const address& lhs, const address& rhs) +static bool operator==(const address& lhs, const address& rhs) { return lhs.m_val == rhs.m_val; } -bool operator==(const name& lhs, const name& rhs) +static bool operator==(const name& lhs, const name& rhs) { return lhs.m_val == rhs.m_val; } -bool operator==(const person& lhs, const person& rhs) +static bool operator==(const person& lhs, const person& rhs) { return std::tie(lhs.m_name, lhs.m_age) == std::tie(rhs.m_name, rhs.m_age); } -bool operator==(const contact& lhs, const contact& rhs) +static bool operator==(const contact& lhs, const contact& rhs) { return std::tie(lhs.m_person, lhs.m_address) == std::tie(rhs.m_person, rhs.m_address); } -bool operator==(const contact_book& lhs, const contact_book& rhs) +static bool operator==(const contact_book& lhs, const contact_book& rhs) { return std::tie(lhs.m_book_name, lhs.m_contacts) == std::tie(rhs.m_book_name, rhs.m_contacts); @@ -182,19 +182,19 @@ bool operator==(const contact_book& lhs, const contact_book& rhs) namespace udt { template -void from_json(const BasicJsonType& j, age& a) +static void from_json(const BasicJsonType& j, age& a) { a.m_val = j.template get(); } template -void from_json(const BasicJsonType& j, name& n) +static void from_json(const BasicJsonType& j, name& n) { n.m_val = j.template get(); } template -void from_json(const BasicJsonType& j, country& c) +static void from_json(const BasicJsonType& j, country& c) { const auto str = j.template get(); static const std::map m = @@ -210,25 +210,25 @@ void from_json(const BasicJsonType& j, country& c) } template -void from_json(const BasicJsonType& j, person& p) +static void from_json(const BasicJsonType& j, person& p) { p.m_age = j["age"].template get(); p.m_name = j["name"].template get(); p.m_country = j["country"].template get(); } -void from_json(const nlohmann::json& j, address& a) +static void from_json(const nlohmann::json& j, address& a) { a.m_val = j.get(); } -void from_json(const nlohmann::json& j, contact& c) +static void from_json(const nlohmann::json& j, contact& c) { c.m_person = j["person"].get(); c.m_address = j["address"].get
(); } -void from_json(const nlohmann::json& j, contact_book& cb) +static void from_json(const nlohmann::json& j, contact_book& cb) { cb.m_book_name = j["name"].get(); cb.m_contacts = j["contacts"].get>(); @@ -621,29 +621,29 @@ struct non_pod }; template -void to_json(BasicJsonType& j, const non_pod& np) +static void to_json(BasicJsonType& j, const non_pod& np) { j = np.s; } template -void from_json(const BasicJsonType& j, non_pod& np) +static void from_json(const BasicJsonType& j, non_pod& np) { np.s = j.template get(); } -bool operator==(small_pod lhs, small_pod rhs) noexcept +static bool operator==(small_pod lhs, small_pod rhs) noexcept { return std::tie(lhs.begin, lhs.middle, lhs.end) == std::tie(rhs.begin, rhs.middle, rhs.end); } -bool operator==(const non_pod& lhs, const non_pod& rhs) noexcept +static bool operator==(const non_pod& lhs, const non_pod& rhs) noexcept { return lhs.s == rhs.s; } -std::ostream& operator<<(std::ostream& os, small_pod l) +static std::ostream& operator<<(std::ostream& os, small_pod l) { return os << "begin: " << l.begin << ", middle: " << l.middle << ", end: " << l.end; } @@ -691,8 +691,6 @@ struct another_adl_serializer TEST_CASE("custom serializer that does adl by default" * doctest::test_suite("udt")) { - using json = nlohmann::json; - auto me = udt::person{{23}, {"theo"}, udt::country::france}; json j = me; @@ -706,8 +704,6 @@ TEST_CASE("custom serializer that does adl by default" * doctest::test_suite("ud TEST_CASE("different basic_json types conversions") { - using json = nlohmann::json; - SECTION("null") { json j; From a3a803a389b5ef7a065bb0e68027ddd4d6c8a3bf Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 10 May 2020 13:49:26 +0200 Subject: [PATCH 02/10] :memo: add FOSSA status badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bb5cb1aa..612b8a66 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ [![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/3lCHrFUZANONKv7a) [![Documentation](https://img.shields.io/badge/docs-doxygen-blue.svg)](http://nlohmann.github.io/json) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT) +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fnlohmann%2Fjson.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fnlohmann%2Fjson?ref=badge_shield) [![GitHub Releases](https://img.shields.io/github/release/nlohmann/json.svg)](https://github.com/nlohmann/json/releases) [![GitHub Downloads](https://img.shields.io/github/downloads/nlohmann/json/total)](https://github.com/nlohmann/json/releases) [![GitHub Issues](https://img.shields.io/github/issues/nlohmann/json.svg)](http://github.com/nlohmann/json/issues) From 18cbcc413586d9d5a2ccb34826eb0243d7b1f576 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 11 May 2020 12:25:41 +0200 Subject: [PATCH 03/10] :alembic: try to fix SSL issue --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index acd542ba..3a3265fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -100,7 +100,7 @@ matrix: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.9', 'ninja-build'] before_script: - - pip install --user cpp-coveralls + - pip install --user requests[security] cpp-coveralls after_success: - coveralls --build-root test --include include/nlohmann --gcov 'gcov-4.9' --gcov-options '\-lp' env: From 697305819f6a74c2116b5dc8592e611fcbc820fa Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 11 May 2020 12:37:24 +0200 Subject: [PATCH 04/10] :alembic: try to fix SSL issue --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3a3265fa..7cc13e93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -100,7 +100,7 @@ matrix: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.9', 'ninja-build'] before_script: - - pip install --user requests[security] cpp-coveralls + - pip install --user httplib2 cpp-coveralls after_success: - coveralls --build-root test --include include/nlohmann --gcov 'gcov-4.9' --gcov-options '\-lp' env: From 19b21e61e572de499e7f0725602ca65ffb55ddde Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 11 May 2020 13:05:53 +0200 Subject: [PATCH 05/10] :alembic: try to fix SSL issue --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7cc13e93..6eae6e4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -100,7 +100,8 @@ matrix: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.9', 'ninja-build'] before_script: - - pip install --user httplib2 cpp-coveralls + - pip install --user urllib3[secure] + - pip install --user cpp-coveralls after_success: - coveralls --build-root test --include include/nlohmann --gcov 'gcov-4.9' --gcov-options '\-lp' env: From 8389c1961b9f92ff8a5de017c10bfb8ff1dc1efd Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 11 May 2020 13:19:22 +0200 Subject: [PATCH 06/10] :alembic: try to fix SSL issue --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6eae6e4b..50f7d7b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -100,6 +100,7 @@ matrix: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.9', 'ninja-build'] before_script: + - pip install --upgrade pip - pip install --user urllib3[secure] - pip install --user cpp-coveralls after_success: From cbb2d4e4d8f0af4ffa6930c074ddf0be5333561d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 11 May 2020 13:29:40 +0200 Subject: [PATCH 07/10] :alembic: try to fix SSL issue --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 50f7d7b1..aa34ef50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -95,13 +95,12 @@ matrix: - os: linux compiler: gcc + dist: bionic addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.9', 'ninja-build'] before_script: - - pip install --upgrade pip - - pip install --user urllib3[secure] - pip install --user cpp-coveralls after_success: - coveralls --build-root test --include include/nlohmann --gcov 'gcov-4.9' --gcov-options '\-lp' From 0ad595709d9a4e0cb608026c27d1b1cd021068c6 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 11 May 2020 13:40:43 +0200 Subject: [PATCH 08/10] :alembic: try to fix SSL issue --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index aa34ef50..e3dd7353 100644 --- a/.travis.yml +++ b/.travis.yml @@ -99,11 +99,11 @@ matrix: addons: apt: sources: ['ubuntu-toolchain-r-test'] - packages: ['g++-4.9', 'ninja-build'] + packages: ['g++-7', 'ninja-build'] before_script: - pip install --user cpp-coveralls after_success: - - coveralls --build-root test --include include/nlohmann --gcov 'gcov-4.9' --gcov-options '\-lp' + - coveralls --build-root test --include include/nlohmann --gcov 'gcov-7' --gcov-options '\-lp' env: - COMPILER=g++-4.9 - CMAKE_OPTIONS=-DJSON_Coverage=ON From 66dfa22de25aefe7a90a58c1d01a2d7d9c3fd48b Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 11 May 2020 14:24:38 +0200 Subject: [PATCH 09/10] :alembic: try to fix SSL issue --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e3dd7353..3aea08ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -105,7 +105,7 @@ matrix: after_success: - coveralls --build-root test --include include/nlohmann --gcov 'gcov-7' --gcov-options '\-lp' env: - - COMPILER=g++-4.9 + - COMPILER=g++-7 - CMAKE_OPTIONS=-DJSON_Coverage=ON - MULTIPLE_HEADERS=ON From 76c01501f7b6ea023cd0b56904fbf122e70089ed Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 11 May 2020 20:03:13 +0200 Subject: [PATCH 10/10] :wrench: fix pedantic maintainer targets --- test/Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/Makefile b/test/Makefile index 499ff3c2..7bf0fef9 100644 --- a/test/Makefile +++ b/test/Makefile @@ -57,7 +57,10 @@ TESTCASES = $(patsubst src/unit-%.cpp,test-%,$(wildcard src/unit-*.cpp)) all: $(TESTCASES) clean: - rm -fr json_unit $(OBJECTS) $(SOURCES:.cpp=.gcno) $(SOURCES:.cpp=.gcda) $(TESTCASES) $(FUZZERS) + rm -fr json_unit $(OBJECTS) $(SOURCES:.cpp=.gcno) $(SOURCES:.cpp=.gcda) $(TESTCASES) $(FUZZERS) test_data.hpp + +test_data.hpp: + @echo "#define TEST_DATA_DIRECTORY" > $@ ############################################################################## # single test file @@ -67,7 +70,7 @@ json_unit: $(OBJECTS) ../single_include/nlohmann/json.hpp thirdparty/doctest/doc @echo "[CXXLD] $@" @$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJECTS) -o $@ -%.o: %.cpp ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h +%.o: %.cpp ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h test_data.hpp @echo "[CXX] $@" @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@ @@ -76,7 +79,7 @@ json_unit: $(OBJECTS) ../single_include/nlohmann/json.hpp thirdparty/doctest/doc # individual test cases ############################################################################## -test-%: src/unit-%.o src/unit.o ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h +test-%: src/unit-%.o src/unit.o ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h test_data.hpp @echo "[CXXLD] $@" @$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $< src/unit.o -o $@