#!/usr/bin/env rdmd module run; import std.stdio; import std.process; import std.string; int main(string[] args) { if (args.length < 2) { stderr.writeln("Missing required sub-command. Should be one of the following:"); stderr.writeln(" - \"unit-test\": Build and run unit tests for the entire project."); stderr.writeln(" - \"integration-test\": Build and run integration tests for the entire project."); return 1; } string command = args[1].toLower.strip; if (command == "unit-test") { return doUnitTests(args[2..$]); } else if (command == "integration-test") { return doIntegrationTests(args[2..$]); } stderr.writefln!"Invalid sub-command: %s."(command); return 1; } int doUnitTests(string[] args) { const subPackages = ["http-primitives", "http-parser"]; uint subPackagesSuccessful = 0; foreach (subPackage; subPackages) { writefln!"Running unit tests for sub-package \"%s\"..."(subPackage); int exitCode = wait(spawnProcess(["dub", "test", ":" ~ subPackage])); if (exitCode == 0) subPackagesSuccessful++; writeln(); } writefln!"Unit tests were successful in %d / %d sub-packages.\n"(subPackagesSuccessful, subPackages.length); if (subPackagesSuccessful != subPackages.length) { writeln("Skipping testing main package because sub-packages have errors."); return 1; } writeln("Running unit tests for main package..."); return wait(spawnProcess(["dub", "test"])); } int doIntegrationTests(string[] args) { writeln("Integration tests not yet implemented."); return 1; }