mirror of
https://github.com/nlohmann/json.git
synced 2025-05-10 09:03:51 +00:00
Improve unit testing (Part 1) (#3380)
* Refactor unit test creation Add functions for creating tests and to supply test- and standard-specific build settings. Raises minimum CMake version to 3.13 in test directory. json_test_add_test_for( <file> MAIN <main> [CXX_STANDARDS <version_number>...] [FORCE]) Given a <file> unit-foo.cpp, produces test-foo_cpp<version_number> if C++ standard <version_number> is supported by the compiler and thesource file contains JSON_HAS_CPP_<version_number>. Use FORCE to create the test regardless of the file containing JSON_HAS_CPP_<version_number>. Test targets are linked against <main>. CXX_STANDARDS defaults to "11". json_test_set_test_options( all|<tests> [CXX_STANDARDS all|<args>...] [COMPILE_DEFINITIONS <args>...] [COMPILE_FEATURES <args>...] [COMPILE_OPTIONS <args>...] [LINK_LIBRARIES <args>...] [LINK_OPTIONS <args>...]) Supply test- and standard-specific build settings. Specify multiple tests using a list e.g., "test-foo;test-bar". Must be called BEFORE the test is created. * Use CMAKE_MODULE_PATH * Don't undef some macros if JSON_TEST_KEEP_MACROS is defined * Use JSON_TEST_KEEP_MACROS Incidentally enables the regression tests for #2546 and #3070. A CHECK_THROWS_WITH_AS in #3070 was disabled which is tracked in #3377 and a line in from_json(..., std_fs::path&) was marked with LCOV_EXCL_LINE. * Add three-way comparison feature test macro * Disable broken comparison if JSON_HAS_THREE_WAY_COMPARISON * Fix redefinition of inline constexpr statics Redelcaration of inline constexpr static data members in namespace scope was deprecated in C++17. Fixes -Werror=deprecated compilation failures. * Fix more test build failures due to missing noexcept * CI: update cmake_flags test to use CMake 3.13 in test directory Also change default for JSON_BuildTests option to depend on CMake version. * CI: turn *_CXXFLAGS into CMake lists * CI: use JSON_TestStandards to set CXX_STANDARD * CI: pass extra CXXFLAGS to standards tests
This commit is contained in:
parent
700b95f447
commit
ad103e5b45
2
.github/workflows/macos.yml
vendored
2
.github/workflows/macos.yml
vendored
@ -38,7 +38,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DCMAKE_CXX_STANDARD_REQUIRED=ON
|
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_TestStandards=${{ matrix.standard }}
|
||||||
- name: build
|
- name: build
|
||||||
run: cmake --build build --parallel 10
|
run: cmake --build build --parallel 10
|
||||||
- name: test
|
- name: test
|
||||||
|
@ -19,6 +19,7 @@ endif()
|
|||||||
## INCLUDE
|
## INCLUDE
|
||||||
##
|
##
|
||||||
##
|
##
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -30,7 +31,13 @@ if (POLICY CMP0077)
|
|||||||
cmake_policy(SET CMP0077 NEW)
|
cmake_policy(SET CMP0077 NEW)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${MAIN_PROJECT})
|
# VERSION_GREATER_EQUAL is not available in CMake 3.1
|
||||||
|
if(${MAIN_PROJECT} AND (${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER 3.13))
|
||||||
|
set(JSON_BuildTests_INIT ON)
|
||||||
|
else()
|
||||||
|
set(JSON_BuildTests_INIT OFF)
|
||||||
|
endif()
|
||||||
|
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${JSON_BuildTests_INIT})
|
||||||
option(JSON_CI "Enable CI build targets." OFF)
|
option(JSON_CI "Enable CI build targets." OFF)
|
||||||
option(JSON_Diagnostics "Use extended diagnostic messages." OFF)
|
option(JSON_Diagnostics "Use extended diagnostic messages." OFF)
|
||||||
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
||||||
@ -39,7 +46,7 @@ option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OF
|
|||||||
option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF)
|
option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF)
|
||||||
|
|
||||||
if (JSON_CI)
|
if (JSON_CI)
|
||||||
include(cmake/ci.cmake)
|
include(ci)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -23,7 +23,7 @@ if(NOT benchmark_POPULATED)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# download test data
|
# download test data
|
||||||
include(${CMAKE_SOURCE_DIR}/../cmake/download_test_data.cmake)
|
include(download_test_data)
|
||||||
|
|
||||||
# benchmark binary
|
# benchmark binary
|
||||||
add_executable(json_benchmarks src/benchmarks.cpp)
|
add_executable(json_benchmarks src/benchmarks.cpp)
|
||||||
|
685
cmake/ci.cmake
685
cmake/ci.cmake
@ -98,18 +98,18 @@ file(GLOB_RECURSE SRC_FILES ${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp)
|
|||||||
# -Wno-weak-vtables The library is header-only.
|
# -Wno-weak-vtables The library is header-only.
|
||||||
# -Wreserved-identifier See https://github.com/onqtam/doctest/issues/536.
|
# -Wreserved-identifier See https://github.com/onqtam/doctest/issues/536.
|
||||||
|
|
||||||
set(CLANG_CXXFLAGS "-std=c++11 \
|
set(CLANG_CXXFLAGS
|
||||||
-Werror \
|
-Werror
|
||||||
-Weverything \
|
-Weverything
|
||||||
-Wno-c++98-compat \
|
-Wno-c++98-compat
|
||||||
-Wno-c++98-compat-pedantic \
|
-Wno-c++98-compat-pedantic
|
||||||
-Wno-deprecated-declarations \
|
-Wno-deprecated-declarations
|
||||||
-Wno-extra-semi-stmt \
|
-Wno-extra-semi-stmt
|
||||||
-Wno-padded \
|
-Wno-padded
|
||||||
-Wno-covered-switch-default \
|
-Wno-covered-switch-default
|
||||||
-Wno-weak-vtables \
|
-Wno-weak-vtables
|
||||||
-Wno-reserved-identifier \
|
-Wno-reserved-identifier
|
||||||
")
|
)
|
||||||
|
|
||||||
# Warning flags determined for GCC 12.0 (experimental) with https://github.com/nlohmann/gcc_flags:
|
# Warning flags determined for GCC 12.0 (experimental) with https://github.com/nlohmann/gcc_flags:
|
||||||
# Ignored GCC warnings:
|
# Ignored GCC warnings:
|
||||||
@ -121,295 +121,295 @@ set(CLANG_CXXFLAGS "-std=c++11 \
|
|||||||
# -Wno-system-headers We do not care about warnings in system headers.
|
# -Wno-system-headers We do not care about warnings in system headers.
|
||||||
# -Wno-templates The library uses templates.
|
# -Wno-templates The library uses templates.
|
||||||
|
|
||||||
set(GCC_CXXFLAGS "-std=c++11 \
|
set(GCC_CXXFLAGS
|
||||||
-pedantic \
|
-pedantic
|
||||||
-Werror \
|
-Werror
|
||||||
--all-warnings \
|
--all-warnings
|
||||||
--extra-warnings \
|
--extra-warnings
|
||||||
-W \
|
-W
|
||||||
-WNSObject-attribute \
|
-WNSObject-attribute
|
||||||
-Wno-abi-tag \
|
-Wno-abi-tag
|
||||||
-Waddress \
|
-Waddress
|
||||||
-Waddress-of-packed-member \
|
-Waddress-of-packed-member
|
||||||
-Wno-aggregate-return \
|
-Wno-aggregate-return
|
||||||
-Waggressive-loop-optimizations \
|
-Waggressive-loop-optimizations
|
||||||
-Waligned-new=all \
|
-Waligned-new=all
|
||||||
-Wall \
|
-Wall
|
||||||
-Walloc-zero \
|
-Walloc-zero
|
||||||
-Walloca \
|
-Walloca
|
||||||
-Wanalyzer-double-fclose \
|
-Wanalyzer-double-fclose
|
||||||
-Wanalyzer-double-free \
|
-Wanalyzer-double-free
|
||||||
-Wanalyzer-exposure-through-output-file \
|
-Wanalyzer-exposure-through-output-file
|
||||||
-Wanalyzer-file-leak \
|
-Wanalyzer-file-leak
|
||||||
-Wanalyzer-free-of-non-heap \
|
-Wanalyzer-free-of-non-heap
|
||||||
-Wanalyzer-malloc-leak \
|
-Wanalyzer-malloc-leak
|
||||||
-Wanalyzer-mismatching-deallocation \
|
-Wanalyzer-mismatching-deallocation
|
||||||
-Wanalyzer-null-argument \
|
-Wanalyzer-null-argument
|
||||||
-Wanalyzer-null-dereference \
|
-Wanalyzer-null-dereference
|
||||||
-Wanalyzer-possible-null-argument \
|
-Wanalyzer-possible-null-argument
|
||||||
-Wanalyzer-possible-null-dereference \
|
-Wanalyzer-possible-null-dereference
|
||||||
-Wanalyzer-shift-count-negative \
|
-Wanalyzer-shift-count-negative
|
||||||
-Wanalyzer-shift-count-overflow \
|
-Wanalyzer-shift-count-overflow
|
||||||
-Wanalyzer-stale-setjmp-buffer \
|
-Wanalyzer-stale-setjmp-buffer
|
||||||
-Wanalyzer-tainted-allocation-size \
|
-Wanalyzer-tainted-allocation-size
|
||||||
-Wanalyzer-tainted-array-index \
|
-Wanalyzer-tainted-array-index
|
||||||
-Wanalyzer-tainted-divisor \
|
-Wanalyzer-tainted-divisor
|
||||||
-Wanalyzer-tainted-offset \
|
-Wanalyzer-tainted-offset
|
||||||
-Wanalyzer-tainted-size \
|
-Wanalyzer-tainted-size
|
||||||
-Wanalyzer-too-complex \
|
-Wanalyzer-too-complex
|
||||||
-Wanalyzer-unsafe-call-within-signal-handler \
|
-Wanalyzer-unsafe-call-within-signal-handler
|
||||||
-Wanalyzer-use-after-free \
|
-Wanalyzer-use-after-free
|
||||||
-Wanalyzer-use-of-pointer-in-stale-stack-frame \
|
-Wanalyzer-use-of-pointer-in-stale-stack-frame
|
||||||
-Wanalyzer-use-of-uninitialized-value \
|
-Wanalyzer-use-of-uninitialized-value
|
||||||
-Wanalyzer-write-to-const \
|
-Wanalyzer-write-to-const
|
||||||
-Wanalyzer-write-to-string-literal \
|
-Wanalyzer-write-to-string-literal
|
||||||
-Warith-conversion \
|
-Warith-conversion
|
||||||
-Warray-bounds \
|
-Warray-bounds
|
||||||
-Warray-bounds=2 \
|
-Warray-bounds=2
|
||||||
-Warray-compare \
|
-Warray-compare
|
||||||
-Warray-parameter=2 \
|
-Warray-parameter=2
|
||||||
-Wattribute-alias=2 \
|
-Wattribute-alias=2
|
||||||
-Wattribute-warning \
|
-Wattribute-warning
|
||||||
-Wattributes \
|
-Wattributes
|
||||||
-Wbool-compare \
|
-Wbool-compare
|
||||||
-Wbool-operation \
|
-Wbool-operation
|
||||||
-Wbuiltin-declaration-mismatch \
|
-Wbuiltin-declaration-mismatch
|
||||||
-Wbuiltin-macro-redefined \
|
-Wbuiltin-macro-redefined
|
||||||
-Wc++0x-compat \
|
-Wc++0x-compat
|
||||||
-Wc++11-compat \
|
-Wc++11-compat
|
||||||
-Wc++11-extensions \
|
-Wc++11-extensions
|
||||||
-Wc++14-compat \
|
-Wc++14-compat
|
||||||
-Wc++14-extensions \
|
-Wc++14-extensions
|
||||||
-Wc++17-compat \
|
-Wc++17-compat
|
||||||
-Wc++17-extensions \
|
-Wc++17-extensions
|
||||||
-Wc++1z-compat \
|
-Wc++1z-compat
|
||||||
-Wc++20-compat \
|
-Wc++20-compat
|
||||||
-Wc++20-extensions \
|
-Wc++20-extensions
|
||||||
-Wc++23-extensions \
|
-Wc++23-extensions
|
||||||
-Wc++2a-compat \
|
-Wc++2a-compat
|
||||||
-Wcannot-profile \
|
-Wcannot-profile
|
||||||
-Wcast-align \
|
-Wcast-align
|
||||||
-Wcast-align=strict \
|
-Wcast-align=strict
|
||||||
-Wcast-function-type \
|
-Wcast-function-type
|
||||||
-Wcast-qual \
|
-Wcast-qual
|
||||||
-Wcatch-value=3 \
|
-Wcatch-value=3
|
||||||
-Wchar-subscripts \
|
-Wchar-subscripts
|
||||||
-Wclass-conversion \
|
-Wclass-conversion
|
||||||
-Wclass-memaccess \
|
-Wclass-memaccess
|
||||||
-Wclobbered \
|
-Wclobbered
|
||||||
-Wcomma-subscript \
|
-Wcomma-subscript
|
||||||
-Wcomment \
|
-Wcomment
|
||||||
-Wcomments \
|
-Wcomments
|
||||||
-Wconditionally-supported \
|
-Wconditionally-supported
|
||||||
-Wconversion \
|
-Wconversion
|
||||||
-Wconversion-null \
|
-Wconversion-null
|
||||||
-Wcoverage-invalid-line-number \
|
-Wcoverage-invalid-line-number
|
||||||
-Wcoverage-mismatch \
|
-Wcoverage-mismatch
|
||||||
-Wcpp \
|
-Wcpp
|
||||||
-Wctad-maybe-unsupported \
|
-Wctad-maybe-unsupported
|
||||||
-Wctor-dtor-privacy \
|
-Wctor-dtor-privacy
|
||||||
-Wdangling-else \
|
-Wdangling-else
|
||||||
-Wdate-time \
|
-Wdate-time
|
||||||
-Wdelete-incomplete \
|
-Wdelete-incomplete
|
||||||
-Wdelete-non-virtual-dtor \
|
-Wdelete-non-virtual-dtor
|
||||||
-Wdeprecated \
|
-Wdeprecated
|
||||||
-Wdeprecated-copy \
|
-Wdeprecated-copy
|
||||||
-Wdeprecated-copy-dtor \
|
-Wdeprecated-copy-dtor
|
||||||
-Wdeprecated-declarations \
|
-Wdeprecated-declarations
|
||||||
-Wdeprecated-enum-enum-conversion \
|
-Wdeprecated-enum-enum-conversion
|
||||||
-Wdeprecated-enum-float-conversion \
|
-Wdeprecated-enum-float-conversion
|
||||||
-Wdisabled-optimization \
|
-Wdisabled-optimization
|
||||||
-Wdiv-by-zero \
|
-Wdiv-by-zero
|
||||||
-Wdouble-promotion \
|
-Wdouble-promotion
|
||||||
-Wduplicated-branches \
|
-Wduplicated-branches
|
||||||
-Wduplicated-cond \
|
-Wduplicated-cond
|
||||||
-Weffc++ \
|
-Weffc++
|
||||||
-Wempty-body \
|
-Wempty-body
|
||||||
-Wendif-labels \
|
-Wendif-labels
|
||||||
-Wenum-compare \
|
-Wenum-compare
|
||||||
-Wenum-conversion \
|
-Wenum-conversion
|
||||||
-Wexceptions \
|
-Wexceptions
|
||||||
-Wexpansion-to-defined \
|
-Wexpansion-to-defined
|
||||||
-Wextra \
|
-Wextra
|
||||||
-Wextra-semi \
|
-Wextra-semi
|
||||||
-Wfloat-conversion \
|
-Wfloat-conversion
|
||||||
-Wfloat-equal \
|
-Wfloat-equal
|
||||||
-Wformat-diag \
|
-Wformat-diag
|
||||||
-Wformat-overflow=2 \
|
-Wformat-overflow=2
|
||||||
-Wformat-signedness \
|
-Wformat-signedness
|
||||||
-Wformat-truncation=2 \
|
-Wformat-truncation=2
|
||||||
-Wformat=2 \
|
-Wformat=2
|
||||||
-Wframe-address \
|
-Wframe-address
|
||||||
-Wfree-nonheap-object \
|
-Wfree-nonheap-object
|
||||||
-Whsa \
|
-Whsa
|
||||||
-Wif-not-aligned \
|
-Wif-not-aligned
|
||||||
-Wignored-attributes \
|
-Wignored-attributes
|
||||||
-Wignored-qualifiers \
|
-Wignored-qualifiers
|
||||||
-Wimplicit-fallthrough=5 \
|
-Wimplicit-fallthrough=5
|
||||||
-Winaccessible-base \
|
-Winaccessible-base
|
||||||
-Winfinite-recursion \
|
-Winfinite-recursion
|
||||||
-Winherited-variadic-ctor \
|
-Winherited-variadic-ctor
|
||||||
-Winit-list-lifetime \
|
-Winit-list-lifetime
|
||||||
-Winit-self \
|
-Winit-self
|
||||||
-Winline \
|
-Winline
|
||||||
-Wint-in-bool-context \
|
-Wint-in-bool-context
|
||||||
-Wint-to-pointer-cast \
|
-Wint-to-pointer-cast
|
||||||
-Winterference-size \
|
-Winterference-size
|
||||||
-Winvalid-imported-macros \
|
-Winvalid-imported-macros
|
||||||
-Winvalid-memory-model \
|
-Winvalid-memory-model
|
||||||
-Winvalid-offsetof \
|
-Winvalid-offsetof
|
||||||
-Winvalid-pch \
|
-Winvalid-pch
|
||||||
-Wliteral-suffix \
|
-Wliteral-suffix
|
||||||
-Wlogical-not-parentheses \
|
-Wlogical-not-parentheses
|
||||||
-Wlogical-op \
|
-Wlogical-op
|
||||||
-Wno-long-long \
|
-Wno-long-long
|
||||||
-Wlto-type-mismatch \
|
-Wlto-type-mismatch
|
||||||
-Wmain \
|
-Wmain
|
||||||
-Wmaybe-uninitialized \
|
-Wmaybe-uninitialized
|
||||||
-Wmemset-elt-size \
|
-Wmemset-elt-size
|
||||||
-Wmemset-transposed-args \
|
-Wmemset-transposed-args
|
||||||
-Wmisleading-indentation \
|
-Wmisleading-indentation
|
||||||
-Wmismatched-dealloc \
|
-Wmismatched-dealloc
|
||||||
-Wmismatched-new-delete \
|
-Wmismatched-new-delete
|
||||||
-Wmismatched-tags \
|
-Wmismatched-tags
|
||||||
-Wmissing-attributes \
|
-Wmissing-attributes
|
||||||
-Wmissing-braces \
|
-Wmissing-braces
|
||||||
-Wmissing-declarations \
|
-Wmissing-declarations
|
||||||
-Wmissing-field-initializers \
|
-Wmissing-field-initializers
|
||||||
-Wmissing-include-dirs \
|
-Wmissing-include-dirs
|
||||||
-Wmissing-profile \
|
-Wmissing-profile
|
||||||
-Wmissing-requires \
|
-Wmissing-requires
|
||||||
-Wmultichar \
|
-Wmultichar
|
||||||
-Wmultiple-inheritance \
|
-Wmultiple-inheritance
|
||||||
-Wmultistatement-macros \
|
-Wmultistatement-macros
|
||||||
-Wno-namespaces \
|
-Wno-namespaces
|
||||||
-Wnarrowing \
|
-Wnarrowing
|
||||||
-Wnoexcept \
|
-Wnoexcept
|
||||||
-Wnoexcept-type \
|
-Wnoexcept-type
|
||||||
-Wnon-template-friend \
|
-Wnon-template-friend
|
||||||
-Wnon-virtual-dtor \
|
-Wnon-virtual-dtor
|
||||||
-Wnonnull \
|
-Wnonnull
|
||||||
-Wnonnull-compare \
|
-Wnonnull-compare
|
||||||
-Wnormalized=nfkc \
|
-Wnormalized=nfkc
|
||||||
-Wnull-dereference \
|
-Wnull-dereference
|
||||||
-Wodr \
|
-Wodr
|
||||||
-Wold-style-cast \
|
-Wold-style-cast
|
||||||
-Wopenacc-parallelism \
|
-Wopenacc-parallelism
|
||||||
-Wopenmp-simd \
|
-Wopenmp-simd
|
||||||
-Woverflow \
|
-Woverflow
|
||||||
-Woverlength-strings \
|
-Woverlength-strings
|
||||||
-Woverloaded-virtual \
|
-Woverloaded-virtual
|
||||||
-Wpacked \
|
-Wpacked
|
||||||
-Wpacked-bitfield-compat \
|
-Wpacked-bitfield-compat
|
||||||
-Wpacked-not-aligned \
|
-Wpacked-not-aligned
|
||||||
-Wno-padded \
|
-Wno-padded
|
||||||
-Wparentheses \
|
-Wparentheses
|
||||||
-Wpedantic \
|
-Wpedantic
|
||||||
-Wpessimizing-move \
|
-Wpessimizing-move
|
||||||
-Wplacement-new=2 \
|
-Wplacement-new=2
|
||||||
-Wpmf-conversions \
|
-Wpmf-conversions
|
||||||
-Wpointer-arith \
|
-Wpointer-arith
|
||||||
-Wpointer-compare \
|
-Wpointer-compare
|
||||||
-Wpragmas \
|
-Wpragmas
|
||||||
-Wprio-ctor-dtor \
|
-Wprio-ctor-dtor
|
||||||
-Wpsabi \
|
-Wpsabi
|
||||||
-Wrange-loop-construct \
|
-Wrange-loop-construct
|
||||||
-Wredundant-decls \
|
-Wredundant-decls
|
||||||
-Wredundant-move \
|
-Wredundant-move
|
||||||
-Wredundant-tags \
|
-Wredundant-tags
|
||||||
-Wregister \
|
-Wregister
|
||||||
-Wreorder \
|
-Wreorder
|
||||||
-Wrestrict \
|
-Wrestrict
|
||||||
-Wreturn-local-addr \
|
-Wreturn-local-addr
|
||||||
-Wreturn-type \
|
-Wreturn-type
|
||||||
-Wscalar-storage-order \
|
-Wscalar-storage-order
|
||||||
-Wsequence-point \
|
-Wsequence-point
|
||||||
-Wshadow=compatible-local \
|
-Wshadow=compatible-local
|
||||||
-Wshadow=global \
|
-Wshadow=global
|
||||||
-Wshadow=local \
|
-Wshadow=local
|
||||||
-Wshift-count-negative \
|
-Wshift-count-negative
|
||||||
-Wshift-count-overflow \
|
-Wshift-count-overflow
|
||||||
-Wshift-negative-value \
|
-Wshift-negative-value
|
||||||
-Wshift-overflow=2 \
|
-Wshift-overflow=2
|
||||||
-Wsign-compare \
|
-Wsign-compare
|
||||||
-Wsign-conversion \
|
-Wsign-conversion
|
||||||
-Wsign-promo \
|
-Wsign-promo
|
||||||
-Wsized-deallocation \
|
-Wsized-deallocation
|
||||||
-Wsizeof-array-argument \
|
-Wsizeof-array-argument
|
||||||
-Wsizeof-array-div \
|
-Wsizeof-array-div
|
||||||
-Wsizeof-pointer-div \
|
-Wsizeof-pointer-div
|
||||||
-Wsizeof-pointer-memaccess \
|
-Wsizeof-pointer-memaccess
|
||||||
-Wstack-protector \
|
-Wstack-protector
|
||||||
-Wstrict-aliasing \
|
-Wstrict-aliasing
|
||||||
-Wstrict-aliasing=3 \
|
-Wstrict-aliasing=3
|
||||||
-Wstrict-null-sentinel \
|
-Wstrict-null-sentinel
|
||||||
-Wstrict-overflow \
|
-Wstrict-overflow
|
||||||
-Wstrict-overflow=5 \
|
-Wstrict-overflow=5
|
||||||
-Wstring-compare \
|
-Wstring-compare
|
||||||
-Wstringop-overflow=4 \
|
-Wstringop-overflow=4
|
||||||
-Wstringop-overread \
|
-Wstringop-overread
|
||||||
-Wstringop-truncation \
|
-Wstringop-truncation
|
||||||
-Wsubobject-linkage \
|
-Wsubobject-linkage
|
||||||
-Wsuggest-attribute=cold \
|
-Wsuggest-attribute=cold
|
||||||
-Wsuggest-attribute=const \
|
-Wsuggest-attribute=const
|
||||||
-Wsuggest-attribute=format \
|
-Wsuggest-attribute=format
|
||||||
-Wsuggest-attribute=malloc \
|
-Wsuggest-attribute=malloc
|
||||||
-Wsuggest-attribute=noreturn \
|
-Wsuggest-attribute=noreturn
|
||||||
-Wsuggest-attribute=pure \
|
-Wsuggest-attribute=pure
|
||||||
-Wsuggest-final-methods \
|
-Wsuggest-final-methods
|
||||||
-Wsuggest-final-types \
|
-Wsuggest-final-types
|
||||||
-Wsuggest-override \
|
-Wsuggest-override
|
||||||
-Wswitch \
|
-Wswitch
|
||||||
-Wswitch-bool \
|
-Wswitch-bool
|
||||||
-Wswitch-default \
|
-Wswitch-default
|
||||||
-Wswitch-enum \
|
-Wswitch-enum
|
||||||
-Wswitch-outside-range \
|
-Wswitch-outside-range
|
||||||
-Wswitch-unreachable \
|
-Wswitch-unreachable
|
||||||
-Wsync-nand \
|
-Wsync-nand
|
||||||
-Wsynth \
|
-Wsynth
|
||||||
-Wno-system-headers \
|
-Wno-system-headers
|
||||||
-Wtautological-compare \
|
-Wtautological-compare
|
||||||
-Wno-templates \
|
-Wno-templates
|
||||||
-Wterminate \
|
-Wterminate
|
||||||
-Wtrampolines \
|
-Wtrampolines
|
||||||
-Wtrigraphs \
|
-Wtrigraphs
|
||||||
-Wtsan \
|
-Wtsan
|
||||||
-Wtype-limits \
|
-Wtype-limits
|
||||||
-Wundef \
|
-Wundef
|
||||||
-Wuninitialized \
|
-Wuninitialized
|
||||||
-Wunknown-pragmas \
|
-Wunknown-pragmas
|
||||||
-Wunreachable-code \
|
-Wunreachable-code
|
||||||
-Wunsafe-loop-optimizations \
|
-Wunsafe-loop-optimizations
|
||||||
-Wunused \
|
-Wunused
|
||||||
-Wunused-but-set-parameter \
|
-Wunused-but-set-parameter
|
||||||
-Wunused-but-set-variable \
|
-Wunused-but-set-variable
|
||||||
-Wunused-const-variable=2 \
|
-Wunused-const-variable=2
|
||||||
-Wunused-function \
|
-Wunused-function
|
||||||
-Wunused-label \
|
-Wunused-label
|
||||||
-Wunused-local-typedefs \
|
-Wunused-local-typedefs
|
||||||
-Wunused-macros \
|
-Wunused-macros
|
||||||
-Wunused-parameter \
|
-Wunused-parameter
|
||||||
-Wunused-result \
|
-Wunused-result
|
||||||
-Wunused-value \
|
-Wunused-value
|
||||||
-Wunused-variable \
|
-Wunused-variable
|
||||||
-Wuseless-cast \
|
-Wuseless-cast
|
||||||
-Wvarargs \
|
-Wvarargs
|
||||||
-Wvariadic-macros \
|
-Wvariadic-macros
|
||||||
-Wvector-operation-performance \
|
-Wvector-operation-performance
|
||||||
-Wvexing-parse \
|
-Wvexing-parse
|
||||||
-Wvirtual-inheritance \
|
-Wvirtual-inheritance
|
||||||
-Wvirtual-move-assign \
|
-Wvirtual-move-assign
|
||||||
-Wvla \
|
-Wvla
|
||||||
-Wvla-parameter \
|
-Wvla-parameter
|
||||||
-Wvolatile \
|
-Wvolatile
|
||||||
-Wvolatile-register-var \
|
-Wvolatile-register-var
|
||||||
-Wwrite-strings \
|
-Wwrite-strings
|
||||||
-Wzero-as-null-pointer-constant \
|
-Wzero-as-null-pointer-constant
|
||||||
-Wzero-length-bounds \
|
-Wzero-length-bounds
|
||||||
")
|
)
|
||||||
|
|
||||||
add_custom_target(ci_test_gcc
|
add_custom_target(ci_test_gcc
|
||||||
COMMAND CXX=${GCC_TOOL} CXXFLAGS=${GCC_CXXFLAGS} ${CMAKE_COMMAND}
|
COMMAND CXX=${GCC_TOOL} CXXFLAGS="${GCC_CXXFLAGS}" ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON
|
-DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_gcc
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_gcc
|
||||||
@ -419,7 +419,7 @@ add_custom_target(ci_test_gcc
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(ci_test_clang
|
add_custom_target(ci_test_clang
|
||||||
COMMAND CXX=${CLANG_TOOL} CXXFLAGS=${CLANG_CXXFLAGS} ${CMAKE_COMMAND}
|
COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON
|
-DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang
|
||||||
@ -434,10 +434,10 @@ add_custom_target(ci_test_clang
|
|||||||
|
|
||||||
foreach(CXX_STANDARD 11 14 17 20)
|
foreach(CXX_STANDARD 11 14 17 20)
|
||||||
add_custom_target(ci_test_gcc_cxx${CXX_STANDARD}
|
add_custom_target(ci_test_gcc_cxx${CXX_STANDARD}
|
||||||
COMMAND CXX=${GCC_TOOL} ${CMAKE_COMMAND}
|
COMMAND CXX=${GCC_TOOL} CXXFLAGS="${GCC_CXXFLAGS}" ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DCMAKE_CXX_STANDARD=${CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=ON
|
|
||||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||||
|
-DJSON_TestStandards=${CXX_STANDARD}
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD}
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD}
|
||||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD}
|
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD}
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
||||||
@ -445,10 +445,10 @@ foreach(CXX_STANDARD 11 14 17 20)
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(ci_test_clang_cxx${CXX_STANDARD}
|
add_custom_target(ci_test_clang_cxx${CXX_STANDARD}
|
||||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DCMAKE_CXX_STANDARD=${CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=ON
|
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||||
-DJSON_BuildTests=ON
|
-DJSON_TestStandards=${CXX_STANDARD}
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
||||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
||||||
@ -769,50 +769,67 @@ add_custom_target(ci_benchmarks
|
|||||||
# CMake flags
|
# CMake flags
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
function(ci_get_cmake version var)
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
set(CMAKE_310_BINARY ${PROJECT_BINARY_DIR}/cmake-3.1.0-Darwin64/CMake.app/Contents/bin/cmake)
|
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}-Darwin64/CMake.app/Contents/bin/cmake)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${CMAKE_310_BINARY}
|
OUTPUT ${${var}}
|
||||||
COMMAND wget https://github.com/Kitware/CMake/releases/download/v3.1.0/cmake-3.1.0-Darwin64.tar.gz
|
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-Darwin64.tar.gz
|
||||||
COMMAND tar xfz cmake-3.1.0-Darwin64.tar.gz
|
COMMAND tar xfz cmake-${version}-Darwin64.tar.gz
|
||||||
COMMAND rm cmake-3.1.0-Darwin64.tar.gz
|
COMMAND rm cmake-${version}-Darwin64.tar.gz
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||||
COMMENT "Download CMake 3.1.0"
|
COMMENT "Download CMake ${version}"
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
set(CMAKE_310_BINARY ${PROJECT_BINARY_DIR}/cmake-3.1.0-Linux-x86_64/bin/cmake)
|
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}-Linux-x86_64/bin/cmake)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${CMAKE_310_BINARY}
|
OUTPUT ${${var}}
|
||||||
COMMAND wget https://github.com/Kitware/CMake/releases/download/v3.1.0/cmake-3.1.0-Linux-x86_64.tar.gz
|
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-Linux-x86_64.tar.gz
|
||||||
COMMAND tar xfz cmake-3.1.0-Linux-x86_64.tar.gz
|
COMMAND tar xfz cmake-${version}-Linux-x86_64.tar.gz
|
||||||
COMMAND rm cmake-3.1.0-Linux-x86_64.tar.gz
|
COMMAND rm cmake-${version}-Linux-x86_64.tar.gz
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||||
COMMENT "Download CMake 3.1.0"
|
COMMENT "Download CMake ${version}"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
set(${var} ${${var}} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
set(JSON_CMAKE_FLAGS "JSON_BuildTests;JSON_Install;JSON_MultipleHeaders;JSON_ImplicitConversions;JSON_Valgrind;JSON_Diagnostics;JSON_SystemInclude")
|
ci_get_cmake(3.1.0 CMAKE_3_1_0_BINARY)
|
||||||
|
ci_get_cmake(3.13.0 CMAKE_3_13_0_BINARY)
|
||||||
|
|
||||||
foreach(JSON_CMAKE_FLAG ${JSON_CMAKE_FLAGS})
|
set(JSON_CMAKE_FLAGS_3_1_0 "JSON_Install;JSON_MultipleHeaders;JSON_ImplicitConversions;JSON_Valgrind;JSON_Diagnostics;JSON_SystemInclude")
|
||||||
string(TOLOWER "ci_cmake_flag_${JSON_CMAKE_FLAG}" JSON_CMAKE_FLAG_TARGET)
|
set(JSON_CMAKE_FLAGS_3_13_0 "JSON_BuildTests")
|
||||||
add_custom_target("${JSON_CMAKE_FLAG_TARGET}"
|
|
||||||
COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake ${CMAKE_VERSION})"
|
function(ci_add_cmake_flags_targets flag min_version)
|
||||||
|
string(TOLOWER "ci_cmake_flag_${flag}" flag_target)
|
||||||
|
string(REPLACE . _ min_version_var ${min_version})
|
||||||
|
set(cmake_binary ${CMAKE_${min_version_var}_BINARY})
|
||||||
|
add_custom_target(${flag_target}
|
||||||
|
COMMENT "Check CMake flag ${flag} (CMake ${CMAKE_VERSION})"
|
||||||
COMMAND ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-Werror=dev
|
-Werror=dev
|
||||||
-D${JSON_CMAKE_FLAG}=ON
|
-D${flag}=ON
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_${JSON_CMAKE_FLAG_TARGET}
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_${flag_target}
|
||||||
)
|
)
|
||||||
add_custom_target("${JSON_CMAKE_FLAG_TARGET}_31"
|
add_custom_target(${flag_target}_${min_version_var}
|
||||||
COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake 3.1)"
|
COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake ${min_version})"
|
||||||
COMMAND mkdir ${PROJECT_BINARY_DIR}/build_${JSON_CMAKE_FLAG_TARGET}_31
|
COMMAND mkdir -pv ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_${JSON_CMAKE_FLAG_TARGET}_31 && ${CMAKE_310_BINARY}
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
||||||
-Werror=dev ${PROJECT_SOURCE_DIR}
|
&& ${cmake_binary} -Werror=dev ${PROJECT_SOURCE_DIR} -D${flag}=ON
|
||||||
-D${JSON_CMAKE_FLAG}=ON
|
DEPENDS ${cmake_binary}
|
||||||
-DCMAKE_CXX_COMPILE_FEATURES="cxx_range_for" -DCMAKE_CXX_FLAGS="-std=gnu++11"
|
|
||||||
DEPENDS ${CMAKE_310_BINARY}
|
|
||||||
)
|
)
|
||||||
list(APPEND JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGET} ${JSON_CMAKE_FLAG_TARGET}_31)
|
list(APPEND JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGET} ${flag_target}_${min_version_var})
|
||||||
list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${JSON_CMAKE_FLAG_TARGET} ${PROJECT_BINARY_DIR}/build_${JSON_CMAKE_FLAG_TARGET}_31)
|
list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${flag_target} ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var})
|
||||||
|
set(JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGETS} PARENT_SCOPE)
|
||||||
|
set(JSON_CMAKE_FLAG_BUILD_DIRS ${JSON_CMAKE_FLAG_BUILD_DIRS} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
foreach(JSON_CMAKE_FLAG ${JSON_CMAKE_FLAGS_3_1_0})
|
||||||
|
ci_add_cmake_flags_targets(${JSON_CMAKE_FLAG} 3.1.0)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
foreach(JSON_CMAKE_FLAG ${JSON_CMAKE_FLAGS_3_13_0})
|
||||||
|
ci_add_cmake_flags_targets(${JSON_CMAKE_FLAG} 3.13.0)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
add_custom_target(ci_cmake_flags
|
add_custom_target(ci_cmake_flags
|
||||||
|
204
cmake/test.cmake
Normal file
204
cmake/test.cmake
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
set(_json_test_cmake_list_file ${CMAKE_CURRENT_LIST_FILE})
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
# download test data
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
include(download_test_data)
|
||||||
|
|
||||||
|
# test fixture to download test data
|
||||||
|
add_test(NAME "download_test_data" COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}
|
||||||
|
--target download_test_data
|
||||||
|
)
|
||||||
|
set_tests_properties(download_test_data PROPERTIES FIXTURES_SETUP TEST_DATA)
|
||||||
|
|
||||||
|
if(JSON_Valgrind)
|
||||||
|
find_program(CMAKE_MEMORYCHECK_COMMAND valgrind)
|
||||||
|
message(STATUS "Executing test suite with Valgrind (${CMAKE_MEMORYCHECK_COMMAND})")
|
||||||
|
set(memcheck_command "${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS} --error-exitcode=1 --leak-check=full")
|
||||||
|
separate_arguments(memcheck_command)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
# detect standard support
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
# C++11 is the minimum required
|
||||||
|
set(compiler_supports_cpp_11 TRUE)
|
||||||
|
|
||||||
|
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
|
||||||
|
if (${feature} STREQUAL cxx_std_14)
|
||||||
|
set(compiler_supports_cpp_14 TRUE)
|
||||||
|
elseif (${feature} STREQUAL cxx_std_17)
|
||||||
|
set(compiler_supports_cpp_17 TRUE)
|
||||||
|
elseif (${feature} STREQUAL cxx_std_20)
|
||||||
|
set(compiler_supports_cpp_20 TRUE)
|
||||||
|
elseif (${feature} STREQUAL cxx_std_23)
|
||||||
|
set(compiler_supports_cpp_23 TRUE)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
# test functions
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
# json_test_set_test_options(
|
||||||
|
# all|<tests>
|
||||||
|
# [CXX_STANDARDS all|<args>...]
|
||||||
|
# [COMPILE_DEFINITIONS <args>...]
|
||||||
|
# [COMPILE_FEATURES <args>...]
|
||||||
|
# [COMPILE_OPTIONS <args>...]
|
||||||
|
# [LINK_LIBRARIES <args>...]
|
||||||
|
# [LINK_OPTIONS <args>...])
|
||||||
|
#
|
||||||
|
# Supply test- and standard-specific build settings.
|
||||||
|
# Specify multiple tests using a list e.g., "test-foo;test-bar".
|
||||||
|
#
|
||||||
|
# Must be called BEFORE the test is created.
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
function(json_test_set_test_options tests)
|
||||||
|
cmake_parse_arguments(args "" ""
|
||||||
|
"CXX_STANDARDS;COMPILE_DEFINITIONS;COMPILE_FEATURES;COMPILE_OPTIONS;LINK_LIBRARIES;LINK_OPTIONS"
|
||||||
|
${ARGN})
|
||||||
|
|
||||||
|
if(NOT args_CXX_STANDARDS)
|
||||||
|
set(args_CXX_STANDARDS "all")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
foreach(test ${tests})
|
||||||
|
if("${test}" STREQUAL "all")
|
||||||
|
set(test "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
foreach(cxx_standard ${args_CXX_STANDARDS})
|
||||||
|
if("${cxx_standard}" STREQUAL "all")
|
||||||
|
if("${test}" STREQUAL "")
|
||||||
|
message(FATAL_ERROR "Not supported. Change defaults in: ${_json_test_cmake_list_file}")
|
||||||
|
endif()
|
||||||
|
set(test_interface _json_test_interface_${test})
|
||||||
|
else()
|
||||||
|
set(test_interface _json_test_interface_${test}_cpp_${cxx_standard})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT TARGET ${test_interface})
|
||||||
|
add_library(${test_interface} INTERFACE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_compile_definitions(${test_interface} INTERFACE ${args_COMPILE_DEFINITIONS})
|
||||||
|
target_compile_features(${test_interface} INTERFACE ${args_COMPILE_FEATURES})
|
||||||
|
target_compile_options(${test_interface} INTERFACE ${args_COMPILE_OPTIONS})
|
||||||
|
target_link_libraries (${test_interface} INTERFACE ${args_LINK_LIBRARIES})
|
||||||
|
target_link_options(${test_interface} INTERFACE ${args_LINK_OPTIONS})
|
||||||
|
endforeach()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# for internal use by json_test_add_test_for()
|
||||||
|
function(_json_test_add_test test_name file main cxx_standard)
|
||||||
|
set(test_target ${test_name}_cpp${cxx_standard})
|
||||||
|
|
||||||
|
if(TARGET ${test_target})
|
||||||
|
message(FATAL_ERROR "Target ${test_target} has already been added.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(${test_target} ${file})
|
||||||
|
target_link_libraries(${test_target} PRIVATE ${main})
|
||||||
|
|
||||||
|
# set and require C++ standard
|
||||||
|
set_target_properties(${test_target} PROPERTIES
|
||||||
|
CXX_STANDARD ${cxx_standard}
|
||||||
|
CXX_STANDARD_REQUIRED ON
|
||||||
|
)
|
||||||
|
|
||||||
|
# apply standard-specific build settings
|
||||||
|
if(TARGET _json_test_interface__cpp_${cxx_standard})
|
||||||
|
target_link_libraries(${test_target} PRIVATE _json_test_interface__cpp_${cxx_standard})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# apply test-specific build settings
|
||||||
|
if(TARGET _json_test_interface_${test_name})
|
||||||
|
target_link_libraries(${test_target} PRIVATE _json_test_interface_${test_name})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# apply test- and standard-specific build settings
|
||||||
|
if(TARGET _json_test_interface_${test_name}_cpp_${cxx_standard})
|
||||||
|
target_link_libraries(${test_target} PRIVATE
|
||||||
|
_json_test_interface_${test_name}_cpp_${cxx_standard}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (JSON_FastTests)
|
||||||
|
add_test(NAME ${test_target}
|
||||||
|
COMMAND ${test_target} ${DOCTEST_TEST_FILTER}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
add_test(NAME ${test_target}
|
||||||
|
COMMAND ${test_target} ${DOCTEST_TEST_FILTER} --no-skip
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
set_tests_properties(${test_target} PROPERTIES LABELS "all" FIXTURES_REQUIRED TEST_DATA)
|
||||||
|
|
||||||
|
if(JSON_Valgrind)
|
||||||
|
add_test(NAME ${test_target}_valgrind
|
||||||
|
COMMAND ${memcheck_command} $<TARGET_FILE:${test_target}> ${DOCTEST_TEST_FILTER}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
set_tests_properties(${test_target}_valgrind PROPERTIES
|
||||||
|
LABELS "valgrind" FIXTURES_REQUIRED TEST_DATA
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
# json_test_add_test_for(
|
||||||
|
# <file>
|
||||||
|
# MAIN <main>
|
||||||
|
# [CXX_STANDARDS <version_number>...] [FORCE])
|
||||||
|
#
|
||||||
|
# Given a <file> unit-foo.cpp, produces
|
||||||
|
#
|
||||||
|
# test-foo_cpp<version_number>
|
||||||
|
#
|
||||||
|
# if C++ standard <version_number> is supported by the compiler and the
|
||||||
|
# source file contains JSON_HAS_CPP_<version_number>.
|
||||||
|
# Use FORCE to create the test regardless of the file containing
|
||||||
|
# JSON_HAS_CPP_<version_number>.
|
||||||
|
# Test targets are linked against <main>.
|
||||||
|
# CXX_STANDARDS defaults to "11".
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
function(json_test_add_test_for file)
|
||||||
|
cmake_parse_arguments(args "FORCE" "MAIN" "CXX_STANDARDS" ${ARGN})
|
||||||
|
|
||||||
|
get_filename_component(file_basename ${file} NAME_WE)
|
||||||
|
string(REGEX REPLACE "unit-([^$]+)" "test-\\1" test_name ${file_basename})
|
||||||
|
|
||||||
|
if("${args_MAIN}" STREQUAL "")
|
||||||
|
message(FATAL_ERROR "Required argument MAIN <main> missing.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if("${args_CXX_STANDARDS}" STREQUAL "")
|
||||||
|
set(args_CXX_STANDARDS 11)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
file(READ ${file} file_content)
|
||||||
|
foreach(cxx_standard ${args_CXX_STANDARDS})
|
||||||
|
if(NOT compiler_supports_cpp_${cxx_standard})
|
||||||
|
continue()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# add unconditionally if C++11 (default) or forced
|
||||||
|
if(NOT ("${cxx_standard}" STREQUAL 11 OR args_FORCE))
|
||||||
|
string(FIND "${file_content}" JSON_HAS_CPP_${cxx_standard} has_cpp_found)
|
||||||
|
if(${has_cpp_found} EQUAL -1)
|
||||||
|
continue()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
_json_test_add_test(${test_name} ${file} ${args_MAIN} ${cxx_standard})
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
@ -464,7 +464,8 @@ void from_json(const BasicJsonType& j, std_fs::path& p)
|
|||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
|
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
|
||||||
{
|
{
|
||||||
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
|
// Not tested because of #3377 (related #3070)
|
||||||
|
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j)); // LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
p = *j.template get_ptr<const typename BasicJsonType::string_t*>();
|
p = *j.template get_ptr<const typename BasicJsonType::string_t*>();
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,15 @@
|
|||||||
#define JSON_HAS_FILESYSTEM 0
|
#define JSON_HAS_FILESYSTEM 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef JSON_HAS_THREE_WAY_COMPARISON
|
||||||
|
#if defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L \
|
||||||
|
&& defined(__cpp_impl_three_way_comparison)&& __cpp_impl_three_way_comparison >= 201907L
|
||||||
|
#define JSON_HAS_THREE_WAY_COMPARISON 1
|
||||||
|
#else
|
||||||
|
#define JSON_HAS_THREE_WAY_COMPARISON 0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// disable documentation warnings on clang
|
// disable documentation warnings on clang
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
|
@ -8,19 +8,23 @@
|
|||||||
// clean up
|
// clean up
|
||||||
#undef JSON_ASSERT
|
#undef JSON_ASSERT
|
||||||
#undef JSON_INTERNAL_CATCH
|
#undef JSON_INTERNAL_CATCH
|
||||||
#undef JSON_CATCH
|
|
||||||
#undef JSON_THROW
|
#undef JSON_THROW
|
||||||
#undef JSON_TRY
|
|
||||||
#undef JSON_PRIVATE_UNLESS_TESTED
|
#undef JSON_PRIVATE_UNLESS_TESTED
|
||||||
|
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
||||||
|
#undef NLOHMANN_BASIC_JSON_TPL
|
||||||
|
#undef JSON_EXPLICIT
|
||||||
|
#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
|
||||||
|
|
||||||
|
#ifndef JSON_TEST_KEEP_MACROS
|
||||||
|
#undef JSON_CATCH
|
||||||
|
#undef JSON_TRY
|
||||||
#undef JSON_HAS_CPP_11
|
#undef JSON_HAS_CPP_11
|
||||||
#undef JSON_HAS_CPP_14
|
#undef JSON_HAS_CPP_14
|
||||||
#undef JSON_HAS_CPP_17
|
#undef JSON_HAS_CPP_17
|
||||||
#undef JSON_HAS_CPP_20
|
#undef JSON_HAS_CPP_20
|
||||||
#undef JSON_HAS_FILESYSTEM
|
#undef JSON_HAS_FILESYSTEM
|
||||||
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
||||||
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
#undef JSON_HAS_THREE_WAY_COMPARISON
|
||||||
#undef NLOHMANN_BASIC_JSON_TPL
|
#endif
|
||||||
#undef JSON_EXPLICIT
|
|
||||||
#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
|
|
||||||
|
|
||||||
#include <nlohmann/thirdparty/hedley/hedley_undef.hpp>
|
#include <nlohmann/thirdparty/hedley/hedley_undef.hpp>
|
||||||
|
@ -147,8 +147,12 @@ struct static_const
|
|||||||
static constexpr T value{};
|
static constexpr T value{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef JSON_HAS_CPP_17
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr T static_const<T>::value; // NOLINT(readability-redundant-declaration)
|
constexpr T static_const<T>::value; // NOLINT(readability-redundant-declaration)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace nlohmann
|
} // namespace nlohmann
|
||||||
|
@ -2394,6 +2394,15 @@ using is_detected_convertible =
|
|||||||
#define JSON_HAS_FILESYSTEM 0
|
#define JSON_HAS_FILESYSTEM 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef JSON_HAS_THREE_WAY_COMPARISON
|
||||||
|
#if defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L \
|
||||||
|
&& defined(__cpp_impl_three_way_comparison)&& __cpp_impl_three_way_comparison >= 201907L
|
||||||
|
#define JSON_HAS_THREE_WAY_COMPARISON 1
|
||||||
|
#else
|
||||||
|
#define JSON_HAS_THREE_WAY_COMPARISON 0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// disable documentation warnings on clang
|
// disable documentation warnings on clang
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
@ -3182,9 +3191,13 @@ struct static_const
|
|||||||
static constexpr T value{};
|
static constexpr T value{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef JSON_HAS_CPP_17
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr T static_const<T>::value; // NOLINT(readability-redundant-declaration)
|
constexpr T static_const<T>::value; // NOLINT(readability-redundant-declaration)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace nlohmann
|
} // namespace nlohmann
|
||||||
|
|
||||||
@ -4266,7 +4279,8 @@ void from_json(const BasicJsonType& j, std_fs::path& p)
|
|||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
|
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
|
||||||
{
|
{
|
||||||
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
|
// Not tested because of #3377 (related #3070)
|
||||||
|
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j)); // LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
p = *j.template get_ptr<const typename BasicJsonType::string_t*>();
|
p = *j.template get_ptr<const typename BasicJsonType::string_t*>();
|
||||||
}
|
}
|
||||||
@ -21939,20 +21953,24 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
|
|||||||
// clean up
|
// clean up
|
||||||
#undef JSON_ASSERT
|
#undef JSON_ASSERT
|
||||||
#undef JSON_INTERNAL_CATCH
|
#undef JSON_INTERNAL_CATCH
|
||||||
#undef JSON_CATCH
|
|
||||||
#undef JSON_THROW
|
#undef JSON_THROW
|
||||||
#undef JSON_TRY
|
|
||||||
#undef JSON_PRIVATE_UNLESS_TESTED
|
#undef JSON_PRIVATE_UNLESS_TESTED
|
||||||
|
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
||||||
|
#undef NLOHMANN_BASIC_JSON_TPL
|
||||||
|
#undef JSON_EXPLICIT
|
||||||
|
#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
|
||||||
|
|
||||||
|
#ifndef JSON_TEST_KEEP_MACROS
|
||||||
|
#undef JSON_CATCH
|
||||||
|
#undef JSON_TRY
|
||||||
#undef JSON_HAS_CPP_11
|
#undef JSON_HAS_CPP_11
|
||||||
#undef JSON_HAS_CPP_14
|
#undef JSON_HAS_CPP_14
|
||||||
#undef JSON_HAS_CPP_17
|
#undef JSON_HAS_CPP_17
|
||||||
#undef JSON_HAS_CPP_20
|
#undef JSON_HAS_CPP_20
|
||||||
#undef JSON_HAS_FILESYSTEM
|
#undef JSON_HAS_FILESYSTEM
|
||||||
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
||||||
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
#undef JSON_HAS_THREE_WAY_COMPARISON
|
||||||
#undef NLOHMANN_BASIC_JSON_TPL
|
#endif
|
||||||
#undef JSON_EXPLICIT
|
|
||||||
#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
|
|
||||||
|
|
||||||
// #include <nlohmann/thirdparty/hedley/hedley_undef.hpp>
|
// #include <nlohmann/thirdparty/hedley/hedley_undef.hpp>
|
||||||
|
|
||||||
|
@ -1,163 +1,131 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
option(JSON_Valgrind "Execute test suite with Valgrind." OFF)
|
option(JSON_Valgrind "Execute test suite with Valgrind." OFF)
|
||||||
option(JSON_FastTests "Skip expensive/slow tests." OFF)
|
option(JSON_FastTests "Skip expensive/slow tests." OFF)
|
||||||
|
|
||||||
# download test data
|
set(JSON_TestStandards "" CACHE STRING "The list of standards to test explicitly.")
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/download_test_data.cmake)
|
|
||||||
|
|
||||||
# test fixture to download test data
|
include(test)
|
||||||
add_test(NAME "download_test_data" COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target download_test_data)
|
|
||||||
set_tests_properties(download_test_data PROPERTIES FIXTURES_SETUP TEST_DATA)
|
|
||||||
|
|
||||||
if(JSON_Valgrind)
|
|
||||||
find_program(CMAKE_MEMORYCHECK_COMMAND valgrind)
|
|
||||||
message(STATUS "Executing test suite with Valgrind (${CMAKE_MEMORYCHECK_COMMAND})")
|
|
||||||
set(memcheck_command "${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS} --error-exitcode=1 --leak-check=full")
|
|
||||||
separate_arguments(memcheck_command)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
# doctest library with the main function to speed up build
|
# override standard support
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
add_library(doctest_main OBJECT src/unit.cpp)
|
# compiling json.hpp in C++14 mode fails with Clang <4.0
|
||||||
set_target_properties(doctest_main PROPERTIES
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0)
|
||||||
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
|
unset(compiler_supports_cpp_14)
|
||||||
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
|
|
||||||
)
|
|
||||||
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
|
|
||||||
target_compile_features(doctest_main PUBLIC cxx_range_for)
|
|
||||||
else()
|
|
||||||
target_compile_features(doctest_main PUBLIC cxx_std_11)
|
|
||||||
endif()
|
|
||||||
target_include_directories(doctest_main PRIVATE "thirdparty/doctest")
|
|
||||||
|
|
||||||
# https://stackoverflow.com/questions/2368811/how-to-set-warning-level-in-cmake
|
|
||||||
if(MSVC)
|
|
||||||
# Force to always compile with W4
|
|
||||||
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
|
||||||
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
||||||
else()
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Disable warning C4566: character represented by universal-character-name '\uFF01' cannot be represented in the current code page (1252)
|
|
||||||
# Disable warning C4996: 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::operator <<': was declared deprecated
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4566 /wd4996")
|
|
||||||
|
|
||||||
# https://github.com/nlohmann/json/issues/1114
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
#############################################################################
|
|
||||||
# one executable for each unit test file
|
|
||||||
#############################################################################
|
|
||||||
|
|
||||||
# check if compiler supports C++17
|
|
||||||
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
|
|
||||||
if (${feature} STREQUAL cxx_std_17)
|
|
||||||
set(compiler_supports_cpp_17 TRUE)
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
# Clang only supports C++17 starting from Clang 5.0
|
# Clang only supports C++17 starting from Clang 5.0
|
||||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
||||||
unset(compiler_supports_cpp_17)
|
unset(compiler_supports_cpp_17)
|
||||||
endif()
|
endif()
|
||||||
# MSVC 2015 (14.0) does not support C++17
|
# MSVC 2015 (14.0) does not support C++17
|
||||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.1)
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.1)
|
||||||
unset(compiler_supports_cpp_17)
|
unset(compiler_supports_cpp_17)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
file(GLOB files src/unit-*.cpp)
|
# Clang C++20 support appears insufficient prior to Clang 9.0 (based on CI build failure)
|
||||||
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
|
||||||
|
unset(compiler_supports_cpp_20)
|
||||||
|
endif()
|
||||||
|
# GCC started supporting C++20 features in 8.0 but a test for #3070 segfaults prior to 9.0
|
||||||
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
|
||||||
|
unset(compiler_supports_cpp_20)
|
||||||
|
endif()
|
||||||
|
|
||||||
foreach(file ${files})
|
#############################################################################
|
||||||
get_filename_component(file_basename ${file} NAME_WE)
|
# test_main library with shared code to speed up build and common settings
|
||||||
string(REGEX REPLACE "unit-([^$]+)" "test-\\1" testcase ${file_basename})
|
#############################################################################
|
||||||
|
|
||||||
add_executable(${testcase} $<TARGET_OBJECTS:doctest_main> ${file})
|
add_library(test_main OBJECT src/unit.cpp)
|
||||||
target_compile_definitions(${testcase} PRIVATE DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
|
target_compile_definitions(test_main PUBLIC
|
||||||
target_compile_options(${testcase} PRIVATE
|
DOCTEST_CONFIG_SUPER_FAST_ASSERTS
|
||||||
|
JSON_TEST_KEEP_MACROS
|
||||||
|
)
|
||||||
|
target_compile_features(test_main PRIVATE cxx_std_11)
|
||||||
|
target_compile_options(test_main PUBLIC
|
||||||
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
|
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
|
||||||
|
# MSVC: Force to always compile with W4
|
||||||
|
# Disable warning C4566: character represented by universal-character-name '\uFF01'
|
||||||
|
# cannot be represented in the current code page (1252)
|
||||||
|
# Disable warning C4996: 'nlohmann::basic_json<...>::operator <<': was declared deprecated
|
||||||
|
$<$<CXX_COMPILER_ID:MSVC>:/W4 /wd4566 /wd4996>
|
||||||
|
# https://github.com/nlohmann/json/issues/1114
|
||||||
|
$<$<CXX_COMPILER_ID:MSVC>:/bigobj> $<$<BOOL:${MINGW}>:-Wa,-mbig-obj>
|
||||||
|
|
||||||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
|
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
|
||||||
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
||||||
)
|
)
|
||||||
target_include_directories(${testcase} PRIVATE ${CMAKE_BINARY_DIR}/include thirdparty/doctest thirdparty/fifo_map)
|
target_include_directories(test_main PUBLIC
|
||||||
target_link_libraries(${testcase} PRIVATE ${NLOHMANN_JSON_TARGET_NAME})
|
thirdparty/doctest
|
||||||
|
thirdparty/fifo_map
|
||||||
# add a copy with C++17 compilation
|
${PROJECT_BINARY_DIR}/include
|
||||||
if (compiler_supports_cpp_17)
|
|
||||||
file(READ ${file} FILE_CONTENT)
|
|
||||||
string(FIND "${FILE_CONTENT}" "JSON_HAS_CPP_17" CPP_17_FOUND)
|
|
||||||
if(NOT ${CPP_17_FOUND} EQUAL -1)
|
|
||||||
add_executable(${testcase}_cpp17 $<TARGET_OBJECTS:doctest_main> ${file})
|
|
||||||
target_compile_definitions(${testcase}_cpp17 PRIVATE DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
|
|
||||||
target_compile_options(${testcase}_cpp17 PRIVATE
|
|
||||||
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
|
|
||||||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
|
|
||||||
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
|
||||||
)
|
)
|
||||||
target_include_directories(${testcase}_cpp17 PRIVATE ${CMAKE_BINARY_DIR}/include thirdparty/doctest thirdparty/fifo_map)
|
target_link_libraries(test_main PUBLIC ${NLOHMANN_JSON_TARGET_NAME})
|
||||||
target_link_libraries(${testcase}_cpp17 PRIVATE ${NLOHMANN_JSON_TARGET_NAME})
|
|
||||||
target_compile_features(${testcase}_cpp17 PRIVATE cxx_std_17)
|
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0 AND NOT MINGW)
|
#############################################################################
|
||||||
|
# define test- and standard-specific build settings
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
|
||||||
|
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0
|
||||||
|
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0 AND NOT MINGW)
|
||||||
# fix for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90050
|
# fix for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90050
|
||||||
target_link_libraries(${testcase}_cpp17 PRIVATE stdc++fs)
|
json_test_set_test_options(all CXX_STANDARDS 17 LINK_LIBRARIES stdc++fs)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (JSON_FastTests)
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
add_test(NAME "${testcase}_cpp17"
|
# avoid stack overflow, see https://github.com/nlohmann/json/issues/2955
|
||||||
COMMAND ${testcase}_cpp17 ${DOCTEST_TEST_FILTER}
|
json_test_set_test_options("test-cbor;test-msgpack;test-ubjson" LINK_OPTIONS /STACK:4000000)
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
add_test(NAME "${testcase}_cpp17"
|
|
||||||
COMMAND ${testcase}_cpp17 ${DOCTEST_TEST_FILTER} --no-skip
|
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
set_tests_properties("${testcase}_cpp17" PROPERTIES LABELS "all" FIXTURES_REQUIRED TEST_DATA)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (JSON_FastTests)
|
|
||||||
add_test(NAME "${testcase}"
|
|
||||||
COMMAND ${testcase} ${DOCTEST_TEST_FILTER}
|
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
add_test(NAME "${testcase}"
|
|
||||||
COMMAND ${testcase} ${DOCTEST_TEST_FILTER} --no-skip
|
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
set_tests_properties("${testcase}" PROPERTIES LABELS "all" FIXTURES_REQUIRED TEST_DATA)
|
|
||||||
|
|
||||||
if(JSON_Valgrind)
|
|
||||||
add_test(NAME "${testcase}_valgrind"
|
|
||||||
COMMAND ${memcheck_command} ${CMAKE_CURRENT_BINARY_DIR}/${testcase} ${DOCTEST_TEST_FILTER}
|
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
||||||
)
|
|
||||||
set_tests_properties("${testcase}_valgrind" PROPERTIES LABELS "valgrind" FIXTURES_REQUIRED TEST_DATA)
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# disable exceptions for test-disabled_exceptions
|
# disable exceptions for test-disabled_exceptions
|
||||||
target_compile_definitions(test-disabled_exceptions PUBLIC JSON_NOEXCEPTION)
|
json_test_set_test_options(test-disabled_exceptions COMPILE_DEFINITIONS JSON_NOEXCEPTION)
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
target_compile_options(test-disabled_exceptions PUBLIC -fno-exceptions)
|
json_test_set_test_options(test-disabled_exceptions COMPILE_OPTIONS -fno-exceptions)
|
||||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
# disabled due to https://github.com/nlohmann/json/discussions/2824
|
# disabled due to https://github.com/nlohmann/json/discussions/2824
|
||||||
#target_compile_options(test-disabled_exceptions PUBLIC /EH)
|
#json_test_set_test_options(test-disabled_exceptions COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0 COMPILE_OPTIONS /EH)
|
||||||
#target_compile_definitions(test-disabled_exceptions PUBLIC _HAS_EXCEPTIONS=0)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# avoid stack overflow, see https://github.com/nlohmann/json/issues/2955
|
#############################################################################
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
# add unit tests
|
||||||
set_property(TARGET test-cbor APPEND_STRING PROPERTY LINK_FLAGS " /STACK:4000000")
|
#############################################################################
|
||||||
set_property(TARGET test-msgpack APPEND_STRING PROPERTY LINK_FLAGS " /STACK:4000000")
|
|
||||||
set_property(TARGET test-ubjson APPEND_STRING PROPERTY LINK_FLAGS " /STACK:4000000")
|
if("${JSON_TestStandards}" STREQUAL "")
|
||||||
|
set(test_cxx_standards 11 14 17 20 23)
|
||||||
|
unset(test_force)
|
||||||
|
else()
|
||||||
|
set(test_cxx_standards ${JSON_TestStandards})
|
||||||
|
set(test_force FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Print selected standards marking unavailable ones with brackets
|
||||||
|
set(msg_standards "")
|
||||||
|
foreach(cxx_standard ${test_cxx_standards})
|
||||||
|
if(compiler_supports_cpp_${cxx_standard})
|
||||||
|
list(APPEND msg_standards ${cxx_standard})
|
||||||
|
else()
|
||||||
|
list(APPEND msg_standards [${cxx_standard}])
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
string(JOIN " " msg_standards ${msg_standards})
|
||||||
|
set(msg "Testing standards: ${msg_standards}")
|
||||||
|
if(test_force)
|
||||||
|
string(APPEND msg " (forced)")
|
||||||
|
endif()
|
||||||
|
message(STATUS "${msg}")
|
||||||
|
|
||||||
|
# *DO* use json_test_set_test_options() above this line
|
||||||
|
|
||||||
|
file(GLOB files src/unit-*.cpp)
|
||||||
|
foreach(file ${files})
|
||||||
|
json_test_add_test_for(${file} MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# *DO NOT* use json_test_set_test_options() below this line
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
# Test the generated build configs
|
# Test the generated build configs
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
@ -37,7 +37,7 @@ SOFTWARE.
|
|||||||
|
|
||||||
/* forward declarations */
|
/* forward declarations */
|
||||||
class alt_string;
|
class alt_string;
|
||||||
bool operator<(const char* op1, const alt_string& op2);
|
bool operator<(const char* op1, const alt_string& op2) noexcept;
|
||||||
void int_to_string(alt_string& target, std::size_t value);
|
void int_to_string(alt_string& target, std::size_t value);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -152,7 +152,7 @@ class alt_string
|
|||||||
private:
|
private:
|
||||||
std::string str_impl {};
|
std::string str_impl {};
|
||||||
|
|
||||||
friend bool ::operator<(const char* /*op1*/, const alt_string& /*op2*/);
|
friend bool ::operator<(const char* /*op1*/, const alt_string& /*op2*/) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
void int_to_string(alt_string& target, std::size_t value)
|
void int_to_string(alt_string& target, std::size_t value)
|
||||||
@ -172,7 +172,7 @@ using alt_json = nlohmann::basic_json <
|
|||||||
nlohmann::adl_serializer >;
|
nlohmann::adl_serializer >;
|
||||||
|
|
||||||
|
|
||||||
bool operator<(const char* op1, const alt_string& op2)
|
bool operator<(const char* op1, const alt_string& op2) noexcept
|
||||||
{
|
{
|
||||||
return op1 < op2.str_impl;
|
return op1 < op2.str_impl;
|
||||||
}
|
}
|
||||||
|
@ -1609,7 +1609,7 @@ TEST_CASE("CBOR")
|
|||||||
|
|
||||||
// callback to set binary_seen to true if a binary value was seen
|
// callback to set binary_seen to true if a binary value was seen
|
||||||
bool binary_seen = false;
|
bool binary_seen = false;
|
||||||
auto callback = [&binary_seen](int /*depth*/, json::parse_event_t /*event*/, json & parsed)
|
auto callback = [&binary_seen](int /*depth*/, json::parse_event_t /*event*/, json & parsed) noexcept
|
||||||
{
|
{
|
||||||
if (parsed.is_binary())
|
if (parsed.is_binary())
|
||||||
{
|
{
|
||||||
|
@ -267,7 +267,7 @@ bool accept_helper(const std::string& s)
|
|||||||
CHECK(json::parser(nlohmann::detail::input_adapter(s)).accept(false) == !el.errored);
|
CHECK(json::parser(nlohmann::detail::input_adapter(s)).accept(false) == !el.errored);
|
||||||
|
|
||||||
// 5. parse with simple callback
|
// 5. parse with simple callback
|
||||||
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/)
|
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -1499,7 +1499,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
// test case to make sure the callback is properly evaluated after reading a key
|
// test case to make sure the callback is properly evaluated after reading a key
|
||||||
{
|
{
|
||||||
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t event, json& /*unused*/)
|
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t event, json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return event != json::parse_event_t::key;
|
return event != json::parse_event_t::key;
|
||||||
};
|
};
|
||||||
@ -1538,14 +1538,14 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("filter nothing")
|
SECTION("filter nothing")
|
||||||
{
|
{
|
||||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
CHECK (j_object == json({{"foo", 2}, {"bar", {{"baz", 1}}}}));
|
CHECK (j_object == json({{"foo", 2}, {"bar", {{"baz", 1}}}}));
|
||||||
|
|
||||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -1555,7 +1555,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("filter everything")
|
SECTION("filter everything")
|
||||||
{
|
{
|
||||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@ -1563,7 +1563,7 @@ TEST_CASE("parser class")
|
|||||||
// the top-level object will be discarded, leaving a null
|
// the top-level object will be discarded, leaving a null
|
||||||
CHECK (j_object.is_null());
|
CHECK (j_object.is_null());
|
||||||
|
|
||||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@ -1574,7 +1574,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("filter specific element")
|
SECTION("filter specific element")
|
||||||
{
|
{
|
||||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j)
|
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j) noexcept
|
||||||
{
|
{
|
||||||
// filter all number(2) elements
|
// filter all number(2) elements
|
||||||
return j != json(2);
|
return j != json(2);
|
||||||
@ -1582,7 +1582,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
CHECK (j_object == json({{"bar", {{"baz", 1}}}}));
|
CHECK (j_object == json({{"bar", {{"baz", 1}}}}));
|
||||||
|
|
||||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j)
|
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j) noexcept
|
||||||
{
|
{
|
||||||
return j != json(2);
|
return j != json(2);
|
||||||
});
|
});
|
||||||
@ -1601,7 +1601,7 @@ TEST_CASE("parser class")
|
|||||||
CHECK (j_filtered1.size() == 2);
|
CHECK (j_filtered1.size() == 2);
|
||||||
CHECK (j_filtered1 == json({1, {{"qux", "baz"}}}));
|
CHECK (j_filtered1 == json({1, {{"qux", "baz"}}}));
|
||||||
|
|
||||||
json j_filtered2 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& /*parsed*/)
|
json j_filtered2 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& /*parsed*/) noexcept
|
||||||
{
|
{
|
||||||
return e != json::parse_event_t::object_end;
|
return e != json::parse_event_t::object_end;
|
||||||
});
|
});
|
||||||
@ -1616,7 +1616,7 @@ TEST_CASE("parser class")
|
|||||||
SECTION("first closing event")
|
SECTION("first closing event")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
static bool first = true;
|
static bool first = true;
|
||||||
if (e == json::parse_event_t::object_end && first)
|
if (e == json::parse_event_t::object_end && first)
|
||||||
@ -1633,7 +1633,7 @@ TEST_CASE("parser class")
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
static bool first = true;
|
static bool first = true;
|
||||||
if (e == json::parse_event_t::array_end && first)
|
if (e == json::parse_event_t::array_end && first)
|
||||||
@ -1657,13 +1657,13 @@ TEST_CASE("parser class")
|
|||||||
// object and array is discarded only after the closing character
|
// object and array is discarded only after the closing character
|
||||||
// has been read
|
// has been read
|
||||||
|
|
||||||
json j_empty_object = json::parse("{}", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
json j_empty_object = json::parse("{}", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return e != json::parse_event_t::object_end;
|
return e != json::parse_event_t::object_end;
|
||||||
});
|
});
|
||||||
CHECK(j_empty_object == json());
|
CHECK(j_empty_object == json());
|
||||||
|
|
||||||
json j_empty_array = json::parse("[]", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
json j_empty_array = json::parse("[]", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return e != json::parse_event_t::array_end;
|
return e != json::parse_event_t::array_end;
|
||||||
});
|
});
|
||||||
@ -1731,7 +1731,7 @@ TEST_CASE("parser class")
|
|||||||
{
|
{
|
||||||
SECTION("parser with callback")
|
SECTION("parser with callback")
|
||||||
{
|
{
|
||||||
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/)
|
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -32,10 +32,6 @@ SOFTWARE.
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
#if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
|
|
||||||
#define JSON_HAS_CPP_20
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// helper function to check std::less<json::value_t>
|
// helper function to check std::less<json::value_t>
|
||||||
@ -211,7 +207,7 @@ TEST_CASE("lexicographical comparison operators")
|
|||||||
{
|
{
|
||||||
// Skip comparing indicies 12 and 13, and 13 and 12 in C++20 pending fix
|
// Skip comparing indicies 12 and 13, and 13 and 12 in C++20 pending fix
|
||||||
// See issue #3207
|
// See issue #3207
|
||||||
#ifdef JSON_HAS_CPP_20
|
#if defined(JSON_HAS_CPP_20) || JSON_HAS_THREE_WAY_COMPARISON
|
||||||
if ((i == 12 && j == 13) || (i == 13 && j == 12))
|
if ((i == 12 && j == 13) || (i == 13 && j == 12))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -41,13 +41,6 @@ using nlohmann::json;
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <valarray>
|
#include <valarray>
|
||||||
|
|
||||||
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
|
|
||||||
#define JSON_HAS_CPP_17
|
|
||||||
#define JSON_HAS_CPP_14
|
|
||||||
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
|
|
||||||
#define JSON_HAS_CPP_14
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// NLOHMANN_JSON_SERIALIZE_ENUM uses a static std::pair
|
// NLOHMANN_JSON_SERIALIZE_ENUM uses a static std::pair
|
||||||
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
||||||
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
|
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
|
||||||
|
@ -32,13 +32,6 @@ SOFTWARE.
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
|
|
||||||
#define JSON_HAS_CPP_17
|
|
||||||
#define JSON_HAS_CPP_14
|
|
||||||
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
|
|
||||||
#define JSON_HAS_CPP_14
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// This test suite uses range for loops where values are copied. This is inefficient in usual code, but required to achieve 100% coverage.
|
// This test suite uses range for loops where values are copied. This is inefficient in usual code, but required to achieve 100% coverage.
|
||||||
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
|
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
|
||||||
DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct")
|
DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct")
|
||||||
|
@ -42,10 +42,6 @@ using nlohmann::json;
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <test_data.hpp>
|
#include <test_data.hpp>
|
||||||
|
|
||||||
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
|
|
||||||
#define JSON_HAS_CPP_17
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#ifdef JSON_HAS_CPP_17
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,70 +42,8 @@ using ordered_json = nlohmann::ordered_json;
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
|
|
||||||
#define JSON_HAS_CPP_17
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#ifdef JSON_HAS_CPP_17
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM)
|
|
||||||
#if defined(__cpp_lib_filesystem)
|
|
||||||
#define JSON_HAS_FILESYSTEM 1
|
|
||||||
#elif defined(__cpp_lib_experimental_filesystem)
|
|
||||||
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
|
|
||||||
#elif !defined(__has_include)
|
|
||||||
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
|
|
||||||
#elif __has_include(<filesystem>)
|
|
||||||
#define JSON_HAS_FILESYSTEM 1
|
|
||||||
#elif __has_include(<experimental/filesystem>)
|
|
||||||
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/
|
|
||||||
#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8
|
|
||||||
#undef JSON_HAS_FILESYSTEM
|
|
||||||
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// no filesystem support before GCC 8: https://en.cppreference.com/w/cpp/compiler_support
|
|
||||||
#if defined(__GNUC__) && __GNUC__ < 8 && !defined(__clang__)
|
|
||||||
#undef JSON_HAS_FILESYSTEM
|
|
||||||
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// no filesystem support before Clang 7: https://en.cppreference.com/w/cpp/compiler_support
|
|
||||||
#if defined(__clang_major__) && __clang_major__ < 7
|
|
||||||
#undef JSON_HAS_FILESYSTEM
|
|
||||||
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// no filesystem support before MSVC 19.14: https://en.cppreference.com/w/cpp/compiler_support
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1940
|
|
||||||
#undef JSON_HAS_FILESYSTEM
|
|
||||||
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// no filesystem support before iOS 13
|
|
||||||
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000
|
|
||||||
#undef JSON_HAS_FILESYSTEM
|
|
||||||
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// no filesystem support before macOS Catalina
|
|
||||||
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
|
|
||||||
#undef JSON_HAS_FILESYSTEM
|
|
||||||
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
|
||||||
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef JSON_HAS_FILESYSTEM
|
|
||||||
#define JSON_HAS_FILESYSTEM 0
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
||||||
@ -656,7 +594,7 @@ TEST_CASE("regression tests 2")
|
|||||||
#ifdef JSON_HAS_CPP_20
|
#ifdef JSON_HAS_CPP_20
|
||||||
SECTION("issue #2546 - parsing containers of std::byte")
|
SECTION("issue #2546 - parsing containers of std::byte")
|
||||||
{
|
{
|
||||||
const char DATA[] = R"("Hello, world!")";
|
const char DATA[] = R"("Hello, world!")"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||||
const auto s = std::as_bytes(std::span(DATA));
|
const auto s = std::as_bytes(std::span(DATA));
|
||||||
json j = json::parse(s);
|
json j = json::parse(s);
|
||||||
CHECK(j.dump() == "\"Hello, world!\"");
|
CHECK(j.dump() == "\"Hello, world!\"");
|
||||||
@ -810,7 +748,8 @@ TEST_CASE("regression tests 2")
|
|||||||
const auto j_path = j.get<nlohmann::detail::std_fs::path>();
|
const auto j_path = j.get<nlohmann::detail::std_fs::path>();
|
||||||
CHECK(j_path == text_path);
|
CHECK(j_path == text_path);
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number", json::type_error);
|
// Disabled pending resolution of #3377
|
||||||
|
// CHECK_THROWS_WITH_AS(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number", json::type_error);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1610,7 +1610,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||||
|
|
||||||
json j;
|
json j;
|
||||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -1624,7 +1624,7 @@ TEST_CASE("UBJSON")
|
|||||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||||
|
|
||||||
json j;
|
json j;
|
||||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user