1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi"). 6 #ifdef CPPX_BOOST_TEST_AS_HEADER_ONLY_PLEASE 7 # include <boost/test/included/unit_test.hpp> 9 # include <boost/test/unit_test.hpp> 15 #ifndef CPPX_NO_DOLLARS_PLEASE 16 # define $begin_test_suite CPPX_BEGIN_TEST_SUITE 17 # define $end_test_suite CPPX_END_TEST_SUITE 19 # define $test_case CPPX_TEST_CASE 21 # define $expect CPPX_EXPECT 22 # define $expect_eq CPPX_EXPECT_EQ 23 # define $require CPPX_REQUIRE 24 # define $require_eq CPPX_REQUIRE_EQ 38 #define CPPX_BEGIN_TEST_SUITE( ... ) \ 39 CPPX_APPLY( CPPX_GENERATE_TEST_SUITE_START_, __VA_ARGS__ ) \ 40 static_assert( true, "- just to support a semicolon after this -" ) 42 #define CPPX_GENERATE_TEST_SUITE_START_( name ) \ 43 BOOST_AUTO_TEST_SUITE( name ); 45 #define CPPX_END_TEST_SUITE( nesting_level ) \ 46 CPPX_REPEAT( nesting_level, CPPX_GENERATE_TEST_SUITE_END_ ) \ 47 static_assert( true, "- just to support a semicolon after this -" ) 49 #define CPPX_GENERATE_TEST_SUITE_END_() \ 50 BOOST_AUTO_TEST_SUITE_END(); 52 #define CPPX_TEST_CASE( testcasename, specificsname ) \ 53 BOOST_AUTO_TEST_CASE( testcasename##_##specificsname ) 55 #define CPPX_EXPECT( ... ) \ 56 CPPX_EXPECT_EXPANSION_HELPER_( CPPX_N_ARGUMENTS( __VA_ARGS__ ), __VA_ARGS__ ) 58 #define CPPX_EXPECT_EXPANSION_HELPER_( n_args, ... ) \ 59 CPPX_INVOKE_MACRO( CPPX_JOINED( CPPX_EXPECT_, n_args ), ( __VA_ARGS__ ) ) 61 #define CPPX_EXPECT_1( condition ) \ 62 BOOST_CHECK( condition ) 64 #define CPPX_EXPECT_2( condition, message_expr ) \ 65 BOOST_CHECK_MESSAGE( condition, message_expr ) 67 #define CPPX_EXPECT_EQ( ... ) \ 68 CPPX_EXPECT_EQ_EXPANSION_HELPER_( CPPX_N_ARGUMENTS( __VA_ARGS__ ), __VA_ARGS__ ) 70 #define CPPX_EXPECT_EQ_EXPANSION_HELPER_( n_args, ... ) \ 71 CPPX_INVOKE_MACRO( CPPX_JOINED( CPPX_EXPECT_EQ_, n_args ), ( __VA_ARGS__ ) ) 73 #define CPPX_EXPECT_EQ_2( a, b ) \ 74 BOOST_CHECK_EQUAL( a, b ) 76 #define CPPX_EXPECT_EQ_3( a, b, message_expr ) \ 77 BOOST_CHECK_MESSAGE( (a) == (b), message_expr ) 79 #define CPPX_REQUIRE( ... ) \ 80 CPPX_REQUIRE_EXPANSION_HELPER_( CPPX_N_ARGUMENTS( __VA_ARGS__ ), __VA_ARGS__ ) 82 #define CPPX_REQUIRE_EXPANSION_HELPER_( n_args, ... ) \ 83 CPPX_INVOKE_MACRO( CPPX_JOINED( CPPX_REQUIRE_, n_args ), ( __VA_ARGS__ ) ) 85 #define CPPX_REQUIRE_1( condition ) \ 86 BOOST_REQUIRE( condition ) 88 #define CPPX_REQUIRE_2( condition, message_expr ) \ 89 BOOST_REQUIRE_MESSAGE( condition, message_expr ) 91 #define CPPX_REQUIRE_EQ( ... ) \ 92 CPPX_REQUIRE_EQ_EXPANSION_HELPER_( CPPX_N_ARGUMENTS( __VA_ARGS__ ), __VA_ARGS__ ) 94 #define CPPX_REQUIRE_EQ_EXPANSION_HELPER_( n_args, ... ) \ 95 CPPX_INVOKE_MACRO( CPPX_JOINED( CPPX_REQUIRE_EQ_, n_args ), ( __VA_ARGS__ ) ) 97 #define CPPX_REQUIRE_EQ_2( a, b ) \ 98 BOOST_REQUIRE_EQUAL( a, b ) 100 #define CPPX_REQUIRE_EQ_3( a, b, message_expr ) \ 101 BOOST_REQUIRE_MESSAGE( (a) == (b), message_expr ) $apply invokes the specified single-argument macro with each of the specified arguments.
$repeat(n, what) produces the what text n times.