From 43c168baef90c1f710719b594e23019d9f3c6ec7 Mon Sep 17 00:00:00 2001 From: pTalanov Date: Tue, 15 May 2012 19:51:13 +0400 Subject: [PATCH] Make js.tests perform each test with different Ecma versions This leads to tests failing --- .../org/jetbrains/k2js/test/BasicTest.java | 8 ++++++++ .../test/MultipleFilesTranslationTest.java | 5 +++-- .../k2js/test/SingleFileTranslationTest.java | 19 +++++-------------- .../k2js/test/config/TestConfig.java | 4 ++-- .../k2js/test/utils/TranslationUtils.java | 16 +++++++++------- 5 files changed, 27 insertions(+), 25 deletions(-) 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 c59798dbabc..b20a4673a29 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/BasicTest.java @@ -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 outputFilePaths, @NotNull RhinoResultChecker checker) throws Exception { + for (String outputFilePath : outputFilePaths) { + runRhinoTest(withAdditionalFiles(outputFilePath), checker); + } + } + protected static String casesDirectoryName() { return CASES; diff --git a/js/js.tests/test/org/jetbrains/k2js/test/MultipleFilesTranslationTest.java b/js/js.tests/test/org/jetbrains/k2js/test/MultipleFilesTranslationTest.java index 2fd8c67b395..172c29cd5b7 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/MultipleFilesTranslationTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/MultipleFilesTranslationTest.java @@ -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 { diff --git a/js/js.tests/test/org/jetbrains/k2js/test/SingleFileTranslationTest.java b/js/js.tests/test/org/jetbrains/k2js/test/SingleFileTranslationTest.java index 4d5a53e00ef..9af0b7034ce 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/SingleFileTranslationTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/SingleFileTranslationTest.java @@ -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 ecmaVersions = EcmaVersion.all(); generateJavaScriptFiles(kotlinFilename, MainCallParameters.noCall(), ecmaVersions); - List 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 ecmaVersions = EcmaVersion.all(); generateJavaScriptFiles(kotlinFilename, MainCallParameters.mainWithArguments(Lists.newArrayList(args)), ecmaVersions); - List 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 { 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 c35a63c3ac6..b71bfed31b9 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 @@ -40,8 +40,8 @@ public final class TestConfig extends Config { @Nullable private /*var*/ List jsLibFiles = null; - public TestConfig(@NotNull Project project) { - super(project, EcmaVersion.v3); + public TestConfig(@NotNull Project project, @NotNull EcmaVersion version) { + super(project, version); } @NotNull 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 8c34792fd46..76c88714074 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 @@ -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 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 inputFiles, @NotNull String outputFile, @NotNull MainCallParameters mainCallParameters, @NotNull EcmaVersion version) throws Exception { - //TODO: ignoring version for the moment List 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; }