diff --git a/compiler/integration-tests/compiler-integration-tests.iml b/compiler/integration-tests/compiler-integration-tests.iml
index 535159981db..9e68b015744 100644
--- a/compiler/integration-tests/compiler-integration-tests.iml
+++ b/compiler/integration-tests/compiler-integration-tests.iml
@@ -9,6 +9,8 @@
+
+
diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java
index ef4cc1801a2..3f9e1cb2ecf 100644
--- a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java
+++ b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java
@@ -16,52 +16,146 @@
package org.jetbrains.kotlin;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.util.ArrayUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.jet.utils.fileUtils.FileUtilsPackage;
+import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker;
+import org.jetbrains.k2js.test.rhino.RhinoUtils;
import org.junit.Test;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
public class AntTaskTest extends KotlinIntegrationTestBase {
- private void doAntTest(String... extraJavaArgs) throws Exception {
- String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
+ private static final int SUCCESSFUL = 0;
+ private static final int FAILED = 1;
+
+ private static final String JS_OUT_FILE = "out.js";
+ private static final String JVM_OUT_FILE = "hello.jar";
+
+ private void doAntTest(int expectedExitCode, String... extraArgs) throws Exception {
+ assertEquals("compilation failed", expectedExitCode, runAnt("build.log", "build.xml", extraArgs));
+ }
+
+ private void doJvmAntTest(String... extraJavaArgs) throws Exception {
+ doAntTest(SUCCESSFUL, extraJavaArgs);
+
+ String jar = getOutputFileByName(JVM_OUT_FILE).getAbsolutePath();
String runtime = getKotlinRuntimePath();
- assertEquals("compilation failed", 0, runAnt("build.log", "build.xml", extraJavaArgs));
runJava("hello.run", "-cp", jar + File.pathSeparator + runtime, "hello.HelloPackage");
}
+ private void doJsAntTest() throws Exception {
+ doAntTest(SUCCESSFUL);
+
+ String outputFilePath = getOutputFileByName(JS_OUT_FILE).getAbsolutePath();
+ RhinoUtils.runRhinoTest(Collections.singletonList(outputFilePath),
+ new RhinoFunctionResultChecker("out", "foo", "box", "OK"));
+ }
+
+ private void doJsAntTestForPostfixPrefix(@Nullable String prefix, @Nullable String postfix) throws Exception {
+ doJsAntTest();
+ File outputFile = getOutputFileByName(JS_OUT_FILE);
+
+ File prefixFile = null;
+ if (prefix != null) {
+ prefixFile = new File(testDataDir, prefix);
+ }
+
+ File postfixFile = null;
+ if (postfix != null) {
+ postfixFile = new File(testDataDir, postfix);
+ }
+
+ checkFilePrefixPostfix(outputFile, prefixFile, postfixFile);
+ }
+
@Test
public void antTaskJvm() throws Exception {
- doAntTest();
+ doJvmAntTest();
}
@Test
public void antTaskJvmManyRoots() throws Exception {
- doAntTest();
+ doJvmAntTest();
}
@Test
public void javacCompiler() throws Exception {
- doAntTest("-cp", getKotlinAntPath(),
- "-Dkotlin.home", getCompilerLib().getAbsolutePath());
+ doJvmAntTest("-cp", getKotlinAntPath(),
+ "-Dkotlin.home", getCompilerLib().getAbsolutePath());
}
@Test
public void externalAnnotations() throws Exception {
- doAntTest("-cp", getKotlinAntPath(),
- "-Didea.sdk", getIdeaSdkHome(),
- "-Dkotlin.home", getCompilerLib().getAbsolutePath());
+ doJvmAntTest("-cp", getKotlinAntPath(),
+ "-Didea.sdk", getIdeaSdkHome(),
+ "-Dkotlin.home", getCompilerLib().getAbsolutePath());
}
@Test
public void kotlinCompiler() throws Exception {
- doAntTest("-cp", getKotlinAntPath(),
- "-Didea.sdk", getIdeaSdkHome(),
- "-Dkotlin.home", getCompilerLib().getAbsolutePath());
+ doJvmAntTest("-cp", getKotlinAntPath(),
+ "-Didea.sdk", getIdeaSdkHome(),
+ "-Dkotlin.home", getCompilerLib().getAbsolutePath());
+ }
+
+ @Test
+ public void k2jsSimple() throws Exception {
+ doJsAntTest();
+ }
+
+ @Test
+ public void k2jsWithMain() throws Exception {
+ doJsAntTest();
+ }
+
+ @Test
+ public void k2jsManySources() throws Exception {
+ doJsAntTest();
+ }
+
+ @Test
+ public void k2jsWithoutSrcParam() throws Exception {
+ doAntTest(FAILED);
+ }
+
+ @Test
+ public void k2jsWithoutOutputParam() throws Exception {
+ doAntTest(FAILED);
+ }
+
+ @Test
+ public void k2jsWithPrefix() throws Exception {
+ doJsAntTestForPostfixPrefix("prefix", null);
+ }
+
+ @Test
+ public void k2jsWithPostfix() throws Exception {
+ doJsAntTestForPostfixPrefix(null, "postfix");
+ }
+
+ @Test
+ public void k2jsWithPrefixAndPostfix() throws Exception {
+ doJsAntTestForPostfixPrefix("prefix", "postfix");
+ }
+
+ @Test
+ public void k2jsWithSourcemap() throws Exception {
+ doJsAntTest();
+
+ File sourcemap = getOutputFileByName(JS_OUT_FILE + ".map");
+ assertTrue("Sourcemap file \"" + sourcemap.getAbsolutePath() + "\" not found", sourcemap.exists());
}
@Override
@@ -81,7 +175,7 @@ public class AntTaskTest extends KotlinIntegrationTestBase {
List strings = new ArrayList();
strings.addAll(Arrays.asList(basicArgs));
strings.addAll(Arrays.asList(extraJavaArgs));
- return runJava(logName, strings.toArray(new String[strings.size()]));
+ return runJava(logName, ArrayUtil.toStringArray(strings));
}
private static String getKotlinAntPath() {
@@ -95,4 +189,18 @@ public class AntTaskTest extends KotlinIntegrationTestBase {
private static String getAntHome() {
return getKotlinProjectHome().getAbsolutePath() + File.separator + "dependencies" + File.separator + "ant-1.8";
}
+
+ private static void checkFilePrefixPostfix(@NotNull File file, @Nullable File prefix, @Nullable File postfix) throws IOException {
+ String fileContent = FileUtil.loadFile(file);
+
+ String prefixContent = FileUtilsPackage.readTextOrEmpty(prefix);
+ assertTrue(fileContent.startsWith(prefixContent));
+
+ String postfixContent = FileUtilsPackage.readTextOrEmpty(postfix);
+ assertTrue(fileContent.endsWith(postfixContent));
+ }
+
+ private File getOutputFileByName(@NotNull String name) {
+ return new File(tmpdir.getTmpDir(), name);
+ }
}
diff --git a/compiler/integration-tests/testData/k2jsManySources/bar.kt b/compiler/integration-tests/testData/k2jsManySources/bar.kt
new file mode 100644
index 00000000000..bfb9872dc76
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsManySources/bar.kt
@@ -0,0 +1 @@
+fun bar() {}
\ No newline at end of file
diff --git a/compiler/integration-tests/testData/k2jsManySources/build.log.expected b/compiler/integration-tests/testData/k2jsManySources/build.log.expected
new file mode 100644
index 00000000000..2f64f91c577
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsManySources/build.log.expected
@@ -0,0 +1,8 @@
+OUT Buildfile: [TestData]/build.xml
+OUT
+OUT build:
+OUT [kotlin2js] Compiling [[TestData]/root1,[TestData]/bar.kt,[TestData]/root2/Foo.kt] => [[Temp]/out.js]
+OUT
+OUT BUILD SUCCESSFUL
+OUT Total time: [time]
+Return code: 0
diff --git a/compiler/integration-tests/testData/k2jsManySources/build.xml b/compiler/integration-tests/testData/k2jsManySources/build.xml
new file mode 100644
index 00000000000..6abaf7716c5
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsManySources/build.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/compiler/integration-tests/testData/k2jsManySources/root1/main.kt b/compiler/integration-tests/testData/k2jsManySources/root1/main.kt
new file mode 100644
index 00000000000..b327990a0cc
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsManySources/root1/main.kt
@@ -0,0 +1,7 @@
+package foo
+
+fun box(): String {
+ Foo()
+ bar()
+ return "OK"
+}
\ No newline at end of file
diff --git a/compiler/integration-tests/testData/k2jsManySources/root2/Bar.js b/compiler/integration-tests/testData/k2jsManySources/root2/Bar.js
new file mode 100644
index 00000000000..af6f049b55d
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsManySources/root2/Bar.js
@@ -0,0 +1 @@
+function Bar () {}
\ No newline at end of file
diff --git a/compiler/integration-tests/testData/k2jsManySources/root2/Foo.kt b/compiler/integration-tests/testData/k2jsManySources/root2/Foo.kt
new file mode 100644
index 00000000000..43c42f1453b
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsManySources/root2/Foo.kt
@@ -0,0 +1 @@
+class Foo
\ No newline at end of file
diff --git a/compiler/integration-tests/testData/k2jsSimple/build.log.expected b/compiler/integration-tests/testData/k2jsSimple/build.log.expected
new file mode 100644
index 00000000000..c29fac465a5
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsSimple/build.log.expected
@@ -0,0 +1,8 @@
+OUT Buildfile: [TestData]/build.xml
+OUT
+OUT build:
+OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
+OUT
+OUT BUILD SUCCESSFUL
+OUT Total time: [time]
+Return code: 0
diff --git a/compiler/integration-tests/testData/k2jsSimple/build.xml b/compiler/integration-tests/testData/k2jsSimple/build.xml
new file mode 100644
index 00000000000..ee620d63b7c
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsSimple/build.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/compiler/integration-tests/testData/k2jsSimple/root1/foo.kt b/compiler/integration-tests/testData/k2jsSimple/root1/foo.kt
new file mode 100644
index 00000000000..f6123b9882f
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsSimple/root1/foo.kt
@@ -0,0 +1,3 @@
+package foo
+
+fun box(): String = "OK"
diff --git a/compiler/integration-tests/testData/k2jsWithMain/build.log.expected b/compiler/integration-tests/testData/k2jsWithMain/build.log.expected
new file mode 100644
index 00000000000..c29fac465a5
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithMain/build.log.expected
@@ -0,0 +1,8 @@
+OUT Buildfile: [TestData]/build.xml
+OUT
+OUT build:
+OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
+OUT
+OUT BUILD SUCCESSFUL
+OUT Total time: [time]
+Return code: 0
diff --git a/compiler/integration-tests/testData/k2jsWithMain/build.xml b/compiler/integration-tests/testData/k2jsWithMain/build.xml
new file mode 100644
index 00000000000..a80ea4410f9
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithMain/build.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/compiler/integration-tests/testData/k2jsWithMain/root1/foo.kt b/compiler/integration-tests/testData/k2jsWithMain/root1/foo.kt
new file mode 100644
index 00000000000..e374b249313
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithMain/root1/foo.kt
@@ -0,0 +1,9 @@
+package foo
+
+var ok = "FAIL"
+
+fun main(args: Array) {
+ ok = "OK"
+}
+
+fun box(): String = ok
diff --git a/compiler/integration-tests/testData/k2jsWithPostfix/build.log.expected b/compiler/integration-tests/testData/k2jsWithPostfix/build.log.expected
new file mode 100644
index 00000000000..c29fac465a5
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPostfix/build.log.expected
@@ -0,0 +1,8 @@
+OUT Buildfile: [TestData]/build.xml
+OUT
+OUT build:
+OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
+OUT
+OUT BUILD SUCCESSFUL
+OUT Total time: [time]
+Return code: 0
diff --git a/compiler/integration-tests/testData/k2jsWithPostfix/build.xml b/compiler/integration-tests/testData/k2jsWithPostfix/build.xml
new file mode 100644
index 00000000000..76cd4eb8c8b
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPostfix/build.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/compiler/integration-tests/testData/k2jsWithPostfix/postfix b/compiler/integration-tests/testData/k2jsWithPostfix/postfix
new file mode 100644
index 00000000000..840c7093427
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPostfix/postfix
@@ -0,0 +1,3 @@
+/*
+ some postfix
+*/
\ No newline at end of file
diff --git a/compiler/integration-tests/testData/k2jsWithPostfix/root1/foo.kt b/compiler/integration-tests/testData/k2jsWithPostfix/root1/foo.kt
new file mode 100644
index 00000000000..f6123b9882f
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPostfix/root1/foo.kt
@@ -0,0 +1,3 @@
+package foo
+
+fun box(): String = "OK"
diff --git a/compiler/integration-tests/testData/k2jsWithPrefix/build.log.expected b/compiler/integration-tests/testData/k2jsWithPrefix/build.log.expected
new file mode 100644
index 00000000000..c29fac465a5
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPrefix/build.log.expected
@@ -0,0 +1,8 @@
+OUT Buildfile: [TestData]/build.xml
+OUT
+OUT build:
+OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
+OUT
+OUT BUILD SUCCESSFUL
+OUT Total time: [time]
+Return code: 0
diff --git a/compiler/integration-tests/testData/k2jsWithPrefix/build.xml b/compiler/integration-tests/testData/k2jsWithPrefix/build.xml
new file mode 100644
index 00000000000..522ef33b8fa
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPrefix/build.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/compiler/integration-tests/testData/k2jsWithPrefix/prefix b/compiler/integration-tests/testData/k2jsWithPrefix/prefix
new file mode 100644
index 00000000000..cd252389ee1
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPrefix/prefix
@@ -0,0 +1,3 @@
+/*
+ some prefix
+*/
\ No newline at end of file
diff --git a/compiler/integration-tests/testData/k2jsWithPrefix/root1/foo.kt b/compiler/integration-tests/testData/k2jsWithPrefix/root1/foo.kt
new file mode 100644
index 00000000000..f6123b9882f
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPrefix/root1/foo.kt
@@ -0,0 +1,3 @@
+package foo
+
+fun box(): String = "OK"
diff --git a/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/build.log.expected b/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/build.log.expected
new file mode 100644
index 00000000000..c29fac465a5
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/build.log.expected
@@ -0,0 +1,8 @@
+OUT Buildfile: [TestData]/build.xml
+OUT
+OUT build:
+OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
+OUT
+OUT BUILD SUCCESSFUL
+OUT Total time: [time]
+Return code: 0
diff --git a/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/build.xml b/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/build.xml
new file mode 100644
index 00000000000..f4fcf02f781
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/build.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/postfix b/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/postfix
new file mode 100644
index 00000000000..840c7093427
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/postfix
@@ -0,0 +1,3 @@
+/*
+ some postfix
+*/
\ No newline at end of file
diff --git a/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/prefix b/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/prefix
new file mode 100644
index 00000000000..cd252389ee1
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/prefix
@@ -0,0 +1,3 @@
+/*
+ some prefix
+*/
\ No newline at end of file
diff --git a/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/root1/foo.kt b/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/root1/foo.kt
new file mode 100644
index 00000000000..f6123b9882f
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithPrefixAndPostfix/root1/foo.kt
@@ -0,0 +1,3 @@
+package foo
+
+fun box(): String = "OK"
diff --git a/compiler/integration-tests/testData/k2jsWithSourcemap/build.log.expected b/compiler/integration-tests/testData/k2jsWithSourcemap/build.log.expected
new file mode 100644
index 00000000000..c29fac465a5
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithSourcemap/build.log.expected
@@ -0,0 +1,8 @@
+OUT Buildfile: [TestData]/build.xml
+OUT
+OUT build:
+OUT [kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
+OUT
+OUT BUILD SUCCESSFUL
+OUT Total time: [time]
+Return code: 0
diff --git a/compiler/integration-tests/testData/k2jsWithSourcemap/build.xml b/compiler/integration-tests/testData/k2jsWithSourcemap/build.xml
new file mode 100644
index 00000000000..d677cbbee62
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithSourcemap/build.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/compiler/integration-tests/testData/k2jsWithSourcemap/root1/foo.kt b/compiler/integration-tests/testData/k2jsWithSourcemap/root1/foo.kt
new file mode 100644
index 00000000000..f6123b9882f
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithSourcemap/root1/foo.kt
@@ -0,0 +1,3 @@
+package foo
+
+fun box(): String = "OK"
diff --git a/compiler/integration-tests/testData/k2jsWithoutOutputParam/build.log.expected b/compiler/integration-tests/testData/k2jsWithoutOutputParam/build.log.expected
new file mode 100644
index 00000000000..20045e2e76d
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithoutOutputParam/build.log.expected
@@ -0,0 +1,9 @@
+OUT Buildfile: [TestData]/build.xml
+OUT
+OUT build:
+ERR
+ERR BUILD FAILED
+ERR [TestData]/build.xml:5: "output" should be specified
+ERR
+ERR Total time: [time]
+Return code: 1
diff --git a/compiler/integration-tests/testData/k2jsWithoutOutputParam/build.xml b/compiler/integration-tests/testData/k2jsWithoutOutputParam/build.xml
new file mode 100644
index 00000000000..e44e5b23173
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithoutOutputParam/build.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/compiler/integration-tests/testData/k2jsWithoutSrcParam/build.log.expected b/compiler/integration-tests/testData/k2jsWithoutSrcParam/build.log.expected
new file mode 100644
index 00000000000..70834e184c6
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithoutSrcParam/build.log.expected
@@ -0,0 +1,9 @@
+OUT Buildfile: [TestData]/build.xml
+OUT
+OUT build:
+ERR
+ERR BUILD FAILED
+ERR [TestData]/build.xml:5: "src" should be specified
+ERR
+ERR Total time: [time]
+Return code: 1
diff --git a/compiler/integration-tests/testData/k2jsWithoutSrcParam/build.xml b/compiler/integration-tests/testData/k2jsWithoutSrcParam/build.xml
new file mode 100644
index 00000000000..83ed284e942
--- /dev/null
+++ b/compiler/integration-tests/testData/k2jsWithoutSrcParam/build.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+