diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2014-01-19 03:54:46 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2014-01-19 03:54:46 +0100 |
commit | d6ca8d5e81881c69f8f52c33375b07cef24f7d85 (patch) | |
tree | d13c602d91087d7f467b786eb6d0a8f5c08b50ef /test/core/src/lombok | |
parent | deb694033a026b807289d3ad6392a8be9b1cc5c9 (diff) | |
download | lombok-d6ca8d5e81881c69f8f52c33375b07cef24f7d85.tar.gz lombok-d6ca8d5e81881c69f8f52c33375b07cef24f7d85.tar.bz2 lombok-d6ca8d5e81881c69f8f52c33375b07cef24f7d85.zip |
[configuration] added facilities to override conf file resolution for test cases, and added first tests to test implementations of configuration-based stuff (FlagUsages, specifically). Error reporter has been refactored.
Diffstat (limited to 'test/core/src/lombok')
-rw-r--r-- | test/core/src/lombok/AbstractRunTests.java | 17 | ||||
-rw-r--r-- | test/core/src/lombok/LombokTestSource.java | 23 | ||||
-rw-r--r-- | test/core/src/lombok/RunTestsViaDelombok.java | 5 | ||||
-rw-r--r-- | test/core/src/lombok/RunTestsViaEcj.java | 3 |
4 files changed, 33 insertions, 15 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java index 64956c7f..db515f0e 100644 --- a/test/core/src/lombok/AbstractRunTests.java +++ b/test/core/src/lombok/AbstractRunTests.java @@ -36,7 +36,11 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; +import lombok.core.AST; +import lombok.core.LombokConfiguration; import lombok.core.LombokImmutableList; +import lombok.core.configuration.ConfigurationResolver; +import lombok.core.configuration.ConfigurationResolverFactory; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; public abstract class AbstractRunTests { @@ -47,7 +51,7 @@ public abstract class AbstractRunTests { } public boolean compareFile(DirectoryRunner.TestParams params, File file) throws Throwable { - LombokTestSource sourceDirectives = LombokTestSource.readDirectives(file); + final LombokTestSource sourceDirectives = LombokTestSource.readDirectives(file); if (sourceDirectives.isIgnore()) return false; String fileName = file.getName(); @@ -57,13 +61,20 @@ public abstract class AbstractRunTests { LinkedHashSet<CompilerMessage> messages = new LinkedHashSet<CompilerMessage>(); StringWriter writer = new StringWriter(); - transformCode(messages, writer, file, sourceDirectives.getConfLines()); + + LombokConfiguration.overrideConfigurationResolverFactory(new ConfigurationResolverFactory() { + @Override public ConfigurationResolver createResolver(AST<?, ?, ?> ast) { + return sourceDirectives.getConfiguration(); + } + }); + + transformCode(messages, writer, file); compare(file.getName(), expected, writer.toString(), messages, params.printErrors()); return true; } - protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, LombokImmutableList<String> confLines) throws Throwable; + protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file) throws Throwable; protected String readFile(File file) throws IOException { BufferedReader reader; diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java index 1ad92109..0cd09707 100644 --- a/test/core/src/lombok/LombokTestSource.java +++ b/test/core/src/lombok/LombokTestSource.java @@ -28,6 +28,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -35,6 +36,10 @@ import java.util.regex.Pattern; import org.junit.Assert; import lombok.core.LombokImmutableList; +import lombok.core.configuration.BubblingConfigurationResolver; +import lombok.core.configuration.ConfigurationProblemReporter; +import lombok.core.configuration.ConfigurationResolver; +import lombok.core.configuration.StringConfigurationSource; public class LombokTestSource { private final File file; @@ -42,7 +47,7 @@ public class LombokTestSource { private final LombokImmutableList<CompilerMessageMatcher> messages; private final boolean ignore; private final int versionLowerLimit, versionUpperLimit; - private final LombokImmutableList<String> confLines; + private final ConfigurationResolver configuration; public boolean versionWithinLimit(int version) { return version >= versionLowerLimit && version <= versionUpperLimit; @@ -64,8 +69,8 @@ public class LombokTestSource { return ignore; } - public LombokImmutableList<String> getConfLines() { - return confLines; + public ConfigurationResolver getConfiguration() { + return configuration; } private static final Pattern VERSION_STYLE_1 = Pattern.compile("^(\\d+)$"); @@ -106,7 +111,7 @@ public class LombokTestSource { this.content = content; this.messages = messages == null ? LombokImmutableList.<CompilerMessageMatcher>of() : LombokImmutableList.copyOf(messages); - List<String> conf = new ArrayList<String>(); + StringBuilder conf = new StringBuilder(); int versionLower = 0; int versionUpper = Integer.MAX_VALUE; boolean ignore = false; @@ -132,7 +137,7 @@ public class LombokTestSource { if (lc.startsWith("conf:")) { String confLine = directive.substring(5).trim(); - conf.add(confLine); + conf.append(confLine).append("\n"); continue; } @@ -143,7 +148,13 @@ public class LombokTestSource { this.versionLowerLimit = versionLower; this.versionUpperLimit = versionUpper; this.ignore = ignore; - this.confLines = LombokImmutableList.copyOf(conf); + ConfigurationProblemReporter reporter = new ConfigurationProblemReporter() { + @Override public void report(String sourceDescription, String problem, int lineNumber, CharSequence line) { + Assert.fail("Problem on directive line: " + problem + " at conf line #" + lineNumber + " (" + line + ")"); + } + }; + + this.configuration = new BubblingConfigurationResolver(Collections.singleton(StringConfigurationSource.forString(conf, reporter, file.getAbsolutePath()))); } public static LombokTestSource readDirectives(File file) throws IOException { diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index f19ad15d..6a08642b 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -26,7 +26,6 @@ import java.io.StringWriter; import java.util.Collection; import java.util.Locale; -import lombok.core.LombokImmutableList; import lombok.delombok.Delombok; import lombok.javac.CapturingDiagnosticListener; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; @@ -35,15 +34,13 @@ public class RunTestsViaDelombok extends AbstractRunTests { private Delombok delombok = new Delombok(); @Override - public void transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, LombokImmutableList<String> confLines) throws Throwable { + public void transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file) throws Throwable { delombok.setVerbose(false); delombok.setForceProcess(true); delombok.setCharset("UTF-8"); delombok.setDiagnosticsListener(new CapturingDiagnosticListener(file, messages)); - // TODO: Create a configuration based on confLines and set this up so that this compile run will use them. - delombok.addFile(file.getAbsoluteFile().getParentFile(), file.getName()); delombok.setSourcepath(file.getAbsoluteFile().getParent()); String bcp = System.getProperty("delombok.bootclasspath"); diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 36f9be49..695ff0a9 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -33,7 +33,6 @@ import java.util.Locale; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import lombok.core.LombokImmutableList; import lombok.eclipse.Eclipse; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; @@ -88,7 +87,7 @@ public class RunTestsViaEcj extends AbstractRunTests { } @Override - public void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, LombokImmutableList<String> confLines) throws Throwable { + public void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file) throws Throwable { final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>(); final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>(); ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() { |