Thread overview
unittest and WinMain
Mar 03, 2008
ElfQT
Mar 03, 2008
Robert Fraser
Mar 03, 2008
Robert Fraser
Mar 03, 2008
ElfQT
March 03, 2008
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
March 03, 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.
March 03, 2008
Robert Fraser wrote:
> 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.

Oops, spoke too soon. You do indeed need to call those, as well as initialize the GC:

http://www.digitalmars.com/d/1.0/windows.html
March 03, 2008
Thank You Robert, I will try that soon. ElfQT