www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - -cov doesn't check templated code

reply "simendsjo" <simendsjo gmail.com> writes:
Code coverage doesn't work with templates. Is this by design?
t.d:
     module t;
     template t(T) {
         static if(is(T == int))
             alias int t;
         else static if(is(T == short))
             alias short t;
     }
     unittest {
         t!int a = 10;
         assert(a == 10);
     }
     void main() {}

$ dmd -unittest -cov -run t

t.lst:
        |    module t;
        |    template t(T) {
        |        static if(is(T == int))
        |            alias int t;
        |        else static if(is(T == short))
        |            alias short t;
        |    }
        |    unittest {
       1|        t!int a = 10;
       1|        assert(a == 10);
        |    }
        |    void main() {}
t.d is 100% covered
Mar 14 2013
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
simendsjo:

 Code coverage doesn't work with templates. Is this by design?
A code coverage tells how many time a line of code is run at run-time. But your template contains no code that is run at run-time. So you are looking for a different kind of counter. Bye, bearophile
Mar 14 2013
parent reply "simendsjo" <simendsjo gmail.com> writes:
On Thursday, 14 March 2013 at 16:09:01 UTC, bearophile wrote:
 simendsjo:

 Code coverage doesn't work with templates. Is this by design?
A code coverage tells how many time a line of code is run at run-time. But your template contains no code that is run at run-time. So you are looking for a different kind of counter.
Makes sense. Would be nice to easily see that the templates are being tested more properly though.
Mar 14 2013
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
simendsjo:

 Would be nice to easily see that the templates are being tested 
 more properly though.
Then add an enhancement request in bugzilla. Maybe there is a way to implement it. I remember someone asking for a compiler switch that lists all the implemented templates... Bye, bearophile
Mar 14 2013
parent "simendsjo" <simendsjo gmail.com> writes:
On Thursday, 14 March 2013 at 16:26:21 UTC, bearophile wrote:
 simendsjo:

 Would be nice to easily see that the templates are being 
 tested more properly though.
Then add an enhancement request in bugzilla. Maybe there is a way to implement it. I remember someone asking for a compiler switch that lists all the implemented templates... Bye, bearophile
Ok: http://d.puremagic.com/issues/show_bug.cgi?id=9721
Mar 14 2013