refactor creating test suites
This commit is contained in:
@@ -1,44 +1,16 @@
|
|||||||
package org.jetbrains.k2js.test;
|
package org.jetbrains.k2js.test;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.UsefulTestCase;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public final class ExampleTestSuite extends TranslationTest {
|
public final class ExampleTestSuite extends UsefulTestCase {
|
||||||
|
|
||||||
|
|
||||||
final private static String MAIN = "examples/";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String mainDirectory() {
|
|
||||||
return MAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void runBoxTest(String filename) throws Exception {
|
|
||||||
testFunctionOutput(filename, "Anonymous", "box", "OK");
|
|
||||||
}
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public ExampleTestSuite(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void runTest() throws Exception {
|
|
||||||
runBoxTest(getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
return TranslatorTestCaseBuilder.suiteForDirectory("translator",
|
return Suite.suiteForDirectory("examples/", new Suite.SingleFileTester() {
|
||||||
"/testFiles/examples/cases/", true, new TranslatorTestCaseBuilder.NamedTestFactory() {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
public void performTest(@NotNull Suite test, @NotNull String filename) throws Exception {
|
||||||
return (new ExampleTestSuite(name));
|
test.testFunctionOutput(filename, "Anonymous", "box", "OK");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public final class MultiFileTest extends TranslationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void testFooBoxIsTrue(String dirName) throws Exception {
|
public void testFooBoxIsTrue(String dirName) throws Exception {
|
||||||
testMultiFile(dirName, "foo", "box", true);
|
testMultiFile(dirName, "foo", "box", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,19 @@
|
|||||||
package org.jetbrains.k2js.test;
|
package org.jetbrains.k2js.test;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.UsefulTestCase;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
*/
|
*/
|
||||||
public final class SimpleTestSuite extends TranslationTest {
|
public final class SimpleTestSuite extends UsefulTestCase {
|
||||||
final private static String MAIN = "simple/";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String mainDirectory() {
|
|
||||||
return MAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void runBoxTest(String filename) throws Exception {
|
|
||||||
testFooBoxIsTrue(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public SimpleTestSuite(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void runTest() throws Exception {
|
|
||||||
runBoxTest(getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
return TranslatorTestCaseBuilder.suiteForDirectory("translator",
|
return Suite.suiteForDirectory("simple/", new Suite.SingleFileTester() {
|
||||||
"/testFiles/simple/cases/", true, new TranslatorTestCaseBuilder.NamedTestFactory() {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public Test createTest(@NotNull String dataPath, @NotNull String name) {
|
public void performTest(@NotNull Suite test, @NotNull String filename) throws Exception {
|
||||||
return (new SimpleTestSuite(name));
|
test.testFooBoxIsTrue(filename);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package org.jetbrains.k2js.test;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestResult;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Pavel Talanov
|
||||||
|
*/
|
||||||
|
public final class Suite extends TranslationTest {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private final SingleFileTester tester;
|
||||||
|
private final String testMain;
|
||||||
|
|
||||||
|
public Suite(@NotNull String testName,
|
||||||
|
@NotNull String suiteDirName,
|
||||||
|
@NotNull final SingleFileTester tester) {
|
||||||
|
this.name = testName;
|
||||||
|
this.tester = tester;
|
||||||
|
this.testMain = suiteDirName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String mainDirectory() {
|
||||||
|
return testMain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest() throws Exception {
|
||||||
|
tester.performTest(this, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
return new Test() {
|
||||||
|
@Override
|
||||||
|
public int countTestCases() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(TestResult testResult) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suiteForDirectory(@NotNull final String mainName, @NotNull final SingleFileTester testMethod) {
|
||||||
|
|
||||||
|
return TranslatorTestCaseBuilder.suiteForDirectory("translator\\testFiles\\",
|
||||||
|
mainName + casesDirectoryName(), true, new TranslatorTestCaseBuilder.NamedTestFactory() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Test createTest(@NotNull String name) {
|
||||||
|
return (new Suite(name, mainName, testMethod));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected interface SingleFileTester {
|
||||||
|
void performTest(@NotNull Suite test, @NotNull String filename) throws Exception;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,20 +28,20 @@ public abstract class TranslationTest extends BaseTest {
|
|||||||
private static final String KOTLIN_JS_LIB = TEST_FILES + "kotlin_lib.js";
|
private static final String KOTLIN_JS_LIB = TEST_FILES + "kotlin_lib.js";
|
||||||
private static final String EXPECTED = "expected/";
|
private static final String EXPECTED = "expected/";
|
||||||
|
|
||||||
protected abstract String mainDirectory();
|
|
||||||
|
|
||||||
protected String kotlinLibraryPath() {
|
protected String kotlinLibraryPath() {
|
||||||
return KOTLIN_JS_LIB;
|
return KOTLIN_JS_LIB;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String casesDirectoryName() {
|
protected static String casesDirectoryName() {
|
||||||
return CASES;
|
return CASES;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String outDirectoryName() {
|
private static String outDirectoryName() {
|
||||||
return OUT;
|
return OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract String mainDirectory();
|
||||||
|
|
||||||
private String testFilesPath() {
|
private String testFilesPath() {
|
||||||
return TEST_FILES + suiteDirectoryName() + mainDirectory();
|
return TEST_FILES + suiteDirectoryName() + mainDirectory();
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ public abstract class TranslationTest extends BaseTest {
|
|||||||
return testFilesPath() + outDirectoryName();
|
return testFilesPath() + outDirectoryName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getInputPath() {
|
protected String getInputPath() {
|
||||||
return testFilesPath() + casesDirectoryName();
|
return testFilesPath() + casesDirectoryName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,11 +136,11 @@ public abstract class TranslationTest extends BaseTest {
|
|||||||
Context.exit();
|
Context.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void testFooBoxIsTrue(String filename) throws Exception {
|
public void testFooBoxIsTrue(String filename) throws Exception {
|
||||||
testFunctionOutput(filename, "foo", "box", true);
|
testFunctionOutput(filename, "foo", "box", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void testFooBoxIsOk(String filename) throws Exception {
|
public void testFooBoxIsOk(String filename) throws Exception {
|
||||||
testFunctionOutput(filename, "foo", "box", "OK");
|
testFunctionOutput(filename, "foo", "box", "OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author PavelTalanov
|
* @author Pavel Talanov
|
||||||
*/
|
*/
|
||||||
public abstract class TranslatorTestCaseBuilder {
|
public abstract class TranslatorTestCaseBuilder {
|
||||||
public static FilenameFilter emptyFilter = new FilenameFilter() {
|
public static FilenameFilter emptyFilter = new FilenameFilter() {
|
||||||
@@ -24,16 +24,18 @@ public abstract class TranslatorTestCaseBuilder {
|
|||||||
|
|
||||||
public interface NamedTestFactory {
|
public interface NamedTestFactory {
|
||||||
@NotNull
|
@NotNull
|
||||||
Test createTest(@NotNull String dataPath, @NotNull String name);
|
Test createTest(@NotNull String filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive, @NotNull NamedTestFactory factory) {
|
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath,
|
||||||
|
boolean recursive, @NotNull NamedTestFactory factory) {
|
||||||
return suiteForDirectory(baseDataDir, dataPath, recursive, emptyFilter, factory);
|
return suiteForDirectory(baseDataDir, dataPath, recursive, emptyFilter, factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive, final FilenameFilter filter, @NotNull NamedTestFactory factory) {
|
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive,
|
||||||
|
final FilenameFilter filter, @NotNull NamedTestFactory factory) {
|
||||||
TestSuite suite = new TestSuite(dataPath);
|
TestSuite suite = new TestSuite(dataPath);
|
||||||
appendTestsInDirectory(baseDataDir, dataPath, recursive, filter, factory, suite);
|
appendTestsInDirectory(baseDataDir, dataPath, recursive, filter, factory, suite);
|
||||||
return suite;
|
return suite;
|
||||||
@@ -82,7 +84,7 @@ public abstract class TranslatorTestCaseBuilder {
|
|||||||
String fileName = file.getName();
|
String fileName = file.getName();
|
||||||
assert fileName != null;
|
assert fileName != null;
|
||||||
String extension = fileName.endsWith(extensionJet) ? extensionJet : extensionKt;
|
String extension = fileName.endsWith(extensionJet) ? extensionJet : extensionKt;
|
||||||
suite.addTest(factory.createTest(dataPath, fileName));
|
suite.addTest(factory.createTest(fileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user