1 /* 2 __ _____ _____ _____ 3 __| | __| | | | JSON for Modern C++ (test suite) 4 | | |__ | | | | | | version 3.10.0 5 |_____|_____|_____|_|___| https://github.com/nlohmann/json 6 7 Licensed under the MIT License <http://opensource.org/licenses/MIT>. 8 SPDX-License-Identifier: MIT 9 Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>. 10 11 Permission is hereby granted, free of charge, to any person obtaining a copy 12 of this software and associated documentation files (the "Software"), to deal 13 in the Software without restriction, including without limitation the rights 14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 copies of the Software, and to permit persons to whom the Software is 16 furnished to do so, subject to the following conditions: 17 18 The above copyright notice and this permission notice shall be included in all 19 copies or substantial portions of the Software. 20 21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 SOFTWARE. 28 */ 29 30 #include "doctest_compatibility.h" 31 32 // avoid warning when assert does not abort 33 DOCTEST_GCC_SUPPRESS_WARNING_PUSH 34 DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-overflow") 35 DOCTEST_CLANG_SUPPRESS_WARNING_PUSH 36 DOCTEST_CLANG_SUPPRESS_WARNING("-Wstrict-overflow") 37 38 /// global variable to record side effect of assert calls 39 static int assert_counter; 40 41 /// set failure variable to true instead of calling assert(x) 42 #define JSON_ASSERT(x) {if (!(x)) ++assert_counter; } 43 44 #include <nlohmann/json.hpp> 45 using nlohmann::json; 46 47 // the test assumes exceptions to work 48 #if !defined(JSON_NOEXCEPTION) 49 TEST_CASE("JSON_ASSERT(x)") 50 { 51 SECTION("basic_json(first, second)") 52 { 53 assert_counter = 0; 54 CHECK(assert_counter == 0); 55 56 json::iterator it; 57 json j; 58 59 // in case assertions do not abort execution, an exception is thrown 60 CHECK_THROWS_WITH_AS(json(it, j.end()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator); 61 62 // check that assertion actually happened 63 CHECK(assert_counter == 1); 64 } 65 } 66 #endif 67 68 DOCTEST_GCC_SUPPRESS_WARNING_POP 69 DOCTEST_CLANG_SUPPRESS_WARNING_POP 70