Problem with unittest in templates.
Peter C. Chapin
pchapin at sover.net
Fri Dec 29 05:48:59 PST 2006
Hello! I'm using dmd 0.178. I'm having trouble getting the unittest
section of a class template to execute. I have two files:
----> main.d <----
import other;
int main( )
{
Foo!(int) my_foo = new Foo!(int);
return( 0 );
}
----> other.d <----
class Foo(T) {
unittest {
assert( 1 == 0 );
}
};
I compile this program using 'dmd -unittest main.d other.d'. It compiles
without error but when it executes there is no assertion failure.
However, if I move the definition of class Foo(T) into main.d (and throw
away other.d) I *do* get the assertion failure. Am I doing something
wrong? Is this supposed to work?
I'm also noticing that the unittest section isn't as useful in a
template as it is in a non-template. It's awkward writing unittests
generically without knowledge of a specific type T. Is this "the way it
is" or is there some nice programming technique that I should be using
here? I find myself thinking about writing a separate test program (C++
style) where I can work with specific specializations of the template.
Peter
More information about the Digitalmars-d-learn
mailing list