diff --git a/test/run.d b/test/run.d index b18b15c02605..6af2c472fc4f 100755 --- a/test/run.d +++ b/test/run.d @@ -67,6 +67,7 @@ Examples: ./run.d runnable/template2962.d # runs a specific tests ./run.d runnable/template2962.d fail_compilation/fail282.d # runs multiple specific tests ./run.d fail_compilation # runs all tests in fail_compilation + ./run.d unit_tests # runs all unit tests ./run.d all # runs all tests ./run.d clean # remove all test results ./run.d -u -- unit/deinitialization.d -f Module # runs the unit tests in the file "unit/deinitialization.d" with a UDA containing "Module" @@ -123,7 +124,7 @@ Options: ensureToolsExists(EnumMembers!TestTools); foreach (target; taskPool.parallel(targets, 1)) { - log("run: %-(%s %)", target.args); + log("%-(%s %)", target.args); ret |= spawnProcess(target.args, env, Config.none, scriptDir).wait; } if (ret) @@ -156,7 +157,7 @@ void ensureToolsExists(const TestTool[] tools ...) const targetBin = resultsDir.buildPath(tool).exeName; const sourceFile = toolsDir.buildPath(tool ~ ".d"); if (targetBin.timeLastModified.ifThrown(SysTime.init) >= sourceFile.timeLastModified) - writefln("%s is already up-to-date", tool); + log("%s is already up-to-date", tool); else { const command = [ @@ -165,8 +166,9 @@ void ensureToolsExists(const TestTool[] tools ...) sourceFile ] ~ tool.extraArgs; - writefln("Executing: %-(%s %)", command); - spawnProcess(command).wait; + stderr.writefln("[run.d] %-(%s %)", command); + if (spawnProcess(command).wait != 0) + exit(1); } } @@ -273,6 +275,8 @@ auto predefinedTargets(string[] targets) foreach (testDir; testDirs) newTargets.put(findFiles(testDir).map!createTestTarget); break; + case "unittest": + case "unittests": case "unit_tests": newTargets ~= createUnitTestTarget(); break; @@ -291,7 +295,7 @@ auto filterTargets(Target[] targets, string[string] env) { if (!target.exists) { - writefln("Warning: %s can't be found", target.normalizedTestName); + stderr.writefln("[run.d] Warning: %s can't be found", target.normalizedTestName); error = true; } } @@ -305,7 +309,7 @@ auto filterTargets(Target[] targets, string[string] env) auto resultRunTime = resultsDir.buildPath(testName ~ ".out").timeLastModified.ifThrown(SysTime.init); if (!force && resultRunTime > testPath(testName).timeLastModified && resultRunTime > env["DMD"].timeLastModified.ifThrown(SysTime.init)) - writefln("%s is already up-to-date", testName); + writefln("[run.d] %s is already up-to-date", testName); else targetsThatNeedUpdating ~= t; } @@ -413,7 +417,10 @@ string[string] getEnvironment() auto log(T...)(T args) { if (verbose) - writefln(args); + { + args[0] = "[run.d]: " ~ args[0]; + stderr.writefln(args); + } } // Add the executable filename extension to the given `name` for the current OS. diff --git a/test/tools/unit_test_runner.d b/test/tools/unit_test_runner.d index ae58be555298..c571a2648570 100755 --- a/test/tools/unit_test_runner.d +++ b/test/tools/unit_test_runner.d @@ -8,8 +8,8 @@ import std.exception : enforce; import std.file : dirEntries, exists, SpanMode, mkdirRecurse, write; import std.format : format; import std.getopt : getopt; -import std.path : absolutePath, buildPath, dirSeparator, stripExtension, - setExtension; +import std.path : absolutePath, buildPath, dirSeparator, relativePath, + setExtension, stripExtension; import std.process : environment, spawnProcess, spawnShell, wait; import std.range : empty; import std.stdio; @@ -19,6 +19,7 @@ import tools.paths; enum unitTestDir = testPath("unit"); enum strtoldObjPath = resultsDir.buildPath("strtold.obj"); +enum dmdSrcDir = projectRootDir.buildPath("src"); string[] testFiles(Range)(Range givenFiles) { @@ -34,10 +35,9 @@ string[] testFiles(Range)(Range givenFiles) auto moduleNames(const string[] testFiles) { return testFiles - .map!(e => e[unitTestDir.length + 1 .. $]) - .map!stripExtension - .array - .map!(e => e.substitute(dirSeparator, ".")); + .map!(e => e.relativePath(unitTestDir) + .stripExtension + .substitute(dirSeparator, ".")); } void writeRunnerFile(Range)(Range moduleNames, string path, string filter) @@ -236,7 +236,7 @@ void writeCmdfile(string path, string runnerPath, string outputPath, "-unittest", "-J" ~ buildOutputPath, "-J" ~ projectRootDir.buildPath("res"), - "-I" ~ projectRootDir.buildPath("src"), + "-I" ~ dmdSrcDir, "-I" ~ unitTestDir, "-i", "-g", @@ -289,10 +289,10 @@ void buildStrtold() "/EHsc", "/TP", "/c", - projectRootDir.buildPath("src", "dmd", "backend", "strtold.c"), + dmdSrcDir.buildPath("dmd", "backend", "strtold.c"), "/Fo" ~ strtoldObjPath, "/I", - projectRootDir.buildPath("src", "dmd", "root") + dmdSrcDir.buildPath("dmd", "root") ].join(" "); enforce(spawnShell(cmd).wait() == 0, "Failed to execute command: " ~ cmd); @@ -321,6 +321,9 @@ int main(string[] args) if (missingTestFiles(givenFiles)) return 1; + const nrOfFiles = givenFiles.length ? givenFiles.length.to!string : "all"; + stderr.writefln("[unit] Starting to build %s test files", nrOfFiles); + enum runnerPath = resultsDir.buildPath("runner.d"); const testFiles = givenFiles.testFiles; @@ -336,5 +339,6 @@ int main(string[] args) buildStrtold(); execute(dmdPath, "@" ~ cmdfilePath); + stderr.writefln("[unit] Starting to run %s test files", nrOfFiles); return spawnProcess(outputPath).wait(); }