1 /* 2 Copyright 2019-2022 René Ferdinand Rivera Morell 3 Distributed under the Boost Software License, Version 1.0. 4 (See accompanying file LICENSE.txt or copy at 5 http://www.boost.org/LICENSE_1_0.txt) 6 */ 7 8 #ifndef BFG_MINI_TEST_HPP 9 #define BFG_MINI_TEST_HPP 10 11 #include <iostream> 12 #include <string> 13 14 namespace bfg { namespace mini_test { 15 16 struct scope 17 { 18 unsigned pass_count = 0; 19 unsigned fail_count = 0; operator intbfg::mini_test::scope20 operator int() const { return fail_count; } operator ()bfg::mini_test::scope21 scope & operator()( 22 bool pass, const std::string & expression, char const * file, int line) 23 { 24 return (*this)("", pass, expression, file, line); 25 } operator ()bfg::mini_test::scope26 scope & operator()( 27 const std::string & message, 28 bool pass, 29 const std::string & expression, 30 char const * file, 31 int line) 32 { 33 if (pass) 34 pass_count += 1; 35 else 36 { 37 fail_count += 1; 38 if (!message.empty()) std::cerr << "[ " << message << " ] "; 39 std::cerr << file << "(" << line << "): test '" << expression 40 << "' failed\n"; 41 } 42 return *this; 43 } 44 }; 45 46 #define CONTEXT __FILE__, __LINE__ 47 #define REQUIRE(condition) (bool(condition)), #condition, __FILE__, __LINE__ 48 }} // namespace bfg::mini_test 49 50 #endif 51