diff --git a/.idea/modules.xml b/.idea/modules.xml
index 94213936f8b..a7a32bf50d1 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -6,6 +6,7 @@
+
diff --git a/compiler/integration-tests/compiler-integration-tests.iml b/compiler/integration-tests/compiler-integration-tests.iml
new file mode 100644
index 00000000000..b9f5f634fdc
--- /dev/null
+++ b/compiler/integration-tests/compiler-integration-tests.iml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/compiler/integration-tests/data/help.gold b/compiler/integration-tests/data/help.gold
new file mode 100644
index 00000000000..9bb334537b7
--- /dev/null
+++ b/compiler/integration-tests/data/help.gold
@@ -0,0 +1,16 @@
+OUT Usage: org.jetbrains.jet.cli.CompilerArguments
+OUT -output [String] output directory
+OUT -jar [String] jar file name
+OUT -src [String] source file or directory
+OUT -module [String] module to compile
+OUT -classpath [String] classpath to use when compiling
+OUT -includeRuntime [flag]
+OUT -stdlib [String] Path to the stdlib.jar
+OUT -jdkHeaders [String] Path to the kotlin-jdk-headers.jar
+OUT -help (-h) [flag]
+OUT -mode [String] Special compiler modes: stubs or jdkHeaders
+OUT -tags [flag]
+OUT -verbose [flag]
+OUT -version [flag]
+ERR exec() finished with INTERNAL_ERROR return code
+Return code: 2
diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java
new file mode 100644
index 00000000000..ef858496679
--- /dev/null
+++ b/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2010-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.kotlin;
+
+import org.junit.Test;
+
+public class CompilerSmokeTest extends KotlinIntegrationTestBase {
+ @Test
+ public void help() throws Exception {
+ runCompiler("help", "--help");
+ }
+}
diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java b/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java
new file mode 100644
index 00000000000..a8e793040ea
--- /dev/null
+++ b/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2010-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.kotlin;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+import com.intellij.execution.ExecutionException;
+import com.intellij.execution.configurations.GeneralCommandLine;
+import com.intellij.execution.process.OSProcessHandler;
+import com.intellij.execution.process.ProcessAdapter;
+import com.intellij.execution.process.ProcessEvent;
+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.util.ArrayUtil;
+import org.apache.commons.lang.SystemUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+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 {
+ Collection javaArgs = new ArrayList();
+ javaArgs.add("-jar");
+ javaArgs.add(getCompilerJar().getAbsolutePath());
+ Collections.addAll(javaArgs, arguments);
+
+ 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 {
+ GeneralCommandLine commandLine = new GeneralCommandLine();
+ commandLine.setExePath(getJavaRuntime().getAbsolutePath());
+ commandLine.addParameters(arguments);
+
+ StringBuilder executionLog = new StringBuilder();
+ int exitCode = runProcess(commandLine, executionLog);
+
+ if (logName == null) {
+ assertEquals("Non-zero exit code", 0, exitCode);
+ }
+ else {
+ check(logName, executionLog);
+ }
+ }
+
+ protected void check(String baseName, StringBuilder content) throws IOException {
+ final File tmpFile = new File(getTestDataDirectory(), baseName + ".tmp");
+ final File goldFile = new File(getTestDataDirectory(), baseName + ".gold");
+
+ if (!goldFile.isFile()) {
+ Files.write(content, tmpFile, Charsets.UTF_8);
+ fail("No gold file " + goldFile);
+ } else {
+ final String goldContent = Files.toString(goldFile, UTF_8);
+ if (!goldContent.equals(content.toString())) {
+ Files.write(content, tmpFile, Charsets.UTF_8);
+ fail("tmp and gold differ, tmp file: " + tmpFile);
+ }
+ tmpFile.delete();
+ }
+ }
+
+ protected int runProcess(final GeneralCommandLine commandLine, final StringBuilder executionLog) throws ExecutionException {
+ OSProcessHandler handler =
+ new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
+
+ final StringBuilder outContent = new StringBuilder();
+ final StringBuilder errContent = new StringBuilder();
+
+ handler.addProcessListener(new ProcessAdapter() {
+ @Override
+ public void onTextAvailable(ProcessEvent event, Key outputType) {
+ if (outputType == ProcessOutputTypes.SYSTEM) {
+ System.out.print(event.getText());
+ }
+ else if (outputType == ProcessOutputTypes.STDOUT) {
+ outContent.append("OUT ");
+ outContent.append(event.getText());
+ }
+ else if (outputType == ProcessOutputTypes.STDERR) {
+ errContent.append("ERR ");
+ errContent.append(event.getText());
+ }
+ }
+ });
+
+ handler.startNotify();
+ handler.waitFor();
+ int exitCode = handler.getProcess().exitValue();
+
+ executionLog.append(outContent);
+ executionLog.append(errContent);
+ executionLog.append("Return code: ").append(exitCode).append(SystemUtils.LINE_SEPARATOR);
+
+ return exitCode;
+ }
+
+ protected static File getJavaRuntime() {
+ final File javaHome = new File(System.getProperty("java.home"));
+ final String javaExe = SystemInfo.isWindows ? "java.exe" : "java";
+
+ final File runtime = new File(javaHome, "bin" + File.separator + javaExe);
+ assertTrue("no java runtime at " + runtime, runtime.isFile());
+
+ 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());
+ return file;
+ }
+
+ protected static File getTestDataDirectory() {
+ return new File(getKotlinProjectHome(), "compiler" + File.separator + "integration-tests" + File.separator + "data");
+ }
+
+ protected static File getKotlinProjectHome() {
+ return new File(PathManager.getHomePath()).getParentFile();
+ }
+}