[unittest] constness

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 16 16:49:20 PST 2015


On Sat, 17 Jan 2015 00:38:08 +0000
Luc Bourhis via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> Testing constness implementation is easy:
> 
> const Foo a;
> a.non_const_method(); // <<< compilation fails
> 
> but how would I catch that in a unittest?
i don't think that you can do it with one command, but at least you can
use `__trait(compiles, ...)` to check if it compiles. and if it's not,
you can either assume that the test is passed, or investigate the thing
further, examining the type of `a` (using `isMutable!`, for example),
or creating `Unqual!(typeof(a)) aa` and try "compiles" with it. it can
be done with cool and hard to decipher template to ease your life. just
don't forget to document what that template intended to so, so you will
not force to reverse-engineer it later. ;-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150117/8e68f0c5/attachment.sig>


More information about the Digitalmars-d mailing list