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.pass from the extended version. Returning false from the handler is equivalent to returning UnitTestResult.fail 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.

  1. ExtendedModuleUnitTester extendedModuleUnitTester [@property setter]
    struct Runtime
    static @property
    void
    extendedModuleUnitTester
  2. ExtendedModuleUnitTester extendedModuleUnitTester [@property getter]

Parameters

h ExtendedModuleUnitTester

The new unit tester. Set both to null to use the default unit tester.

Examples

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;
}

Meta