diff --git a/compiler/integration-tests/data/hello.compile.gold b/compiler/integration-tests/data/hello.compile.gold new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/integration-tests/data/hello.compile.gold @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/integration-tests/data/hello.kt b/compiler/integration-tests/data/hello.kt new file mode 100644 index 00000000000..4c4a4b67c8c --- /dev/null +++ b/compiler/integration-tests/data/hello.kt @@ -0,0 +1,5 @@ +package Hello + +fun main(args : Array) { + System.out?.println("Hello!") +} diff --git a/compiler/integration-tests/data/hello.run.gold b/compiler/integration-tests/data/hello.run.gold new file mode 100644 index 00000000000..fc47ec99014 --- /dev/null +++ b/compiler/integration-tests/data/hello.run.gold @@ -0,0 +1,2 @@ +OUT Hello! +Return code: 0 diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java index ef858496679..72550b8a5a5 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java @@ -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"); + } } diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java b/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java index a8e793040ea..3f6f26c807c 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java @@ -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() { + @Override + public String fun(File file) { + return file.getAbsolutePath(); + } + }, File.pathSeparator); + Collection javaArgs = new ArrayList(); - 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; }