std.unittests for (final?) review
Nick Sabalausky
a at a.a
Mon Jan 3 15:49:26 PST 2011
"Andrej Mitrovic" <andrej.mitrovich at gmail.com> wrote in message
news:mailman.389.1294063698.4748.digitalmars-d at puremagic.com...
> We can always resort to hacks!
>
> module namedUnittest;
>
> import std.stdio;
> import std.string;
>
> void main()
> {
> }
>
> unittest // Foo
> {
> scope(failure)
> {
> writefln("Unittest '%s' Failed: ",
> split(split(import(.stringof[7..$] ~ ".d"),
> "\r\n")[__LINE__-5..__LINE__-4][0])[2]);
> }
> assert(0 == 1, "0 != 1");
> }
>
> ..what..? Why are you looking at me like that? :p
Using this:
http://www.dsource.org/projects/semitwist/browser/trunk/src/semitwist/util/deferAssert.d#L185
--------------------------------
module myproj.foo;
import semitwist.util.all;
alias unittestSection!"MyProject_unittest" unittestMyProject;
// Old:
unittest
{
assert(x == y);
}
class Foo
{
unittest
{
assert(x == y);
}
}
// New:
mixin(unittestMyProject(q{
assert(x == y);
}));
class Foo
{
mixin(unittestMyProject("This is for class Foo", q{
assert(x == y);
}));
}
--------------------------------
Compile with:
-unittest -debug=MyProject_unittest
Output upon running:
== unittest: myproj.foo
== unittest: myproj.foo: This is for class Foo
(This message has been brought to you, in part, by a grant from "Reasons we
need a better syntax to invoke string mixins.")
More information about the Digitalmars-d
mailing list