Why can't we put import in functions.

Bill Baxter dnewsgroup at billbaxter.com
Tue Oct 16 02:47:26 PDT 2007


Kyle Furlong wrote:
> Don Clugston wrote:
>> Bill Baxter wrote:
>>> Yang Bo wrote:
>>>> We can put "using namesapce" in any place in C++. Why not do the same
>>>> way in D?
>>> Yes it is lacking.  Definitely on my top ten features list for D.
>>>
>>> --bb
>> It's particularly annoying that you can't use import in unittest{} blocks.
> 
> I see lots of code that looks like this:
> 
> // Dont pollute module with unittest only symbols
> debug(UnitTesting) import testingdepedencies;
> 
> unittest
> {
>     ...
> }

I started doing this bit of verbose silliness.

version(Unittest) {
    import some.module.needed.for.tests;
}
unittest {
    /// tests....

    version(Unittest) {} else {
        static assert(false, "<filename>.d: This unittest must be run
with -version=Unittest");
    }
}



More information about the Digitalmars-d mailing list