Ah, simple solution to unittests inside templates

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 18 18:24:12 PDT 2016


On Sunday, September 18, 2016 20:11:56 Andrei Alexandrescu via Digitalmars-d 
wrote:
> Understood. I don't want anyone to get furious later on account of my
> sugarcoating things, so let me say this: I'm likely to oppose such a
> proposal. Walter and I have similar design sensibilities so he's likely
> to oppose it too. I don't think this is an important issue that should
> be addressed. The ease of implementation argument is, as discussed
> before, fallacious. What you call an ugly workaround I call business as
> usual using the nice facilities of the D language. I suggest you work on
> ideas with more impact. -- Andrei

The ease of implementation argument is not fallacious when you're arguing
that it shouldn't be done, because it's not the most critical thing on the
list of things to be done. Certainly, we shouldn't add such a feature just
because it's easy. It being easy to implement would just mean that the fact
that there are other critical things taking up Walter's time doesn't mean
that we shouldn't do it. The decision should be made on the merits of the
feature. When it gets done is then affected by how easy it is and what else
there is to do which is more critical.

Regardless, your workaround doesn't even fully work around the problem,
because the unittest block still ends up in user code - just less user code,
because it's just the one instantiation that gets it. So, it's an
improvement, but it's not a fix. That problem can be fixed by defining
special version idefintiers for your code that you put the unittest blocks
within templates inside of and that no one would define in their own
projects, but then you end up with quite a bit of extra plumbing just so
that you can have your unittest blocks next to your functions inside of
templated types without them ending up in user code or being compiled and
run multiple times when testing your own code. Having an attribute take care
of this (be it static or something else) would be far cleaner and would make
it far more likely that folks would actually do it, so you wouldn't end up
with someone else's tests in your code, just because they had a templated
type that you're using that was unit tested.

But I don't think that there's much that I can do to convince you if you
think that adding a bunch of extra version blocks and static ifs just so
that you can have the functions inside of templated types have their unit
tests next to them without impacting the code of users or resulting in the
tests being compiled and run an excess number of times is not ugly.

- Jonathan M Davis



More information about the Digitalmars-d mailing list