1//     __ _____ _____ _____
2//  __|  |   __|     |   | |  JSON for Modern C++ (supporting code)
3// |  |  |__   |  |  | | | |  version 3.11.2
4// |_____|_____|_____|_|___|  https://github.com/nlohmann/json
5//
6// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
7// SPDX-License-Identifier: MIT
8
9#include "doctest_compatibility.h"
10
11// avoid warning when assert does not abort
12DOCTEST_GCC_SUPPRESS_WARNING_PUSH
13DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-overflow")
14DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
15DOCTEST_CLANG_SUPPRESS_WARNING("-Wstrict-overflow")
16
17/// global variable to record side effect of assert calls
18static int assert_counter;
19
20/// set failure variable to true instead of calling assert(x)
21#define JSON_ASSERT(x) {if (!(x)) ++assert_counter; }
22
23#include <nlohmann/json.hpp>
24using nlohmann::json;
25
26// the test assumes exceptions to work
27#if !defined(JSON_NOEXCEPTION)
28TEST_CASE("JSON_ASSERT(x)")
29{
30    SECTION("basic_json(first, second)")
31    {
32        assert_counter = 0;
33        CHECK(assert_counter == 0);
34
35        json::iterator it;
36        json j;
37
38        // in case assertions do not abort execution, an exception is thrown
39        CHECK_THROWS_WITH_AS(json(it, j.end()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator);
40
41        // check that assertion actually happened
42        CHECK(assert_counter == 1);
43    }
44}
45#endif
46
47DOCTEST_GCC_SUPPRESS_WARNING_POP
48DOCTEST_CLANG_SUPPRESS_WARNING_POP
49