Fixed the collection output of processes in integration tests.

This commit is contained in:
Zalim Bashorov
2013-12-13 16:53:19 +04:00
parent 13214d2dec
commit cf5174d798
24 changed files with 195 additions and 154 deletions
@@ -19,13 +19,10 @@ package org.jetbrains.kotlin;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.intellij.execution.ExecutionException; import com.intellij.execution.ExecutionException;
import com.intellij.execution.OutputListener;
import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.OSProcessHandler; import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.text.StringUtil;
@@ -119,6 +116,7 @@ public abstract class KotlinIntegrationTestBase {
content = normalizePath(content, testDataDir, "[TestData]"); content = normalizePath(content, testDataDir, "[TestData]");
content = normalizePath(content, tmpdir.getTmpDir(), "[Temp]"); content = normalizePath(content, tmpdir.getTmpDir(), "[Temp]");
content = normalizePath(content, getCompilerLib(), "[CompilerLib]"); content = normalizePath(content, getCompilerLib(), "[CompilerLib]");
content = StringUtil.convertLineSeparators(content);
return content; return content;
} }
@@ -135,6 +133,7 @@ public abstract class KotlinIntegrationTestBase {
else { else {
try { try {
JetTestUtils.assertEqualsToFile(expectedFile, normalizedContent); JetTestUtils.assertEqualsToFile(expectedFile, normalizedContent);
//noinspection ResultOfMethodCallIgnored
actualFile.delete(); actualFile.delete();
} }
catch (ComparisonFailure e) { catch (ComparisonFailure e) {
@@ -148,41 +147,30 @@ public abstract class KotlinIntegrationTestBase {
OSProcessHandler handler = OSProcessHandler handler =
new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset()); new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
final StringBuilder outContent = new StringBuilder(); StringBuilder outContent = new StringBuilder();
final StringBuilder errContent = new StringBuilder(); StringBuilder errContent = new StringBuilder();
handler.addProcessListener(new ProcessAdapter() { handler.addProcessListener(new OutputListener(outContent, errContent));
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
if (outputType == ProcessOutputTypes.SYSTEM) {
System.out.print(event.getText());
}
else if (outputType == ProcessOutputTypes.STDOUT) {
appendToContent(outContent, "OUT ", event.getText());
}
else if (outputType == ProcessOutputTypes.STDERR) {
appendToContent(errContent, "ERR ", event.getText());
}
}
private synchronized void appendToContent(StringBuilder content, String prefix, String line) {
content.append(prefix);
content.append(StringUtil.trimTrailing(line));
content.append("\n");
}
});
handler.startNotify(); handler.startNotify();
handler.waitFor(); handler.waitFor();
int exitCode = handler.getProcess().exitValue(); int exitCode = handler.getProcess().exitValue();
executionLog.append(outContent); appendIfNotEmpty(executionLog, "OUT:\n", outContent);
executionLog.append(errContent); appendIfNotEmpty(executionLog, "\nERR:\n", errContent);
executionLog.append("Return code: ").append(exitCode).append("\n");
executionLog.append("\nReturn code: ").append(exitCode).append("\n");
return exitCode; return exitCode;
} }
private static void appendIfNotEmpty(StringBuilder executionLog, String prefix, StringBuilder content) {
if (content.length() > 0) {
executionLog.append(prefix);
executionLog.append(content);
}
}
protected static File getJavaRuntime() { protected static File getJavaRuntime() {
File javaHome = new File(System.getProperty("java.home")); File javaHome = new File(System.getProperty("java.home"));
String javaExe = SystemInfo.isWindows ? "java.exe" : "java"; String javaExe = SystemInfo.isWindows ? "java.exe" : "java";
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [kotlinc] Compiling [[[TestData]/hello.kt]] => [[Temp]/hello.jar] build:
OUT [kotlinc] Compiling [[[TestData]/hello.kt]] => [[Temp]/hello.jar]
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,2 +1,4 @@
OUT Hello, a! OUT:
Hello, a!
Return code: 0 Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [kotlinc] Compiling [[[TestData]/root1, [TestData]/root2]] => [[Temp]/hello.jar] build:
OUT [kotlinc] Compiling [[[TestData]/root1, [TestData]/root2]] => [[Temp]/hello.jar]
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,2 +1,4 @@
OUT Hello, a! OUT:
Hello, a!
Return code: 0 Return code: 0
@@ -1,3 +1,7 @@
OUT ERROR: [TestData]/hello.kt: (4, 5) Unresolved reference: a OUT:
ERR exec() finished with COMPILATION_ERROR return code ERROR: [TestData]/hello.kt: (4, 5) Unresolved reference: a
ERR:
exec() finished with COMPILATION_ERROR return code
Return code: 1 Return code: 1
@@ -1,2 +1,4 @@
OUT Hello! OUT:
Hello!
Return code: 0 Return code: 0
@@ -1,2 +1,3 @@
OUT 1|2|3 OUT:
1|2|3
Return code: 0 Return code: 0
@@ -1,12 +1,14 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [mkdir] Created dir: [Temp]/classes build:
OUT [javac] Compiling 1 source file to [Temp]/classes [mkdir] Created dir: [Temp]/classes
OUT [javac] Compiling [[[TestData]/root1]] => [[Temp]/classes] [javac] Compiling 1 source file to [Temp]/classes
OUT [javac] Running javac... [javac] Compiling [[[TestData]/root1]] => [[Temp]/classes]
OUT [jar] Building jar: [Temp]/hello.jar [javac] Running javac...
OUT [jar] Building jar: [Temp]/hello.jar
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,3 +1,5 @@
OUT Hello, a! OUT:
OUT Java Hello Hello, a!
Java Hello
Return code: 0 Return code: 0
@@ -1,12 +1,14 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [mkdir] Created dir: [Temp]/classes build:
OUT [javac] Compiling 1 source file to [Temp]/classes [mkdir] Created dir: [Temp]/classes
OUT [javac] Compiling [[[TestData]/root1]] => [[Temp]/classes] [javac] Compiling 1 source file to [Temp]/classes
OUT [javac] Running javac... [javac] Compiling [[[TestData]/root1]] => [[Temp]/classes]
OUT [jar] Building jar: [Temp]/hello.jar [javac] Running javac...
OUT [jar] Building jar: [Temp]/hello.jar
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,3 +1,5 @@
OUT Hello, a! OUT:
OUT Java Hello, a!
Java
Return code: 0 Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1,[TestData]/bar.kt,[TestData]/root2/Foo.kt] => [[Temp]/out.js] build:
OUT [kotlin2js] Compiling [[TestData]/root1,[TestData]/bar.kt,[TestData]/root2/Foo.kt] => [[Temp]/out.js]
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,9 +1,13 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
ERR build:
ERR BUILD FAILED
ERR [TestData]/build.xml:5: "output" should be specified ERR:
ERR
ERR Total time: [time] BUILD FAILED
[TestData]/build.xml:5: "output" should be specified
Total time: [time]
Return code: 1 Return code: 1
@@ -1,9 +1,13 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
ERR build:
ERR BUILD FAILED
ERR [TestData]/build.xml:5: "src" should be specified ERR:
ERR
ERR Total time: [time] BUILD FAILED
[TestData]/build.xml:5: "src" should be specified
Total time: [time]
Return code: 1 Return code: 1
@@ -1,11 +1,13 @@
OUT Buildfile: [TestData]/build.xml OUT:
OUT Buildfile: [TestData]/build.xml
OUT build:
OUT [mkdir] Created dir: [Temp]/classes build:
OUT [kotlinc] Compiling [[[TestData]/root1]] => [[Temp]/classes] [mkdir] Created dir: [Temp]/classes
OUT [javac] Compiling 1 source file to [Temp]/classes [kotlinc] Compiling [[[TestData]/root1]] => [[Temp]/classes]
OUT [jar] Building jar: [Temp]/hello.jar [javac] Compiling 1 source file to [Temp]/classes
OUT [jar] Building jar: [Temp]/hello.jar
OUT BUILD SUCCESSFUL
OUT Total time: [time] BUILD SUCCESSFUL
Total time: [time]
Return code: 0 Return code: 0
@@ -1,3 +1,5 @@
OUT Hello, a! OUT:
OUT Java Hello Hello, a!
Java Hello
Return code: 0 Return code: 0
@@ -1,3 +1,7 @@
OUT ERROR: [TestData]/test.kt: (4, 20) Expecting an element OUT:
ERR exec() finished with COMPILATION_ERROR return code ERROR: [TestData]/test.kt: (4, 20) Expecting an element
ERR:
exec() finished with COMPILATION_ERROR return code
Return code: 1 Return code: 1