Simplified kotlinc tests.

This commit is contained in:
Evgeny Gerashchenko
2014-02-11 22:17:11 +04:00
parent aeade9e68d
commit 5a1f98041e
2 changed files with 18 additions and 33 deletions
@@ -16,10 +16,9 @@
package org.jetbrains.jet.cli; package org.jetbrains.jet.cli;
import com.intellij.openapi.util.Ref; import com.intellij.execution.process.ProcessOutput;
import com.intellij.execution.util.ExecUtil;
import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.cli.common.ExitCode; import org.jetbrains.jet.cli.common.ExitCode;
@@ -27,7 +26,7 @@ import org.jetbrains.jet.test.TestCaseWithTmpdir;
import org.jetbrains.jet.utils.PathUtil; import org.jetbrains.jet.utils.PathUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.util.List;
public abstract class AbstractKotlincExecutableTest extends TestCaseWithTmpdir { public abstract class AbstractKotlincExecutableTest extends TestCaseWithTmpdir {
private void doTest(@NotNull String argsFilePath, @NotNull String executableName, @NotNull String testDataDir) throws Exception { private void doTest(@NotNull String argsFilePath, @NotNull String executableName, @NotNull String testDataDir) throws Exception {
@@ -35,38 +34,24 @@ public abstract class AbstractKotlincExecutableTest extends TestCaseWithTmpdir {
File kotlincFile = new File(PathUtil.getKotlinPathsForDistDirectory().getHomePath(), "bin/" + executableFileName); File kotlincFile = new File(PathUtil.getKotlinPathsForDistDirectory().getHomePath(), "bin/" + executableFileName);
assertTrue("kotlinc executable not found, probably you need to invoke 'dist' Ant target: " + kotlincFile.getAbsolutePath(), kotlincFile.exists()); assertTrue("kotlinc executable not found, probably you need to invoke 'dist' Ant target: " + kotlincFile.getAbsolutePath(), kotlincFile.exists());
String[] args = CliBaseTest.readArgs(argsFilePath, testDataDir, tmpdir.getAbsolutePath()); List<String> args = CliBaseTest.readArgs(argsFilePath, testDataDir, tmpdir.getAbsolutePath());
args.add(0, kotlincFile.getAbsolutePath());
ProcessOutput processOutput = ExecUtil.execAndGetOutput(args, null);
final Process process = Runtime.getRuntime().exec(ArrayUtil.prepend(kotlincFile.getAbsolutePath(), args)); String stdout = processOutput.getStdout();
String stderr = processOutput.getStderr();
int exitCode = processOutput.getExitCode();
final Ref<String> stderr = Ref.create(); String normalizedOutput = CliBaseTest.getNormalizedCompilerOutput(stdout, ExitCode.values()[exitCode], testDataDir);
new Thread(new Runnable() {
@Override
public void run() {
try {
stderr.set(FileUtil.loadTextAndClose(process.getErrorStream()));
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
}).start();
String output = FileUtil.loadTextAndClose(process.getInputStream());
int intExitCode = process.waitFor();
ExitCode exitCode = ExitCode.values()[intExitCode];
String normalizedOutput = CliBaseTest.getNormalizedCompilerOutput(output, exitCode, testDataDir);
File outFile = new File(argsFilePath.replace(".args", ".out")); File outFile = new File(argsFilePath.replace(".args", ".out"));
try { try {
JetTestUtils.assertEqualsToFile(outFile, normalizedOutput); JetTestUtils.assertEqualsToFile(outFile, normalizedOutput);
} }
catch (Exception e) { catch (Exception e) {
System.out.println("exitcode " + intExitCode); System.err.println("exitcode " + exitCode);
System.out.println("<stdout>" + output + "</stdout>"); System.err.println("<stdout>" + stdout + "</stdout>");
System.out.println("<stderr>" + stderr + "</stderr>"); System.err.println("<stderr>" + stderr + "</stderr>");
throw e; throw e;
} }
@@ -45,12 +45,12 @@ public class CliBaseTest {
public final TestName testName = new TestName(); public final TestName testName = new TestName();
@NotNull @NotNull
private static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLICompiler<?> compiler, @NotNull String[] args) { private static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLICompiler<?> compiler, @NotNull List<String> args) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ByteArrayOutputStream bytes = new ByteArrayOutputStream();
PrintStream origOut = System.out; PrintStream origOut = System.out;
try { try {
System.setOut(new PrintStream(bytes)); System.setOut(new PrintStream(bytes));
ExitCode exitCode = CLICompiler.doMainNoExit(compiler, args); ExitCode exitCode = CLICompiler.doMainNoExit(compiler, ArrayUtil.toStringArray(args));
return Pair.create(bytes.toString("utf-8"), exitCode); return Pair.create(bytes.toString("utf-8"), exitCode);
} }
catch (Exception e) { catch (Exception e) {
@@ -79,14 +79,14 @@ public class CliBaseTest {
} }
@NotNull @NotNull
static String[] readArgs( static List<String> readArgs(
@NotNull String argsFilePath, @NotNull String argsFilePath,
@NotNull final String testDataDir, @NotNull final String testDataDir,
@NotNull final String tempDir @NotNull final String tempDir
) throws IOException { ) throws IOException {
List<String> lines = FileUtil.loadLines(new FileInputStream(argsFilePath)); List<String> lines = FileUtil.loadLines(new FileInputStream(argsFilePath));
return ArrayUtil.toStringArray(ContainerUtil.mapNotNull(lines, new Function<String, String>() { return ContainerUtil.mapNotNull(lines, new Function<String, String>() {
@Override @Override
public String fun(String arg) { public String fun(String arg) {
if (arg.isEmpty()) { if (arg.isEmpty()) {
@@ -97,7 +97,7 @@ public class CliBaseTest {
.replace("$TEMP_DIR$", tempDir) .replace("$TEMP_DIR$", tempDir)
.replace("$TESTDATA_DIR$", testDataDir); .replace("$TESTDATA_DIR$", testDataDir);
} }
})); });
} }
protected void executeCompilerCompareOutputJVM() throws Exception { protected void executeCompilerCompareOutputJVM() throws Exception {