Phobos should provide unit testing faciilities
Steven Schveighoffer
schveiguy at gmail.com
Mon Sep 12 14:04:40 UTC 2022
On 9/12/22 7:28 AM, Quirin Schroll wrote:
> 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.
Great idea! Many things come to mind here.
Like a forward-range-accepting functions should be tested to make sure
it's properly using `.save` when copying, one could probably construct a
range that doesn't work without using that method.
-Steve
More information about the Digitalmars-d
mailing list