Boost logo

Boost :

From: Beman Dawes (beman_at_[hidden])
Date: 2000-12-03 20:48:17

At 12:13 PM 12/1/2000 -0600, Ed Brey wrote:

>From: "Beman Dawes" <beman_at_[hidden]>
>> A preliminary Test Tools Library has been uploaded at
>I think it's a great way to get the boost regression test started. I
>think that it should be a library that is designed to be used by boost
>for their own non-boost code, as well as being used by boost library
>developers to test other library code. I know I'm planning on using it
>my work to as a way to kickstart a more formalized unit-level regression
>testing process.

I've used an earlier version some years now, it really is quite handy. But
thanks for the encouragement; I needed someone else to look at it and
confirm that it looks useful.

>Looking at the implementation, I see one major problem: If there are
>multiple translation units that include test_tools.hpp,
>boost::report_non_fatal_error and boost::report_fatal_error will be
>defined. To solve the problem, I'd recommend moving the implementation
>those functions to test_main.hpp.


>> I also would rename test_main.hpp to
>test_main.cpp, to make it obvious that it should only be included in from
>single translation unit (or not #included at all, but rather linked in
>the boost library (.a, .lib, or .dll).

I'll have to think about that. Packaging the whole implementation in the
header has some advantages.

>I also have a semi-nit: The long list of catches for classes deriving
>std::exception, could be replaced by:
> catch ( const std::exception & ex )
> { std::cout << typeid(ex).name() << ": " << ex.what() << std::endl; }

Yes, that long list is a bit ugly, but at least the output is quite
clear. Also, as others pointed out, using typeid(ex).name() has problems
on some compilers.

>And finally some fundamentally nitty nits:
>1. test_main.hpp(66): xmain -> test_main

Fixed. A holdover from a earlier name.

>2. test_main.hpp(75): ex.c_str() -> ex

Fixed. Had to #include <string> as a result.

>3. test_main.hpp(69): boost::test_tools_exception& -> const

Well, I certainly was inconsistent! Two catches used const, the rest
didn't. The rules for catching const &'s are a bit different from
function arguments (ISO 15.3 paragraphs 18 & 19) so const apparently isn't
required, but const doesn't hurt anything either so I added it to all. (I
skimmed the appropriate sections of C++ Programming Language, Special
Edition, and More Effective C++, and neither is very clear as to whether
const ref or just plain ref is preferred.)

A nit about your nitty nits:-)

The name of the header is main.hpp, following the logic that that's the
name of the supplied function. Your "test_main" might be a bit clearer,
but since we can't change the name of main(), I'll leave the name alone.

>And then a question: In order to better support existing test apps that
>return a value to indicate an error (as opposed to using the BOOST_TEST
>macros or exceptions), would it be useful to have main print out the
>of "result"?

It already does:

{ std::cout << "\n**** error; test_main returned: " << result << ...
Or am I misunderstanding your question?

Thanks for the comments. I've updated the files in the vault.


Boost list run by bdawes at, gregod at, cpdaniel at, john at