Split TranslationTest into SingleFileTranslationTest and MultipleFilesTranslationTest
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.k2js.test.rhino.RhinoUtils.runRhinoTest;
|
||||
import static org.jetbrains.k2js.test.utils.TranslationUtils.translateFiles;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class MultipleFilesTranslationTest extends BasicTest {
|
||||
|
||||
public MultipleFilesTranslationTest(@NotNull String main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
protected void generateJsFromDir(@NotNull String dirName) throws Exception {
|
||||
String dirPath = getInputFilePath(dirName);
|
||||
File dir = new File(dirPath);
|
||||
List<String> fullFilePaths = new ArrayList<String>();
|
||||
for (String fileName : dir.list()) {
|
||||
fullFilePaths.add(getInputFilePath(dirName) + "/" + fileName);
|
||||
}
|
||||
assert dir.isDirectory();
|
||||
translateFiles(getProject(), fullFilePaths, getOutputFilePath(dirName + ".kt"));
|
||||
}
|
||||
|
||||
protected void runMultiFileTest(@NotNull String dirName, @NotNull String namespaceName,
|
||||
@NotNull String functionName, @NotNull Object expectedResult) throws Exception {
|
||||
generateJsFromDir(dirName);
|
||||
runRhinoTest(withKotlinJsLib(getOutputFilePath(dirName + ".kt")),
|
||||
new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
public void checkFooBoxIsTrue(@NotNull String dirName) throws Exception {
|
||||
runMultiFileTest(dirName, "foo", "box", true);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-25
@@ -21,22 +21,18 @@ import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoSystemOutputChecker;
|
||||
import org.jetbrains.k2js.test.utils.TranslationUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.k2js.test.rhino.RhinoUtils.runRhinoTest;
|
||||
import static org.jetbrains.k2js.test.utils.JsTestUtils.readFile;
|
||||
import static org.jetbrains.k2js.test.utils.TranslationUtils.translateFiles;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
|
||||
public abstract class TranslationTest extends BasicTest {
|
||||
public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
|
||||
public TranslationTest(@NotNull String main) {
|
||||
public SingleFileTranslationTest(@NotNull String main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@@ -47,29 +43,10 @@ public abstract class TranslationTest extends BasicTest {
|
||||
new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
protected void runMultiFileTest(String dirName, String namespaceName,
|
||||
String functionName, Object expectedResult) throws Exception {
|
||||
generateJsFromDir(dirName);
|
||||
runRhinoTest(withKotlinJsLib(getOutputFilePath(dirName + ".kt")),
|
||||
new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
protected void generateJsFromFile(@NotNull String filename) throws Exception {
|
||||
TranslationUtils.translateFile(getProject(), getInputFilePath(filename), getOutputFilePath(filename));
|
||||
}
|
||||
|
||||
protected void generateJsFromDir(@NotNull String dirName) throws Exception {
|
||||
String dirPath = getInputFilePath(dirName);
|
||||
File dir = new File(dirPath);
|
||||
List<String> fullFilePaths = new ArrayList<String>();
|
||||
for (String fileName : dir.list()) {
|
||||
fullFilePaths.add(getInputFilePath(dirName) + "/" + fileName);
|
||||
}
|
||||
assert dir.isDirectory();
|
||||
translateFiles(getProject(), fullFilePaths, getOutputFilePath(dirName + ".kt"));
|
||||
}
|
||||
|
||||
|
||||
public void checkFooBoxIsTrue(@NotNull String filename) throws Exception {
|
||||
runFunctionOutputTest(filename, "foo", "box", true);
|
||||
}
|
||||
@@ -17,12 +17,12 @@
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class AbstractExpressionTest extends TranslationTest {
|
||||
public abstract class AbstractExpressionTest extends SingleFileTranslationTest {
|
||||
|
||||
public AbstractExpressionTest(@NotNull String main) {
|
||||
super("expression/" + main);
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class ClassInheritanceTest extends TranslationTest {
|
||||
public final class ClassInheritanceTest extends SingleFileTranslationTest {
|
||||
|
||||
public ClassInheritanceTest() {
|
||||
super("inheritance/");
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.k2js.test.semantics;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
import org.jetbrains.k2js.test.utils.SuiteBuilder;
|
||||
|
||||
@SuppressWarnings("JUnitTestCaseWithNoTests")
|
||||
@@ -28,7 +28,7 @@ public final class ExamplesTest extends UsefulTestCase {
|
||||
public static Test suite() throws Exception {
|
||||
return SuiteBuilder.suiteForDirectory("examples/", new SuiteBuilder.Tester() {
|
||||
@Override
|
||||
public void performTest(@NotNull TranslationTest test, @NotNull String filename) throws Exception {
|
||||
public void performTest(@NotNull SingleFileTranslationTest test, @NotNull String filename) throws Exception {
|
||||
test.runFunctionOutputTest(filename, "Anonymous", "box", "OK");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class ExtensionFunctionTest extends TranslationTest {
|
||||
public final class ExtensionFunctionTest extends SingleFileTranslationTest {
|
||||
|
||||
public ExtensionFunctionTest() {
|
||||
super("extensionFunction/");
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class ExtensionPropertyTest extends TranslationTest {
|
||||
public final class ExtensionPropertyTest extends SingleFileTranslationTest {
|
||||
|
||||
public ExtensionPropertyTest() {
|
||||
super("extensionProperty/");
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class JavaClassesTest extends TranslationTest {
|
||||
public abstract class JavaClassesTest extends SingleFileTranslationTest {
|
||||
|
||||
public JavaClassesTest(@NotNull String main) {
|
||||
super("java/" + main);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoResultChecker;
|
||||
import org.mozilla.javascript.Context;
|
||||
@@ -30,7 +30,7 @@ import static org.jetbrains.k2js.test.rhino.RhinoUtils.runRhinoTest;
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class KotlinLibTest extends TranslationTest {
|
||||
public final class KotlinLibTest extends SingleFileTranslationTest {
|
||||
|
||||
public KotlinLibTest() {
|
||||
super("kotlinLib/");
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.MultipleFilesTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class MultiFileTest extends TranslationTest {
|
||||
|
||||
public final class MultiFileTest extends MultipleFilesTranslationTest {
|
||||
|
||||
public MultiFileTest() {
|
||||
super("multiFile/");
|
||||
@@ -36,9 +34,4 @@ public final class MultiFileTest extends TranslationTest {
|
||||
public void testClassesInheritedFromOtherFile() throws Exception {
|
||||
checkFooBoxIsTrue("classesInheritedFromOtherFile");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkFooBoxIsTrue(@NotNull String dirName) throws Exception {
|
||||
runMultiFileTest(dirName, "foo", "box", true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.MultipleFilesTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class MultiNamespaceTest extends TranslationTest {
|
||||
public class MultiNamespaceTest extends MultipleFilesTranslationTest {
|
||||
|
||||
|
||||
public MultiNamespaceTest() {
|
||||
@@ -37,9 +36,5 @@ public class MultiNamespaceTest extends TranslationTest {
|
||||
checkFooBoxIsTrue("classesInheritedFromOtherNamespace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkFooBoxIsTrue(@NotNull String dirName) throws Exception {
|
||||
runMultiFileTest(dirName, "foo", "box", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class NameClashesTest extends TranslationTest {
|
||||
public final class NameClashesTest extends SingleFileTranslationTest {
|
||||
|
||||
|
||||
public NameClashesTest() {
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class ObjectTest extends TranslationTest {
|
||||
public final class ObjectTest extends SingleFileTranslationTest {
|
||||
|
||||
public ObjectTest() {
|
||||
super("object/");
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class OperatorOverloadingTest extends TranslationTest {
|
||||
public final class OperatorOverloadingTest extends SingleFileTranslationTest {
|
||||
|
||||
public OperatorOverloadingTest() {
|
||||
super("operatorOverloading/");
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
import org.mozilla.javascript.JavaScriptException;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class PatternMatchingTest extends TranslationTest {
|
||||
public final class PatternMatchingTest extends SingleFileTranslationTest {
|
||||
|
||||
public PatternMatchingTest() {
|
||||
super("patternMatching/");
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class PropertyAccessTest extends TranslationTest {
|
||||
public final class PropertyAccessTest extends SingleFileTranslationTest {
|
||||
|
||||
public PropertyAccessTest() {
|
||||
super("propertyAccess/");
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class RTTITest extends TranslationTest {
|
||||
public class RTTITest extends SingleFileTranslationTest {
|
||||
|
||||
public RTTITest() {
|
||||
super("rtti/");
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class RangeTest extends TranslationTest {
|
||||
public final class RangeTest extends SingleFileTranslationTest {
|
||||
|
||||
public RangeTest() {
|
||||
super("range/");
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class SafeCallTest extends TranslationTest {
|
||||
public final class SafeCallTest extends SingleFileTranslationTest {
|
||||
|
||||
public SafeCallTest() {
|
||||
super("safeCall/");
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.k2js.test.semantics;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
import org.jetbrains.k2js.test.utils.SuiteBuilder;
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ public final class SimpleTest extends UsefulTestCase {
|
||||
public static Test suite() throws Exception {
|
||||
return SuiteBuilder.suiteForDirectory("simple/", new SuiteBuilder.Tester() {
|
||||
@Override
|
||||
public void performTest(@NotNull TranslationTest test, @NotNull String filename) throws Exception {
|
||||
public void performTest(@NotNull SingleFileTranslationTest test, @NotNull String filename) throws Exception {
|
||||
test.checkFooBoxIsTrue(filename);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class StandardClassesTest extends TranslationTest {
|
||||
public final class StandardClassesTest extends SingleFileTranslationTest {
|
||||
|
||||
public StandardClassesTest() {
|
||||
super("standardClasses/");
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class TraitTest extends TranslationTest {
|
||||
public final class TraitTest extends SingleFileTranslationTest {
|
||||
|
||||
public TraitTest() {
|
||||
super("trait/");
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class TupleTest extends TranslationTest {
|
||||
public final class TupleTest extends SingleFileTranslationTest {
|
||||
|
||||
|
||||
public TupleTest() {
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class WebDemoExamples1Test extends TranslationTest {
|
||||
public final class WebDemoExamples1Test extends SingleFileTranslationTest {
|
||||
|
||||
public WebDemoExamples1Test() {
|
||||
super("webDemoExamples1/");
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class WebDemoExamples2Test extends TranslationTest {
|
||||
public final class WebDemoExamples2Test extends SingleFileTranslationTest {
|
||||
|
||||
public WebDemoExamples2Test() {
|
||||
super("webDemoExamples2/");
|
||||
|
||||
@@ -19,21 +19,21 @@ package org.jetbrains.k2js.test.utils;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.TranslationTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
import org.jetbrains.k2js.test.semantics.TranslatorTestCaseBuilder;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
@SuppressWarnings("JUnitTestCaseWithNoTests")
|
||||
public abstract class SuiteBuilder extends TranslationTest {
|
||||
public abstract class SuiteBuilder extends SingleFileTranslationTest {
|
||||
|
||||
private SuiteBuilder(@NotNull String pathToMain) {
|
||||
super(pathToMain);
|
||||
}
|
||||
|
||||
public interface Tester {
|
||||
void performTest(@NotNull TranslationTest test, @NotNull String filename) throws Exception;
|
||||
void performTest(@NotNull SingleFileTranslationTest test, @NotNull String filename) throws Exception;
|
||||
}
|
||||
|
||||
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
|
||||
|
||||
Reference in New Issue
Block a user