BOOST_AUTO_TEST_CASE(tweak)

Something minor. The code: BOOST_UNIT_TEST_CASE(something) { ... } expands to struct something_id {}; static void something(); static boost::unit_test::ut_detail::auto_test_unit_registrar something_registrar( boost::unit_test::make_test_case( boost::unit_test::callback0<>(something), boost::unit_test::literal_string( "something", sizeof( "something" ) - 1 ) ), boost::unit_test::ut_detail::auto_tc_exp_fail< something_id>::value ); static void something() { ... } And if you're testing, say, smart_cast of something, you might naturally code (as I just did) BOOST_UNIT_TEST_CASE(smart_cast) { ... } which will contain static void smart_cast() and you'll get a fairly cryptic error, test_smart_cast.cpp:198: error: no matching function for call to 'boost::unit_test::callback0<boost::unit_test::ut_detail::unused>::callback0(<unknown type>)' The docs specify that
To use automatic registration facility you need to define a test case as a zero arity free function, but instead of usual void tc_name(), use following statement
BOOST_AUTO_UNIT_TEST( tc_name )
BOOST_TEST_CASE hides all the machinery used to implement automatic registration. The only requirements are that test case names are unique within compilation unit and no two test case definition are located on the same line.
Which I didn't see until just now. The context implies that tc_name must be a valid function name, so I guess there's no problem. But it does seem a little redundant to write BOOST_AUTO_TEST_CASE(test_of_smart_cast) { ... } as it's clear you're writing a test. I had assumed the static function were instead named test_case_smart_cast() and hidden in a namespace, something like namespace boost::unit_test::ut_detail::user_tests { struct test_case_smart_cast_id {}; void test_case_smart_cast(); } [etc., etc.] void boost::unit_test::ut_detail::user_tests::test_case_smart_cast() { ... } for added safety against name collisions, as one sees in, e.g., boost::python: # define BOOST_PYTHON_MODULE_INIT(name) \ void init_module_##name(); \ Anyhow, just thinking out loud, not trying to nitpick. I also noticed that the header file auto_unit_test.hpp shows // deprecated #define BOOST_AUTO_UNIT_TEST( f ) BOOST_AUTO_TEST_CASE( f ) so the example in the docs uses the deprecated interface. Just FYI. Thanks for a very handy testing lib, -t

And if you're testing, say, smart_cast of something, you might naturally code (as I just did)
BOOST_UNIT_TEST_CASE(smart_cast) { ... }
which will contain
static void smart_cast()
and you'll get a fairly cryptic error,
test_smart_cast.cpp:198: error: no matching function for call to 'boost::unit_test::callback0<boost::unit_test::ut_detail::unused>::callback0(<unknown type>)'
The docs specify that
To use automatic registration facility you need to define a test case as a zero arity free function, but instead of usual void tc_name(), use following statement
BOOST_AUTO_UNIT_TEST( tc_name )
BOOST_TEST_CASE hides all the machinery used to implement automatic registration. The only requirements are that test case names are unique within compilation unit and no two test case definition are located on the same line.
Which I didn't see until just now. The context implies that tc_name must be a valid function name, so I guess there's no problem. But it does seem a little redundant to write
BOOST_AUTO_TEST_CASE(test_of_smart_cast) { ... }
as it's clear you're writing a test. I had assumed the static function were instead named test_case_smart_cast() and hidden in a namespace, something like
namespace boost::unit_test::ut_detail::user_tests { struct test_case_smart_cast_id {}; void test_case_smart_cast(); } [etc., etc.] void boost::unit_test::ut_detail::user_tests::test_case_smart_cast() { ... }
for added safety against name collisions, as one sees in, e.g., boost::python:
# define BOOST_PYTHON_MODULE_INIT(name) \ void init_module_##name(); \
Anyhow, just thinking out loud, not trying to nitpick.
Test case name has several usages. It referred in both test log and test report. It also going to be used as the value to specify a run test by name. Accordingly I dont think it's good idea to silently behind the scene mandle the test case name. It's going to be more confusing then convinient. As for hame collision you could always put your test cases in a namespace.
I also noticed that the header file auto_unit_test.hpp shows
// deprecated #define BOOST_AUTO_UNIT_TEST( f ) BOOST_AUTO_TEST_CASE( f )
so the example in the docs uses the deprecated interface. Just FYI.
Thanks. Will fix Gennadiy
participants (2)
-
Gennadiy Rozental
-
troy d. straszheim