mirror of
https://github.com/nlohmann/json.git
synced 2024-08-20 20:12:26 +02:00
Merge pull request #2202 from nlohmann/issue2189
Add option to not rely on Internet connectivity during test stage
This commit is contained in:
commit
8dade80499
|
@ -1557,4 +1557,6 @@ $ cmake --build .
|
||||||
$ ctest --output-on-failure
|
$ ctest --output-on-failure
|
||||||
```
|
```
|
||||||
|
|
||||||
For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml).
|
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.
|
||||||
|
|
||||||
|
In case you have downloaded the library rather than checked out the code via Git, test `cmake_fetch_content_configure`. Please execute `ctest -LE git_required` to skip these tests. See [issue #2189](https://github.com/nlohmann/json/issues/2189) for more information.
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
find_package(Git)
|
|
||||||
|
|
||||||
set(JSON_TEST_DATA_URL https://github.com/nlohmann/json_test_data)
|
set(JSON_TEST_DATA_URL https://github.com/nlohmann/json_test_data)
|
||||||
set(JSON_TEST_DATA_VERSION 3.0.0)
|
set(JSON_TEST_DATA_VERSION 3.0.0)
|
||||||
|
|
||||||
# target to download test data
|
# if variable is set, use test data from given directory rather than downloading them
|
||||||
add_custom_target(download_test_data
|
if(JSON_TestDataDirectory)
|
||||||
COMMAND test -d json_test_data || ${GIT_EXECUTABLE} clone -c advice.detachedHead=false --branch v${JSON_TEST_DATA_VERSION} ${JSON_TEST_DATA_URL}.git --quiet --depth 1
|
message(STATUS "Using test data in ${JSON_TestDataDirectory}.")
|
||||||
COMMENT "Downloading test data from ${JSON_TEST_DATA_URL} (v${JSON_TEST_DATA_VERSION})"
|
add_custom_target(download_test_data)
|
||||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${JSON_TestDataDirectory}\"\n")
|
||||||
)
|
else()
|
||||||
|
find_package(Git)
|
||||||
# create a header with the path to the downloaded test data
|
# target to download test data
|
||||||
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/json_test_data\"\n")
|
add_custom_target(download_test_data
|
||||||
|
COMMAND test -d json_test_data || ${GIT_EXECUTABLE} clone -c advice.detachedHead=false --branch v${JSON_TEST_DATA_VERSION} ${JSON_TEST_DATA_URL}.git --quiet --depth 1
|
||||||
|
COMMENT "Downloading test data from ${JSON_TEST_DATA_URL} (v${JSON_TEST_DATA_VERSION})"
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
|
)
|
||||||
|
# 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\"\n")
|
||||||
|
endif()
|
||||||
|
|
||||||
# determine the operating system (for debug and support purposes)
|
# determine the operating system (for debug and support purposes)
|
||||||
find_program(UNAME_COMMAND uname)
|
find_program(UNAME_COMMAND uname)
|
||||||
|
|
|
@ -11,8 +11,10 @@ if (${CMAKE_VERSION} VERSION_GREATER "3.11.0")
|
||||||
)
|
)
|
||||||
set_tests_properties(cmake_fetch_content_configure PROPERTIES
|
set_tests_properties(cmake_fetch_content_configure PROPERTIES
|
||||||
FIXTURES_SETUP cmake_fetch_content
|
FIXTURES_SETUP cmake_fetch_content
|
||||||
|
LABELS git_required
|
||||||
)
|
)
|
||||||
set_tests_properties(cmake_fetch_content_build PROPERTIES
|
set_tests_properties(cmake_fetch_content_build PROPERTIES
|
||||||
FIXTURES_REQUIRED cmake_fetch_content
|
FIXTURES_REQUIRED cmake_fetch_content
|
||||||
|
LABELS git_required
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -4,9 +4,8 @@ project(DummyImport CXX)
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
FetchContent_Declare(json
|
get_filename_component(GIT_REPOSITORY_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. ABSOLUTE)
|
||||||
GIT_REPOSITORY ${CMAKE_CURRENT_SOURCE_DIR}/../../..
|
FetchContent_Declare(json GIT_REPOSITORY ${GIT_REPOSITORY_DIRECTORY} GIT_TAG HEAD)
|
||||||
GIT_TAG HEAD)
|
|
||||||
|
|
||||||
FetchContent_GetProperties(json)
|
FetchContent_GetProperties(json)
|
||||||
if(NOT json_POPULATED)
|
if(NOT json_POPULATED)
|
||||||
|
|
Loading…
Reference in a new issue