Continuous Integration
Lars Ivar Igesund
larsivar at igesund.net
Thu Mar 27 02:27:20 PDT 2008
Jason House Wrote:
> Sean Kelly wrote:
>
> > == Quote from Jason House (jason.james.house at gmail.com)'s article
> >> I'd like to stay with the D style of unit tests. Maybe I should check
> >> what
> >> enhancement requests are in there. It'd be nice to be able to hook in a
> >> unit test handler...
> >
> > Tango has one. Look at "moduleUnitTester" here:
> >
> > http://www.dsource.org/projects/tango/docs/current/tango.core.Runtime.html
> >
> >
> > Sean
>
> See http://d.puremagic.com/issues/show_bug.cgi?id=1952 for the enhancement
> request. Per unit test customization (such as a unit test name) is very
> useful to have. I also don't see a way to tell the program to run all unit
> tests (and just report the individual passes/failures)
Here is a simple program that uses the above hook - note that you need to link one of the stacktrace libs (jive on linux) to actually get stacktraces printed on exceptions, not just assert line numbers. Also, I think it will be unable to continue after a segfault.:
module myunittestrunner;
import tango.io.Stdout;
import tango.core.Runtime;
bool tangoUnitTester()
{
uint count = 0;
Stdout ("NOTE: This is still fairly rudimentary, and will only report the").newline;
Stdout (" first error per module.").newline;
foreach ( m; ModuleInfo ) // moduleinfo array
{
if ( m.unitTest) {
Stdout.format ("{}. Executing unittests in '{}' ", count, m.name);
try {
m.unitTest();
}
catch (Exception e) {
Stdout(" - Unittest failed.").newline;
Stdout.format(" File '{}', line '{}'.", e.file, e.line).newline;
Stdout.format(" Message is : '{}'", e.msg).newline;
if (e.info)
Stdout.format(" TraceInfo: {}", e.info.toString).newline;
continue;
}
Stdout(" - Success.").newline;
count++;
}
}
return true;
}
static this() {
Runtime.moduleUnitTester( &tangoUnitTester );
}
void main() {}
More information about the Digitalmars-d
mailing list