Unittest in a windows app

Dan Nestor via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 19 13:39:37 PST 2014


Hello everybody, this is my first post on this forum.

I have a question about unit testing a Windows application. I
have slightly modified Visual D's default Windows application
stub to the following:

<code>
module winmain;

import core.runtime;
import core.sys.windows.windows;

unittest {
	assert(false);
}

extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
{
	int result;

	void exceptionHandler(Throwable e)
	{
		throw e;
	}

	try
	{
		Runtime.initialize();
		result = myWinMain(hInstance, hPrevInstance, lpCmdLine,
nCmdShow);
		Runtime.terminate();
	}
	catch (Throwable o)		// catch any uncaught exceptions
	{
		MessageBoxA(null, cast(char *)o.toString(), "Error", MB_OK |
MB_ICONEXCLAMATION);
		result = 0;		// failed
	}

	return result;
}

int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
{
	/* ... insert user code here ... */
	throw new Exception("not implemented");
	return 0;
}
</code>

I compiled it with the `-unittest` option. Strangely, when
running the app, no error is displayed, and the application
proceeds as usual. I would expect the program to display the unit
test failure and stop (the behaviour I have observed for console
applications). What am I missing?

Thanks for helping!

Dan


More information about the Digitalmars-d-learn mailing list