Skip to content

Commit e3ac5a6

Browse files
authored
Add test for libstdc++ (#4495)
* 👷 add test for libstdc++ * 👷 add test for libstdc++ * 💚 add fixes from #4490 * 💚 add fixes from #4490
1 parent e509007 commit e3ac5a6

File tree

7 files changed

+50
-28
lines changed

7 files changed

+50
-28
lines changed

.github/workflows/ubuntu.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
run: apt-get update ; apt-get install -y git unzip
2626
- uses: actions/checkout@v4
2727
- name: Get latest CMake and ninja
28-
uses: lukka/get-cmake@v3.27.7
28+
uses: lukka/get-cmake@v3.31.0
2929
- name: Run CMake
3030
run: cmake -S . -B build -DJSON_CI=On
3131
- name: Build
@@ -62,7 +62,7 @@ jobs:
6262
steps:
6363
- uses: actions/checkout@v4
6464
- name: Get latest CMake and ninja
65-
uses: lukka/get-cmake@v3.27.7
65+
uses: lukka/get-cmake@v3.31.0
6666
- name: Run CMake
6767
run: cmake -S . -B build -DJSON_CI=On
6868
- name: Build
@@ -79,7 +79,7 @@ jobs:
7979
run: apt-get update ; apt-get install -y git clang-tools unzip
8080
- uses: actions/checkout@v4
8181
- name: Get latest CMake and ninja
82-
uses: lukka/get-cmake@v3.27.7
82+
uses: lukka/get-cmake@v3.31.0
8383
- name: Run CMake
8484
run: cmake -S . -B build -DJSON_CI=On
8585
- name: Build
@@ -96,7 +96,7 @@ jobs:
9696
run: apt-get update ; apt-get install -y build-essential unzip wget git
9797
- uses: actions/checkout@v4
9898
- name: Get latest CMake and ninja
99-
uses: lukka/get-cmake@v3.27.7
99+
uses: lukka/get-cmake@v3.31.0
100100
- name: Run CMake
101101
run: cmake -S . -B build -DJSON_CI=On
102102
- name: Build
@@ -148,7 +148,7 @@ jobs:
148148
steps:
149149
- uses: actions/checkout@v4
150150
- name: Get latest CMake and ninja
151-
uses: lukka/get-cmake@v3.27.7
151+
uses: lukka/get-cmake@v3.31.0
152152
- name: Run CMake
153153
run: cmake -S . -B build -DJSON_CI=On
154154
- name: Build
@@ -165,7 +165,7 @@ jobs:
165165
run: apt-get update ; apt-get install -y unzip git
166166
- uses: actions/checkout@v4
167167
- name: Get latest CMake and ninja
168-
uses: lukka/get-cmake@v3.27.7
168+
uses: lukka/get-cmake@v3.31.0
169169
- name: Set env FORCE_STDCPPFS_FLAG for clang 7 / 8 / 9 / 10
170170
run: echo "JSON_FORCED_GLOBAL_COMPILE_OPTIONS=-DJSON_HAS_FILESYSTEM=0;-DJSON_HAS_EXPERIMENTAL_FILESYSTEM=0" >> "$GITHUB_ENV"
171171
if: ${{ matrix.compiler == '7' || matrix.compiler == '8' || matrix.compiler == '9' || matrix.compiler == '10' }}
@@ -206,16 +206,21 @@ jobs:
206206
strategy:
207207
matrix:
208208
standard: [11, 14, 17, 20, 23]
209+
stdlib: [libcxx, libstdcxx]
209210
steps:
210211
- name: Install git and unzip
211212
run: apt-get update ; apt-get install -y git unzip
212213
- uses: actions/checkout@v4
213214
- name: Get latest CMake and ninja
214-
uses: lukka/get-cmake@v3.27.7
215+
uses: lukka/get-cmake@v3.31.0
215216
- name: Run CMake
216217
run: cmake -S . -B build -DJSON_CI=On
217-
- name: Build
218+
- name: Build with libc++
219+
run: cmake --build build --target ci_test_clang_libcxx_cxx${{ matrix.standard }}
220+
if: ${{ matrix.stdlib == 'libcxx' }}
221+
- name: Build with libstdc++
218222
run: cmake --build build --target ci_test_clang_cxx${{ matrix.standard }}
223+
if: ${{ matrix.stdlib == 'libstdcxx' }}
219224

220225
ci_cuda_example:
221226
runs-on: ubuntu-latest
@@ -231,7 +236,7 @@ jobs:
231236
runs-on: ubuntu-latest
232237
container: ghcr.io/nlohmann/json-ci:v2.2.0
233238
steps:
234-
- uses: actions/checkout@v2
239+
- uses: actions/checkout@v4
235240
- name: Run CMake
236241
run: cmake -S . -B build -DJSON_CI=On
237242
- name: Build
@@ -243,7 +248,9 @@ jobs:
243248
runs-on: ubuntu-latest
244249
steps:
245250
- uses: actions/checkout@v4
246-
- uses: actions/setup-python@v3
251+
- uses: actions/setup-python@v5
252+
with:
253+
python-version: '3.11'
247254
- name: Install REUSE tool
248255
run: python -m pip install reuse
249256
- name: Run REUSE lint

cmake/ci.cmake

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ execute_process(COMMAND ${ASTYLE_TOOL} --version OUTPUT_VARIABLE ASTYLE_TOOL_VER
1313
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" ASTYLE_TOOL_VERSION "${ASTYLE_TOOL_VERSION}")
1414
message(STATUS "🔖 Artistic Style ${ASTYLE_TOOL_VERSION} (${ASTYLE_TOOL})")
1515

16-
find_program(CLANG_TOOL NAMES clang++-HEAD clang++ clang++-17 clang++-16 clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++)
16+
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++)
1717
execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION)
1818
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
1919
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
@@ -461,6 +461,19 @@ foreach(CXX_STANDARD 11 14 17 20 23)
461461
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
462462
COMMENT "Compile and test with Clang for C++${CXX_STANDARD}"
463463
)
464+
465+
add_custom_target(ci_test_clang_libcxx_cxx${CXX_STANDARD}
466+
COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND}
467+
-DCMAKE_BUILD_TYPE=Debug -GNinja
468+
-DJSON_BuildTests=ON -DJSON_FastTests=ON
469+
-DJSON_TestStandards=${CXX_STANDARD}
470+
-DCMAKE_CXX_FLAGS="-stdlib=libc++"
471+
-DCMAKE_EXE_LINKER_FLAGS="-lc++abi"
472+
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
473+
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
474+
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
475+
COMMENT "Compile and test with Clang for C++${CXX_STANDARD} (libc++)"
476+
)
464477
endforeach()
465478

466479
###############################################################################
@@ -900,7 +913,7 @@ add_custom_target(ci_cmake_flags
900913
# Use more installed compilers.
901914
###############################################################################
902915

903-
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)
916+
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)
904917
find_program(COMPILER_TOOL NAMES ${COMPILER})
905918
if (COMPILER_TOOL)
906919
unset(ADDITIONAL_FLAGS)

tests/src/unit-bson.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ TEST_CASE("BSON input/output_adapters")
621621
{
622622
SECTION("std::ostringstream")
623623
{
624-
std::basic_ostringstream<std::uint8_t> ss;
624+
std::basic_ostringstream<char> ss;
625625
json::to_bson(json_representation, ss);
626626
json j3 = json::from_bson(ss.str());
627627
CHECK(json_representation == j3);

tests/src/unit-cbor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ TEST_CASE("single CBOR roundtrip")
18801880
{
18811881
SECTION("std::ostringstream")
18821882
{
1883-
std::basic_ostringstream<std::uint8_t> ss;
1883+
std::basic_ostringstream<char> ss;
18841884
json::to_cbor(j1, ss);
18851885
json j3 = json::from_cbor(ss.str());
18861886
CHECK(j1 == j3);

tests/src/unit-deserialization.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using nlohmann::json;
2020
#include <sstream>
2121
#include <valarray>
2222

23+
2324
namespace
2425
{
2526
struct SaxEventLogger : public nlohmann::json_sax<json>
@@ -1131,13 +1132,15 @@ TEST_CASE("deserialization")
11311132
}
11321133
}
11331134

1134-
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, // NOLINT(readability-math-missing-parentheses)
1135-
char, unsigned char, signed char,
1136-
wchar_t,
1137-
char16_t, char32_t,
1138-
std::uint8_t, std::int8_t,
1139-
std::int16_t, std::uint16_t,
1140-
std::int32_t, std::uint32_t)
1135+
// select the types to test - char8_t is only available in C++20
1136+
#define TYPE_LIST(...) __VA_ARGS__
1137+
#ifdef JSON_HAS_CPP_20
1138+
#define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t, char8_t)
1139+
#else
1140+
#define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t)
1141+
#endif
1142+
1143+
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, ASCII_TYPES) // NOLINT(readability-math-missing-parentheses)
11411144
{
11421145
std::vector<T> const v = {'t', 'r', 'u', 'e'};
11431146
CHECK(json::parse(v) == json(true));
@@ -1149,8 +1152,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, //
11491152
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
11501153
}
11511154

1152-
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, // NOLINT(readability-math-missing-parentheses)
1153-
char, unsigned char, std::uint8_t)
1155+
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, char, unsigned char, std::uint8_t) // NOLINT(readability-math-missing-parentheses)
11541156
{
11551157
// a star emoji
11561158
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, //
11621164
CHECK(l.events.size() == 1);
11631165
}
11641166

1165-
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, // NOLINT(readability-math-missing-parentheses)
1166-
char16_t, std::uint16_t)
1167+
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, char16_t) // NOLINT(readability-math-missing-parentheses)
11671168
{
11681169
// a star emoji
11691170
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, /
11751176
CHECK(l.events.size() == 1);
11761177
}
11771178

1178-
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, // NOLINT(readability-math-missing-parentheses)
1179-
char32_t, std::uint32_t)
1179+
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, char32_t) // NOLINT(readability-math-missing-parentheses)
11801180
{
11811181
// a star emoji
11821182
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};

tests/src/unit-msgpack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ TEST_CASE("single MessagePack roundtrip")
16041604
{
16051605
SECTION("std::ostringstream")
16061606
{
1607-
std::basic_ostringstream<std::uint8_t> ss;
1607+
std::basic_ostringstream<char> ss;
16081608
json::to_msgpack(j1, ss);
16091609
json j3 = json::from_msgpack(ss.str());
16101610
CHECK(j1 == j3);

tests/src/unit-regression2.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ TEST_CASE("regression tests 2")
675675
}
676676

677677
#ifdef JSON_HAS_CPP_20
678+
#ifndef _LIBCPP_VERSION // see https://github.com/nlohmann/json/issues/4490
678679
#if __has_include(<span>)
679680
SECTION("issue #2546 - parsing containers of std::byte")
680681
{
@@ -684,6 +685,7 @@ TEST_CASE("regression tests 2")
684685
CHECK(j.dump() == "\"Hello, world!\"");
685686
}
686687
#endif
688+
#endif
687689
#endif
688690

689691
SECTION("issue #2574 - Deserialization to std::array, std::pair, and std::tuple with non-default constructable types fails")

0 commit comments

Comments
 (0)