Code That Says Exactly What It Means
jmh530
john.michael.hall at gmail.com
Thu Oct 30 16:02:36 UTC 2025
On Thursday, 30 October 2025 at 15:19:37 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> On 31/10/2025 4:03 AM, Dom DiSc wrote:
>> On Thursday, 30 October 2025 at 03:48:01 UTC, Steven
>> Schveighoffer wrote:
>>> There has always been only ONE deficiency for this, and that
>>> is documented unittests being allowed to use private symbols
>>> in the module.
>>
>> I consider not even this a deficiency, because unittests
>> _within_the_same_module_ are per definition whitebox tests, so
>> they should be allowed to use private stuff. (In C++ they are
>> required to be "friends").
>>
>> If you want to do blackbox tests, by definition they have to
>> be written in a different file (as touching the original file
>> would be a violation of "blackbox"). And then they really
>> can't see the private stuff.
>>
>> So, everything is fine.
>>
>> Having scope private would simply be lying in your pocket. Not
>> having this is a clear improvement.
>
> This isn't what Steven is talking about.
>
> What Steven is talking about is documentation unittests.
>
> These need to be runnable by the user, in a different module.
>
> We've had cases where documentation unittests that are used in
> examples for Phobos not work outside of the module when tried
> by people.
Steve’s point was a little confusing. He said it’s a unit test
problem and not an accessibility problem. Regular unit tests
should be able to access the rest of the module but documented
unit tests shouldn’t. But would we really want to strictly
enforce that for documented unit tests? The point might be that
it’s not an issue of other parts of the module accessing the
internals of the unittest, it’s about the ability of the unittest
to access the private elements of the module. So I don’t think
the equivalent of scope-private would solve that issue. You would
need to make everything else in the module scope-private instead
of private, which you may not want to do. Seems like it would
need something else. Maybe instead of a “friend” you would need
an “enemy”. ;)
More information about the Digitalmars-d
mailing list