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.io.Files;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.OutputListener;
import com.intellij.execution.configurations.GeneralCommandLine;
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.util.Key;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
@@ -119,6 +116,7 @@ public abstract class KotlinIntegrationTestBase {
content = normalizePath(content, testDataDir, "[TestData]");
content = normalizePath(content, tmpdir.getTmpDir(), "[Temp]");
content = normalizePath(content, getCompilerLib(), "[CompilerLib]");
content = StringUtil.convertLineSeparators(content);
return content;
}
@@ -135,6 +133,7 @@ public abstract class KotlinIntegrationTestBase {
else {
try {
JetTestUtils.assertEqualsToFile(expectedFile, normalizedContent);
//noinspection ResultOfMethodCallIgnored
actualFile.delete();
}
catch (ComparisonFailure e) {
@@ -148,41 +147,30 @@ public abstract class KotlinIntegrationTestBase {
OSProcessHandler handler =
new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
final StringBuilder outContent = new StringBuilder();
final StringBuilder errContent = new StringBuilder();
StringBuilder outContent = new StringBuilder();
StringBuilder errContent = new StringBuilder();
handler.addProcessListener(new ProcessAdapter() {
@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.addProcessListener(new OutputListener(outContent, errContent));
handler.startNotify();
handler.waitFor();
int exitCode = handler.getProcess().exitValue();
executionLog.append(outContent);
executionLog.append(errContent);
executionLog.append("Return code: ").append(exitCode).append("\n");
appendIfNotEmpty(executionLog, "OUT:\n", outContent);
appendIfNotEmpty(executionLog, "\nERR:\n", errContent);
executionLog.append("\nReturn code: ").append(exitCode).append("\n");
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() {
File javaHome = new File(System.getProperty("java.home"));
String javaExe = SystemInfo.isWindows ? "java.exe" : "java";
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [kotlinc] Compiling [[[TestData]/hello.kt]] => [[Temp]/hello.jar]
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[kotlinc] Compiling [[[TestData]/hello.kt]] => [[Temp]/hello.jar]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,2 +1,4 @@
OUT Hello, a!
OUT:
Hello, a!
Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [kotlinc] Compiling [[[TestData]/root1, [TestData]/root2]] => [[Temp]/hello.jar]
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[kotlinc] Compiling [[[TestData]/root1, [TestData]/root2]] => [[Temp]/hello.jar]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,2 +1,4 @@
OUT Hello, a!
OUT:
Hello, a!
Return code: 0
@@ -1,3 +1,7 @@
OUT ERROR: [TestData]/hello.kt: (4, 5) Unresolved reference: a
ERR exec() finished with COMPILATION_ERROR return code
OUT:
ERROR: [TestData]/hello.kt: (4, 5) Unresolved reference: a
ERR:
exec() finished with COMPILATION_ERROR return code
Return code: 1
@@ -1,2 +1,4 @@
OUT Hello!
OUT:
Hello!
Return code: 0
@@ -1,2 +1,3 @@
OUT 1|2|3
OUT:
1|2|3
Return code: 0
@@ -1,12 +1,14 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [mkdir] Created dir: [Temp]/classes
OUT [javac] Compiling 1 source file to [Temp]/classes
OUT [javac] Compiling [[[TestData]/root1]] => [[Temp]/classes]
OUT [javac] Running javac...
OUT [jar] Building jar: [Temp]/hello.jar
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[mkdir] Created dir: [Temp]/classes
[javac] Compiling 1 source file to [Temp]/classes
[javac] Compiling [[[TestData]/root1]] => [[Temp]/classes]
[javac] Running javac...
[jar] Building jar: [Temp]/hello.jar
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,3 +1,5 @@
OUT Hello, a!
OUT Java Hello
OUT:
Hello, a!
Java Hello
Return code: 0
@@ -1,12 +1,14 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [mkdir] Created dir: [Temp]/classes
OUT [javac] Compiling 1 source file to [Temp]/classes
OUT [javac] Compiling [[[TestData]/root1]] => [[Temp]/classes]
OUT [javac] Running javac...
OUT [jar] Building jar: [Temp]/hello.jar
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[mkdir] Created dir: [Temp]/classes
[javac] Compiling 1 source file to [Temp]/classes
[javac] Compiling [[[TestData]/root1]] => [[Temp]/classes]
[javac] Running javac...
[jar] Building jar: [Temp]/hello.jar
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,3 +1,5 @@
OUT Hello, a!
OUT Java
OUT:
Hello, a!
Java
Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1,[TestData]/bar.kt,[TestData]/root2/Foo.kt] => [[Temp]/out.js]
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1,[TestData]/bar.kt,[TestData]/root2/Foo.kt] => [[Temp]/out.js]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,8 +1,10 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,9 +1,13 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
ERR
ERR BUILD FAILED
ERR [TestData]/build.xml:5: "output" should be specified
ERR
ERR Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
ERR:
BUILD FAILED
[TestData]/build.xml:5: "output" should be specified
Total time: [time]
Return code: 1
@@ -1,9 +1,13 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
ERR
ERR BUILD FAILED
ERR [TestData]/build.xml:5: "src" should be specified
ERR
ERR Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
ERR:
BUILD FAILED
[TestData]/build.xml:5: "src" should be specified
Total time: [time]
Return code: 1
@@ -1,11 +1,13 @@
OUT Buildfile: [TestData]/build.xml
OUT
OUT build:
OUT [mkdir] Created dir: [Temp]/classes
OUT [kotlinc] Compiling [[[TestData]/root1]] => [[Temp]/classes]
OUT [javac] Compiling 1 source file to [Temp]/classes
OUT [jar] Building jar: [Temp]/hello.jar
OUT
OUT BUILD SUCCESSFUL
OUT Total time: [time]
OUT:
Buildfile: [TestData]/build.xml
build:
[mkdir] Created dir: [Temp]/classes
[kotlinc] Compiling [[[TestData]/root1]] => [[Temp]/classes]
[javac] Compiling 1 source file to [Temp]/classes
[jar] Building jar: [Temp]/hello.jar
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -1,3 +1,5 @@
OUT Hello, a!
OUT Java Hello
OUT:
Hello, a!
Java Hello
Return code: 0
@@ -1,3 +1,7 @@
OUT ERROR: [TestData]/test.kt: (4, 20) Expecting an element
ERR exec() finished with COMPILATION_ERROR return code
OUT:
ERROR: [TestData]/test.kt: (4, 20) Expecting an element
ERR:
exec() finished with COMPILATION_ERROR return code
Return code: 1