Lookahead in unittest
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 13 09:39:43 PDT 2017
On 5/12/17 5:46 PM, H. S. Teoh via Digitalmars-d-learn wrote:
> On Fri, May 12, 2017 at 05:23:23PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote:
> [...]
>> Note, you can achieve what you want with version(unittest):
>>
>> version(unittest)
>> {
>> class A { B b; }
>> class B { }
>> }
>>
>> unittest
>> {
>> // use A and B here
>> }
> [...]
>
> This advice, unfortunately, needs to be tempered with caution about
> namespace pollution and accidental dependency of things outside
> unittests on things inside a version(unittest) block. There's also the
> issue of library code introducing extraneous import dependencies that
> are really only necessary for unittesting, but get pulled in anyway
> because user code happens to compile with -unittest.
This actually already happens. Any imports count, even inside unittests.
But yes, this does mean that symbols in the version(unittest) are in the
module namespace.
You could create a struct or class namespace to avoid the pollution, as
long as you use really horrible names that wouldn't possibly conflict.
-Steve
More information about the Digitalmars-d-learn
mailing list