Minor, refactor integration tests

This commit is contained in:
Alexander Udalov
2014-07-30 21:26:53 -07:00
parent 3ca6c8615b
commit 6533c49f6d
2 changed files with 35 additions and 39 deletions
@@ -16,12 +16,16 @@
package org.jetbrains.kotlin; package org.jetbrains.kotlin;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName; import org.junit.rules.TestName;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -35,6 +39,19 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
return new File(new File(INTEGRATION_TEST_DATA_BASE_DIR, "smoke"), name.getMethodName()); return new File(new File(INTEGRATION_TEST_DATA_BASE_DIR, "smoke"), name.getMethodName());
} }
private int runCompiler(String logName, String... arguments) throws Exception {
String classpath = getCompilerLib().getAbsolutePath() + File.separator + "kotlin-compiler.jar" + File.pathSeparator +
getKotlinRuntimePath();
Collection<String> javaArgs = new ArrayList<String>();
javaArgs.add("-cp");
javaArgs.add(classpath);
javaArgs.add("org.jetbrains.jet.cli.jvm.K2JVMCompiler");
Collections.addAll(javaArgs, arguments);
return runJava(logName, ArrayUtil.toStringArray(javaArgs));
}
@Test @Test
public void helloApp() throws Exception { public void helloApp() throws Exception {
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar"; String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
@@ -26,21 +26,19 @@ import com.intellij.openapi.application.PathManager;
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;
import com.intellij.util.ArrayUtil;
import kotlin.Function1; import kotlin.Function1;
import kotlin.KotlinPackage; import kotlin.KotlinPackage;
import org.intellij.lang.annotations.Language; import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.jet.test.Tmpdir; import org.jetbrains.jet.test.Tmpdir;
import org.jetbrains.jet.utils.PathUtil;
import org.junit.ComparisonFailure; import org.junit.ComparisonFailure;
import org.junit.Rule; import org.junit.Rule;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.regex.MatchResult; import java.util.regex.MatchResult;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -60,22 +58,6 @@ public abstract class KotlinIntegrationTestBase {
@NotNull @NotNull
protected abstract File getTestDataDir(); protected abstract File getTestDataDir();
protected int runCompiler(String logName, String... arguments) throws Exception {
File lib = getCompilerLib();
String classpath = lib.getAbsolutePath() + File.separator +
"kotlin-compiler.jar" + File.pathSeparator +
getKotlinRuntimePath();
Collection<String> javaArgs = new ArrayList<String>();
javaArgs.add("-cp");
javaArgs.add(classpath);
javaArgs.add("org.jetbrains.jet.cli.jvm.K2JVMCompiler");
Collections.addAll(javaArgs, arguments);
return runJava(logName, ArrayUtil.toStringArray(javaArgs));
}
protected int runJava(String logName, String... arguments) throws Exception { protected int runJava(String logName, String... arguments) throws Exception {
GeneralCommandLine commandLine = new GeneralCommandLine(); GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setWorkDirectory(getTestDataDir()); commandLine.setWorkDirectory(getTestDataDir());
@@ -117,7 +99,7 @@ public abstract class KotlinIntegrationTestBase {
return content; return content;
} }
protected void check(String baseName, String content) throws IOException { private void check(String baseName, String content) throws IOException {
File actualFile = new File(getTestDataDir(), baseName + ".actual"); File actualFile = new File(getTestDataDir(), baseName + ".actual");
File expectedFile = new File(getTestDataDir(), baseName + ".expected"); File expectedFile = new File(getTestDataDir(), baseName + ".expected");
@@ -127,20 +109,19 @@ public abstract class KotlinIntegrationTestBase {
Files.write(normalizedContent, actualFile, Charsets.UTF_8); Files.write(normalizedContent, actualFile, Charsets.UTF_8);
fail("No .expected file " + expectedFile); fail("No .expected file " + expectedFile);
} }
else {
try { try {
JetTestUtils.assertEqualsToFile(expectedFile, normalizedContent); JetTestUtils.assertEqualsToFile(expectedFile, normalizedContent);
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
actualFile.delete(); actualFile.delete();
} }
catch (ComparisonFailure e) { catch (ComparisonFailure e) {
Files.write(normalizedContent, actualFile, Charsets.UTF_8); Files.write(normalizedContent, actualFile, Charsets.UTF_8);
throw e; throw e;
}
} }
} }
protected static int runProcess(GeneralCommandLine commandLine, StringBuilder executionLog) throws ExecutionException { private static int runProcess(GeneralCommandLine commandLine, StringBuilder executionLog) throws ExecutionException {
OSProcessHandler handler = OSProcessHandler handler =
new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset()); new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
@@ -168,26 +149,24 @@ public abstract class KotlinIntegrationTestBase {
} }
} }
protected static File getJavaRuntime() { private 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";
File runtime = new File(javaHome, "bin" + File.separator + javaExe); File runtime = new File(javaHome, "bin" + File.separator + javaExe);
assertTrue("no java runtime at " + runtime, runtime.isFile()); assertTrue("No java runtime at " + runtime, runtime.isFile());
return runtime; return runtime;
} }
protected static File getCompilerLib() { protected static File getCompilerLib() {
File file = new File(getKotlinProjectHome(), "dist" + File.separator + "kotlinc" + File.separator + "lib"); File file = PathUtil.getKotlinPathsForDistDirectory().getLibPath().getAbsoluteFile();
assertTrue("no kotlin compiler lib at " + file, file.isDirectory()); assertTrue("Lib directory doesn't exist. Run 'ant dist'", file.isDirectory());
return file; return file;
} }
protected static String getKotlinRuntimePath() { protected static String getKotlinRuntimePath() {
File file = new File(getCompilerLib(), "kotlin-runtime.jar"); return ForTestCompileRuntime.runtimeJarForTests().getAbsolutePath();
assertTrue("no kotlin runtime at " + file, file.isFile());
return file.getAbsolutePath();
} }
protected static File getKotlinProjectHome() { protected static File getKotlinProjectHome() {