1 /* 2 Copyright 2020-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 #undef main 9 10 #ifndef BFG_MAIN_TEST_HPP 11 #define BFG_MAIN_TEST_HPP 12 13 #include "mini_test.hpp" 14 15 int test_main_f(int argc, const char** argv); 16 17 namespace bfg 18 { 19 namespace mini_test 20 { 21 template <class... A> test_main(scope & s,char const * file,int line,bool success,A...args)22 scope & test_main(scope & s, char const* file, int line, bool success, A... args) 23 { 24 const char * main_args[] = { args..., nullptr }; 25 int main_argc = 0; 26 while (main_args[main_argc]) main_argc += 1; 27 std::string condition = "main(" + std::to_string(main_argc) + ", {"; 28 for (int a = 0; main_args[a]; ++a) 29 { 30 condition += "\""; 31 condition += main_args[a]; 32 condition += "\", "; 33 } 34 condition += "0})"; 35 s(test_main_f(main_argc, main_args) == 0 ? success : !success, condition.c_str(), file, line); 36 return s; 37 } 38 } 39 } 40 #define main test_main_f 41 #define TEST_MAIN(S,...) test_main(S, __FILE__, __LINE__, true, __VA_ARGS__) 42 #define TEST_MAIN_FAIL(S,...) test_main(S, __FILE__, __LINE__, false, __VA_ARGS__) 43 44 #endif 45