www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13454] New: Unit tests should be compiled in a module, where

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: nobody puremagic.com
          Reporter: dfj1esp02 sneakemail.com

http://forum.dlang.org/post/luoc6f$2qcg$1 digitalmars.com
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.

--
Sep 10 2014