integration tests: compile and run hello app

This commit is contained in:
Leonid Shalupov
2012-04-22 22:54:13 +04:00
parent 22d601ffcb
commit 40e594668b
5 changed files with 41 additions and 20 deletions
@@ -0,0 +1 @@
Return code: 0
+5
View File
@@ -0,0 +1,5 @@
package Hello
fun main(args : Array<String>) {
System.out?.println("Hello!")
}
@@ -0,0 +1,2 @@
OUT Hello!
Return code: 0
@@ -18,9 +18,17 @@ package org.jetbrains.kotlin;
import org.junit.Test;
import static junit.framework.Assert.*;
public class CompilerSmokeTest extends KotlinIntegrationTestBase {
@Test
public void help() throws Exception {
runCompiler("help", "--help");
}
@Test
public void compileAndRunHelloApp() throws Exception {
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-src", "hello.kt", "-jar", "hello.jar"));
runJava("hello.run", "-cp", "hello.jar", "Hello.namespace");
}
}
@@ -27,8 +27,11 @@ 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.text.StringUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import org.apache.commons.lang.SystemUtils;
import sun.misc.JarFilter;
import java.io.File;
import java.io.IOException;
@@ -40,29 +43,29 @@ import static com.google.common.base.Charsets.UTF_8;
import static org.junit.Assert.*;
public abstract class KotlinIntegrationTestBase {
protected void runCompiler(String logName, String... arguments) throws Exception {
protected int runCompiler(String logName, String... arguments) throws Exception {
final File lib = getCompilerLib();
final File[] jars = lib.listFiles(new JarFilter());
final String classpath = StringUtil.join(jars, new Function<File, String>() {
@Override
public String fun(File file) {
return file.getAbsolutePath();
}
}, File.pathSeparator);
Collection<String> javaArgs = new ArrayList<String>();
javaArgs.add("-jar");
javaArgs.add(getCompilerJar().getAbsolutePath());
javaArgs.add("-cp");
javaArgs.add(classpath);
javaArgs.add("org.jetbrains.jet.cli.KotlinCompiler");
Collections.addAll(javaArgs, arguments);
runJava(logName, ArrayUtil.toStringArray(javaArgs));
return runJava(logName, ArrayUtil.toStringArray(javaArgs));
}
protected void runCompiler(StringBuilder executionLog) throws ExecutionException {
final File compilerJar = getCompilerJar();
assertTrue("no kotlin compiler at " + compilerJar, compilerJar.isFile());
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setExePath(getJavaRuntime().getAbsolutePath());
commandLine.addParameters("-jar", compilerJar.getAbsolutePath());
commandLine.addParameters("--help");
runProcess(commandLine, executionLog);
}
protected void runJava(String logName, String... arguments) throws Exception {
protected int runJava(String logName, String... arguments) throws Exception {
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setWorkDirectory(getTestDataDirectory());
commandLine.setExePath(getJavaRuntime().getAbsolutePath());
commandLine.addParameters(arguments);
@@ -75,6 +78,8 @@ public abstract class KotlinIntegrationTestBase {
else {
check(logName, executionLog);
}
return exitCode;
}
protected void check(String baseName, StringBuilder content) throws IOException {
@@ -139,9 +144,9 @@ public abstract class KotlinIntegrationTestBase {
return runtime;
}
protected static File getCompilerJar() {
final File file = new File(getKotlinProjectHome(), "dist" + File.separator + "kotlin-compiler.jar");
assertTrue("no kotlin compiler at " + file, file.isFile());
protected static File getCompilerLib() {
final File file = new File(getKotlinProjectHome(), "dist" + File.separator + "kotlinc" + File.separator + "lib");
assertTrue("no kotlin compiler lib at " + file, file.isDirectory());
return file;
}