trompeloeil.hpp (1527B)
1 /* 2 * Trompeloeil C++ mocking framework 3 * 4 * Copyright Björn Fahller 2014-2019 5 * Copyright Tore Martin Hagen 2019 6 * 7 * Use, modification and distribution is subject to the 8 * Boost Software License, Version 1.0. (See accompanying 9 * file LICENSE_1_0.txt or copy at 10 * http://www.boost.org/LICENSE_1_0.txt) 11 * 12 * Project home: https://github.com/rollbear/trompeloeil 13 */ 14 15 16 #ifndef TROMPELOEIL_CATCH2_HPP_ 17 #define TROMPELOEIL_CATCH2_HPP_ 18 19 #ifndef CATCH_VERSION_MAJOR 20 #error "<catch.hpp> must be included before <catch2/trompeloeil.hpp>" 21 #endif 22 23 #include "../trompeloeil.hpp" 24 25 namespace trompeloeil 26 { 27 template <> 28 inline void reporter<specialized>::send( 29 severity s, 30 const char* file, 31 unsigned long line, 32 const char* msg) 33 { 34 std::ostringstream os; 35 if (line) os << file << ':' << line << '\n'; 36 os << msg; 37 auto failure = os.str(); 38 if (s == severity::fatal) 39 { 40 #ifdef CATCH_CONFIG_PREFIX_ALL 41 CATCH_FAIL(failure); 42 #else 43 FAIL(failure); 44 #endif 45 } 46 else 47 { 48 #ifdef CATCH_CONFIG_PREFIX_ALL 49 CATCH_CAPTURE(failure); 50 CATCH_CHECK(failure.empty()); 51 #else 52 CAPTURE(failure); 53 CHECK(failure.empty()); 54 #endif 55 } 56 } 57 58 template <> 59 inline void reporter<specialized>::sendOk( 60 const char* trompeloeil_mock_calls_done_correctly) 61 { 62 #ifdef CATCH_CONFIG_PREFIX_ALL 63 CATCH_REQUIRE(trompeloeil_mock_calls_done_correctly != 0); 64 #else 65 REQUIRE(trompeloeil_mock_calls_done_correctly != 0); 66 #endif 67 } 68 } 69 70 71 #endif //TROMPELOEIL_CATCH2_HPP_