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:

```d
version(D_Coverage) @disable string toString();
else string toString(){...}
```

2. use `toString` in a `unittest` that does nothing

```d
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.

Reply via email to