JS backend: added smoke test for sourcemap -- just checks that it is compiled
#KT-4054 in progress
This commit is contained in:
@@ -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<String> files, @NotNull String testName,
|
||||
protected void generateJavaScriptFiles(
|
||||
@NotNull List<String> files,
|
||||
@NotNull String testName,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Iterable<EcmaVersion> 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<String> files, @NotNull String testName,
|
||||
@NotNull MainCallParameters mainCallParameters, @NotNull Iterable<EcmaVersion> ecmaVersions)
|
||||
throws Exception {
|
||||
for (EcmaVersion version : ecmaVersions) {
|
||||
TranslationUtils.translateFiles(getProject(), withAdditionalFiles(files),
|
||||
getOutputFilePath(testName, version), mainCallParameters,
|
||||
version, TestConfig.FACTORY);
|
||||
}
|
||||
protected void generateJavaScriptFiles(
|
||||
@NotNull List<String> files,
|
||||
@NotNull String testName,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions
|
||||
) throws Exception {
|
||||
generateJavaScriptFiles(files, testName, mainCallParameters, ecmaVersions, getConfigFactory());
|
||||
}
|
||||
|
||||
protected void translateFiles(
|
||||
@NotNull Project project,
|
||||
@NotNull List<String> 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
|
||||
|
||||
@@ -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<JetFile> 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<JetFile> 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<JetFile> files, @NotNull BindingContext context) {
|
||||
super(project, REWRITABLE_MODULE_NAME, version);
|
||||
@NotNull List<JetFile> files, @NotNull BindingContext context, boolean sourcemap) {
|
||||
super(project, REWRITABLE_MODULE_NAME, version, sourcemap);
|
||||
jsLibFiles = files;
|
||||
libraryContext = context;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,6 @@ public class TestConfigWithUnitTests extends TestConfig {
|
||||
@NotNull EcmaVersion version,
|
||||
@NotNull List<JetFile> files,
|
||||
@NotNull BindingContext context) {
|
||||
super(project, version, files, context);
|
||||
super(project, version, files, context, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String> 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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public final class TranslationUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<JetFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
|
||||
public static List<JetFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
|
||||
List<JetFile> libFiles = Lists.newArrayList();
|
||||
for (String libFileName : list) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user