From 5966255d4bbb7c745ba76f9d3df3d18d05dbde75 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Mon, 7 Oct 2013 20:09:56 +0400 Subject: [PATCH] JS backend: added smoke test for sourcemap -- just checks that it is compiled #KT-4054 in progress --- .../org/jetbrains/k2js/test/BasicTest.java | 45 ++++++---- .../k2js/test/config/TestConfig.java | 18 +++- .../test/config/TestConfigWithUnitTests.java | 2 +- .../k2js/test/semantics/SourcemapTest.java | 83 +++++++++++++++++++ .../k2js/test/utils/TranslationUtils.java | 2 +- 5 files changed, 130 insertions(+), 20 deletions(-) create mode 100644 js/js.tests/test/org/jetbrains/k2js/test/semantics/SourcemapTest.java diff --git a/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java b/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java index adcd50a3a44..c6190fd7f4e 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java @@ -17,6 +17,7 @@ package org.jetbrains.k2js.test; import com.google.common.collect.Lists; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetTestUtils; @@ -106,26 +107,42 @@ public abstract class BasicTest extends KotlinTestWithEnvironment { ecmaVersions); } - protected void generateJavaScriptFiles(@NotNull List files, @NotNull String testName, + protected void generateJavaScriptFiles( + @NotNull List files, + @NotNull String testName, @NotNull MainCallParameters mainCallParameters, @NotNull Iterable ecmaVersions, - @NotNull TestConfigFactory configFactory) - throws Exception { + @NotNull TestConfigFactory configFactory + ) throws Exception { for (EcmaVersion version : ecmaVersions) { - TranslationUtils.translateFiles(getProject(), withAdditionalFiles(files), - getOutputFilePath(testName, version), mainCallParameters, - version, configFactory); + translateFiles(getProject(), withAdditionalFiles(files), getOutputFilePath(testName, version), mainCallParameters, + version, configFactory); } } - protected void generateJavaScriptFiles(@NotNull List files, @NotNull String testName, - @NotNull MainCallParameters mainCallParameters, @NotNull Iterable ecmaVersions) - throws Exception { - for (EcmaVersion version : ecmaVersions) { - TranslationUtils.translateFiles(getProject(), withAdditionalFiles(files), - getOutputFilePath(testName, version), mainCallParameters, - version, TestConfig.FACTORY); - } + protected void generateJavaScriptFiles( + @NotNull List files, + @NotNull String testName, + @NotNull MainCallParameters mainCallParameters, + @NotNull Iterable ecmaVersions + ) throws Exception { + generateJavaScriptFiles(files, testName, mainCallParameters, ecmaVersions, getConfigFactory()); + } + + protected void translateFiles( + @NotNull Project project, + @NotNull List files, + @NotNull String outputFile, + @NotNull MainCallParameters mainCallParameters, + @NotNull EcmaVersion version, + @NotNull TestConfigFactory configFactory + ) throws Exception { + TranslationUtils.translateFiles(project, files, outputFile, mainCallParameters, version, configFactory); + } + + @NotNull + protected TestConfigFactory getConfigFactory() { + return TestConfig.FACTORY_WITHOUT_SOURCEMAP; } @NotNull diff --git a/js/js.tests/test/org/jetbrains/k2js/test/config/TestConfig.java b/js/js.tests/test/org/jetbrains/k2js/test/config/TestConfig.java index 9f2b74cc376..fa02a62b124 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/config/TestConfig.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/config/TestConfig.java @@ -28,13 +28,23 @@ import java.util.List; public class TestConfig extends Config { @NotNull - public static TestConfigFactory FACTORY = new TestConfigFactory() { + public static TestConfigFactory FACTORY_WITHOUT_SOURCEMAP = new TestConfigFactory() { @Override public TestConfig create(@NotNull Project project, @NotNull EcmaVersion version, @NotNull List files, @NotNull BindingContext context) { - return new TestConfig(project, version, files, context); + return new TestConfig(project, version, files, context, false); + } + }; + + public static TestConfigFactory FACTORY_WITH_SOURCEMAP = new TestConfigFactory() { + @Override + public TestConfig create(@NotNull Project project, + @NotNull EcmaVersion version, + @NotNull List files, + @NotNull BindingContext context) { + return new TestConfig(project, version, files, context, true); } }; @@ -44,8 +54,8 @@ public class TestConfig extends Config { private final BindingContext libraryContext; public TestConfig(@NotNull Project project, @NotNull EcmaVersion version, - @NotNull List files, @NotNull BindingContext context) { - super(project, REWRITABLE_MODULE_NAME, version); + @NotNull List files, @NotNull BindingContext context, boolean sourcemap) { + super(project, REWRITABLE_MODULE_NAME, version, sourcemap); jsLibFiles = files; libraryContext = context; } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/config/TestConfigWithUnitTests.java b/js/js.tests/test/org/jetbrains/k2js/test/config/TestConfigWithUnitTests.java index f624433f253..1a676622dce 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/config/TestConfigWithUnitTests.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/config/TestConfigWithUnitTests.java @@ -48,6 +48,6 @@ public class TestConfigWithUnitTests extends TestConfig { @NotNull EcmaVersion version, @NotNull List files, @NotNull BindingContext context) { - super(project, version, files, context); + super(project, version, files, context, false); } } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/SourcemapTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/SourcemapTest.java new file mode 100644 index 00000000000..0973cc0e4c1 --- /dev/null +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/SourcemapTest.java @@ -0,0 +1,83 @@ +/* + * 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; + +import com.intellij.openapi.project.Project; +import junit.framework.Test; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.k2js.config.EcmaVersion; +import org.jetbrains.k2js.facade.K2JSTranslator; +import org.jetbrains.k2js.facade.MainCallParameters; +import org.jetbrains.k2js.test.BasicTest; +import org.jetbrains.k2js.test.SingleFileTranslationTest; +import org.jetbrains.k2js.test.config.TestConfig; +import org.jetbrains.k2js.test.config.TestConfigFactory; + +import java.util.List; + +import static org.jetbrains.k2js.test.utils.TranslationUtils.createJetFileList; +import static org.jetbrains.k2js.test.utils.TranslationUtils.getConfig; + +@SuppressWarnings("JUnitTestCaseWithNoTests") +public final class SourcemapTest extends SingleFileTranslationTest { + + @NotNull + private final String filename; + + @SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors") + public SourcemapTest(@NotNull String filename) { + super("sourcemap/"); + this.filename = filename; + } + + @Override + protected void translateFiles( + @NotNull Project project, + @NotNull List files, + @NotNull String outputFile, + @NotNull MainCallParameters mainCallParameters, + @NotNull EcmaVersion version, + @NotNull TestConfigFactory configFactory + ) throws Exception { + K2JSTranslator.translateWithMainCallParametersAndSaveToFile(mainCallParameters, createJetFileList(project, files, null), outputFile, + getConfig(project, version, configFactory)); + } + + @NotNull + @Override + protected TestConfigFactory getConfigFactory() { + return TestConfig.FACTORY_WITH_SOURCEMAP; + } + + @Override + public void runTest() throws Exception { + checkFooBoxIsOk(filename); + } + + public static Test suite() throws Exception { + return TranslatorTestCaseBuilder + .suiteForDirectory(BasicTest.pathToTestFilesRoot() + "sourcemap/cases/", new TranslatorTestCaseBuilder.NamedTestFactory() { + @NotNull + @Override + public Test createTest(@NotNull String filename) { + SourcemapTest examplesTest = new SourcemapTest(filename); + examplesTest.setName(filename); + return examplesTest; + } + }); + } +} diff --git a/js/js.tests/test/org/jetbrains/k2js/test/utils/TranslationUtils.java b/js/js.tests/test/org/jetbrains/k2js/test/utils/TranslationUtils.java index cc85e8a86f1..97ec4915864 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/utils/TranslationUtils.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/utils/TranslationUtils.java @@ -120,7 +120,7 @@ public final class TranslationUtils { return result; } - private static List createJetFileList(@NotNull Project project, @NotNull List list, @Nullable String root) { + public static List createJetFileList(@NotNull Project project, @NotNull List list, @Nullable String root) { List libFiles = Lists.newArrayList(); for (String libFileName : list) { try {