@@ -13,57 +13,64 @@ void Fail(string error)
13
13
14
14
string CallProcess ( string processName , string args , out int exitCode )
15
15
{
16
+ StringBuilder outputBuilder ;
16
17
System . Diagnostics . ProcessStartInfo processStartInfo ;
17
18
System . Diagnostics . Process process ;
18
19
20
+ outputBuilder = new StringBuilder ( ) ;
21
+
19
22
processStartInfo = new System . Diagnostics . ProcessStartInfo ( ) ;
20
23
processStartInfo . CreateNoWindow = true ;
21
- processStartInfo . RedirectStandardOutput = false ;
22
- processStartInfo . RedirectStandardInput = false ;
24
+ processStartInfo . RedirectStandardOutput = true ;
25
+ processStartInfo . RedirectStandardInput = true ;
23
26
processStartInfo . UseShellExecute = false ;
24
27
processStartInfo . Arguments = args ;
25
28
processStartInfo . FileName = processName ;
26
29
27
30
process = new System . Diagnostics . Process ( ) ;
28
31
process . StartInfo = processStartInfo ;
29
32
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
+ ) ;
30
41
31
42
process . Start ( ) ;
43
+ process . BeginOutputReadLine ( ) ;
32
44
process . WaitForExit ( ) ;
45
+ process . CancelOutputRead ( ) ;
33
46
34
47
exitCode = process . ExitCode ;
35
48
36
- return "" ;
49
+ return outputBuilder . ToString ( ) ;
37
50
}
38
51
39
- string scriptFile = "tmp\\ code.lls" ;
52
+ string scriptFile = "tmp/ code.lls" ;
40
53
41
54
void TestWithParams ( string test , string param )
42
55
{
43
56
Console . WriteLine ( "\t " + ( string . IsNullOrEmpty ( param ) ? "(default)" : param ) ) ;
44
57
45
- string byteCodeFile = "tmp\\ bytecode.lls" ;
46
- string outputFile = "tmp\\ out.txt" ;
58
+ string byteCodeFile = "tmp/bytecode.lls" ;
47
59
48
60
string output = CallProcess ( "..\\ builds\\ bin\\ llsc.exe" , $ "{ scriptFile } { param } -o=\" { byteCodeFile } \" ", out int exitCode ) ;
49
61
50
62
if ( exitCode != 0 )
51
63
Fail ( $ "Failed to compile test { test } (error code 0x{ exitCode : X} )\n \n { output } ") ;
52
64
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 ) ;
54
66
55
67
if ( exitCode != 0 )
56
68
Fail ( $ "Failed to execute test { test } (error code 0x{ exitCode : X} )\n \n { output } ") ;
57
-
58
- System . Threading . Thread . Sleep ( 200 ) ;
59
69
60
70
var expected = File . ReadAllText ( test . Replace ( "lls" , "txt" ) ) ;
61
- var received = File . ReadAllText ( outputFile ) ;
62
71
63
- File . Delete ( outputFile ) ;
64
-
65
- if ( expected != received )
66
- Fail ( $ "Invalid output for test { test } \n \n Expected: ({ expected . Length } chars) '{ expected } '\n Received: ({ received . Length } chars) '{ received } '") ;
72
+ if ( expected != output )
73
+ Fail ( $ "Invalid output for test { test } \n \n Expected: ({ expected . Length } chars) '{ expected } '\n Retrieved: ({ output . Length } chars) '{ output } '") ;
67
74
}
68
75
69
76
try
0 commit comments