Subject: Re: [boost] Is there interest in unit testing both passing and failing BOOST_MPL_ASSERTs?
From: Ábel Sinkovics (abel_at_[hidden])
Date: 2011-09-15 15:27:30
The suggestions I've made are all based on a library I have already
implemented: this is the metatest (sub)-library of mpllibs I mentioned
on another thread (Template metaprogramming libraries). You can download
and try it out.
The repository is here:
The source tree follows the structure of the Boost libraries but uses
the mpllibs namespace (and macro prefix) instead of boost.
Documentation is here:
Examples on how to use it: in the libs/metatest/example directory of the
source tree. You can find a number of the unit tests of Boost.MPL ported
to use metatest in the boost_mpl_unit_test example.
> BOOST_MPL_ASSERT(( mpl::equal<preorder_adj::type, mpl::vector<A,B,C,D,E,F,G,A> > ));
Gordon, you can rewrite this example using metatest:
---- #include <mpllibs/metatest/test.hpp> const mpllibs::metatest::suite_path suite("example_test_suite"); typedef mpl::equal<preorder_adj::type, mpl::vector<A,B,C,D,E,F,G,A> > my_test; MPLLIBS_ADD_TEST(suite, my_test) ---- You need a main function as well. You can use one of the already created ones (eg. "#include <mpllibs/metatest/main.hpp>"). It will show you a pretty-printed error message in case of a failure. The way the library works at the moment: instead of asserting or throwing exceptions it collects the results and pretty-printed reasons in a runtime tree structure. A main() function can browse this tree and display a report or call the assertion solution of any testing tool (such integration code for Boost.Test is included - see documentation). The reason I implemented it this way was that I could easily (by implementing/changing the integration function only) use it in any testing framework. I have tested the rest of the mpllibs libraries using this tool, you can take a look at the tests of those libraries as examples as well. Ben, your idea of throwing an exception for a failed compile-time predicate can be easily implemented in this library by using a template function taking the predicate as template argument. Note that Boost.MPL data-type support for the pretty-printer (to_stream) is proof-of-concept only in its current form. That should be implemented inside Boost.MPL instead (the rest of the libraries in mpllibs implement pretty-printing support themselves as well). If you have a chance to play with it, I'm happy to receive feedback and suggestions. Regards, Abel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk