Skip to content

Commit

Permalink
build.d: Add test target to run the test suite
Browse files Browse the repository at this point in the history
Calling `./build.d test` will now build dmd and run the test suite
as done for the makefile.
  • Loading branch information
MoonlightSentinel committed Sep 28, 2020
1 parent 9bf41e9 commit f96d7dd
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/build.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ import std.parallelism : TaskPool, totalCPUs;
const thisBuildScript = __FILE_FULL_PATH__.buildNormalizedPath;
const srcDir = thisBuildScript.dirName;
const dmdRepo = srcDir.dirName;
const testDir = dmdRepo.buildPath("test");

shared bool verbose; // output verbose logging
shared bool force; // always build everything (ignores timestamp checking)
shared bool dryRun; /// dont execute targets, just print command to be executed
__gshared int jobs; // Number of jobs to run in parallel

__gshared string[string] env;
__gshared string[][string] flags;
Expand All @@ -38,6 +41,7 @@ immutable rootRules = [
&runDmdUnittest,
&clean,
&checkwhitespace,
&runTests,
&buildFrontendHeaders,
&runCxxHeadersTest,
&runCxxUnittest,
Expand Down Expand Up @@ -72,7 +76,7 @@ int main(string[] args)

void runMain(string[] args)
{
int jobs = totalCPUs;
jobs = totalCPUs;
bool calledFromMake = false;
auto res = getopt(args,
"j|jobs", "Specifies the number of jobs (commands) to run simultaneously (default: %d)".format(totalCPUs), &jobs,
Expand Down Expand Up @@ -438,6 +442,30 @@ alias dmdDefault = makeRule!((builder, rule) => builder
.deps([dmdExe(null, null, null), dmdConf])
);

/// Run's the test suite using `run.d`
alias runTests = makeRule!((testBuilder, testRule)
{
// Precompiles the test runner
alias runner = methodInit!(BuildRule, (rundBuilder, rundRule) => rundBuilder
.msg("(DMD) RUN.D")
.sources([ testDir.buildPath( "run.d") ])
.target(env["GENERATED"].buildPath("run".exeName))
.command([ env["HOST_DMD"], "-of=" ~ rundRule.target, "-i", "-I" ~ testDir] ~ rundRule.sources));

testBuilder
.name("test")
.description("Run the test suite using test/run.d")
.msg("(RUN) TEST")
.deps([dmdDefault, runner])
.commandFunction({
// Use spawnProcess to avoid output redirection for `command`s
const scope cmd = [ runner.targets[0], "-j" ~ jobs.to!string ];
log("%-(%s %)", cmd);
if (spawnProcess(cmd, null, Config.init, testDir).wait())
abortBuild("Tests failed!");
});
});

/// BuildRule to run the DMD unittest executable.
alias runDmdUnittest = makeRule!((builder, rule) {
auto dmdUnittestExe = dmdExe("-unittest", ["-version=NoMain", "-unittest", "-main"], ["-unittest"]);
Expand Down

0 comments on commit f96d7dd

Please sign in to comment.