Shared static this() not executed for unittest

Timoses timosesu at gmail.com
Sat Dec 15 17:19:05 UTC 2018


Spec 27.5 states: "Unit tests, when enabled, are run after all 
static initialization is complete and before the main() function 
is called. " (https://dlang.org/spec/unittest.html)


main.d:
-------------------
import std.stdio;

shared static this()
{
     import vibe.core.log;
     setLogLevel(LogLevel.trace);

     logDebug("log: statc this");
     WRITELN("WRiteln: static this");
}

void main()
{
     writeln("Edit source/app.d to start your project.");
}

test.d:
-------------------
import std.stdio;

unittest
{
     import vibe.core.log;
     logDebug("log: unittest");
     writeln("writeln: unittest");
}


Running `dub test` will output:
Running ./unit-test-library
writeln: unittest
All unit tests have been run successfully.

Why is the `shared static this()` not executed?


More information about the Digitalmars-d-learn mailing list