Skip to content

Commit

Permalink
[CSharp] Add extra diagnostics to the C# runtime tests.
Browse files Browse the repository at this point in the history
Log the command / stdout / stderr / exit status at three places
during the C# runtime tests.

At these places we are executing subprocesses, but if those fail we
weren't logging the info that we may need to diagnose the problem.
  • Loading branch information
ewanmellor committed Nov 14, 2017
1 parent 5a3ef86 commit 4e4f1ca
Showing 1 changed file with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenSource;
import org.antlr.v4.runtime.WritableToken;
import org.antlr.v4.runtime.misc.Utils;
import org.antlr.v4.test.runtime.ErrorQueue;
import org.antlr.v4.test.runtime.RuntimeTestSupport;
import org.antlr.v4.test.runtime.StreamVacuum;
Expand Down Expand Up @@ -394,10 +395,15 @@ private boolean buildProject() throws Exception {
stdoutVacuum.join();
stderrVacuum.join();
// xbuild sends errors to output, so check exit code
boolean success = process.exitValue()==0;
int exitValue = process.exitValue();
boolean success = (exitValue == 0);
if ( !success ) {
this.stderrDuringParse = stdoutVacuum.toString();
System.err.println("buildProject stderrVacuum: "+ this.stderrDuringParse);
String stderrString = stderrVacuum.toString();
System.err.println("buildProject command: " + Utils.join(args, " "));
System.err.println("buildProject exitValue: " + exitValue);
System.err.println("buildProject stdout: " + stderrDuringParse);
System.err.println("buildProject stderr: " + stderrString);
}
return success;
}
Expand Down Expand Up @@ -552,10 +558,14 @@ private boolean runProcess(String[] args, String path) throws Exception {
process.waitFor();
stdoutVacuum.join();
stderrVacuum.join();
boolean success = process.exitValue()==0;
int exitValue = process.exitValue();
boolean success = (exitValue == 0);
if ( !success ) {
this.stderrDuringParse = stderrVacuum.toString();
System.err.println("runProcess stderrVacuum: "+ this.stderrDuringParse);
System.err.println("runProcess command: " + Utils.join(args, " "));
System.err.println("runProcess exitValue: " + exitValue);
System.err.println("runProcess stdoutVacuum: " + stdoutVacuum.toString());
System.err.println("runProcess stderrVacuum: " + stderrDuringParse);
}
return success;
}
Expand Down Expand Up @@ -584,9 +594,28 @@ public String execTest() {
ProcessBuilder pb = new ProcessBuilder(args);
pb.directory(tmpdirFile);
Process process = pb.start();
StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream());
stdoutVacuum.start();
stderrVacuum.start();
process.waitFor();
stdoutVacuum.join();
stderrVacuum.join();
String writtenOutput = TestOutputReading.read(output);
this.stderrDuringParse = TestOutputReading.read(errorOutput);
int exitValue = process.exitValue();
String stdoutString = stdoutVacuum.toString().trim();
String stderrString = stderrVacuum.toString().trim();
if (exitValue != 0) {
System.err.println("execTest command: " + Utils.join(args, " "));
System.err.println("execTest exitValue: " + exitValue);
}
if (!stdoutString.isEmpty()) {
System.err.println("execTest stdoutVacuum: " + stdoutString);
}
if (!stderrString.isEmpty()) {
System.err.println("execTest stderrVacuum: " + stderrString);
}
return writtenOutput;
}
catch (Exception e) {
Expand Down

0 comments on commit 4e4f1ca

Please sign in to comment.