minor refactor of the JS test cases to ensure they don't collide in the generated JS code
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.ExitCode;
|
||||
import org.jetbrains.jet.cli.js.K2JSCompiler;
|
||||
import org.jetbrains.jet.cli.js.K2JSCompilerArguments;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class StdLibTestSupport extends SingleFileTranslationTest {
|
||||
|
||||
public StdLibTestSupport() {
|
||||
super("stdlib/");
|
||||
}
|
||||
|
||||
protected void generateJavaScriptFiles(@NotNull EnumSet<EcmaVersion> ecmaVersions,
|
||||
@NotNull String sourceDir, @NotNull String... stdLibFiles) throws Exception {
|
||||
List<String> files = Lists.newArrayList();
|
||||
|
||||
File stdlibDir = new File(sourceDir);
|
||||
assertTrue("Cannot find stdlib source: " + stdlibDir, stdlibDir.exists());
|
||||
for (String file : stdLibFiles) {
|
||||
files.add(new File(stdlibDir, file).getPath());
|
||||
}
|
||||
|
||||
Set<String> ignoreFiles = Sets.newHashSet(
|
||||
"/jquery/common.kt",
|
||||
"/jquery/ui.kt",
|
||||
"/dom/domcore.kt",
|
||||
"/dom/html/htmlcore.kt",
|
||||
"/dom/html5/canvas.kt",
|
||||
"/dom/html/window.kt");
|
||||
|
||||
// lets add the standard JS library files
|
||||
for (String libFileName : Config.LIB_FILE_NAMES) {
|
||||
if (!ignoreFiles.contains(libFileName)) {
|
||||
System.out.println("Compiling " + libFileName);
|
||||
files.add(Config.LIBRARIES_LOCATION + libFileName);
|
||||
}
|
||||
}
|
||||
|
||||
// now lets try invoke the compiler
|
||||
for (EcmaVersion version : ecmaVersions) {
|
||||
K2JSCompiler compiler = new K2JSCompiler();
|
||||
K2JSCompilerArguments arguments = new K2JSCompilerArguments();
|
||||
arguments.outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version);
|
||||
arguments.sourceFiles = files;
|
||||
arguments.verbose = true;
|
||||
System.out.println("Compiling with version: " + version + " to: " + arguments.outputFile);
|
||||
ExitCode answer = compiler.exec(System.out, arguments);
|
||||
assertEquals("Compile failed", ExitCode.OK, answer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class StdLibTestToJSTest extends StdLibToJSTest {
|
||||
public void testCompileJavaScriptFiles() throws Exception {
|
||||
public class StdLibTestToJSTest extends StdLibTestSupport {
|
||||
public void testGenerateTestCase() throws Exception {
|
||||
|
||||
generateJavaScriptFiles(EcmaVersion.all(),
|
||||
"libraries/stdlib/test",
|
||||
|
||||
@@ -33,11 +33,7 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class StdLibToJSTest extends SingleFileTranslationTest {
|
||||
|
||||
public StdLibToJSTest() {
|
||||
super("stdlib/");
|
||||
}
|
||||
public class StdLibToJSTest extends StdLibTestSupport {
|
||||
|
||||
public void testCompileJavaScriptFiles() throws Exception {
|
||||
|
||||
@@ -45,43 +41,4 @@ public class StdLibToJSTest extends SingleFileTranslationTest {
|
||||
"libraries/stdlib/src",
|
||||
"kotlin/Preconditions.kt", "kotlin/dom/Dom.kt", "kotlin/support/AbstractIterator.kt");
|
||||
}
|
||||
|
||||
protected void generateJavaScriptFiles(@NotNull EnumSet<EcmaVersion> ecmaVersions,
|
||||
@NotNull String sourceDir, @NotNull String... stdLibFiles) throws Exception {
|
||||
List<String> files = Lists.newArrayList();
|
||||
|
||||
File stdlibDir = new File(sourceDir);
|
||||
assertTrue("Cannot find stdlib source: " + stdlibDir, stdlibDir.exists());
|
||||
for (String file : stdLibFiles) {
|
||||
files.add(new File(stdlibDir, file).getPath());
|
||||
}
|
||||
|
||||
Set<String> ignoreFiles = Sets.newHashSet(
|
||||
"/jquery/common.kt",
|
||||
"/jquery/ui.kt",
|
||||
"/dom/domcore.kt",
|
||||
"/dom/html/htmlcore.kt",
|
||||
"/dom/html5/canvas.kt",
|
||||
"/dom/html/window.kt");
|
||||
|
||||
// lets add the standard JS library files
|
||||
for (String libFileName : Config.LIB_FILE_NAMES) {
|
||||
if (!ignoreFiles.contains(libFileName)) {
|
||||
System.out.println("Compiling " + libFileName);
|
||||
files.add(Config.LIBRARIES_LOCATION + libFileName);
|
||||
}
|
||||
}
|
||||
|
||||
// now lets try invoke the compiler
|
||||
for (EcmaVersion version : ecmaVersions) {
|
||||
K2JSCompiler compiler = new K2JSCompiler();
|
||||
K2JSCompilerArguments arguments = new K2JSCompilerArguments();
|
||||
arguments.outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version);
|
||||
arguments.sourceFiles = files;
|
||||
arguments.verbose = true;
|
||||
System.out.println("Compiling with version: " + version + " to: " + arguments.outputFile);
|
||||
ExitCode answer = compiler.exec(System.out, arguments);
|
||||
assertEquals("Compile failed", ExitCode.OK, answer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<link rel="stylesheet" href="qunit.css">
|
||||
<script src="qunit.js"></script>
|
||||
|
||||
<script src="../testFiles/kotlin_lib.js"></script>
|
||||
<script src="../testFiles/stdlib/out/CompileJavaScriptFiles.compiler_v3.js"></script>
|
||||
<script src="../testFiles/kotlin_lib_ecma3.js"></script>
|
||||
<script src="../testFiles/stdlib/out/GenerateTestCase.compiler_v3.js"></script>
|
||||
|
||||
<script src="deepEqual.js"></script>
|
||||
<script src="swarminject.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user