On Wednesday, 22 September 2021 at 15:27:23 UTC, wjoe wrote:
>Is there a convenient way to exclude it from coverage ?
Because adjusting the -cov=xx percentage is kind of annoying and may omit other things as well.
Do you care and if yes how do you handle it ?
You have several options
- conditional compilation
make toString not existing if instrumentation for coverage is enabled:
version(D_Coverage) @disable string toString();
else string toString(){...}
- use
toString
in aunittest
that does nothing
unittest {
static foreach (T; AliasSeq!(StuffWithToString)){
{
T t = new T; // or T t;
t.toString();
}}
}
I'd use option 2.
For example I already employ this technic to cover string generator functions used in mixin()
for example.
Also in case toString
is finally a bit used the option 1 will be hard to manage.