-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port
test.sh
to platform independent D.
This executes also way faster by not spawning GNU diff.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env rdmd | ||
/** | ||
Platform independent port of `test.sh`. Runs the tests in this directory. | ||
Ignores differences in line endings, unless the test uses `--end_of_line`. | ||
**/ | ||
import std.algorithm, std.array, std.conv, std.file, std.path, std.process; | ||
import std.stdio, std.string, std.typecons, std.range, std.uni; | ||
|
||
version (Windows) | ||
enum dfmt = `..\bin\dfmt.exe`; | ||
else | ||
enum dfmt = `../bin/dfmt`; | ||
|
||
int main() | ||
{ | ||
foreach (braceStyle; ["allman", "otbs", "knr"]) | ||
{ | ||
foreach (entry; dirEntries(".", "*.d", SpanMode.shallow). | ||
filter!(e => e.baseName(".d") != thisExePath.baseName(".exe"))) | ||
{ | ||
const source = entry.baseName; | ||
const argsFile = source.stripExtension ~ ".args"; | ||
const dfmtCommand = | ||
[dfmt, "--brace_style=" ~ braceStyle] ~ | ||
(argsFile.exists ? readText(argsFile).splitter!isWhite.filter!(a => a.length).array : []) ~ | ||
[source]; | ||
writeln(dfmtCommand.join(" ")); | ||
auto output = File(buildPath(braceStyle, source ~ ".out"), "w+"); | ||
if (const result = spawnProcess(dfmtCommand, stdin, output, stderr, null, Config.retainStdout).wait) | ||
return result; | ||
|
||
output.rewind; | ||
auto keepTerminator = dfmtCommand.any!(a => a.canFind("--end_of_line")).to!(Flag!"keepTerminator"); | ||
auto reference = buildPath(braceStyle, source ~ ".ref").readText.splitLines(keepTerminator); | ||
foreach (i, line; output.byLine(keepTerminator).enumerate) | ||
if (line != reference[i]) | ||
{ | ||
writeln("Found difference between ", output.name, " and ", | ||
buildPath(braceStyle, source ~ ".ref"), " on line ", i + 1, ":"); | ||
writeln("dfmt: ", line.stripRight); | ||
writeln("ref : ", reference[i].stripRight); | ||
writeln("Representation:"); | ||
writeln("dfmt: ", line.representation); | ||
writeln("ref : ", reference[i].representation); | ||
return 1; | ||
} | ||
} | ||
} | ||
|
||
foreach (entry; dirEntries("expected_failures", "*.d", SpanMode.shallow)) | ||
if (execute([dfmt, entry]).status == 0) | ||
{ | ||
stderr.writeln("Expected failure on test " ~ entry ~ " but passed."); | ||
return 1; | ||
} | ||
|
||
writeln("All tests succeeded."); | ||
return 0; | ||
} |