Print JSON meta at the start of each unit test
This commit is contained in:
parent
77baab32e6
commit
c24067e5fc
@ -148,7 +148,18 @@ function(_json_test_add_test test_name file main cxx_standard)
|
||||
message(FATAL_ERROR "Target ${test_target} has already been added.")
|
||||
endif()
|
||||
|
||||
file(READ ${file} file_content)
|
||||
string(REGEX MATCH "[\n\r \t]+#[ \t]*include[ \t]+\"print_meta.cpp\"" match_result "${file_content}")
|
||||
if(NOT match_result)
|
||||
message(FATAL_ERROR "Please append\n"
|
||||
"#include \"print_meta.cpp\" // NOLINT(bugprone-suspicious-include)\n"
|
||||
"to the end of file: ${file}")
|
||||
endif()
|
||||
|
||||
# add test executable
|
||||
add_executable(${test_target} ${file})
|
||||
# add parentheses to silence clang-tidy warning
|
||||
target_compile_definitions(${test_target} PRIVATE "JSON_TEST_NAME=(${test_target})")
|
||||
target_link_libraries(${test_target} PRIVATE ${main})
|
||||
|
||||
# set and require C++ standard
|
||||
|
||||
44
tests/src/print_meta.cpp
Normal file
44
tests/src/print_meta.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.10.5
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#ifdef JSON_TEST_PRINT_META_WITH_MAIN
|
||||
#include <nlohmann/json.hpp>
|
||||
#endif
|
||||
|
||||
#define STRINGIZE_EX(x) #x
|
||||
#define STRINGIZE(x) STRINGIZE_EX(x)
|
||||
|
||||
void print_meta();
|
||||
|
||||
void print_meta()
|
||||
{
|
||||
auto meta = nlohmann::ordered_json::meta();
|
||||
meta.erase("name");
|
||||
meta.erase("url");
|
||||
meta.erase("copyright");
|
||||
meta["version"] = meta["version"]["string"];
|
||||
|
||||
// strip off the parentheses added to silence clang-tidy warning
|
||||
auto strip_parens = [](const std::string & str)
|
||||
{
|
||||
return (str[0] == '(') ? std::string(str.data() + 1, str.size() - 2) : str;
|
||||
};
|
||||
std::cout << strip_parens(STRINGIZE(JSON_TEST_NAME)) << '\n';
|
||||
std::cout << meta.dump(4) << '\n' << std::endl;
|
||||
}
|
||||
|
||||
#ifdef JSON_TEST_PRINT_META_WITH_MAIN
|
||||
int main(int /*argc*/, char* /*argv*/[])
|
||||
{
|
||||
print_meta();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@ -134,3 +134,5 @@ TEST_CASE("BJData")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -295,3 +295,5 @@ TEST_CASE("algorithms")
|
||||
CHECK(j_array == json({false, true, 3, 13, 29, {{"one", 1}, {"two", 2}}, {1, 2, 3}, "baz", "foo"}));
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -252,3 +252,5 @@ TEST_CASE("bad my_allocator::construct")
|
||||
j["test"].push_back("should not leak");
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -322,3 +322,5 @@ TEST_CASE("alternative string type")
|
||||
CHECK(j.at(alt_json::json_pointer("/foo/1")) == j["foo"][1]);
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -46,3 +46,5 @@ TEST_CASE("JSON_ASSERT(x)")
|
||||
|
||||
DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -209,3 +209,5 @@ TEST_CASE("Binary Formats" * doctest::skip())
|
||||
CHECK((100.0 * double(ubjson_3_size) / double(json_size)) == Approx(89.450));
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -3547,3 +3547,5 @@ TEST_CASE("BJData roundtrips" * doctest::skip())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1296,3 +1296,5 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -75,3 +75,5 @@ TEST_CASE("byte_container_with_subtype")
|
||||
CHECK(container2 == container4);
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -541,3 +541,5 @@ TEST_CASE("capacity")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -2665,3 +2665,5 @@ TEST_CASE("Tagged values")
|
||||
CHECK(!jb["binary"].get_binary().has_subtype());
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -391,3 +391,5 @@ TEST_CASE("const_iterator class")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -466,3 +466,5 @@ TEST_CASE("iterator class")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -224,3 +224,5 @@ TEST_CASE("lexer class")
|
||||
CHECK((scan_string("/**//**//**/", true) == json::lexer::token_type::end_of_input));
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1689,3 +1689,5 @@ TEST_CASE("parser class")
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("/*", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid comment; missing closing '*/'; last read: '/*<U+0000>'", json::parse_error);
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -593,3 +593,5 @@ TEST_CASE("lexicographical comparison operators")
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -148,3 +148,5 @@ TEST_CASE("concepts")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1569,3 +1569,5 @@ TEST_CASE("constructors")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -184,3 +184,5 @@ TEST_CASE("other constructors and destructor")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -203,3 +203,5 @@ TEST_CASE("convenience functions")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1570,3 +1570,5 @@ TEST_CASE("JSON to enum mapping")
|
||||
}
|
||||
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1187,3 +1187,5 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T,
|
||||
CHECK(json::sax_parse(v, &l));
|
||||
CHECK(l.events.size() == 1);
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -244,3 +244,5 @@ TEST_CASE("Regression tests for extended diagnostics")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -50,3 +50,5 @@ TEST_CASE("Tests with disabled exceptions")
|
||||
}
|
||||
|
||||
DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -879,3 +879,5 @@ TEST_CASE("element access 1")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1488,3 +1488,5 @@ TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nl
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -111,3 +111,5 @@ TEST_CASE("hash<nlohmann::ordered_json>")
|
||||
|
||||
CHECK(hashes.size() == 21);
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -457,3 +457,5 @@ TEST_CASE("object inspection")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1431,3 +1431,5 @@ TEST_CASE("items()")
|
||||
|
||||
DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1628,3 +1628,5 @@ TEST_CASE("iterators 1")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -970,3 +970,5 @@ TEST_CASE("iterators 2")
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1319,3 +1319,5 @@ TEST_CASE("JSON patch")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -699,3 +699,5 @@ TEST_CASE("JSON pointers")
|
||||
CHECK_FALSE(ptr != ptr_oj);
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -27,3 +27,5 @@ TEST_CASE("tests on very large JSONs")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -242,3 +242,5 @@ TEST_CASE("JSON Merge Patch")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -34,3 +34,5 @@ TEST_CASE("version information")
|
||||
CHECK(j.at("compiler").find("c++") != j.at("compiler").end());
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -951,3 +951,5 @@ TEST_CASE("modifiers")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1835,3 +1835,5 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -80,3 +80,5 @@ TEST_CASE("runtime checks")
|
||||
}
|
||||
|
||||
DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -70,3 +70,5 @@ TEST_CASE("ordered_json")
|
||||
CHECK(oj1.size() == 4);
|
||||
CHECK(oj1.dump() == "{\"c\":1,\"b\":2,\"a\":3,\"d\":42}");
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -309,3 +309,5 @@ TEST_CASE("ordered_map")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -477,3 +477,5 @@ TEST_CASE("pointer access")
|
||||
CHECK(value.get_ptr<const json::binary_t*>() != nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -303,3 +303,5 @@ TEST_CASE("README" * doctest::skip())
|
||||
}
|
||||
|
||||
DOCTEST_MSVC_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -245,3 +245,5 @@ TEST_CASE("reference access")
|
||||
CHECK_NOTHROW(value.get_ref<json::number_float_t&>());
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1511,3 +1511,5 @@ template <typename T> class number_integer {};
|
||||
template <typename T> class number_unsigned {};
|
||||
template <typename T> class number_float {};
|
||||
#endif
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -926,3 +926,5 @@ TEST_CASE("regression tests 2")
|
||||
}
|
||||
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -295,3 +295,5 @@ TEST_CASE("dump with binary values")
|
||||
"]");
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -1389,3 +1389,5 @@ TEST_CASE("Big List of Naughty Strings")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -514,3 +514,5 @@ TEST_CASE("formatting")
|
||||
check_integer(1000000000000000000LL, "1000000000000000000");
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -2515,3 +2515,5 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -55,3 +55,5 @@ TEST_CASE("user-defined string literals")
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -862,3 +862,5 @@ TEST_CASE("compatible array type, without iterator type alias")
|
||||
}
|
||||
|
||||
DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -412,3 +412,5 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -618,3 +618,5 @@ TEST_CASE("Markus Kuhn's UTF-8 decoder capability and stress test")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -608,3 +608,5 @@ TEST_CASE("Unicode (2/5)" * doctest::skip())
|
||||
}
|
||||
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -322,3 +322,5 @@ TEST_CASE("Unicode (3/5)" * doctest::skip())
|
||||
}
|
||||
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -322,3 +322,5 @@ TEST_CASE("Unicode (4/5)" * doctest::skip())
|
||||
}
|
||||
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -322,3 +322,5 @@ TEST_CASE("Unicode (5/5)" * doctest::skip())
|
||||
}
|
||||
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -128,3 +128,5 @@ TEST_CASE("Custom iterator")
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -19,3 +19,5 @@ TEST_CASE("include windows.h")
|
||||
{
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -97,3 +97,5 @@ TEST_CASE("wide strings")
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include)
|
||||
|
||||
@ -6,5 +6,17 @@
|
||||
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#define DOCTEST_CONFIG_IMPLEMENT
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
// defined in print_meta.cpp which is automatically appended to each unit test
|
||||
extern void print_meta();
|
||||
|
||||
DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4007)
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
print_meta();
|
||||
|
||||
return doctest::Context(argc, argv).run();
|
||||
}
|
||||
DOCTEST_MSVC_SUPPRESS_WARNING_POP
|
||||
|
||||
Loading…
Reference in New Issue
Block a user