core.runtime.Runtime.moduleUnitTester
- multiple declarations
Function Runtime.moduleUnitTester
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.
static void moduleUnitTester
(
bool function() h
) @property;
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.moduleUnitTester
Gets the current legacy module unit tester.
static bool moduleUnitTester();
This property should not be used, but is supported for legacy purposes.
Note that if the extended unit test handler is set, this handler will be ignored.
Returns
The current legacy module unit tester handler or null if none has been set.
Authors
Sean Kelly