Subject: Re: [boost] Is there interest in unit testing both passing and failing BOOST_MPL_ASSERTs?
From: Gordon Woodhull (gordon_at_[hidden])
Date: 2011-09-15 02:30:14
On Sep 13, 2011, at 2:33 PM, Ábel Sinkovics wrote:
> On Sep 13, 2011, at 12:10 PM, Dave Abrahams wrote:
>> If you're just checking MPL assertions, then presumably there's a
>> predicate that can be evaluated without throwing. Why not just feed
>> those predicates' results to regular runtime assertions?
> In addition to feeding those predicates to runtime assertions a type
> pretty-printing utility can be used to provide more detail on why the
> predicate failed. Relying on a pretty-printer rather than the compiler
> error messages makes the output standard across platforms/compilers and
> more readable in many cases.
Yes. I am sold.
I currently rely on compilation failure in order to determine that an assertion has **failed in the right way** - e.g. if I need to verify that a compile-time expression fails to parse, I need to see the details of why it didn't parse. Currently I can only get that by generating an error and looking over it by eye.
Or more prosaically, if I do a depth-first search on a compile-time graph, and verify that I get the expected sequence, it's not good enough to have only success cases. For how do I know I'm not just doing the comparison wrong?
Currently I only have examples and not proper tests for MPL.Graph, because I couldn't figure out how to automate these necessary failures. I have a few 'bad' examples which are commented out which I occasionally uncomment in order to verify those failures. Not robust!
In addition to compilation failure not being unit test material, you also only get one per file which is pretty inefficient if your metaprogram spent 30 seconds just getting everything set up.
One thing I'd like to clarify: I don't think anyone is talking about capturing general compilation failures and turning them into exceptions. That would be freakin' amazing if possible * but I'm pretty sure we're just talking about an exception with some type metadata (pretty-printed). It is equivalent to or can be #def'd into a static_assert.
Thanks Abel & Ben, this will be a big help!
* Sounds like the kind of thing Godel proved impossible.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk