Thread overview
toString and code coverage...
Sep 22, 2021
wjoe
Sep 22, 2021
user1234
Sep 22, 2021
wjoe
September 22, 2021
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 ?
September 22, 2021

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

  1. conditional compilation

make toString not existing if instrumentation for coverage is enabled:

version(D_Coverage) @disable string toString();
else string toString(){...}
  1. use toString in a unittest 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.

September 22, 2021
On Wednesday, 22 September 2021 at 18:59:11 UTC, user1234 wrote:
> [...]
> I'd use option 2.

Thanks, I'll do just that :)