Unittests and windows application
Stefan via Digitalmars-d
digitalmars-d at puremagic.com
Thu Mar 26 05:11:31 PDT 2015
On Thursday, 26 March 2015 at 10:50:06 UTC, Vladimir Panteleev
wrote:
> On Thursday, 26 March 2015 at 10:23:58 UTC, Stefan wrote:
..
>
> That's a bug. You'll notice that if an exception is thrown in
> main() (or anything called from it), you'll get a MessageBox
> for GUI applications. That this doesn't also occur with
> unittest failures is a bug.
Do you have the bug/issue number for that?
>
> For now, you can work around this by writing your own WinMain,
> which calls rt_runModuleUnitTests explicitly, inside a
> try/catch block which will then display a MessageBox.
Hmm, that is what i tried to do, but the code in
Runtime.runModuleUnitTests() catches already all exceptions and
writes that to the console.
I have not found rt_runModuleUnitTests in the current D runtime
(2.067.0).
However, I was successful in setting the moduleUnitTester
property of Runtime. Inside my main module I do:
static this() {
Runtime.moduleUnitTester = &unitTestRunner;
}
bool unitTestRunner() {
string line = "";
void printErr(in char[] buf) {
string message = to!string(buf);
if ( message == "\n" ) {
Logger.send( line );
line = "";
} else {
line ~= message;
}
}
size_t failed = 0;
foreach( m; ModuleInfo ) {
if( m ) {
auto fp = m.unitTest;
if( fp ) {
try {
fp();
} catch( Throwable e ) {
e.toString(&printErr); printErr("\n");
failed++;
}
}
}
}
return failed == 0;
}
where the Logger.send() delegates to OutputDebugStringA().
More information about the Digitalmars-d
mailing list