Add ABI tests
This commit is contained in:
parent
a752d1c35d
commit
2fd7d25420
@ -25,5 +25,6 @@ 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
tests/abi/config/CMakeLists.txt
Normal file
22
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})
|
||||
27
tests/abi/config/config.hpp
Normal file
27
tests/abi/config/config.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
#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();
|
||||
}
|
||||
25
tests/abi/config/custom.cpp
Normal file
25
tests/abi/config/custom.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#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
|
||||
std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
|
||||
|
||||
CHECK(namespace_name<nlohmann::json>(ns) == expected);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
33
tests/abi/config/default.cpp
Normal file
33
tests/abi/config/default.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#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
|
||||
std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
|
||||
|
||||
CHECK(namespace_name<nlohmann::json>(ns) == expected);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
32
tests/abi/config/noversion.cpp
Normal file
32
tests/abi/config/noversion.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#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
|
||||
std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
|
||||
|
||||
CHECK(namespace_name<nlohmann::json>(ns) == expected);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -36,8 +36,8 @@ SOFTWARE.
|
||||
* file doc/README.md. *
|
||||
\****************************************************************************/
|
||||
|
||||
#ifndef INCLUDE_NLOHMANN_JSON_HPP_
|
||||
#define INCLUDE_NLOHMANN_JSON_HPP_
|
||||
#ifndef INCLUDE_NLOHMANN_JSON_V3_10_5_HPP_
|
||||
#define INCLUDE_NLOHMANN_JSON_V3_10_5_HPP_
|
||||
|
||||
#define NLOHMANN_JSON_VERSION_MAJOR 3
|
||||
#define NLOHMANN_JSON_VERSION_MINOR 10
|
||||
@ -22088,4 +22088,4 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
|
||||
|
||||
|
||||
|
||||
#endif // INCLUDE_NLOHMANN_JSON_HPP_
|
||||
#endif // INCLUDE_NLOHMANN_JSON_V3_10_5_HPP_
|
||||
|
||||
Loading…
Reference in New Issue
Block a user