mirror of
https://github.com/nlohmann/json
synced 2024-11-21 11:40:05 +00:00
Add test for libstdc++ (#4495)
* 👷 add test for libstdc++ * 👷 add test for libstdc++ * 💚 add fixes from #4490 * 💚 add fixes from #4490
This commit is contained in:
parent
e509007df2
commit
e3ac5a64bf
27
.github/workflows/ubuntu.yml
vendored
27
.github/workflows/ubuntu.yml
vendored
@ -25,7 +25,7 @@ jobs:
|
|||||||
run: apt-get update ; apt-get install -y git unzip
|
run: apt-get update ; apt-get install -y git unzip
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@v3.27.7
|
uses: lukka/get-cmake@v3.31.0
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@ -62,7 +62,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@v3.27.7
|
uses: lukka/get-cmake@v3.31.0
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@ -79,7 +79,7 @@ jobs:
|
|||||||
run: apt-get update ; apt-get install -y git clang-tools unzip
|
run: apt-get update ; apt-get install -y git clang-tools unzip
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@v3.27.7
|
uses: lukka/get-cmake@v3.31.0
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@ -96,7 +96,7 @@ jobs:
|
|||||||
run: apt-get update ; apt-get install -y build-essential unzip wget git
|
run: apt-get update ; apt-get install -y build-essential unzip wget git
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@v3.27.7
|
uses: lukka/get-cmake@v3.31.0
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@ -148,7 +148,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@v3.27.7
|
uses: lukka/get-cmake@v3.31.0
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@ -165,7 +165,7 @@ jobs:
|
|||||||
run: apt-get update ; apt-get install -y unzip git
|
run: apt-get update ; apt-get install -y unzip git
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@v3.27.7
|
uses: lukka/get-cmake@v3.31.0
|
||||||
- name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10
|
- name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10
|
||||||
run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV"
|
run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV"
|
||||||
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
|
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
|
||||||
@ -206,16 +206,21 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
standard: [11, 14, 17, 20, 23]
|
standard: [11, 14, 17, 20, 23]
|
||||||
|
stdlib: [libcxx, libstdcxx]
|
||||||
steps:
|
steps:
|
||||||
- name: Install git and unzip
|
- name: Install git and unzip
|
||||||
run: apt-get update ; apt-get install -y git unzip
|
run: apt-get update ; apt-get install -y git unzip
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@v3.27.7
|
uses: lukka/get-cmake@v3.31.0
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build with libc++
|
||||||
|
run: cmake --build build --target ci_test_clang_libcxx_cxx${{ matrix.standard }}
|
||||||
|
if: ${{ matrix.stdlib == 'libcxx' }}
|
||||||
|
- name: Build with libstdc++
|
||||||
run: cmake --build build --target ci_test_clang_cxx${{ matrix.standard }}
|
run: cmake --build build --target ci_test_clang_cxx${{ matrix.standard }}
|
||||||
|
if: ${{ matrix.stdlib == 'libstdcxx' }}
|
||||||
|
|
||||||
ci_cuda_example:
|
ci_cuda_example:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -231,7 +236,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/nlohmann/json-ci:v2.2.0
|
container: ghcr.io/nlohmann/json-ci:v2.2.0
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
@ -243,7 +248,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-python@v3
|
- uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.11'
|
||||||
- name: Install REUSE tool
|
- name: Install REUSE tool
|
||||||
run: python -m pip install reuse
|
run: python -m pip install reuse
|
||||||
- name: Run REUSE lint
|
- name: Run REUSE lint
|
||||||
|
@ -13,7 +13,7 @@ execute_process(COMMAND ${ASTYLE_TOOL} --version OUTPUT_VARIABLE ASTYLE_TOOL_VER
|
|||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" ASTYLE_TOOL_VERSION "${ASTYLE_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" ASTYLE_TOOL_VERSION "${ASTYLE_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Artistic Style ${ASTYLE_TOOL_VERSION} (${ASTYLE_TOOL})")
|
message(STATUS "🔖 Artistic Style ${ASTYLE_TOOL_VERSION} (${ASTYLE_TOOL})")
|
||||||
|
|
||||||
find_program(CLANG_TOOL NAMES clang++-HEAD clang++ clang++-17 clang++-16 clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++)
|
find_program(CLANG_TOOL NAMES clang++-HEAD clang++ clang++-20 clang++-19 clang++-18 clang++-17 clang++-16 clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++)
|
||||||
execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION)
|
execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
|
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
|
||||||
@ -461,6 +461,19 @@ foreach(CXX_STANDARD 11 14 17 20 23)
|
|||||||
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
|
||||||
COMMENT "Compile and test with Clang for C++${CXX_STANDARD}"
|
COMMENT "Compile and test with Clang for C++${CXX_STANDARD}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_custom_target(ci_test_clang_libcxx_cxx${CXX_STANDARD}
|
||||||
|
COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND}
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
|
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||||
|
-DJSON_TestStandards=${CXX_STANDARD}
|
||||||
|
-DCMAKE_CXX_FLAGS="-stdlib=libc++"
|
||||||
|
-DCMAKE_EXE_LINKER_FLAGS="-lc++abi"
|
||||||
|
-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 cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
||||||
|
COMMENT "Compile and test with Clang for C++${CXX_STANDARD} (libc++)"
|
||||||
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -900,7 +913,7 @@ add_custom_target(ci_cmake_flags
|
|||||||
# Use more installed compilers.
|
# Use more installed compilers.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
foreach(COMPILER g++-4.8 g++-4.9 g++-5 g++-6 g++-7 g++-8 g++-9 g++-10 g++-11 clang++-3.5 clang++-3.6 clang++-3.7 clang++-3.8 clang++-3.9 clang++-4.0 clang++-5.0 clang++-6.0 clang++-7 clang++-8 clang++-9 clang++-10 clang++-11 clang++-12 clang++-13 clang++-14 clang++-15 clang++-16 clang++-17)
|
foreach(COMPILER g++-4.8 g++-4.9 g++-5 g++-6 g++-7 g++-8 g++-9 g++-10 g++-11 clang++-3.5 clang++-3.6 clang++-3.7 clang++-3.8 clang++-3.9 clang++-4.0 clang++-5.0 clang++-6.0 clang++-7 clang++-8 clang++-9 clang++-10 clang++-11 clang++-12 clang++-13 clang++-14 clang++-15 clang++-16 clang++-17 clang++-18 clang++-19 clang++-20)
|
||||||
find_program(COMPILER_TOOL NAMES ${COMPILER})
|
find_program(COMPILER_TOOL NAMES ${COMPILER})
|
||||||
if (COMPILER_TOOL)
|
if (COMPILER_TOOL)
|
||||||
unset(ADDITIONAL_FLAGS)
|
unset(ADDITIONAL_FLAGS)
|
||||||
|
@ -621,7 +621,7 @@ TEST_CASE("BSON input/output_adapters")
|
|||||||
{
|
{
|
||||||
SECTION("std::ostringstream")
|
SECTION("std::ostringstream")
|
||||||
{
|
{
|
||||||
std::basic_ostringstream<std::uint8_t> ss;
|
std::basic_ostringstream<char> ss;
|
||||||
json::to_bson(json_representation, ss);
|
json::to_bson(json_representation, ss);
|
||||||
json j3 = json::from_bson(ss.str());
|
json j3 = json::from_bson(ss.str());
|
||||||
CHECK(json_representation == j3);
|
CHECK(json_representation == j3);
|
||||||
|
@ -1880,7 +1880,7 @@ TEST_CASE("single CBOR roundtrip")
|
|||||||
{
|
{
|
||||||
SECTION("std::ostringstream")
|
SECTION("std::ostringstream")
|
||||||
{
|
{
|
||||||
std::basic_ostringstream<std::uint8_t> ss;
|
std::basic_ostringstream<char> ss;
|
||||||
json::to_cbor(j1, ss);
|
json::to_cbor(j1, ss);
|
||||||
json j3 = json::from_cbor(ss.str());
|
json j3 = json::from_cbor(ss.str());
|
||||||
CHECK(j1 == j3);
|
CHECK(j1 == j3);
|
||||||
|
@ -20,6 +20,7 @@ using nlohmann::json;
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <valarray>
|
#include <valarray>
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
struct SaxEventLogger : public nlohmann::json_sax<json>
|
struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||||
@ -1131,13 +1132,15 @@ TEST_CASE("deserialization")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, // NOLINT(readability-math-missing-parentheses)
|
// select the types to test - char8_t is only available in C++20
|
||||||
char, unsigned char, signed char,
|
#define TYPE_LIST(...) __VA_ARGS__
|
||||||
wchar_t,
|
#ifdef JSON_HAS_CPP_20
|
||||||
char16_t, char32_t,
|
#define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t, char8_t)
|
||||||
std::uint8_t, std::int8_t,
|
#else
|
||||||
std::int16_t, std::uint16_t,
|
#define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t)
|
||||||
std::int32_t, std::uint32_t)
|
#endif
|
||||||
|
|
||||||
|
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, ASCII_TYPES) // NOLINT(readability-math-missing-parentheses)
|
||||||
{
|
{
|
||||||
std::vector<T> const v = {'t', 'r', 'u', 'e'};
|
std::vector<T> const v = {'t', 'r', 'u', 'e'};
|
||||||
CHECK(json::parse(v) == json(true));
|
CHECK(json::parse(v) == json(true));
|
||||||
@ -1149,8 +1152,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, //
|
|||||||
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
|
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, // NOLINT(readability-math-missing-parentheses)
|
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, char, unsigned char, std::uint8_t) // NOLINT(readability-math-missing-parentheses)
|
||||||
char, unsigned char, std::uint8_t)
|
|
||||||
{
|
{
|
||||||
// a star emoji
|
// a star emoji
|
||||||
std::vector<T> const v = {'"', static_cast<T>(0xe2u), static_cast<T>(0xadu), static_cast<T>(0x90u), static_cast<T>(0xefu), static_cast<T>(0xb8u), static_cast<T>(0x8fu), '"'};
|
std::vector<T> const v = {'"', static_cast<T>(0xe2u), static_cast<T>(0xadu), static_cast<T>(0x90u), static_cast<T>(0xefu), static_cast<T>(0xb8u), static_cast<T>(0x8fu), '"'};
|
||||||
@ -1162,8 +1164,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, //
|
|||||||
CHECK(l.events.size() == 1);
|
CHECK(l.events.size() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, // NOLINT(readability-math-missing-parentheses)
|
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, char16_t) // NOLINT(readability-math-missing-parentheses)
|
||||||
char16_t, std::uint16_t)
|
|
||||||
{
|
{
|
||||||
// a star emoji
|
// a star emoji
|
||||||
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
|
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
|
||||||
@ -1175,8 +1176,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, /
|
|||||||
CHECK(l.events.size() == 1);
|
CHECK(l.events.size() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, // NOLINT(readability-math-missing-parentheses)
|
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, char32_t) // NOLINT(readability-math-missing-parentheses)
|
||||||
char32_t, std::uint32_t)
|
|
||||||
{
|
{
|
||||||
// a star emoji
|
// a star emoji
|
||||||
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
|
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
|
||||||
|
@ -1604,7 +1604,7 @@ TEST_CASE("single MessagePack roundtrip")
|
|||||||
{
|
{
|
||||||
SECTION("std::ostringstream")
|
SECTION("std::ostringstream")
|
||||||
{
|
{
|
||||||
std::basic_ostringstream<std::uint8_t> ss;
|
std::basic_ostringstream<char> ss;
|
||||||
json::to_msgpack(j1, ss);
|
json::to_msgpack(j1, ss);
|
||||||
json j3 = json::from_msgpack(ss.str());
|
json j3 = json::from_msgpack(ss.str());
|
||||||
CHECK(j1 == j3);
|
CHECK(j1 == j3);
|
||||||
|
@ -675,6 +675,7 @@ TEST_CASE("regression tests 2")
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_20
|
#ifdef JSON_HAS_CPP_20
|
||||||
|
#ifndef _LIBCPP_VERSION // see https://github.com/nlohmann/json/issues/4490
|
||||||
#if __has_include(<span>)
|
#if __has_include(<span>)
|
||||||
SECTION("issue #2546 - parsing containers of std::byte")
|
SECTION("issue #2546 - parsing containers of std::byte")
|
||||||
{
|
{
|
||||||
@ -684,6 +685,7 @@ TEST_CASE("regression tests 2")
|
|||||||
CHECK(j.dump() == "\"Hello, world!\"");
|
CHECK(j.dump() == "\"Hello, world!\"");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SECTION("issue #2574 - Deserialization to std::array, std::pair, and std::tuple with non-default constructable types fails")
|
SECTION("issue #2574 - Deserialization to std::array, std::pair, and std::tuple with non-default constructable types fails")
|
||||||
|
Loading…
Reference in New Issue
Block a user