View source code
Display the source code in core/runtime.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function core.runtime.runModuleUnitTests

This routine is called by the runtime to run module unit tests on startup. The user-supplied unit tester will be called if one has been set, otherwise all unit tests will be run in sequence.

extern(C) UnitTestResult runModuleUnitTests();

If the extended unittest handler is registered, this function returns the result from that handler directly.

If a legacy boolean returning custom handler is used, false maps to UnitTestResult.fail, and true maps to UnitTestResult.pass. This was the original behavior of the unit testing system.

If no unittest custom handlers are registered, the following algorithm is executed (the behavior can be affected by the --DRT-testmode switch below): 1. Run all unit tests, tracking tests executed and passes. For each that fails, print the stack trace, and continue. 2. If there are no failures, set the summarize flag to false, and the runMain flag to true. 3. If there are failures, set the summarize flag to true, and the runMain flag to false.

See the documentation for UnitTestResult for details on how the runtime treats the return value from this function.

If the switch --DRT-testmode is passed to the executable, it can have one of 3 values: 1. "run-main": even if unit tests are run (and all pass), main is still run. This is currently the default. 2. "test-or-main": any unit tests present will cause the program to summarize the results and exit regardless of the result. This will be the default in 2.080. 3. "test-only", the runtime will always summarize and never run main, even if no tests are present.

This command-line parameter does not affect custom unit test handlers.

Returns

A UnitTestResult struct indicating the result of running unit tests.

Authors

Sean Kelly

License

Boost License 1.0