Boost logo

Boost :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2005-10-11 04:13:18


> 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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk