Build fix attempt: reorganised test inheritance.

This commit is contained in:
pTalanov
2012-03-06 20:44:43 +04:00
parent ecdc8115f6
commit f6ad975269
4 changed files with 35 additions and 27 deletions
@@ -56,7 +56,7 @@ public abstract class BasicTest extends TestWithEnvironment {
} }
@Override @Override
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
if (!shouldCreateOut()) { if (!shouldCreateOut()) {
return; return;
@@ -114,7 +114,7 @@ public abstract class BasicTest extends TestWithEnvironment {
} }
@NotNull @NotNull
private String getInputPath() { public String getInputPath() {
return pathToTestFiles() + casesDirectoryName(); return pathToTestFiles() + casesDirectoryName();
} }
@@ -16,17 +16,20 @@
package org.jetbrains.k2js.test.semantics; package org.jetbrains.k2js.test.semantics;
import com.intellij.testFramework.UsefulTestCase;
import junit.framework.Test; import junit.framework.Test;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.k2js.test.SingleFileTranslationTest; import org.jetbrains.k2js.test.SingleFileTranslationTest;
import org.jetbrains.k2js.test.utils.SuiteBuilder; import org.jetbrains.k2js.test.utils.SuiteBuilder;
@SuppressWarnings("JUnitTestCaseWithNoTests") @SuppressWarnings("JUnitTestCaseWithNoTests")
public final class ExamplesTest extends UsefulTestCase { public final class ExamplesTest extends SingleFileTranslationTest {
public ExamplesTest() {
super("examples/");
}
public static Test suite() throws Exception { public static Test suite() throws Exception {
return SuiteBuilder.suiteForDirectory("examples/", new SuiteBuilder.Tester() { return SuiteBuilder.suiteForTestClass(new ExamplesTest(), new SuiteBuilder.Tester() {
@Override @Override
public void performTest(@NotNull SingleFileTranslationTest test, @NotNull String filename) throws Exception { public void performTest(@NotNull SingleFileTranslationTest test, @NotNull String filename) throws Exception {
test.runFunctionOutputTest(filename, "Anonymous", "box", "OK"); test.runFunctionOutputTest(filename, "Anonymous", "box", "OK");
@@ -16,7 +16,6 @@
package org.jetbrains.k2js.test.semantics; package org.jetbrains.k2js.test.semantics;
import com.intellij.testFramework.UsefulTestCase;
import junit.framework.Test; import junit.framework.Test;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.k2js.test.SingleFileTranslationTest; import org.jetbrains.k2js.test.SingleFileTranslationTest;
@@ -26,9 +25,14 @@ import org.jetbrains.k2js.test.utils.SuiteBuilder;
* @author Pavel Talanov * @author Pavel Talanov
*/ */
@SuppressWarnings("JUnitTestCaseWithNoTests") @SuppressWarnings("JUnitTestCaseWithNoTests")
public final class SimpleTest extends UsefulTestCase { public final class SimpleTest extends SingleFileTranslationTest {
public SimpleTest() {
super("simple/");
}
public static Test suite() throws Exception { public static Test suite() throws Exception {
return SuiteBuilder.suiteForDirectory("simple/", new SuiteBuilder.Tester() { return SuiteBuilder.suiteForTestClass(new SimpleTest(), new SuiteBuilder.Tester() {
@Override @Override
public void performTest(@NotNull SingleFileTranslationTest test, @NotNull String filename) throws Exception { public void performTest(@NotNull SingleFileTranslationTest test, @NotNull String filename) throws Exception {
test.checkFooBoxIsTrue(filename); test.checkFooBoxIsTrue(filename);
@@ -26,46 +26,47 @@ import org.jetbrains.k2js.test.semantics.TranslatorTestCaseBuilder;
* @author Pavel Talanov * @author Pavel Talanov
*/ */
@SuppressWarnings("JUnitTestCaseWithNoTests") @SuppressWarnings("JUnitTestCaseWithNoTests")
public abstract class SuiteBuilder extends SingleFileTranslationTest { public abstract class SuiteBuilder {
private SuiteBuilder(@NotNull String pathToMain) {
super(pathToMain);
}
public interface Tester { public interface Tester {
void performTest(@NotNull SingleFileTranslationTest test, @NotNull String filename) throws Exception; void performTest(@NotNull SingleFileTranslationTest test, @NotNull String filename) throws Exception;
} }
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors") @SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
private class SingleFileTest extends UsefulTestCase { private static class SingleFileTest extends UsefulTestCase {
public SingleFileTest(@NotNull String name, @NotNull Tester tester) {
setName(name);
this.tester = tester;
this.name = name;
}
@NotNull @NotNull
private final Tester tester; private final Tester tester;
@NotNull @NotNull
private final String name; private final String name;
@NotNull
private final SingleFileTranslationTest actualTest;
public SingleFileTest(@NotNull SingleFileTranslationTest actualTest, @NotNull String name, @NotNull Tester tester) {
setName(name);
this.tester = tester;
this.name = name;
this.actualTest = actualTest;
}
public void runTest() throws Exception { public void runTest() throws Exception {
tester.performTest(SuiteBuilder.this, name); tester.performTest(actualTest, name);
} }
} }
public static Test suiteForDirectory(@NotNull final String main, @NotNull final SuiteBuilder.Tester testMethod) throws Exception { public static Test suiteForTestClass(@NotNull final SingleFileTranslationTest actualTest,
final SuiteBuilder singleFileTest = new SuiteBuilder(main) { @NotNull final SuiteBuilder.Tester testMethod) throws Exception {
}; //TODO: tearDown not called
singleFileTest.setUp(); actualTest.setUp();
return TranslatorTestCaseBuilder.suiteForDirectory(pathToTestFilesRoot() + main + casesDirectoryName(), return TranslatorTestCaseBuilder.suiteForDirectory(actualTest.getInputPath(),
true, true,
new TranslatorTestCaseBuilder.NamedTestFactory() { new TranslatorTestCaseBuilder.NamedTestFactory() {
@NotNull @NotNull
@Override @Override
public Test createTest(@NotNull String name) { public Test createTest(@NotNull String name) {
return singleFileTest.new SingleFileTest(name, testMethod); return new SingleFileTest(actualTest, name, testMethod);
} }
}); });
} }