Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error message if test suite cannot be found #3585

Merged
merged 8 commits into from
Jul 20, 2022
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/nlohmann/json#execute-unit-tests> 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.
Expand Down
22 changes: 22 additions & 0 deletions tests/src/make_test_data_available.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <cstdio> // fopen, fclose, FILE
#include <memory> // unique_ptr
#include <test_data.hpp>
#include <doctest.h>

namespace utils
{

inline bool check_testsuite_downloaded()
{
std::unique_ptr<std::FILE, decltype(&std::fclose)> 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 <https://github.com/nlohmann/json#execute-unit-tests> for more information.");
}

} // namespace utils
2 changes: 1 addition & 1 deletion tests/src/unit-binary_formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SOFTWARE.
using nlohmann::json;

#include <fstream>
#include <test_data.hpp>
#include "make_test_data_available.hpp"

TEST_CASE("Binary Formats" * doctest::skip())
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-bjdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using nlohmann::json;
#include <iostream>
#include <fstream>
#include <set>
#include <test_data.hpp>
#include "make_test_data_available.hpp"
#include "test_utils.hpp"

namespace
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-bson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ using nlohmann::json;

#include <fstream>
#include <sstream>
#include <test_data.hpp>
#include "make_test_data_available.hpp"
#include "test_utils.hpp"

TEST_CASE("BSON")
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-cbor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using nlohmann::json;
#include <iomanip>
#include <iostream>
#include <set>
#include <test_data.hpp>
#include "make_test_data_available.hpp"
#include "test_utils.hpp"

namespace
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-inspection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ using nlohmann::json;

#include <fstream>
#include <sstream>
#include <test_data.hpp>
#include "make_test_data_available.hpp"

TEST_CASE("object inspection")
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-json_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SOFTWARE.
using nlohmann::json;

#include <fstream>
#include <test_data.hpp>
#include "make_test_data_available.hpp"

TEST_CASE("JSON patch")
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-msgpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using nlohmann::json;
#include <sstream>
#include <iomanip>
#include <set>
#include <test_data.hpp>
#include "make_test_data_available.hpp"
#include "test_utils.hpp"

namespace
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-regression1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using nlohmann::json;
#include <sstream>
#include <list>
#include <cstdio>
#include <test_data.hpp>
#include "make_test_data_available.hpp"

#ifdef JSON_HAS_CPP_17
#include <variant>
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-testsuites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SOFTWARE.
using nlohmann::json;

#include <fstream>
#include <test_data.hpp>
#include "make_test_data_available.hpp"

TEST_CASE("compliance tests from json.org")
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-ubjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using nlohmann::json;
#include <iostream>
#include <fstream>
#include <set>
#include <test_data.hpp>
#include "make_test_data_available.hpp"
#include "test_utils.hpp"

namespace
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-unicode1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using nlohmann::json;
#include <fstream>
#include <sstream>
#include <iomanip>
#include <test_data.hpp>
#include "make_test_data_available.hpp"

TEST_CASE("Unicode (1/5)" * doctest::skip())
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-unicode2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using nlohmann::json;
#include <sstream>
#include <iostream>
#include <iomanip>
#include <test_data.hpp>
#include "make_test_data_available.hpp"

// this test suite uses static variables with non-trivial destructors
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-unicode3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using nlohmann::json;
#include <sstream>
#include <iostream>
#include <iomanip>
#include <test_data.hpp>
#include "make_test_data_available.hpp"

// this test suite uses static variables with non-trivial destructors
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-unicode4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using nlohmann::json;
#include <sstream>
#include <iostream>
#include <iomanip>
#include <test_data.hpp>
#include "make_test_data_available.hpp"

// this test suite uses static variables with non-trivial destructors
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-unicode5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using nlohmann::json;
#include <sstream>
#include <iostream>
#include <iomanip>
#include <test_data.hpp>
#include "make_test_data_available.hpp"

// this test suite uses static variables with non-trivial destructors
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
Expand Down