new ant test for kotlin javascript library support
This commit is contained in:
@@ -307,37 +307,6 @@
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="jslib-example">
|
||||
<property name="jslib-example-name" value="jslib-example" />
|
||||
<property name="jslib-example-dir" value="${basedir}/compiler/testData/cli/js" />
|
||||
|
||||
<kotlin2js output="${output}/${jslib-example-name}.js" main="noCall">
|
||||
<src>
|
||||
<fileset dir="${jslib-example-dir}">
|
||||
<include name="LibraryExample.kt" />
|
||||
</fileset>
|
||||
</src>
|
||||
</kotlin2js>
|
||||
|
||||
<jar jarfile="${output}/jslib-example.jar">
|
||||
<fileset dir="${jslib-example-dir}">
|
||||
<include name="LibraryExample.kt" />
|
||||
</fileset>
|
||||
<zipfileset file="${output}/${jslib-example-name}.js" prefix=""/>
|
||||
|
||||
<manifest>
|
||||
<attribute name="Built-By" value="${manifest.impl.vendor}"/>
|
||||
|
||||
<attribute name="Implementation-Vendor" value="${manifest.impl.vendor}"/>
|
||||
<attribute name="Implementation-Version" value="${build.number}"/>
|
||||
<attribute name="Specification-Title" value="${manifest.spec.title.kotlin.javascript.lib}"/>
|
||||
<attribute name="Kotlin-JS-Module-Name" value="${jslib-example-name}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
|
||||
<unzip src="${output}/jslib-example.jar" dest="${output}/jslib-example" />
|
||||
</target>
|
||||
|
||||
<target name="preloader">
|
||||
<cleandir dir="${output}/classes/preloader"/>
|
||||
<javac2 destdir="${output}/classes/preloader" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false"
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.jetbrains.kotlin;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker;
|
||||
@@ -27,7 +29,9 @@ import org.junit.rules.TestName;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -43,12 +47,20 @@ public class AntTaskJsTest extends AntTaskBaseTest {
|
||||
return new File(new File(ANT_TASK_TEST_DATA_BASE_DIR, "js"), name.getMethodName());
|
||||
}
|
||||
|
||||
private void doJsAntTest() throws Exception {
|
||||
private void doJsAntTest(String... jsFiles) throws Exception {
|
||||
doAntTest(SUCCESSFUL);
|
||||
|
||||
String outputFilePath = getOutputFileByName(JS_OUT_FILE).getAbsolutePath();
|
||||
RhinoUtils.runRhinoTest(Collections.singletonList(outputFilePath),
|
||||
new RhinoFunctionResultChecker("out", "foo", "box", "OK"));
|
||||
List<String> fileNames = new ArrayList<String>(Arrays.asList(jsFiles));
|
||||
fileNames.add(JS_OUT_FILE);
|
||||
|
||||
List<String> filePaths = ContainerUtil.map(fileNames, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String s) {
|
||||
return getOutputFileByName(s).getAbsolutePath();
|
||||
}
|
||||
});
|
||||
|
||||
RhinoUtils.runRhinoTest(filePaths, new RhinoFunctionResultChecker("out", "foo", "box", "OK"));
|
||||
}
|
||||
|
||||
private void doJsAntTestForPostfixPrefix(@Nullable String prefix, @Nullable String postfix) throws Exception {
|
||||
@@ -90,6 +102,16 @@ public class AntTaskJsTest extends AntTaskBaseTest {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleWithStdlibAndAnotherLib() throws Exception {
|
||||
doJsAntTest("jslib-example.js");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleWithStdlibAndFolderAsAnotherLib() throws Exception {
|
||||
doJsAntTest("jslib-example.js");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleWithMainFQArgs() throws Exception {
|
||||
doJsAntTest();
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
OUT:
|
||||
Buildfile: [TestData]/build.xml
|
||||
|
||||
build:
|
||||
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
|
||||
[unzip] Expanding: [TestData]/jslib-example.jar into [Temp]
|
||||
|
||||
BUILD SUCCESSFUL
|
||||
Total time: [time]
|
||||
|
||||
Return code: 0
|
||||
@@ -0,0 +1,17 @@
|
||||
<project name="Ant Task Test" default="build">
|
||||
<taskdef resource="org/jetbrains/jet/buildtools/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
|
||||
<property name="library.path" value="${test.data}/jslib-example.jar"/>
|
||||
<target name="build">
|
||||
<kotlin2js src="${test.data}/root1" output="${temp}/out.js" main="call">
|
||||
<library>
|
||||
<pathelement path="${library.path}"/>
|
||||
</library>
|
||||
</kotlin2js>
|
||||
<unzip src="${library.path}" dest="${temp}">
|
||||
<patternset>
|
||||
<include name="*.js"/>
|
||||
<exclude name="META-INF/**"/>
|
||||
</patternset>
|
||||
</unzip>
|
||||
</target>
|
||||
</project>
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
import library.sample.*
|
||||
|
||||
var ok = "FAIL"
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val p = Pair(10, 20)
|
||||
val x = pairAdd(p)
|
||||
ok = "OK"
|
||||
println("x=$x")
|
||||
}
|
||||
|
||||
fun box(): String = ok
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
OUT:
|
||||
Buildfile: [TestData]/build.xml
|
||||
|
||||
build:
|
||||
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
|
||||
[copy] Copying 1 file to [Temp]
|
||||
|
||||
BUILD SUCCESSFUL
|
||||
Total time: [time]
|
||||
|
||||
Return code: 0
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<project name="Ant Task Test" default="build">
|
||||
<taskdef resource="org/jetbrains/jet/buildtools/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
|
||||
<property name="library.path" value="${test.data}/jslib-example"/>
|
||||
<target name="build">
|
||||
<kotlin2js src="${test.data}/root1" output="${temp}/out.js" main="call">
|
||||
<library>
|
||||
<pathelement path="${library.path}"/>
|
||||
</library>
|
||||
</kotlin2js>
|
||||
<copy todir="${temp}">
|
||||
<fileset dir="${library.path}">
|
||||
<include name="**/*.js"/>
|
||||
<exclude name="META-INF/**"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
</project>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package library.sample
|
||||
|
||||
public fun pairAdd(p: Pair<Int, Int>): Int = p.first + p.second
|
||||
|
||||
public fun pairMul(p: Pair<Int, Int>): Int = p.first * p.second
|
||||
|
||||
public data class IntHolder(val value: Int)
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
Manifest-Version: 1.0
|
||||
Ant-Version: Apache Ant 1.9.1
|
||||
Created-By: 1.7.0_72-b14 (Oracle Corporation)
|
||||
Built-By: JetBrains
|
||||
Implementation-Vendor: JetBrains
|
||||
Implementation-Version: snapshot
|
||||
Specification-Title: Kotlin JavaScript Lib
|
||||
Kotlin-JS-Module-Name: jslib-example
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
# jslib-example
|
||||
|
||||
Path to sources: compiler/integration-tests/testData/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example
|
||||
|
||||
The archive compiler/integration-tests/testData/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar should be updated after
|
||||
changing some files in source folder.
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
(function (Kotlin) {
|
||||
'use strict';
|
||||
var _ = Kotlin.defineRootPackage(null, /** @lends _ */ {
|
||||
library: Kotlin.definePackage(null, /** @lends _.library */ {
|
||||
sample: Kotlin.definePackage(null, /** @lends _.library.sample */ {
|
||||
pairAdd_bunuun$: function (p) {
|
||||
return p.first + p.second;
|
||||
},
|
||||
pairMul_bunuun$: function (p) {
|
||||
return p.first * p.second;
|
||||
},
|
||||
IntHolder: Kotlin.createClass(null, function (value) {
|
||||
this.value = value;
|
||||
}, /** @lends _.library.sample.IntHolder.prototype */ {
|
||||
component1: function () {
|
||||
return this.value;
|
||||
},
|
||||
copy_za3lpa$: function (value) {
|
||||
return new _.library.sample.IntHolder(value === void 0 ? this.value : value);
|
||||
},
|
||||
toString: function () {
|
||||
return 'IntHolder(value=' + Kotlin.toString(this.value) + ')';
|
||||
},
|
||||
hashCode: function () {
|
||||
var result = 0;
|
||||
result = result * 31 + Kotlin.hashCode(this.value) | 0;
|
||||
return result;
|
||||
},
|
||||
equals_za3rmp$: function (other) {
|
||||
return this === other || (other !== null && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.value, other.value)));
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
Kotlin.defineModule('jslib-example', _);
|
||||
}(Kotlin));
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
import library.sample.*
|
||||
|
||||
var ok = "FAIL"
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val p = Pair(10, 20)
|
||||
val x = pairAdd(p)
|
||||
ok = "OK"
|
||||
println("x=$x")
|
||||
}
|
||||
|
||||
fun box(): String = ok
|
||||
@@ -1,5 +1,5 @@
|
||||
$TESTDATA_DIR$/withLib.kt
|
||||
-library-files
|
||||
dist/jslib-example
|
||||
compiler/integration-tests/testData/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example
|
||||
-output
|
||||
$TEMP_DIR$/out.js
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
$TESTDATA_DIR$/withLib.kt
|
||||
-library-files
|
||||
dist/jslib-example.jar
|
||||
compiler/integration-tests/testData/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar
|
||||
-output
|
||||
$TEMP_DIR$/out.js
|
||||
|
||||
Reference in New Issue
Block a user