Unit tests in D
Michel Fortin
michel.fortin at michelf.com
Tue May 4 19:13:28 PDT 2010
On 2010-05-04 21:24:50 -0400, bearophile <bearophileHUGS at lycos.com> said:
> There are ways to partially implement this for run-time asserts, but badly:
>
> void throws(Exceptions, TCallable, string filename=__FILE__, int line=__LINE__)
> (lazy TCallable callable) {
> try
> callable();
> catch (Exception e) {
> if (cast(Exceptions)e !is null)
> return;
> }
>
> assert(0, text(filename, "(", line, "): doesn't throw any of the
> specified exceptions."));
> }
Your 'throws' template seems good. Should create std.testing and
include it there.
Also, perhaps it'd work to use a double-template for this:
template throws(Exceptions...) {
void throws(TCallable, string filename=__FILE__, int line=__LINE__)
(lazy TCallable callable) {
...
}
}
I know this trick was working in D1, but I'm not sure if it wasn't
broken in D2.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list