www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Unit testing D module

reply "Dfr" <deflexor yandex.ru> writes:
If i do not want to unit test whole codebase, because it big 
enough and all tests take noticeable time to run.

So i trying this:

dmd -unittest mymodule.d

And getting error: "undefined reference to `main'"
But i don't want to run 'main' here, just unit test please.
Any idea how to test single module without putting 'main' in 
every module ?
Dec 26 2013
next sibling parent "Chris Cain" <clcain uncg.edu> writes:
On Thursday, 26 December 2013 at 09:25:14 UTC, Dfr wrote:
 If i do not want to unit test whole codebase, because it big 
 enough and all tests take noticeable time to run.

 So i trying this:

 dmd -unittest mymodule.d

 And getting error: "undefined reference to `main'"
 But i don't want to run 'main' here, just unit test please.
 Any idea how to test single module without putting 'main' in 
 every module ?
Use the `-main` compiler switch: "Add a default main() function when compiling. This is useful when unittesting a library, as it enables the user to run the unittests in a library without having to manually define an entry-point function." So, dmd -unittest -main mymodule.d
Dec 26 2013
prev sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Thursday, 26 December 2013 at 09:25:14 UTC, Dfr wrote:
 If i do not want to unit test whole codebase, because it big 
 enough and all tests take noticeable time to run.

 So i trying this:

 dmd -unittest mymodule.d

 And getting error: "undefined reference to `main'"
 But i don't want to run 'main' here, just unit test please.
 Any idea how to test single module without putting 'main' in 
 every module ?
the -main flag will do the trick, e.g. dmd -unittest -main mymodule.d Also, if you find you need more control then check out some of the testing frameworks/helpers here: http://code.dlang.org/ (ctrl+f test)
Dec 26 2013