unittest and WinMain

Robert Fraser fraserofthenight at gmail.com
Mon Mar 3 13:27:14 PST 2008


ElfQT wrote:
> How can I run the unittest part in the code below?
> 
> I've tried several ways, but ni succes.
> dmd -unittest tangoUnitTest.d
> (I use "tango-0.99.4-bin-win32-dmd.1.024.zip".)
> 
> import tango.sys.win32.UserGdi;
> 
> extern (C) void rt_init( void delegate(Exception) dg = null );
> extern (C) void rt_term( void delegate(Exception) dg = null );
> 
> extern (Windows)
> int WinMain(HINSTANCE hInstance,
>             HINSTANCE hPrevInstance,
>             LPSTR lpCmdLine,
>             int nCmdShow)
> {
>     rt_init();
>     rt_term(); 
> 
> 	return 0;
> }
> 
> unittest
> {
> 	assert(1==2);
> }
> 
> ElfQT

Method 1:
---------
extern(C) _moduleUnitTests();

BOOL WinMain(...) {
     _moduleUnitTests();
}

Method 2:
---------

http://flectioned.kuehne.cn/#unittest

Or my own:

http://www.dsource.org/projects/descent/browser/trunk/descent.unittest/flute/src/org/dsource/descent/unittests/flute.d

These run the unit tests from within a static this() block, which 
hopefully runs before WinMain() (if not, you'll have to manually call 
_minit() and _moduleCtor(), but you'd probably need that anyway), and 
don't stop as soon as a test fails.



More information about the Digitalmars-d mailing list