Use DEFAULT_ECMA_VERSIONS constant in tests instead of EcmaVersions#all(). Some code style issues as well.

Adapted from https://github.com/develar/kotlin/commit/a9e0a42fb1347fa8e21c86b5a073ef8a7c873da0.
This commit is contained in:
Pavel V. Talanov
2012-08-13 15:51:10 +04:00
parent a7c6776876
commit 40ea266a8a
9 changed files with 23 additions and 38 deletions
@@ -42,6 +42,8 @@ import static org.jetbrains.k2js.test.utils.JsTestUtils.convertFileNameToDotJsFi
* @author Pavel Talanov
*/
public abstract class BasicTest extends KotlinTestWithEnvironment {
// predictable order of ecma version in tests
protected static final Iterable<EcmaVersion> DEFAULT_ECMA_VERSIONS = Lists.newArrayList(EcmaVersion.v5, EcmaVersion.v3);
private static final boolean DELETE_OUT = false;
private static final String TEST_FILES = "js/js.translator/testFiles/";
@@ -21,7 +21,6 @@ import org.jetbrains.k2js.config.EcmaVersion;
import org.jetbrains.k2js.facade.MainCallParameters;
import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker;
import java.util.EnumSet;
import java.util.List;
import static org.jetbrains.k2js.test.utils.JsTestUtils.getAllFilesInDir;
@@ -35,17 +34,17 @@ public abstract class MultipleFilesTranslationTest extends BasicTest {
super(main);
}
protected void generateJsFromDir(@NotNull String dirName, @NotNull EnumSet<EcmaVersion> ecmaVersions) throws Exception {
protected void generateJsFromDir(@NotNull String dirName, @NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
List<String> fullFilePaths = getAllFilesInDir(getInputFilePath(dirName));
generateJavaScriptFiles(fullFilePaths, dirName, MainCallParameters.noCall(), ecmaVersions);
}
protected void runMultiFileTest(@NotNull String dirName, @NotNull String namespaceName,
@NotNull String functionName, @NotNull Object expectedResult) throws Exception {
runMultiFileTests(EcmaVersion.all(), dirName, namespaceName, functionName, expectedResult);
runMultiFileTests(DEFAULT_ECMA_VERSIONS, dirName, namespaceName, functionName, expectedResult);
}
protected void runMultiFileTests(@NotNull EnumSet<EcmaVersion> ecmaVersions, @NotNull String dirName,
protected void runMultiFileTests(@NotNull Iterable<EcmaVersion> ecmaVersions, @NotNull String dirName,
@NotNull String namespaceName,
@NotNull String functionName,
@NotNull Object expectedResult)
@@ -23,8 +23,6 @@ import org.jetbrains.k2js.facade.MainCallParameters;
import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker;
import org.jetbrains.k2js.test.rhino.RhinoSystemOutputChecker;
import java.util.EnumSet;
import static org.jetbrains.k2js.test.utils.JsTestUtils.readFile;
/**
@@ -32,14 +30,13 @@ import static org.jetbrains.k2js.test.utils.JsTestUtils.readFile;
*/
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
public abstract class SingleFileTranslationTest extends BasicTest {
public SingleFileTranslationTest(@NotNull String main) {
super(main);
}
public void runFunctionOutputTest(@NotNull String kotlinFilename, @NotNull String namespaceName,
@NotNull String functionName, @NotNull Object expectedResult) throws Exception {
runFunctionOutputTest(EcmaVersion.all(), kotlinFilename, namespaceName, functionName, expectedResult);
runFunctionOutputTest(DEFAULT_ECMA_VERSIONS, kotlinFilename, namespaceName, functionName, expectedResult);
}
protected void runFunctionOutputTest(@NotNull Iterable<EcmaVersion> ecmaVersions, @NotNull String kotlinFilename,
@@ -54,16 +51,20 @@ public abstract class SingleFileTranslationTest extends BasicTest {
runFunctionOutputTest(ecmaVersions, filename, "foo", "box", true);
}
public void checkFooBoxIsValue(@NotNull String filename, @NotNull EnumSet<EcmaVersion> ecmaVersions, Object expected) throws Exception {
public void checkFooBoxIsTrue(@NotNull String filename) throws Exception {
runFunctionOutputTest(DEFAULT_ECMA_VERSIONS, filename, "foo", "box", true);
}
public void checkFooBoxIsValue(@NotNull String filename, @NotNull Iterable<EcmaVersion> ecmaVersions, Object expected) throws Exception {
runFunctionOutputTest(ecmaVersions, filename, "foo", "box", expected);
}
protected void fooBoxTest() throws Exception {
checkFooBoxIsTrue(getTestName(true) + ".kt", EcmaVersion.all());
checkFooBoxIsTrue(getTestName(true) + ".kt", DEFAULT_ECMA_VERSIONS);
}
protected void fooBoxIsValue(Object expected) throws Exception {
checkFooBoxIsValue(getTestName(true) + ".kt", EcmaVersion.all(), expected);
checkFooBoxIsValue(getTestName(true) + ".kt", DEFAULT_ECMA_VERSIONS, expected);
}
protected void fooBoxTest(@NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
@@ -71,17 +72,17 @@ public abstract class SingleFileTranslationTest extends BasicTest {
}
protected void checkFooBoxIsOk(@NotNull String filename) throws Exception {
checkFooBoxIsOk(EcmaVersion.all(), filename);
checkFooBoxIsOk(DEFAULT_ECMA_VERSIONS, filename);
}
protected void checkFooBoxIsOk(@NotNull EnumSet<EcmaVersion> versions, @NotNull String filename) throws Exception {
protected void checkFooBoxIsOk(@NotNull Iterable<EcmaVersion> versions, @NotNull String filename) throws Exception {
runFunctionOutputTest(versions, filename, "foo", "box", "OK");
}
protected void checkOutput(@NotNull String kotlinFilename,
@NotNull String expectedResult,
@NotNull String... args) throws Exception {
checkOutput(kotlinFilename, expectedResult, EcmaVersion.all(), args);
checkOutput(kotlinFilename, expectedResult, DEFAULT_ECMA_VERSIONS, args);
}
protected void checkOutput(@NotNull String kotlinFilename,
@@ -100,6 +101,6 @@ public abstract class SingleFileTranslationTest extends BasicTest {
}
protected void performTestWithMain(@NotNull String testName, @NotNull String testId, @NotNull String... args) throws Exception {
performTestWithMain(EcmaVersion.all(), testName, testId, args);
performTestWithMain(DEFAULT_ECMA_VERSIONS, testName, testId, args);
}
}
@@ -17,21 +17,16 @@
*/
package org.jetbrains.k2js.test.semantics;
import com.google.common.collect.Iterables;
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;
/**
* Lets test compiling all the JS code thats used by the library-js-library from the maven build
@@ -59,7 +54,7 @@ public class CompileMavenGeneratedJSLibrary extends SingleFileTranslationTest {
public void DISABLED_testGenerateTestCase() throws Exception {
if (generatedJsLibraryDir.exists() && generatedJsLibraryDir.isDirectory()) {
generateJavaScriptFiles(EcmaVersion.all(),
generateJavaScriptFiles(DEFAULT_ECMA_VERSIONS,
"libraries/stdlib/test",
"ArraysTest.kt",
"dom/DomTest.kt",
@@ -77,7 +72,7 @@ public class CompileMavenGeneratedJSLibrary extends SingleFileTranslationTest {
}
}
protected void generateJavaScriptFiles(@NotNull EnumSet<EcmaVersion> ecmaVersions,
protected void generateJavaScriptFiles(@NotNull Iterable<EcmaVersion> ecmaVersions,
@NotNull String sourceDir, @NotNull String... stdLibFiles) throws Exception {
List<String> files = Lists.newArrayList();
@@ -18,7 +18,6 @@ package org.jetbrains.k2js.test.semantics;
import junit.framework.Test;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.k2js.config.EcmaVersion;
import org.jetbrains.k2js.test.BasicTest;
import org.jetbrains.k2js.test.SingleFileTranslationTest;
@@ -39,7 +38,7 @@ public final class SimpleTest extends SingleFileTranslationTest {
@Override
public void runTest() throws Exception {
checkFooBoxIsTrue(filename, EcmaVersion.all());
checkFooBoxIsTrue(filename, DEFAULT_ECMA_VERSIONS);
}
public static Test suite() throws Exception {
@@ -41,7 +41,7 @@ public final class StdLibTest extends SingleFileTranslationTest {
}
public void testBrowserDocumentAccessCompiles() throws Exception {
generateJavaScriptFiles("browserDocumentAccess.kt", MainCallParameters.noCall(), EcmaVersion.all());
generateJavaScriptFiles("browserDocumentAccess.kt", MainCallParameters.noCall(), DEFAULT_ECMA_VERSIONS);
}
@Override
@@ -16,13 +16,11 @@
package org.jetbrains.k2js.test.semantics;
import org.jetbrains.k2js.config.EcmaVersion;
/**
*/
public class StdLibTestToJSTest extends StdLibTestBase {
public void testGenerateTestCase() throws Exception {
performStdLibTest(EcmaVersion.all(),
performStdLibTest(DEFAULT_ECMA_VERSIONS,
"libraries/stdlib/test",
"dom/DomTest.kt",
"js/MapJsTest.kt",
@@ -16,14 +16,12 @@
package org.jetbrains.k2js.test.semantics;
import org.jetbrains.k2js.config.EcmaVersion;
/**
*/
public class StdLibToJSTest extends StdLibTestBase {
public void testCompileJavaScriptFiles() throws Exception {
performStdLibTest(EcmaVersion.all(),
performStdLibTest(DEFAULT_ECMA_VERSIONS,
"libraries/stdlib/src");
}
}
@@ -20,8 +20,6 @@ import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.EnumSet;
/**
* @author Pavel Talanov
*/
@@ -37,9 +35,4 @@ public enum EcmaVersion {
public static EcmaVersion defaultVersion() {
return v3;
}
@NotNull
public static EnumSet<EcmaVersion> all() {
return EnumSet.allOf(EcmaVersion.class);
}
}