diff --git a/README.md b/README.md index c94c3eea26..c632538b0f 100644 --- a/README.md +++ b/README.md @@ -1728,6 +1728,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 0000000000..740c839278 --- /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 05e889b0fc..f920c2adf3 100644 --- a/tests/src/unit-binary_formats.cpp +++ b/tests/src/unit-binary_formats.cpp @@ -33,7 +33,7 @@ SOFTWARE. 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 7442ea5885..ccf5ca590a 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -37,7 +37,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 1920d31550..9f6b3f589b 100644 --- a/tests/src/unit-bson.cpp +++ b/tests/src/unit-bson.cpp @@ -34,7 +34,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 83c8ada54f..f233d493a0 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -37,7 +37,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 49d2431d71..219d0f466d 100644 --- a/tests/src/unit-inspection.cpp +++ b/tests/src/unit-inspection.cpp @@ -34,7 +34,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 4ece3a5059..cf411963d4 100644 --- a/tests/src/unit-json_patch.cpp +++ b/tests/src/unit-json_patch.cpp @@ -33,7 +33,7 @@ SOFTWARE. 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 483f8ed462..8721998c6d 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -36,7 +36,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 5a6e31e738..dc32b3b66c 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -40,7 +40,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 7fbf831d94..d02f77029c 100644 --- a/tests/src/unit-testsuites.cpp +++ b/tests/src/unit-testsuites.cpp @@ -33,7 +33,7 @@ SOFTWARE. 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 d60edf6655..c181912ee3 100644 --- a/tests/src/unit-ubjson.cpp +++ b/tests/src/unit-ubjson.cpp @@ -35,7 +35,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 a988ba8907..1fd4174664 100644 --- a/tests/src/unit-unicode1.cpp +++ b/tests/src/unit-unicode1.cpp @@ -37,7 +37,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 8438f176fe..ad994e99fd 100644 --- a/tests/src/unit-unicode2.cpp +++ b/tests/src/unit-unicode2.cpp @@ -39,7 +39,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 5bc1afe317..e5f8fec045 100644 --- a/tests/src/unit-unicode3.cpp +++ b/tests/src/unit-unicode3.cpp @@ -39,7 +39,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 d51880dae4..38ff021239 100644 --- a/tests/src/unit-unicode4.cpp +++ b/tests/src/unit-unicode4.cpp @@ -39,7 +39,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 b63ad16009..2175dafe7c 100644 --- a/tests/src/unit-unicode5.cpp +++ b/tests/src/unit-unicode5.cpp @@ -39,7 +39,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