diff options
-rw-r--r-- | test/core/src/lombok/AbstractRunTests.java | 48 | ||||
-rw-r--r-- | test/core/src/lombok/DirectoryRunner.java | 39 |
2 files changed, 56 insertions, 31 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java index 85c3674f..f564d0dc 100644 --- a/test/core/src/lombok/AbstractRunTests.java +++ b/test/core/src/lombok/AbstractRunTests.java @@ -39,6 +39,7 @@ import java.util.Map; import org.junit.Assert; +import lombok.DirectoryRunner.FileTester; import lombok.core.AST; import lombok.core.LombokConfiguration; import lombok.core.LombokImmutableList; @@ -54,35 +55,38 @@ public abstract class AbstractRunTests { this.dumpActualFilesHere = findPlaceToDumpActualFiles(); } - public boolean compareFile(DirectoryRunner.TestParams params, File file) throws Throwable { + public final FileTester createTester(final DirectoryRunner.TestParams params, final File file) throws IOException { ConfigurationKeysLoader.LoaderLoader.loadAllConfigurationKeys(); final LombokTestSource sourceDirectives = LombokTestSource.readDirectives(file); - if (sourceDirectives.isIgnore()) return false; - if (!sourceDirectives.versionWithinLimit(params.getVersion())) return false; - if (!sourceDirectives.versionWithinLimit(getClasspathVersion())) return false; + if (sourceDirectives.isIgnore()) return null; + if (!sourceDirectives.versionWithinLimit(params.getVersion())) return null; + if (!sourceDirectives.versionWithinLimit(getClasspathVersion())) return null; String fileName = file.getName(); - LombokTestSource expected = LombokTestSource.read(params.getAfterDirectory(), params.getMessagesDirectory(), fileName); + final LombokTestSource expected = LombokTestSource.read(params.getAfterDirectory(), params.getMessagesDirectory(), fileName); - if (expected.isIgnore()) return false; - if (!expected.versionWithinLimit(params.getVersion())) return false; + if (expected.isIgnore()) return null; + if (!expected.versionWithinLimit(params.getVersion())) return null; - LinkedHashSet<CompilerMessage> messages = new LinkedHashSet<CompilerMessage>(); - StringWriter writer = new StringWriter(); - - LombokConfiguration.overrideConfigurationResolverFactory(new ConfigurationResolverFactory() { - @Override public ConfigurationResolver createResolver(AST<?, ?, ?> ast) { - return sourceDirectives.getConfiguration(); + return new FileTester() { + @Override public void runTest() throws Throwable { + LinkedHashSet<CompilerMessage> messages = new LinkedHashSet<CompilerMessage>(); + StringWriter writer = new StringWriter(); + + LombokConfiguration.overrideConfigurationResolverFactory(new ConfigurationResolverFactory() { + @Override public ConfigurationResolver createResolver(AST<?, ?, ?> ast) { + return sourceDirectives.getConfiguration(); + } + }); + + boolean changed = transformCode(messages, writer, file, sourceDirectives.getSpecifiedEncoding(), sourceDirectives.getFormatPreferences()); + boolean forceUnchanged = sourceDirectives.forceUnchanged() || sourceDirectives.isSkipCompareContent(); + if (params.expectChanges() && !forceUnchanged && !changed) messages.add(new CompilerMessage(-1, -1, true, "not flagged modified")); + if (!params.expectChanges() && changed) messages.add(new CompilerMessage(-1, -1, true, "unexpected modification")); + + compare(file.getName(), expected, writer.toString(), messages, params.printErrors(), sourceDirectives.isSkipCompareContent() || expected.isSkipCompareContent()); } - }); - - boolean changed = transformCode(messages, writer, file, sourceDirectives.getSpecifiedEncoding(), sourceDirectives.getFormatPreferences()); - boolean forceUnchanged = sourceDirectives.forceUnchanged() || sourceDirectives.isSkipCompareContent(); - if (params.expectChanges() && !forceUnchanged && !changed) messages.add(new CompilerMessage(-1, -1, true, "not flagged modified")); - if (!params.expectChanges() && changed) messages.add(new CompilerMessage(-1, -1, true, "unexpected modification")); - - compare(file.getName(), expected, writer.toString(), messages, params.printErrors(), sourceDirectives.isSkipCompareContent() || expected.isSkipCompareContent()); - return true; + }; } private static int getClasspathVersion() { diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java index c1758c57..d4275b09 100644 --- a/test/core/src/lombok/DirectoryRunner.java +++ b/test/core/src/lombok/DirectoryRunner.java @@ -23,6 +23,7 @@ package lombok; import java.io.File; import java.io.FileFilter; +import java.io.IOException; import java.util.Map; import java.util.TreeMap; @@ -116,19 +117,29 @@ public class DirectoryRunner extends Runner { @Override public void run(RunNotifier notifier) { if (failure != null) { - notifier.fireTestStarted(description); - notifier.fireTestFailure(new Failure(description, failure)); - notifier.fireTestFinished(description); + reportInitializationFailure(notifier, description, failure); return; } for (Map.Entry<String, Description> entry : tests.entrySet()) { Description testDescription = entry.getValue(); + + FileTester tester; + try { + tester = createTester(entry.getKey()); + } catch (IOException e) { + reportInitializationFailure(notifier, testDescription, e); + continue; + } + + if (tester == null) { + notifier.fireTestIgnored(testDescription); + continue; + } + notifier.fireTestStarted(testDescription); try { - if (!runTest(entry.getKey())) { - notifier.fireTestIgnored(testDescription); - } + tester.runTest(); } catch (Throwable t) { notifier.fireTestFailure(new Failure(testDescription, t)); } @@ -136,17 +147,27 @@ public class DirectoryRunner extends Runner { } } - private boolean runTest(String fileName) throws Throwable { + private void reportInitializationFailure(RunNotifier notifier, Description description, Throwable throwable) { + notifier.fireTestStarted(description); + notifier.fireTestFailure(new Failure(description, throwable)); + notifier.fireTestFinished(description); + } + + private FileTester createTester(String fileName) throws IOException { File file = new File(params.getBeforeDirectory(), fileName); switch (params.getCompiler()) { case DELOMBOK: - return new RunTestsViaDelombok().compareFile(params, file); + return new RunTestsViaDelombok().createTester(params, file); case ECJ: - return new RunTestsViaEcj().compareFile(params, file); + return new RunTestsViaEcj().createTester(params, file); default: case JAVAC: throw new UnsupportedOperationException(); } } + + public interface FileTester { + void runTest() throws Throwable; + } } |