JS tests: refactored StdLibTestBase and derived classes.
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.k2js.test.semantics;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class StdLibJsArrayQUnitTest extends StdLibQUnitTestSupport {
|
||||
public void testDummy() {
|
||||
}
|
||||
|
||||
// TODO for some reason this test fails when ran as part of all the js-backend tests, but works stand alone
|
||||
// generates: ReferenceError: "QUnit" is not defined. (js/js.translator/testData/stdlib/out/ArrayQUnitTest.compiler_v3.js#3058)
|
||||
// when ran in batch
|
||||
|
||||
public void DISABLED_testArrayQUnitTest() throws Exception {
|
||||
performStdLibTest(DEFAULT_ECMA_VERSIONS,
|
||||
"libraries/stdlib/test",
|
||||
"js/JsArrayTest.kt");
|
||||
}
|
||||
}
|
||||
@@ -16,17 +16,11 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.rhino.CompositeRhinoResultsChecker;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoResultChecker;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.k2js.test.rhino.RhinoUtils.runRhinoTest;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class StdLibJsArrayScriptTest extends StdLibTestBase {
|
||||
@@ -36,28 +30,12 @@ public class StdLibJsArrayScriptTest extends StdLibTestBase {
|
||||
"js/JsArrayScript.kt");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected void performChecksOnGeneratedJavaScript(String path, EcmaVersion version) throws Exception {
|
||||
Map<String, Object> variables = ContainerUtil.newHashMap();
|
||||
String moduleId = moduleIdFromOutputFile(path);
|
||||
RhinoResultChecker checker = new CompositeRhinoResultsChecker(
|
||||
new RhinoFunctionResultChecker(moduleId, "jstest", "testSize", 3.0),
|
||||
new RhinoFunctionResultChecker(moduleId, "jstest", "testToListToString", "[]-[foo]-[foo, bar]")
|
||||
protected RhinoResultChecker getResultChecker() {
|
||||
return new CompositeRhinoResultsChecker(
|
||||
new RhinoFunctionResultChecker(TEST_MODULE, "jstest", "testSize", 3.0),
|
||||
new RhinoFunctionResultChecker(TEST_MODULE, "jstest", "testToListToString", "[]-[foo]-[foo, bar]")
|
||||
);
|
||||
runRhinoTest(Lists.newArrayList(path), checker, variables, version);
|
||||
|
||||
/*
|
||||
RhinoResultChecker checker = new RhinoFunctionResultChecker(moduleId, "jstest", "runTest", 2.0) {
|
||||
|
||||
@Override
|
||||
protected String functionCallString() {
|
||||
//return "QUnit.test('JsArrayTest.arraySizeAndToList', function(){ (new Kotlin.modules['" + moduleId + "'].jstest.JsArrayTest).arraySizeAndToList(); });";
|
||||
return "(new Kotlin.modules['" + moduleId + "'].jstest.JsArrayTest).arraySizeAndToList();";
|
||||
}
|
||||
};
|
||||
runRhinoTest(Lists.newArrayList(path),
|
||||
checker, variables, version,
|
||||
Lists.newArrayList("js/js.translator/qunit/qunit.js"));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,36 +17,32 @@
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoQUnitResultChecker;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoResultChecker;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.k2js.test.rhino.RhinoUtils.runRhinoTest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A base class for any JS compile test cases which should run the generated JS file as a QUnit test case
|
||||
*/
|
||||
public abstract class StdLibQUnitTestSupport extends StdLibTestBase {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected void performChecksOnGeneratedJavaScript(String path, EcmaVersion version) throws Exception {
|
||||
runQUnitTestCase(path, version);
|
||||
protected RhinoResultChecker getResultChecker() {
|
||||
return new RhinoQUnitResultChecker();
|
||||
}
|
||||
|
||||
protected void runQUnitTestCase(String path, EcmaVersion version) throws Exception {
|
||||
runQUnitTestCase(path, version, new HashMap<String, Object>());
|
||||
}
|
||||
|
||||
protected void runQUnitTestCase(String path, EcmaVersion version, Map<String, Object> variables) throws Exception {
|
||||
RhinoResultChecker checker = new RhinoQUnitResultChecker();
|
||||
runRhinoTest(Lists.newArrayList(path),
|
||||
checker, variables, version,
|
||||
Lists.newArrayList(
|
||||
"js/js.translator/qunit/qunit.js",
|
||||
"js/js.translator/qunit/headless.js"
|
||||
));
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<String> additionalJsFiles(@NotNull EcmaVersion ecmaVersion) {
|
||||
ArrayList<String> files = Lists.newArrayList(super.additionalJsFiles(ecmaVersion));
|
||||
files.add("js/js.translator/qunit/qunit.js");
|
||||
files.add("js/js.translator/qunit/headless.js");
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,75 +17,39 @@
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.ExitCode;
|
||||
import org.jetbrains.jet.cli.js.K2JSCompiler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
import org.jetbrains.k2js.test.utils.LibraryFilePathsUtil;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoResultChecker;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
// TODO: should be dropped with derived classes?
|
||||
abstract class StdLibTestBase extends SingleFileTranslationTest {
|
||||
protected StdLibTestBase() {
|
||||
super("stdlib/");
|
||||
}
|
||||
|
||||
protected void performStdLibTest(@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull String sourceDir, @NotNull String... stdLibFiles) throws Exception {
|
||||
List<String> files = constructFilesToCompileList(sourceDir, stdLibFiles);
|
||||
compileFiles(ecmaVersions, files);
|
||||
}
|
||||
@Nullable
|
||||
protected abstract RhinoResultChecker getResultChecker();
|
||||
|
||||
private void compileFiles(@NotNull Iterable<EcmaVersion> ecmaVersions, @NotNull List<String> files) throws Exception {
|
||||
List<String> libFiles = LibraryFilePathsUtil.getBasicLibraryFiles();
|
||||
for (EcmaVersion version : ecmaVersions) {
|
||||
String outputFilePath = getOutputFilePath(getTestName(false) + ".compiler.kt", version);
|
||||
invokeCompiler(files, libFiles, version, outputFilePath);
|
||||
performChecksOnGeneratedJavaScript(outputFilePath, version);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strategy method allowing the generated JS file to be invoked
|
||||
*/
|
||||
protected void performChecksOnGeneratedJavaScript(String path, EcmaVersion version) throws Exception {
|
||||
}
|
||||
|
||||
protected String moduleIdFromOutputFile(String path) {
|
||||
String moduleId = new File(path).getName();
|
||||
if (moduleId.endsWith(".js")) {
|
||||
moduleId = moduleId.substring(0, moduleId.length() - 3);
|
||||
}
|
||||
return moduleId;
|
||||
}
|
||||
|
||||
//TODO: reuse this in CompileMavenGeneratedJSLibrary
|
||||
private static void invokeCompiler(
|
||||
@NotNull List<String> files,
|
||||
@NotNull List<String> libFiles,
|
||||
@NotNull EcmaVersion version,
|
||||
@NotNull String outputFilePath
|
||||
) {
|
||||
System.out.println("Compiling with version: " + version + " to: " + outputFilePath);
|
||||
|
||||
List<String> args = new ArrayList<String>(Arrays.asList("-output", outputFilePath, "-verbose", "-library-files"));
|
||||
args.addAll(libFiles);
|
||||
args.addAll(files);
|
||||
ExitCode answer = new K2JSCompiler().exec(System.out, ArrayUtil.toStringArray(args));
|
||||
|
||||
assertEquals("Compile failed", ExitCode.OK, answer);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<String> constructFilesToCompileList(@NotNull String sourceDir, @NotNull String[] stdLibFiles) {
|
||||
protected void performStdLibTest(
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull String sourceDir,
|
||||
@NotNull String... stdLibFiles
|
||||
) throws Exception {
|
||||
List<String> files = filesFromDir(sourceDir, stdLibFiles);
|
||||
files.addAll(LibraryFilePathsUtil.getAdditionalLibraryFiles());
|
||||
return files;
|
||||
String testFileName = getTestName(true) + ".kt";
|
||||
|
||||
generateJavaScriptFiles(files, testFileName, MainCallParameters.noCall(), ecmaVersions);
|
||||
|
||||
RhinoResultChecker checker = getResultChecker();
|
||||
if (checker != null) {
|
||||
runRhinoTests(testFileName, ecmaVersions, checker);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -16,22 +16,35 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoResultChecker;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class StdLibTestToJSTest extends StdLibTestBase {
|
||||
public class StdLibTestToJSTest extends StdLibQUnitTestSupport {
|
||||
public void testGenerateTestCase() throws Exception {
|
||||
performStdLibTest(DEFAULT_ECMA_VERSIONS,
|
||||
"libraries/stdlib/test",
|
||||
"dom/DomTest.kt",
|
||||
"js/JsArrayTest.kt",
|
||||
"js/MapJsTest.kt",
|
||||
"js/JsDomTest.kt",
|
||||
"collections/StreamTest.kt",
|
||||
"collections/IteratorsTest.kt",
|
||||
"GetOrElseTest.kt",
|
||||
"collections/ListSpecificTest.kt",
|
||||
"collections/IteratorsTest.kt",
|
||||
"text/StringTest.kt",
|
||||
// TODO review: somethings FAILED if run:
|
||||
"js/JsDomTest.kt",
|
||||
"dom/DomTest.kt",
|
||||
"collections/StreamTest.kt",
|
||||
"collections/IterableTests.kt",
|
||||
"language/RangeTest.kt",
|
||||
"language/RangeIterationTest.kt",
|
||||
"text/StringTest.kt");
|
||||
"language/RangeIterationTest.kt"
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected RhinoResultChecker getResultChecker() {
|
||||
// don't run, it's just smoke test this tests should be run in maven build.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoResultChecker;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class StdLibToJSTest extends StdLibTestBase {
|
||||
@@ -24,4 +27,10 @@ public class StdLibToJSTest extends StdLibTestBase {
|
||||
performStdLibTest(DEFAULT_ECMA_VERSIONS,
|
||||
"libraries/stdlib/src");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected RhinoResultChecker getResultChecker() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user