"spir" <denis.s...@gmail.com> wrote in message news:mailman.2341.1299588465.4748.digitalmar...@puremagic.com... > On 03/08/2011 09:25 AM, Nick Sabalausky wrote: >> "Nick Sabalausky"<a@a.a> wrote in message >> news:il3tra$3gg$1...@digitalmars.com... >>> "Jonathan M Davis"<jmdavisp...@gmx.com> wrote in message >>> news:mailman.2328.1299539399.4748.digitalmar...@puremagic.com... >>>> On Monday, March 07, 2011 12:43:00 Nick Sabalausky wrote: >>>>> "Jonathan M Davis"<jmdavisp...@gmx.com> wrote in message >>>>> news:mailman.2297.1299478837.4748.digitalmar...@puremagic.com... >>>>> >>>>>> On Sunday 06 March 2011 21:57:30 Nick Sabalausky wrote: >>>>> >>>>> Yea, that's what I figured, and that's why I was strongly in favor of >>>>> assertPred despite the "promise" of assert improvements. >>>>> >>>>> You're the sole author of assertPred, right? Do you mind if I include >>>>> it >>>>> in >>>>> my zlib/libpng-licensed SemiTwist D Tools library ( >>>>> http://www.dsource.org/projects/semitwist ) ? I already have an >>>>> assert-alternative in there, but assertPred is vastly superior. >>>>> (Although, >>>>> my assert-alternative does save a list of failures instead of >>>>> immediately >>>>> throwing, which I personally find to be essential for unittests, so I >>>>> would >>>>> probably add the *optional* ability to have assertPred do the same.) >>>> >>>> Yes. I'm the sole author. Feel free to re-use it. It's under Boost, so >>>> you can >>>> use it for whatever Boost lets you do with it, and even if what you're >>>> doing >>>> isn't Boost compatible, it's fine with me if you use it anyway. >>>> >>> >>> Thanks. >>> >> >> I've added it and made an optional 'autoThrow' flag that, if set to >> false, >> prevents a failure from immediately bailing out of the whole unittest >> (some >> people like that, like me, and others don't). >> >> http://www.dsource.org/projects/semitwist/changeset?new=%2F%40196&old=%2F%40193 > > I like it as well. >
If you do use it, and have autoThrow set to false, be aware that it doesn't *yet* catch exceptions that are thrown from the actual code being tested. Ie: unittest { autoThrow = true; // Ie, the default (unless you use the unittestSection mixin) // A: AssertError is thrown, not caught and unittest bails out assertPred!"a"(false); // B: Exception is thrown, not caught and unittest bails out assertPred!"throw new Exception()"(10); autoThrow = false; // C: Error message is displayed, assertCount is incremented, unittest continues assertPred!"a"(false); // D: *Should* do same as C, but currently does same as B assertPred!"throw new Exception()"(10); } void main() { // If autoThrow is false and there were any failures, // then this throws an actual AssertError flushAsserts(); // Rest of main here } I plan to fix that though.