unittest can't have extern (C) or import?

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Jan 27 08:41:24 PST 2008


"Leandro Lucarella" <llucax at gmail.com> wrote in message 
news:20080127154946.GA27400 at homero.springfield.home...
> Hi! I'm trying to do some unittest on a C bindings. First, I found I can't
> use import inside a unittest block (why?). Should I polute the module with
> symbols I only want for the unittest? :S
>
> Second, and whorst, I can't specify extern (C) in the unittest. I need to
> use some functions with C linking, but I can't create them inside the
> unittest. Using extern (C): or extern (C) {} gives me a parse error and
> extern (C) void f() {} parses OK but the extern (C) is ignored and
> compiler complains about trying to use a pointer to a D linked function
> where it expects a C linked function.
>
> Is this a bug? A feature?
>
> TIA.
>
> PS: Using gdc 0.25 (GCC 4.1.3) debian package.

A unittest block is a function body.  Anything that's illegal in a function 
body is also illegal in a unittest block.  I would kind of like imports to 
be legal in functions but that's another story.

Basically there's no built-in solution to this.  Tango does something like:

debug(UnitTest)
{
    import my.stuff;
    extern(C) void some_func();

    unittest
    {
        some_func();
        my.stuff.fweep();
    }
}

And when running unittests they'll also define a UnitTest debug symbol.  Not 
built-in but it works. 




More information about the Digitalmars-d-learn mailing list