Boost logo

Boost :

From: troy d. straszheim (troy_at_[hidden])
Date: 2005-10-10 02:14:43


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


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