• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
12 DOCTEST_GCC_SUPPRESS_WARNING_PUSH
13 DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-overflow")
14 DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
15 DOCTEST_CLANG_SUPPRESS_WARNING("-Wstrict-overflow")
16 
17 /// global variable to record side effect of assert calls
18 static 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>
24 using nlohmann::json;
25 
26 // the test assumes exceptions to work
27 #if !defined(JSON_NOEXCEPTION)
28 TEST_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 
47 DOCTEST_GCC_SUPPRESS_WARNING_POP
48 DOCTEST_CLANG_SUPPRESS_WARNING_POP
49