mirror of
https://github.com/nlohmann/json.git
synced 2026-10-10 08:27:13 +00:00
Two changes roughly halve the CPU time needed to build the unit tests (clang 21: ~300 s -> ~150 s, GCC 16: ~750-820 s -> ~395-420 s, Debug): - Move the C++14/17/20-dependent tests into separate unit-<name>-cpp<N>.cpp files. A test file is built for every standard whose JSON_HAS_CPP_<N> macro it mentions, so far whole large files were rebuilt for C++14/17/20 because of a few #ifdef sections. The main files are now built for C++11 only; the ci_test_*_cxx<N> jobs still build every file for every standard. - Add the CMake option JSON_TestUnityBuild (ON by default, OFF with MinGW): compatible test files are compiled in batches as one translation unit so they share the template instantiations of the library. Each file keeps its own CTest test, which runs the batch executable filtered to that file's test cases. The binary-format tests form an explicit group; the rest is batched by JSON_TestUnityBatchSize. Fix the name clashes that merging files exposed, document the rules for test files in tests/README.md, and point CONTRIBUTING.md to it. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
38 lines
1.6 KiB
C++
38 lines
1.6 KiB
C++
// __ _____ _____ _____
|
|
// __| | __| | | | JSON for Modern C++ (supporting code)
|
|
// | | |__ | | | | | | version 3.12.0
|
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
//
|
|
// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// cmake/test.cmake builds a unit test with C++ standards beyond C++11 only if the
|
|
// source file mentions the corresponding version macro. The regression below only
|
|
// showed on C++17, and the whole file is just this explicit instantiation, so it
|
|
// cannot be split: build this file for every standard like the other regression tests:
|
|
// JSON_HAS_CPP_17 JSON_HAS_CPP_20 (do not remove)
|
|
|
|
#include "doctest_compatibility.h"
|
|
|
|
#include <nlohmann/json.hpp>
|
|
using json = nlohmann::json;
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
// for #4825 - explicitly instantiating basic_json must compile; this
|
|
// forces instantiation of binary_writer::write_bjdata_ndarray, whose
|
|
// static_cast<string_t> was ambiguous under explicit instantiation on
|
|
// C++17. Merely compiling this translation unit is the regression test.
|
|
//
|
|
// The instantiation compiles every member function, so it has a file of its
|
|
// own: in unit-regression3.cpp it made the object too large for the MinGW
|
|
// linker to relocate (see #5511).
|
|
/////////////////////////////////////////////////////////////////////
|
|
template class nlohmann::basic_json<>;
|
|
|
|
TEST_CASE("explicit instantiation of basic_json (#4825)")
|
|
{
|
|
const json j = {1, "two", 3.0};
|
|
CHECK(j.size() == 3);
|
|
CHECK(json::from_bjdata(json::to_bjdata(j)) == j);
|
|
}
|