From feef0eb59500ba5e36cbc2fe1b03d9ed1f2472b6 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 20 Jul 2022 12:41:33 +0200 Subject: [PATCH] Add error message if test suite cannot be found (#3585) * :children_crossing: add error message if test suite cannot be found Fixes #3584 --- README.md | 16 ++++++++++++++++ tests/src/make_test_data_available.hpp | 22 ++++++++++++++++++++++ tests/src/unit-binary_formats.cpp | 2 +- tests/src/unit-bjdata.cpp | 2 +- tests/src/unit-bson.cpp | 2 +- tests/src/unit-cbor.cpp | 2 +- tests/src/unit-inspection.cpp | 2 +- tests/src/unit-json_patch.cpp | 2 +- tests/src/unit-msgpack.cpp | 2 +- tests/src/unit-regression1.cpp | 2 +- tests/src/unit-testsuites.cpp | 2 +- tests/src/unit-ubjson.cpp | 2 +- tests/src/unit-unicode1.cpp | 2 +- tests/src/unit-unicode2.cpp | 2 +- tests/src/unit-unicode3.cpp | 2 +- tests/src/unit-unicode4.cpp | 2 +- tests/src/unit-unicode5.cpp | 2 +- 17 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 tests/src/make_test_data_available.hpp diff --git a/README.md b/README.md index 34d737e96..7ca1a1808 100644 --- a/README.md +++ b/README.md @@ -1790,6 +1790,22 @@ $ ctest --output-on-failure Note that during the `ctest` stage, several JSON test files are downloaded from an [external repository](https://github.com/nlohmann/json_test_data). If policies forbid downloading artifacts during testing, you can download the files yourself and pass the directory with the test files via `-DJSON_TestDataDirectory=path` to CMake. Then, no Internet connectivity is required. See [issue #2189](https://github.com/nlohmann/json/issues/2189) for more information. +If the test suite is not found, several test suites will fail like this: + +``` +=============================================================================== +json/tests/src/make_test_data_available.hpp:21: +TEST CASE: check test suite is downloaded + +json/tests/src/make_test_data_available.hpp:23: FATAL ERROR: REQUIRE( utils::check_testsuite_downloaded() ) is NOT correct! + values: REQUIRE( false ) + logged: Test data not found in 'json/cmake-build-debug/json_test_data'. + Please execute target 'download_test_data' before running this test suite. + See for more information. + +=============================================================================== +``` + In case you have downloaded the library rather than checked out the code via Git, test `cmake_fetch_content_configure` will fail. Please execute `ctest -LE git_required` to skip these tests. See [issue #2189](https://github.com/nlohmann/json/issues/2189) for more information. Some tests change the installed files and hence make the whole process not reproducible. Please execute `ctest -LE not_reproducible` to skip these tests. See [issue #2324](https://github.com/nlohmann/json/issues/2324) for more information. diff --git a/tests/src/make_test_data_available.hpp b/tests/src/make_test_data_available.hpp new file mode 100644 index 000000000..740c83927 --- /dev/null +++ b/tests/src/make_test_data_available.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include // fopen, fclose, FILE +#include // unique_ptr +#include +#include + +namespace utils +{ + +inline bool check_testsuite_downloaded() +{ + std::unique_ptr file(std::fopen(TEST_DATA_DIRECTORY "/README.md", "r"), &std::fclose); + return file != nullptr; +} + +TEST_CASE("check test suite is downloaded") +{ + REQUIRE_MESSAGE(utils::check_testsuite_downloaded(), "Test data not found in '" TEST_DATA_DIRECTORY "'. Please execute target 'download_test_data' before running this test suite. See for more information."); +} + +} // namespace utils diff --git a/tests/src/unit-binary_formats.cpp b/tests/src/unit-binary_formats.cpp index 820ae844a..08899122e 100644 --- a/tests/src/unit-binary_formats.cpp +++ b/tests/src/unit-binary_formats.cpp @@ -12,7 +12,7 @@ using nlohmann::json; #include -#include +#include "make_test_data_available.hpp" TEST_CASE("Binary Formats" * doctest::skip()) { diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index 92fed6d20..e52ae47a1 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -16,7 +16,7 @@ using nlohmann::json; #include #include #include -#include +#include "make_test_data_available.hpp" #include "test_utils.hpp" namespace diff --git a/tests/src/unit-bson.cpp b/tests/src/unit-bson.cpp index 9876e28cc..c5067b274 100644 --- a/tests/src/unit-bson.cpp +++ b/tests/src/unit-bson.cpp @@ -13,7 +13,7 @@ using nlohmann::json; #include #include -#include +#include "make_test_data_available.hpp" #include "test_utils.hpp" TEST_CASE("BSON") diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index a4a375464..1ea95a5ee 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -16,7 +16,7 @@ using nlohmann::json; #include #include #include -#include +#include "make_test_data_available.hpp" #include "test_utils.hpp" namespace diff --git a/tests/src/unit-inspection.cpp b/tests/src/unit-inspection.cpp index 1fad96650..0fb956845 100644 --- a/tests/src/unit-inspection.cpp +++ b/tests/src/unit-inspection.cpp @@ -13,7 +13,7 @@ using nlohmann::json; #include #include -#include +#include "make_test_data_available.hpp" TEST_CASE("object inspection") { diff --git a/tests/src/unit-json_patch.cpp b/tests/src/unit-json_patch.cpp index 11378e11c..cdb287a9e 100644 --- a/tests/src/unit-json_patch.cpp +++ b/tests/src/unit-json_patch.cpp @@ -12,7 +12,7 @@ using nlohmann::json; #include -#include +#include "make_test_data_available.hpp" TEST_CASE("JSON patch") { diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index 3918231f8..e848dd202 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -15,7 +15,7 @@ using nlohmann::json; #include #include #include -#include +#include "make_test_data_available.hpp" #include "test_utils.hpp" namespace diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index 1e2a5ff1c..a4e82134a 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -19,7 +19,7 @@ using nlohmann::json; #include #include #include -#include +#include "make_test_data_available.hpp" #ifdef JSON_HAS_CPP_17 #include diff --git a/tests/src/unit-testsuites.cpp b/tests/src/unit-testsuites.cpp index 82f087d09..ee15c84da 100644 --- a/tests/src/unit-testsuites.cpp +++ b/tests/src/unit-testsuites.cpp @@ -12,7 +12,7 @@ using nlohmann::json; #include -#include +#include "make_test_data_available.hpp" TEST_CASE("compliance tests from json.org") { diff --git a/tests/src/unit-ubjson.cpp b/tests/src/unit-ubjson.cpp index 2cc280421..db6b01d18 100644 --- a/tests/src/unit-ubjson.cpp +++ b/tests/src/unit-ubjson.cpp @@ -14,7 +14,7 @@ using nlohmann::json; #include #include #include -#include +#include "make_test_data_available.hpp" #include "test_utils.hpp" namespace diff --git a/tests/src/unit-unicode1.cpp b/tests/src/unit-unicode1.cpp index 0e258b45d..3b02f9f1b 100644 --- a/tests/src/unit-unicode1.cpp +++ b/tests/src/unit-unicode1.cpp @@ -16,7 +16,7 @@ using nlohmann::json; #include #include #include -#include +#include "make_test_data_available.hpp" TEST_CASE("Unicode (1/5)" * doctest::skip()) { diff --git a/tests/src/unit-unicode2.cpp b/tests/src/unit-unicode2.cpp index 893431564..47d12d70e 100644 --- a/tests/src/unit-unicode2.cpp +++ b/tests/src/unit-unicode2.cpp @@ -18,7 +18,7 @@ using nlohmann::json; #include #include #include -#include +#include "make_test_data_available.hpp" // this test suite uses static variables with non-trivial destructors DOCTEST_CLANG_SUPPRESS_WARNING_PUSH diff --git a/tests/src/unit-unicode3.cpp b/tests/src/unit-unicode3.cpp index f6df32d31..d4d821807 100644 --- a/tests/src/unit-unicode3.cpp +++ b/tests/src/unit-unicode3.cpp @@ -18,7 +18,7 @@ using nlohmann::json; #include #include #include -#include +#include "make_test_data_available.hpp" // this test suite uses static variables with non-trivial destructors DOCTEST_CLANG_SUPPRESS_WARNING_PUSH diff --git a/tests/src/unit-unicode4.cpp b/tests/src/unit-unicode4.cpp index 8c3df14ab..1477b814a 100644 --- a/tests/src/unit-unicode4.cpp +++ b/tests/src/unit-unicode4.cpp @@ -18,7 +18,7 @@ using nlohmann::json; #include #include #include -#include +#include "make_test_data_available.hpp" // this test suite uses static variables with non-trivial destructors DOCTEST_CLANG_SUPPRESS_WARNING_PUSH diff --git a/tests/src/unit-unicode5.cpp b/tests/src/unit-unicode5.cpp index a9cc8de80..1793f6e26 100644 --- a/tests/src/unit-unicode5.cpp +++ b/tests/src/unit-unicode5.cpp @@ -18,7 +18,7 @@ using nlohmann::json; #include #include #include -#include +#include "make_test_data_available.hpp" // this test suite uses static variables with non-trivial destructors DOCTEST_CLANG_SUPPRESS_WARNING_PUSH