mirror of
https://github.com/minetest/irrlicht.git
synced 2025-07-12 21:30:20 +02:00
Dump the entire json library in
This commit is contained in:
30
source/Irrlicht/lib/json/tests/abi/CMakeLists.txt
Normal file
30
source/Irrlicht/lib/json/tests/abi/CMakeLists.txt
Normal file
@ -0,0 +1,30 @@
|
||||
# common build settings
|
||||
add_library(abi_compat_common INTERFACE)
|
||||
target_compile_definitions(abi_compat_common INTERFACE
|
||||
DOCTEST_CONFIG_SUPER_FAST_ASSERTS
|
||||
JSON_TEST_KEEP_MACROS)
|
||||
target_compile_features(abi_compat_common INTERFACE cxx_std_11)
|
||||
target_compile_options(abi_compat_common INTERFACE
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
|
||||
# MSVC: Force to always compile with W4
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/W4>
|
||||
|
||||
# https://github.com/nlohmann/json/pull/3229
|
||||
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=2196>
|
||||
|
||||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
|
||||
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
||||
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=1786>)
|
||||
target_include_directories(abi_compat_common SYSTEM INTERFACE
|
||||
../thirdparty/doctest
|
||||
include)
|
||||
target_link_libraries(abi_compat_common INTERFACE ${NLOHMANN_JSON_TARGET_NAME})
|
||||
|
||||
# shared main()
|
||||
add_library(abi_compat_main STATIC main.cpp)
|
||||
target_link_libraries(abi_compat_main PUBLIC abi_compat_common)
|
||||
|
||||
# add individual tests
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(diag)
|
||||
add_subdirectory(inline_ns)
|
22
source/Irrlicht/lib/json/tests/abi/config/CMakeLists.txt
Normal file
22
source/Irrlicht/lib/json/tests/abi/config/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
||||
# test the different options to change the namespace
|
||||
|
||||
# test default namespace
|
||||
add_executable(abi_config_default default.cpp)
|
||||
target_link_libraries(abi_config_default PRIVATE abi_compat_main)
|
||||
add_test(
|
||||
NAME test-abi_config_default
|
||||
COMMAND abi_config_default ${DOCTEST_TEST_FILTER})
|
||||
|
||||
# test no version namespace
|
||||
add_executable(abi_config_noversion noversion.cpp)
|
||||
target_link_libraries(abi_config_noversion PRIVATE abi_compat_main)
|
||||
add_test(
|
||||
NAME test-abi_config_noversion
|
||||
COMMAND abi_config_noversion ${DOCTEST_TEST_FILTER})
|
||||
|
||||
# test custom namespace
|
||||
add_executable(abi_config_custom custom.cpp)
|
||||
target_link_libraries(abi_config_custom PRIVATE abi_compat_main)
|
||||
add_test(
|
||||
NAME test-abi_config_custom
|
||||
COMMAND abi_config_custom ${DOCTEST_TEST_FILTER})
|
35
source/Irrlicht/lib/json/tests/abi/config/config.hpp
Normal file
35
source/Irrlicht/lib/json/tests/abi/config/config.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.2
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "doctest.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
#define STRINGIZE_EX(x) #x
|
||||
#define STRINGIZE(x) STRINGIZE_EX(x)
|
||||
|
||||
template<typename T>
|
||||
std::string namespace_name(std::string ns, T* /*unused*/ = nullptr) // NOLINT(performance-unnecessary-value-param)
|
||||
{
|
||||
#if DOCTEST_MSVC && !DOCTEST_CLANG
|
||||
ns = __FUNCSIG__;
|
||||
#elif !DOCTEST_CLANG
|
||||
ns = __PRETTY_FUNCTION__;
|
||||
#endif
|
||||
std::smatch m;
|
||||
|
||||
// extract the true namespace name from the function signature
|
||||
CAPTURE(ns);
|
||||
CHECK(std::regex_search(ns, m, std::regex("nlohmann(::[a-zA-Z0-9_]+)*::basic_json")));
|
||||
|
||||
return m.str();
|
||||
}
|
33
source/Irrlicht/lib/json/tests/abi/config/custom.cpp
Normal file
33
source/Irrlicht/lib/json/tests/abi/config/custom.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.2
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
// define custom namespace
|
||||
#define NLOHMANN_JSON_NAMESPACE nlohmann // this line may be omitted
|
||||
#define NLOHMANN_JSON_NAMESPACE_BEGIN namespace nlohmann {
|
||||
#define NLOHMANN_JSON_NAMESPACE_END }
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
TEST_CASE("custom namespace")
|
||||
{
|
||||
// GCC 4.8 fails with regex_error
|
||||
#if !DOCTEST_GCC || DOCTEST_GCC >= DOCTEST_COMPILER(4, 9, 0)
|
||||
SECTION("namespace matches expectation")
|
||||
{
|
||||
std::string expected = "nlohmann::basic_json";
|
||||
|
||||
// fallback for Clang
|
||||
const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
|
||||
|
||||
CHECK(namespace_name<nlohmann::json>(ns) == expected);
|
||||
}
|
||||
#endif
|
||||
}
|
41
source/Irrlicht/lib/json/tests/abi/config/default.cpp
Normal file
41
source/Irrlicht/lib/json/tests/abi/config/default.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.2
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
TEST_CASE("default namespace")
|
||||
{
|
||||
// GCC 4.8 fails with regex_error
|
||||
#if !DOCTEST_GCC || DOCTEST_GCC >= DOCTEST_COMPILER(4, 9, 0)
|
||||
SECTION("namespace matches expectation")
|
||||
{
|
||||
std::string expected = "nlohmann::json_abi";
|
||||
|
||||
#if JSON_DIAGNOSTICS
|
||||
expected += "_diag";
|
||||
#endif
|
||||
|
||||
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
|
||||
expected += "_ldvcmp";
|
||||
#endif
|
||||
|
||||
expected += "_v" STRINGIZE(NLOHMANN_JSON_VERSION_MAJOR);
|
||||
expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_MINOR);
|
||||
expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_PATCH) "::basic_json";
|
||||
|
||||
// fallback for Clang
|
||||
const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
|
||||
|
||||
CHECK(namespace_name<nlohmann::json>(ns) == expected);
|
||||
}
|
||||
#endif
|
||||
}
|
40
source/Irrlicht/lib/json/tests/abi/config/noversion.cpp
Normal file
40
source/Irrlicht/lib/json/tests/abi/config/noversion.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.2
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 1
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
TEST_CASE("default namespace without version component")
|
||||
{
|
||||
// GCC 4.8 fails with regex_error
|
||||
#if !DOCTEST_GCC || DOCTEST_GCC >= DOCTEST_COMPILER(4, 9, 0)
|
||||
SECTION("namespace matches expectation")
|
||||
{
|
||||
std::string expected = "nlohmann::json_abi";
|
||||
|
||||
#if JSON_DIAGNOSTICS
|
||||
expected += "_diag";
|
||||
#endif
|
||||
|
||||
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
|
||||
expected += "_ldvcmp";
|
||||
#endif
|
||||
|
||||
expected += "::basic_json";
|
||||
|
||||
// fallback for Clang
|
||||
const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
|
||||
|
||||
CHECK(namespace_name<nlohmann::json>(ns) == expected);
|
||||
}
|
||||
#endif
|
||||
}
|
19
source/Irrlicht/lib/json/tests/abi/diag/CMakeLists.txt
Normal file
19
source/Irrlicht/lib/json/tests/abi/diag/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
||||
# test linking library built with different JSON_DIAGNOSTICS setting
|
||||
# into the same executable
|
||||
|
||||
# compile code using JSON_DIAGNOSTICS=1
|
||||
add_library(abi_compat_diag_on STATIC diag_on.cpp)
|
||||
target_link_libraries(abi_compat_diag_on PUBLIC abi_compat_common)
|
||||
|
||||
# compile code using JSON_DIAGNOSTICS=0
|
||||
add_library(abi_compat_diag_off STATIC diag_off.cpp)
|
||||
target_link_libraries(abi_compat_diag_off PUBLIC abi_compat_common)
|
||||
|
||||
# build test executable and add test
|
||||
add_executable(abi_compat_diag diag.cpp)
|
||||
target_link_libraries(abi_compat_diag PRIVATE
|
||||
abi_compat_main abi_compat_diag_on abi_compat_diag_off)
|
||||
|
||||
add_test(
|
||||
NAME test-abi_compat_diag
|
||||
COMMAND abi_compat_diag ${DOCTEST_TEST_FILTER})
|
29
source/Irrlicht/lib/json/tests/abi/diag/diag.cpp
Normal file
29
source/Irrlicht/lib/json/tests/abi/diag/diag.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.2
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include "diag.hpp"
|
||||
|
||||
TEST_CASE("ABI compatible diagnostics")
|
||||
{
|
||||
SECTION("basic_json size")
|
||||
{
|
||||
// basic_json with diagnostics is larger because of added data members
|
||||
CHECK(json_sizeof_diag_on() == json_sizeof_diag_on_explicit());
|
||||
CHECK(json_sizeof_diag_off() == json_sizeof_diag_off_explicit());
|
||||
CHECK(json_sizeof_diag_on() > json_sizeof_diag_off());
|
||||
}
|
||||
|
||||
SECTION("basic_json at")
|
||||
{
|
||||
// accessing a nonexistent key throws different exception with diagnostics
|
||||
CHECK_THROWS_WITH(json_at_diag_on(), "[json.exception.out_of_range.403] (/foo) key 'bar' not found");
|
||||
CHECK_THROWS_WITH(json_at_diag_off(), "[json.exception.out_of_range.403] key 'bar' not found");
|
||||
}
|
||||
}
|
20
source/Irrlicht/lib/json/tests/abi/diag/diag.hpp
Normal file
20
source/Irrlicht/lib/json/tests/abi/diag/diag.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.2
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
std::size_t json_sizeof_diag_on();
|
||||
std::size_t json_sizeof_diag_on_explicit();
|
||||
|
||||
std::size_t json_sizeof_diag_off();
|
||||
std::size_t json_sizeof_diag_off_explicit();
|
||||
|
||||
void json_at_diag_on();
|
||||
void json_at_diag_off();
|
30
source/Irrlicht/lib/json/tests/abi/diag/diag_off.cpp
Normal file
30
source/Irrlicht/lib/json/tests/abi/diag/diag_off.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.2
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#undef JSON_DIAGNOSTICS
|
||||
#define JSON_DIAGNOSTICS 0
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "diag.hpp"
|
||||
|
||||
std::size_t json_sizeof_diag_off()
|
||||
{
|
||||
return sizeof(nlohmann::json);
|
||||
}
|
||||
|
||||
std::size_t json_sizeof_diag_off_explicit()
|
||||
{
|
||||
return sizeof(::NLOHMANN_JSON_NAMESPACE::json);
|
||||
}
|
||||
|
||||
void json_at_diag_off()
|
||||
{
|
||||
using nlohmann::json;
|
||||
json j = json{{"foo", json::object()}};
|
||||
j.at(json::json_pointer("/foo/bar"));
|
||||
}
|
30
source/Irrlicht/lib/json/tests/abi/diag/diag_on.cpp
Normal file
30
source/Irrlicht/lib/json/tests/abi/diag/diag_on.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.2
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#undef JSON_DIAGNOSTICS
|
||||
#define JSON_DIAGNOSTICS 1
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "diag.hpp"
|
||||
|
||||
std::size_t json_sizeof_diag_on()
|
||||
{
|
||||
return sizeof(nlohmann::json);
|
||||
}
|
||||
|
||||
std::size_t json_sizeof_diag_on_explicit()
|
||||
{
|
||||
return sizeof(::NLOHMANN_JSON_NAMESPACE::json);
|
||||
}
|
||||
|
||||
void json_at_diag_on()
|
||||
{
|
||||
using nlohmann::json;
|
||||
json j = json{{"foo", json::object()}};
|
||||
j.at(json::json_pointer("/foo/bar"));
|
||||
}
|
22091
source/Irrlicht/lib/json/tests/abi/include/nlohmann/json_v3_10_5.hpp
Normal file
22091
source/Irrlicht/lib/json/tests/abi/include/nlohmann/json_v3_10_5.hpp
Normal file
File diff suppressed because it is too large
Load Diff
12
source/Irrlicht/lib/json/tests/abi/inline_ns/CMakeLists.txt
Normal file
12
source/Irrlicht/lib/json/tests/abi/inline_ns/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
# test linking an old library version without an inline namespace
|
||||
# with the current library using an inline namespace into the same executable
|
||||
|
||||
# build test executable and add test
|
||||
add_executable(abi_compat_inline_ns
|
||||
use_v3_10_5.cpp
|
||||
use_current.cpp)
|
||||
target_link_libraries(abi_compat_inline_ns PRIVATE abi_compat_main)
|
||||
|
||||
add_test(
|
||||
NAME test-abi_compat_inline_ns
|
||||
COMMAND abi_compat_inline_ns ${DOCTEST_TEST_FILTER})
|
36
source/Irrlicht/lib/json/tests/abi/inline_ns/use_current.cpp
Normal file
36
source/Irrlicht/lib/json/tests/abi/inline_ns/use_current.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.2
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
TEST_CASE("use current library with inline namespace")
|
||||
{
|
||||
SECTION("implicitly")
|
||||
{
|
||||
using nlohmann::json;
|
||||
using nlohmann::ordered_json;
|
||||
|
||||
json j;
|
||||
// In v3.10.5 mixing json_pointers of different basic_json types
|
||||
// results in implicit string conversion
|
||||
j[ordered_json::json_pointer("/root")] = json::object();
|
||||
CHECK(j.dump() == "{\"root\":{}}");
|
||||
}
|
||||
|
||||
SECTION("explicitly")
|
||||
{
|
||||
using NLOHMANN_JSON_NAMESPACE::json;
|
||||
using NLOHMANN_JSON_NAMESPACE::ordered_json;
|
||||
|
||||
json j;
|
||||
j[ordered_json::json_pointer("/root")] = json::object();
|
||||
CHECK(j.dump() == "{\"root\":{}}");
|
||||
}
|
||||
}
|
22
source/Irrlicht/lib/json/tests/abi/inline_ns/use_v3_10_5.cpp
Normal file
22
source/Irrlicht/lib/json/tests/abi/inline_ns/use_v3_10_5.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.2
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <nlohmann/json_v3_10_5.hpp>
|
||||
using nlohmann::json;
|
||||
using nlohmann::ordered_json;
|
||||
|
||||
TEST_CASE("use library v3.10.5 without inline namespace")
|
||||
{
|
||||
json j;
|
||||
j[ordered_json::json_pointer("/root")] = json::object();
|
||||
// In v3.10.5 mixing json_pointers of different basic_json types
|
||||
// results in implicit string conversion
|
||||
CHECK(j.dump() == "{\"/root\":{}}");
|
||||
}
|
11
source/Irrlicht/lib/json/tests/abi/main.cpp
Normal file
11
source/Irrlicht/lib/json/tests/abi/main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.2
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest_compatibility.h"
|
Reference in New Issue
Block a user