On Sat, 08 Aug 2009 17:32:30 -0400, Jeremie Pelletier <jerem...@gmail.com> wrote:
>I just had an idea to help keep track of unittests, right now we're turning on >printf's at the beginning of a test to know which one fails, and adding >printfs everywhere quickly becomes redundant. Also if the test succeeds and >execution fails at some other point, the last printf is then misleading. > >--- >module sample; >unittest("myTest") {} >--- > >With a few runtime changes, it could be made to print "unittest: >sample.myTest..." before calling the test routine, and "PASS\n" as the routine >returns. It could have its own compiler switch to turn it on or off globally, >and support for a custom output handler should the user want to redirect >output to a GUI or something. > >Right now I made the following template to do that: >--- >private template UnittestTrace(string test) { > debug(TEST) > immutable UnittestTrace = > "printf(\"unittest: std.text.String." ~ test ~ "... > \");" > "scope(success) printf(\"PASS\n\");"; > else > immutable UnittestTrace = ""; >} >unittest { > mixin(UnittestTrace!"myTest"); >} >--- > >However being a dreamer and all, I would like to see support for such a >feature pushed to the D runtime. > >J Something similar has been purposed. http://d.puremagic.com/issues/show_bug.cgi?id=2749 Gide