From 60738b7b4fdc09a6932626e80b7dcdd48ba5f4ba Mon Sep 17 00:00:00 2001 From: James Strachan Date: Tue, 12 Jun 2012 19:51:34 +0100 Subject: [PATCH] minor refactor of the JS test cases to ensure they don't collide in the generated JS code --- .../test/semantics/StdLibTestSupport.java | 81 +++++++++++++++++++ .../test/semantics/StdLibTestToJSTest.java | 4 +- .../k2js/test/semantics/StdLibToJSTest.java | 45 +---------- js/js.translator/qunit/index.html | 4 +- 4 files changed, 86 insertions(+), 48 deletions(-) create mode 100644 js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestSupport.java diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestSupport.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestSupport.java new file mode 100644 index 00000000000..f83fd15b155 --- /dev/null +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestSupport.java @@ -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 ecmaVersions, + @NotNull String sourceDir, @NotNull String... stdLibFiles) throws Exception { + List 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 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); + } + } +} diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestToJSTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestToJSTest.java index a9c81396158..b022a481a05 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestToJSTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestToJSTest.java @@ -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", diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibToJSTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibToJSTest.java index 99b47af5d79..0cd9e1ab726 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibToJSTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibToJSTest.java @@ -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 ecmaVersions, - @NotNull String sourceDir, @NotNull String... stdLibFiles) throws Exception { - List 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 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); - } - } } diff --git a/js/js.translator/qunit/index.html b/js/js.translator/qunit/index.html index ee18ba2db3a..efa915718e6 100644 --- a/js/js.translator/qunit/index.html +++ b/js/js.translator/qunit/index.html @@ -6,8 +6,8 @@ - - + +