unittext extension proposal

Jeremie Pelletier jeremiep at gmail.com
Sat Aug 8 14:32:30 PDT 2009


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



More information about the Digitalmars-d mailing list