Skip to content

Commit

Permalink
Output test files to test directory
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrejMitrovic committed Nov 25, 2012
1 parent b67fbdb commit 04c2026
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions test/d_do_test.d
Expand Up @@ -208,9 +208,10 @@ string[] combinations(string argstr)
return results;
}

string genTempFilename()
string genTempFilename(string result_path)
{
auto a = appender!string();
a.put(result_path);
foreach (ref e; 0 .. 8)
{
formattedWrite(a, "%x", rndGen.front);
Expand Down Expand Up @@ -247,9 +248,9 @@ void removeIfExists(in char[] filename)
std.file.remove(filename);
}

string execute(ref File f, string command, bool expectpass)
string execute(ref File f, string command, bool expectpass, string result_path)
{
auto filename = genTempFilename();
auto filename = genTempFilename(result_path);
scope(exit) removeIfExists(filename);

auto rc = system(command ~ " > " ~ filename ~ " 2>&1");
Expand Down Expand Up @@ -302,6 +303,7 @@ int main(string[] args)
string output_dir = envData.results_dir ~ envData.sep ~ input_dir;
string output_file = envData.results_dir ~ envData.sep ~ input_dir ~ envData.sep ~ test_name ~ "." ~ test_extension ~ ".out";
string test_app_dmd_base = output_dir ~ envData.sep ~ test_name ~ "_";
string result_path = envData.results_dir ~ envData.sep;

TestArgs testArgs;

Expand Down Expand Up @@ -341,7 +343,7 @@ int main(string[] args)
string[] toCleanup;
scope(exit) foreach (file; toCleanup) collectException(std.file.remove(file));

auto thisRunName = genTempFilename();
auto thisRunName = genTempFilename(result_path);
auto fThisRun = File(thisRunName, "w");
scope(exit)
{
Expand All @@ -367,7 +369,7 @@ int main(string[] args)
join(testArgs.sources, " "));
version(Windows) command ~= " -map nul.map";

compile_output = execute(fThisRun, command, testArgs.mode != TestMode.FAIL_COMPILE);
compile_output = execute(fThisRun, command, testArgs.mode != TestMode.FAIL_COMPILE, result_path);
}
else
{
Expand All @@ -379,7 +381,7 @@ int main(string[] args)

string command = format("%s -m%s -I%s %s %s -od%s -c %s", envData.dmd, envData.model, input_dir,
testArgs.requiredArgs, c, output_dir, filename);
compile_output ~= execute(fThisRun, command, testArgs.mode != TestMode.FAIL_COMPILE);
compile_output ~= execute(fThisRun, command, testArgs.mode != TestMode.FAIL_COMPILE, result_path);
}

if (testArgs.mode == TestMode.RUN)
Expand All @@ -391,7 +393,7 @@ int main(string[] args)
// add after building the command so that before now, it's purely the .o's involved
toCleanup ~= test_app_dmd;

execute(fThisRun, command, true);
execute(fThisRun, command, true, result_path);
}
}

Expand All @@ -410,7 +412,7 @@ int main(string[] args)
string command = test_app_dmd;
if (testArgs.executeArgs) command ~= " " ~ testArgs.executeArgs;

execute(fThisRun, command, true);
execute(fThisRun, command, true, result_path);
}

fThisRun.close();
Expand All @@ -420,7 +422,7 @@ int main(string[] args)
f.write("Executing post-test script: ");
string prefix = "";
version (Windows) prefix = "bash ";
execute(f, prefix ~ testArgs.postScript ~ " " ~ thisRunName, true);
execute(f, prefix ~ testArgs.postScript ~ " " ~ thisRunName, true, result_path);
}
}
catch(Exception e)
Expand Down

0 comments on commit 04c2026

Please sign in to comment.