Phobos should provide unit testing faciilities
Quirin Schroll
qs.il.paperinik at gmail.com
Mon Sep 12 11:28:53 UTC 2022
In [*Taming Immutable Data Types in D with
librebindable*](https://www.youtube.com/watch?v=eGX_fxlig8I) by
Mathis Beer, in the Q&A, it was pointed out that it’s quite
common to forget testing template code against types that do
exotic (yet valid) things, e.g. `@disable this()`,
define/`@disable` the copy constructor, contain qualified
members, be immutable, etc.
One way to mitigate this would be a Phobos module (name it
`std.testing` or something) that – possibly among other things –
defines aptly named types that are irregular for the sole purpose
of being used as examples, together with various AliasSeqs that
group types that belong together somehow. Then, one could do:
```D
unittest
{
import std.testing;
static foreach (T; IrregularStructs)
{
T obj; // can default construct? T = NoDefaultCtor fails.
auto obj2 = obj; // can copy? T = NoCopyCtor fails.
// etc.?
}
}
```
Anyone can find *some* irregular types and test against them, but
looking into *every* corner requires extensive knowledge about
the language’s niches.
More information about the Digitalmars-d
mailing list