www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - unittest and WinMain

reply ElfQT <elf_qt _deletethis_yahoo.com> writes:
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
Mar 03 2008
parent reply Robert Fraser <fraserofthenight gmail.com> writes:
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.
Mar 03 2008
next sibling parent Robert Fraser <fraserofthenight gmail.com> writes:
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/desce t/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
Mar 03 2008
prev sibling parent ElfQT <elf_qt _deletethis_yahoo.com> writes:
Thank You Robert, I will try that soon. ElfQT
Mar 03 2008