www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How to trigger unit tests in all modules in a linked-in library?

reply =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
Hi,

Imagine the following setup:

foo1.d: Compiled into a library. Has a couple of unit tests.
foo2.d: Compiled into the same library as foo1.d. Also has tests.
main.d: Dummy main function. Compiled into an executable. Links to 
foo.a/.lib (produced from foo1/2.d).

Assume that -unittest is passed to all of these.

Now, my question is: In the executable consisting of main.d, what 
exactly do I need to do to ensure that all tests in both foo1 and foo2 
are executed on start-up? Do I need to import the modules? Do I need to 
call some dummy function in them?

Is this well-defined at all?

Thanks!

- Alex
Sep 03 2011
parent Jacob Carlborg <doob me.com> writes:
On 2011-09-03 17:45, Alex Rønne Petersen wrote:
 Hi,

 Imagine the following setup:

 foo1.d: Compiled into a library. Has a couple of unit tests.
 foo2.d: Compiled into the same library as foo1.d. Also has tests.
 main.d: Dummy main function. Compiled into an executable. Links to
 foo.a/.lib (produced from foo1/2.d).

 Assume that -unittest is passed to all of these.

 Now, my question is: In the executable consisting of main.d, what
 exactly do I need to do to ensure that all tests in both foo1 and foo2
 are executed on start-up? Do I need to import the modules? Do I need to
 call some dummy function in them?

 Is this well-defined at all?

 Thanks!

 - Alex
You need to import them an make sure they are compiled with the -unittest flag. -- /Jacob Carlborg
Sep 03 2011