Make js.tests perform each test with different Ecma versions
This leads to tests failing
This commit is contained in:
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoResultChecker;
|
||||
import org.jetbrains.k2js.test.utils.TranslationUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -29,6 +30,7 @@ import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.k2js.test.rhino.RhinoUtils.runRhinoTest;
|
||||
import static org.jetbrains.k2js.test.utils.JsTestUtils.convertFileNameToDotJsFile;
|
||||
|
||||
/**
|
||||
@@ -103,6 +105,12 @@ public abstract class BasicTest extends TestWithEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
protected void runRhinoTests(@NotNull List<String> outputFilePaths, @NotNull RhinoResultChecker checker) throws Exception {
|
||||
for (String outputFilePath : outputFilePaths) {
|
||||
runRhinoTest(withAdditionalFiles(outputFilePath), checker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected static String casesDirectoryName() {
|
||||
return CASES;
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.k2js.test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -41,8 +42,8 @@ public abstract class MultipleFilesTranslationTest extends BasicTest {
|
||||
protected void runMultiFileTest(@NotNull String dirName, @NotNull String namespaceName,
|
||||
@NotNull String functionName, @NotNull Object expectedResult) throws Exception {
|
||||
generateJsFromDir(dirName);
|
||||
//runRhinoTest(withAdditionalFiles(getOutputFilePaths(dirName + ".kt", EcmaVersion.all())),
|
||||
// new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
runRhinoTests(getOutputFilePaths(dirName + ".kt", EcmaVersion.all()),
|
||||
new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
public void checkFooBoxIsTrue(@NotNull String dirName) throws Exception {
|
||||
|
||||
@@ -24,9 +24,7 @@ import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoSystemOutputChecker;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.k2js.test.rhino.RhinoUtils.runRhinoTest;
|
||||
import static org.jetbrains.k2js.test.utils.JsTestUtils.readFile;
|
||||
|
||||
/**
|
||||
@@ -39,15 +37,12 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
super(main);
|
||||
}
|
||||
|
||||
public void runFunctionOutputTest(String kotlinFilename, String namespaceName,
|
||||
String functionName, Object expectedResult) throws Exception {
|
||||
public void runFunctionOutputTest(@NotNull String kotlinFilename, @NotNull String namespaceName,
|
||||
@NotNull String functionName, @NotNull Object expectedResult) throws Exception {
|
||||
EnumSet<EcmaVersion> ecmaVersions = EcmaVersion.all();
|
||||
generateJavaScriptFiles(kotlinFilename, MainCallParameters.noCall(), ecmaVersions);
|
||||
List<String> outputFilePaths = getOutputFilePaths(kotlinFilename, ecmaVersions);
|
||||
for (String outputFilePath : outputFilePaths) {
|
||||
runRhinoTest(withAdditionalFiles(outputFilePath),
|
||||
new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
}
|
||||
runRhinoTests(getOutputFilePaths(kotlinFilename, ecmaVersions),
|
||||
new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
public void checkFooBoxIsTrue(@NotNull String filename) throws Exception {
|
||||
@@ -65,11 +60,7 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
protected void checkOutput(@NotNull String kotlinFilename, @NotNull String expectedResult, @NotNull String... args) throws Exception {
|
||||
EnumSet<EcmaVersion> ecmaVersions = EcmaVersion.all();
|
||||
generateJavaScriptFiles(kotlinFilename, MainCallParameters.mainWithArguments(Lists.newArrayList(args)), ecmaVersions);
|
||||
List<String> outputFilePaths = getOutputFilePaths(kotlinFilename, ecmaVersions);
|
||||
for (String outputFilePath : outputFilePaths) {
|
||||
runRhinoTest(withAdditionalFiles(outputFilePath),
|
||||
new RhinoSystemOutputChecker(expectedResult));
|
||||
}
|
||||
runRhinoTests(getOutputFilePaths(kotlinFilename, ecmaVersions), new RhinoSystemOutputChecker(expectedResult));
|
||||
}
|
||||
|
||||
protected void performTestWithMain(@NotNull String testName, @NotNull String testId, @NotNull String... args) throws Exception {
|
||||
|
||||
@@ -40,8 +40,8 @@ public final class TestConfig extends Config {
|
||||
@Nullable
|
||||
private /*var*/ List<JetFile> jsLibFiles = null;
|
||||
|
||||
public TestConfig(@NotNull Project project) {
|
||||
super(project, EcmaVersion.v3);
|
||||
public TestConfig(@NotNull Project project, @NotNull EcmaVersion version) {
|
||||
super(project, version);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.jetbrains.k2js.test.utils;
|
||||
|
||||
import closurecompiler.internal.com.google.common.collect.Maps;
|
||||
import com.google.dart.compiler.backend.js.ast.JsProgram;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.facade.K2JSTranslator;
|
||||
@@ -31,6 +31,7 @@ import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.k2js.utils.JetFileUtils.createPsiFileList;
|
||||
|
||||
@@ -42,8 +43,8 @@ public final class TranslationUtils {
|
||||
private TranslationUtils() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static /*var*/ K2JSTranslator translator = null;
|
||||
@NotNull
|
||||
private static final Map<EcmaVersion, K2JSTranslator> translators = Maps.newHashMap();
|
||||
|
||||
public static void translateFile(@NotNull Project project, @NotNull String inputFile,
|
||||
@NotNull String outputFile, @NotNull MainCallParameters mainCallParameters, @NotNull EcmaVersion version) throws Exception {
|
||||
@@ -52,9 +53,8 @@ public final class TranslationUtils {
|
||||
|
||||
public static void translateFiles(@NotNull Project project, @NotNull List<String> inputFiles,
|
||||
@NotNull String outputFile, @NotNull MainCallParameters mainCallParameters, @NotNull EcmaVersion version) throws Exception {
|
||||
//TODO: ignoring version for the moment
|
||||
List<JetFile> psiFiles = createPsiFileList(inputFiles, project);
|
||||
JsProgram program = getTranslator(project).generateProgram(psiFiles, mainCallParameters);
|
||||
JsProgram program = getTranslator(project, version).generateProgram(psiFiles, mainCallParameters);
|
||||
FileWriter writer = new FileWriter(new File(outputFile));
|
||||
try {
|
||||
writer.write("\"use strict\";\n");
|
||||
@@ -66,9 +66,11 @@ public final class TranslationUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static K2JSTranslator getTranslator(@NotNull Project project) {
|
||||
private static K2JSTranslator getTranslator(@NotNull Project project, @NotNull EcmaVersion version) {
|
||||
K2JSTranslator translator = translators.get(version);
|
||||
if (translator == null) {
|
||||
translator = new K2JSTranslator(new TestConfig(project));
|
||||
translators.put(version, translator);
|
||||
translator = new K2JSTranslator(new TestConfig(project, version));
|
||||
}
|
||||
return translator;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user