www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - unittest behavior

reply eris <jvburnes gmail.com> writes:
Assuming -unittest is asserted, should a D compiler generate and run unittest
code for classes that have unittests, but don't reference the class during
execution?

I noticed that gdc does compile them in, but the current version of ldc doesn't.

eris
Jul 12 2010
next sibling parent eris <jvburnes gmail.com> writes:
Slight clarification of unittest behavior:

- ldc will compile the unittest as long as a single reference to the class
remains
- gdc will compile the unittest regardless

ie:

class A { void hello() { Stdout("hello"); }
          unittest { A myobj; myobj = new A(); a.hello() }

void main() {
   A myobj;         // without this LDC wont compile the unittest

   myobj = new A(); // not necessary for LDC to generate unittest
}

/* void main() { Stdout("hello world"); }   // this would generate unittest in
gdc */
Jul 12 2010
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Mon, 12 Jul 2010 12:38:47 -0400, eris <jvburnes gmail.com> wrote:

 Assuming -unittest is asserted, should a D compiler generate and run  
 unittest
 code for classes that have unittests, but don't reference the class  
 during
 execution?

 I noticed that gdc does compile them in, but the current version of ldc  
 doesn't.
I would assume that it's because ldc is better at trimming out unused code. However, I'd say it's annoying that you have to actually use the object in question. But on top of that, I'd say that in unit test mode, all unit tests compiled should assume to be called because the runtime will call them, even if main doesn't. You should file a bug against ldc. -Steve
Jul 12 2010