Skip to content

Commit

Permalink
fix a few d_do_test.d issues
Browse files Browse the repository at this point in the history
1) output of required args parameter had a few whitespace issues
2) include a few of denis-sh's refactorings
3) add a missing f.flush
  • Loading branch information
braddr committed Sep 23, 2012
1 parent 0facc54 commit 12ce4d2
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions test/d_do_test.d
Expand Up @@ -132,11 +132,7 @@ void gatherTestParameters(ref TestArgs testArgs, string input_dir, string input_
{
string file = cast(string)std.file.read(input_file);

if (findTestParameter(file, "REQUIRED_ARGS", testArgs.requiredArgs) &&
testArgs.requiredArgs.length > 0)
{
testArgs.requiredArgs ~= " ";
}
findTestParameter(file, "REQUIRED_ARGS", testArgs.requiredArgs);

if (! findTestParameter(file, "PERMUTE_ARGS", testArgs.permuteArgs))
{
Expand Down Expand Up @@ -245,10 +241,16 @@ version(Windows)
}
}

void removeIfExists(in char[] filename)
{
if (std.file.exists(filename))
std.file.remove(filename);
}

string execute(ref File f, string command, bool expectpass)
{
auto filename = genTempFilename();
scope(exit) if (std.file.exists(filename)) std.file.remove(filename);
scope(exit) removeIfExists(filename);

f.writeln(command);
auto rc = system(command ~ " > " ~ filename ~ " 2>&1");
Expand Down Expand Up @@ -318,16 +320,15 @@ int main(string[] args)
writef(" ... %-30s %s%s(%s)",
input_file,
testArgs.requiredArgs,
(testArgs.requiredArgs ? " " : ""),
(!testArgs.requiredArgs.empty ? " " : ""),
testArgs.permuteArgs);

if (testArgs.disabled)
writefln("!!! [DISABLED: %s]", testArgs.disabled_reason);
else
write("\n");

if (std.file.exists(output_file))
std.file.remove(output_file);
removeIfExists(output_file);

auto f = File(output_file, "a");

Expand Down Expand Up @@ -404,6 +405,7 @@ int main(string[] args)
if (testArgs.postScript)
{
f.write("Executing post-test script: ");
f.flush();
version (Windows) testArgs.postScript = "bash " ~ testArgs.postScript;
execute(f, testArgs.postScript, true);
}
Expand All @@ -427,11 +429,8 @@ int main(string[] args)
f.close();

writeln("Test failed. The logged output:");
if (std.file.exists(output_file))
{
writeln(cast(string)std.file.read(output_file));
std.file.remove(output_file);
}
writeln(cast(string)std.file.read(output_file));
std.file.remove(output_file);
return 1;
}
}
Expand Down

0 comments on commit 12ce4d2

Please sign in to comment.