function vs. delegate in a unittest

rikki cattermole rikki at cattermole.co.nz
Sun Apr 21 06:39:37 UTC 2019


On 21/04/2019 6:35 PM, Manfred Nowak wrote:
> Because unittests are special functions, the functions declared within 
> the body of a unittest have the type of a `delegate'. By this the intent 
> to include a unittest for functions with the type of a `function' 
> requires the definition of a function outside of the body of the unittest.

---
void main()
{
     void func() {
     }

     pragma(msg, typeof(&func));
}

unittest {
     void func() {
     }

     pragma(msg, typeof(&func));
}
---

void delegate() pure nothrow @nogc @safe
void delegate() pure nothrow @nogc @safe

vs

---
void main()
{
     static void func() {
     }

     pragma(msg, typeof(&func));
}

unittest {
     static void func() {
     }

     pragma(msg, typeof(&func));
}
---

void function() pure nothrow @nogc @safe
void function() pure nothrow @nogc @safe


More information about the Digitalmars-d mailing list