Skip to content

Commit ebe3d99

Browse files
Restoring the UnitTests to their former glory
1 parent 6dfc229 commit ebe3d99

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

buildscripts/unittest.csx

+21-14
Original file line numberDiff line numberDiff line change
@@ -13,57 +13,64 @@ void Fail(string error)
1313

1414
string CallProcess(string processName, string args, out int exitCode)
1515
{
16+
StringBuilder outputBuilder;
1617
System.Diagnostics.ProcessStartInfo processStartInfo;
1718
System.Diagnostics.Process process;
1819

20+
outputBuilder = new StringBuilder();
21+
1922
processStartInfo = new System.Diagnostics.ProcessStartInfo();
2023
processStartInfo.CreateNoWindow = true;
21-
processStartInfo.RedirectStandardOutput = false;
22-
processStartInfo.RedirectStandardInput = false;
24+
processStartInfo.RedirectStandardOutput = true;
25+
processStartInfo.RedirectStandardInput = true;
2326
processStartInfo.UseShellExecute = false;
2427
processStartInfo.Arguments = args;
2528
processStartInfo.FileName = processName;
2629

2730
process = new System.Diagnostics.Process();
2831
process.StartInfo = processStartInfo;
2932
process.EnableRaisingEvents = true;
33+
34+
process.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler
35+
(
36+
delegate(object sender, System.Diagnostics.DataReceivedEventArgs e)
37+
{
38+
outputBuilder.Append(e.Data);
39+
}
40+
);
3041

3142
process.Start();
43+
process.BeginOutputReadLine();
3244
process.WaitForExit();
45+
process.CancelOutputRead();
3346

3447
exitCode = process.ExitCode;
3548

36-
return "";
49+
return outputBuilder.ToString();
3750
}
3851

39-
string scriptFile = "tmp\\code.lls";
52+
string scriptFile = "tmp/code.lls";
4053

4154
void TestWithParams(string test, string param)
4255
{
4356
Console.WriteLine("\t" + (string.IsNullOrEmpty(param) ? "(default)" : param));
4457

45-
string byteCodeFile = "tmp\\bytecode.lls";
46-
string outputFile = "tmp\\out.txt";
58+
string byteCodeFile = "tmp/bytecode.lls";
4759

4860
string output = CallProcess("..\\builds\\bin\\llsc.exe", $"{scriptFile}{param} -o=\"{byteCodeFile}\"", out int exitCode);
4961

5062
if (exitCode != 0)
5163
Fail($"Failed to compile test {test} (error code 0x{exitCode:X})\n\n{output}");
5264

53-
output = CallProcess("C:\\Windows\\System32\\cmd.exe", $"/C ..\\builds\\bin\\llscript_exec.exe {byteCodeFile} > {outputFile}", out exitCode);
65+
output = CallProcess("..\\builds\\bin\\llscript_exec.exe", byteCodeFile, out exitCode);
5466

5567
if (exitCode != 0)
5668
Fail($"Failed to execute test {test} (error code 0x{exitCode:X})\n\n{output}");
57-
58-
System.Threading.Thread.Sleep(200);
5969

6070
var expected = File.ReadAllText(test.Replace("lls", "txt"));
61-
var received = File.ReadAllText(outputFile);
6271

63-
File.Delete(outputFile);
64-
65-
if (expected != received)
66-
Fail($"Invalid output for test {test}\n\nExpected: ({expected.Length} chars) '{expected}'\nReceived: ({received.Length} chars) '{received}'");
72+
if (expected != output)
73+
Fail($"Invalid output for test {test}\n\nExpected: ({expected.Length} chars) '{expected}'\nRetrieved: ({output.Length} chars) '{output}'");
6774
}
6875

6976
try

0 commit comments

Comments
 (0)