Unit testing with asserts: Why is assertHandler required to throw?
Trip Volpe
mraccident at gmail.com
Sun Jan 31 22:30:50 PST 2010
Pelle MÃ¥nsson Wrote:
>
> An assertion handler should be created for use in unittests. Preferably
> with colorized output. :)
>
> I stole and changed slightly from std.contracts.enforce (untested)
>
> T test(T, string file=__FILE__, int line=__LINE__)
> (T value, string message="Test failed") {
> if (!value) writeln(file, "(", line, "): ", message);
> return value;
> }
>
> Use just like an assert, but will just write on errors.
Heh, yeah, if I had just noticed std.contracts in the first place, I would have realized that I still had __FILE__ and __LINE__ to play around with. Ah well -- D's usual thoughtfulness pulls through again!
And I'm a sucker for bright colors too, so I'm building colorized output into my set of unit test augmentations. :-)
More information about the Digitalmars-d
mailing list