unittest blocks not being run inside of class and struct templates
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 27 05:19:58 PDT 2017
On Tuesday, July 25, 2017 09:31:28 Steven Schveighoffer via Digitalmars-d-
learn wrote:
> The unfortunate thing is that if you want to have non-templated unit
> tests, you have to put them outside the struct itself. This sucks for
> documented unit tests, and for tests being close to the thing being
> tested. I'd love to have a way to specify that a unit test is really
> outside the struct, but still have it written inside. I'm not sure if it
> would be accepted though.
When there was a discussion that previously (earlier this year, I think), I
was talking about updating the DIP on this that I'd created, and Andrei
basically said that it was a waste of my time to do so and that it would be
rejected. I don't know what Walter's position on it is (though previous
discussions on the topic imply that Walter doesn't think that the issue is a
big deal), and I don't know what it would take to talk Andrei into it, but I
expect that it would require a _very_ well written DIP with very good
reasons as to why a language feature was better than the pain of doing
something like you did with RedBlackTree. But Andrei certainly seemed to
think that doing what you did with RedBlackTree was perfectly acceptable as
opposed to disgustingly ugly, albeit better than just letting the tests sit
there and get compiled into every instantiation.
The DIP I wrote previously suggested using static on the unittest blocks to
indicate that they weren't really part of the template, which seemed
perfectly reasonable to me, but Timon had a decent argument as to why
reusing static didn't make sense. So, we'd need some other sort of attribute
to do it, but regardless, IMHO having an attribute of some kind to solve
this problem would be light years better than what we have now.
Unfortunately, previous discussions on the topic indicate that any DIP on
the subject is likely to get rejected, which pisses me off given how ugly
the workaround is, but I don't know what to do about it except maybe wait
awhile before creating the DIP in the hopes that putting some time between
the DIP being proposed and Andrei basically saying that any such DIP would
be rejected would make it less likely that he'd remember that and more
likely that he'd be receptive to it. However, without something more that
shows that it's a serious problem, I question that we stand much chance of
convincing him. But maybe I just suck at explaining why this issue is bad
enough to merit a language fix and someone else could explain it in a way
that would convince him.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list