"Andrej Mitrovic" <andrej.mitrov...@gmail.com> wrote in message news:mailman.389.1294063698.4748.digitalmar...@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.")