core.runtime.Runtime.extendedModuleUnitTester
- multiple declarations
Function Runtime.extendedModuleUnitTester
Overrides the default module unit tester with a user-supplied version. This routine will be called once on program initialization. The return value of this routine indicates to the runtime whether the tests ran without error.
There are two options for handlers. The bool
version is deprecated but
will be kept for legacy support. Returning true
from the handler is
equivalent to returning UnitTestResult
from the extended version.
Returning false
from the handler is equivalent to returning
UnitTestResult
from the extended version.
See the documentation for UnitTestResult
to see how you should set up
the return structure.
See the documentation for runModuleUnitTests
for how the default
algorithm works, or read the example below.
Parameters
Name | Description |
---|---|
h | The new unit tester. Set both to null to use the default unit tester. |
Example
shared static this()
{
import core .runtime;
Runtime .extendedModuleUnitTester = &customModuleUnitTester;
}
UnitTestResult customModuleUnitTester()
{
import std .stdio;
writeln("Using customModuleUnitTester");
// Do the same thing as the default moduleUnitTester:
UnitTestResult result;
foreach (m; ModuleInfo)
{
if (m)
{
auto fp = m .unitTest;
if (fp)
{
++result .executed;
try
{
fp();
++result .passed;
}
catch (Throwable e)
{
writeln(e);
}
}
}
}
if (result .executed != result .passed)
{
result .runMain = false; // don't run main
result .summarize = true; // print failure
}
else
{
result .runMain = true; // all UT passed
result .summarize = false; // be quiet about it.
}
return result;
}
Function Runtime.extendedModuleUnitTester
Gets the current module unit tester.
This handler overrides any legacy module unit tester set by the moduleUnitTester property.
Returns
The current module unit tester handler or null if none has been set.
Authors
Sean Kelly