https://issues.dlang.org/show_bug.cgi?id=13454
Issue ID: 13454
Summary: Unit tests should be compiled in a module, where they
are declared
Product: D
Version: D1 & D2
Hardware: All
OS: All
Status: NEW
Keywords: performance
Severity: normal
Priority: P1
Component: DMD
Assignee: [email protected]
Reporter: [email protected]
http://forum.dlang.org/post/[email protected]
There's no way to disable unittests compiled as part of templates, instantiated
from another library.
Error:
---
template A(T)
{
int a;
unittest{ f(); }
}
version(unittest) void f(){}
---
If this module is compiled without unittests, `f` function will not be
compiled, then if another module is compiled with unittests and instantiates
the template, the template's unittest is compiled and it will link with `f`
function, which wasn't compiled, so linking will fail? There will be no way to
compile the importing module with unittests.
Performance:
---
import core.stdc.stdio:puts;
template A(T)
{
shared int a;
unittest { puts("test"); }
}
int main()
{
A!(int).a=0;
A!(long).a=0;
return 0;
}
---
test
test
---
The same test was executed twice (for each instance of a template). It's
questionable that duplicating tests for each instantiation of a template is
intended.
--