Skip to content

Commit

Permalink
Add error message if test suite cannot be found (#3585)
Browse files Browse the repository at this point in the history
* 🚸 add error message if test suite cannot be found

Fixes #3584
  • Loading branch information
nlohmann committed Jul 20, 2022
1 parent 527da54 commit feef0eb
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 15 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 @@ -12,7 +12,7 @@
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 @@ -16,7 +16,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 @@ -13,7 +13,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 @@ -16,7 +16,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 @@ -13,7 +13,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 @@ -12,7 +12,7 @@
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 @@ -15,7 +15,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 @@ -19,7 +19,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 @@ -12,7 +12,7 @@
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 @@ -14,7 +14,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 @@ -16,7 +16,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 @@ -18,7 +18,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 @@ -18,7 +18,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 @@ -18,7 +18,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 @@ -18,7 +18,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

0 comments on commit feef0eb

Please sign in to comment.