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.

std.experimental.testing.gen_ut_main_mixin

This module implements a template mixin containing a program to search a list of directories for all .d files therein, then writes a D program to run all unit tests in those files using std.experimental.testing. The program implemented by this mixin only writes out a D file that itself must be compiled and run.
To use this as a runnable program, simply mix in and compile:
#!/usr/bin/rdmd
import std.experimental.testing;
mixin genUtMain;

Or just use rdmd with the included gen_ut_main.d which does the above. The examples below use the second option.

By default, genUtMain will look for unit tests in a tests folder and write a program out to a file named ut.d. To change the file to write to, use the -f option. To change what directories to look in, simply pass them in as the remaining command-line arguments.
Examples:
# write ut.d that finds unit tests from files in the tests directory
rdmd $PHOBOS/std/experimental/testing/gen_ut_main.d

# write foo.d that finds unit tests from the src and other directories
rdmd $PHOBOS/std/experimental/testing/gen_ut_main.d -f foo.d src other

The resulting ut.d file (or as named by the -f option) is also a program that must be compiled and, when run, will run the unit tests found. By default, it will run all tests. To run one test or all tests in a particular package, pass them in as command-line arguments. The -h option will list all command-line options.

Examples (assuming the generated file is called ut.d):
rdmd -unittest ut.d # run all tests
rdmd -unittest ut.d tests.foo tests.bar # run all tests from these packages
rdmd ut.d -h # list command-line options