integration tests: compile and run hello app
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
Return code: 0
|
||||||
@@ -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 org.junit.Test;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.*;
|
||||||
|
|
||||||
public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
||||||
@Test
|
@Test
|
||||||
public void help() throws Exception {
|
public void help() throws Exception {
|
||||||
runCompiler("help", "--help");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-20
@@ -27,8 +27,11 @@ 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.Key;
|
||||||
import com.intellij.openapi.util.SystemInfo;
|
import com.intellij.openapi.util.SystemInfo;
|
||||||
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
|
import com.intellij.util.Function;
|
||||||
import org.apache.commons.lang.SystemUtils;
|
import org.apache.commons.lang.SystemUtils;
|
||||||
|
import sun.misc.JarFilter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -40,29 +43,29 @@ import static com.google.common.base.Charsets.UTF_8;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public abstract class KotlinIntegrationTestBase {
|
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>();
|
Collection<String> javaArgs = new ArrayList<String>();
|
||||||
javaArgs.add("-jar");
|
javaArgs.add("-cp");
|
||||||
javaArgs.add(getCompilerJar().getAbsolutePath());
|
javaArgs.add(classpath);
|
||||||
|
javaArgs.add("org.jetbrains.jet.cli.KotlinCompiler");
|
||||||
Collections.addAll(javaArgs, arguments);
|
Collections.addAll(javaArgs, arguments);
|
||||||
|
|
||||||
runJava(logName, ArrayUtil.toStringArray(javaArgs));
|
return runJava(logName, ArrayUtil.toStringArray(javaArgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void runCompiler(StringBuilder executionLog) throws ExecutionException {
|
protected int runJava(String logName, String... arguments) throws Exception {
|
||||||
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 {
|
|
||||||
GeneralCommandLine commandLine = new GeneralCommandLine();
|
GeneralCommandLine commandLine = new GeneralCommandLine();
|
||||||
|
commandLine.setWorkDirectory(getTestDataDirectory());
|
||||||
commandLine.setExePath(getJavaRuntime().getAbsolutePath());
|
commandLine.setExePath(getJavaRuntime().getAbsolutePath());
|
||||||
commandLine.addParameters(arguments);
|
commandLine.addParameters(arguments);
|
||||||
|
|
||||||
@@ -75,6 +78,8 @@ public abstract class KotlinIntegrationTestBase {
|
|||||||
else {
|
else {
|
||||||
check(logName, executionLog);
|
check(logName, executionLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void check(String baseName, StringBuilder content) throws IOException {
|
protected void check(String baseName, StringBuilder content) throws IOException {
|
||||||
@@ -139,9 +144,9 @@ public abstract class KotlinIntegrationTestBase {
|
|||||||
return runtime;
|
return runtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static File getCompilerJar() {
|
protected static File getCompilerLib() {
|
||||||
final File file = new File(getKotlinProjectHome(), "dist" + File.separator + "kotlin-compiler.jar");
|
final File file = new File(getKotlinProjectHome(), "dist" + File.separator + "kotlinc" + File.separator + "lib");
|
||||||
assertTrue("no kotlin compiler at " + file, file.isFile());
|
assertTrue("no kotlin compiler lib at " + file, file.isDirectory());
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user