diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-01-30 18:17:00 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-01-30 18:17:00 +0100 |
commit | e5705f94cd3778a2e0d25060f1e013d0c33bfb90 (patch) | |
tree | 679dac4dce518d253c34f125a573b66aaf167f43 /test/core/src/lombok | |
parent | 26b2fb5cd6d4d73b270be3787fa876cc1bfe80f2 (diff) | |
download | lombok-e5705f94cd3778a2e0d25060f1e013d0c33bfb90.tar.gz lombok-e5705f94cd3778a2e0d25060f1e013d0c33bfb90.tar.bz2 lombok-e5705f94cd3778a2e0d25060f1e013d0c33bfb90.zip |
* Added config key ‘lombok.addGeneratedAnnotation’.
* Added ‘format’ directive for tests.
* Updates tests to salt in some more format and config keys.
Diffstat (limited to 'test/core/src/lombok')
-rw-r--r-- | test/core/src/lombok/AbstractRunTests.java | 5 | ||||
-rw-r--r-- | test/core/src/lombok/LombokTestSource.java | 19 | ||||
-rw-r--r-- | test/core/src/lombok/RunTestsViaDelombok.java | 4 | ||||
-rw-r--r-- | test/core/src/lombok/RunTestsViaEcj.java | 2 |
4 files changed, 26 insertions, 4 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java index 85d4d4f3..4e1c83dd 100644 --- a/test/core/src/lombok/AbstractRunTests.java +++ b/test/core/src/lombok/AbstractRunTests.java @@ -35,6 +35,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import org.junit.Assert; @@ -75,7 +76,7 @@ public abstract class AbstractRunTests { } }); - transformCode(messages, writer, file, sourceDirectives.getSpecifiedEncoding()); + transformCode(messages, writer, file, sourceDirectives.getSpecifiedEncoding(), sourceDirectives.getFormatPreferences()); compare(file.getName(), expected, writer.toString(), messages, params.printErrors(), sourceDirectives.isSkipCompareContent() || expected.isSkipCompareContent()); return true; @@ -97,7 +98,7 @@ public abstract class AbstractRunTests { return 8; } - protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding) throws Throwable; + protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences) 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 f31d7be7..9b5607ef 100644 --- a/test/core/src/lombok/LombokTestSource.java +++ b/test/core/src/lombok/LombokTestSource.java @@ -29,7 +29,9 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -45,6 +47,7 @@ public class LombokTestSource { private final File file; private final String content; private final LombokImmutableList<CompilerMessageMatcher> messages; + private final Map<String, String> formatPreferences; private final boolean ignore; private final boolean skipCompareContent; private final int versionLowerLimit, versionUpperLimit; @@ -83,6 +86,10 @@ public class LombokTestSource { return configuration; } + public Map<String, String> getFormatPreferences() { + return formatPreferences; + } + private static final Pattern VERSION_STYLE_1 = Pattern.compile("^(\\d+)$"); private static final Pattern VERSION_STYLE_2 = Pattern.compile("^\\:(\\d+)$"); private static final Pattern VERSION_STYLE_3 = Pattern.compile("^(\\d+):$"); @@ -129,6 +136,7 @@ public class LombokTestSource { boolean ignore = false; boolean skipCompareContent = false; String encoding = null; + Map<String, String> formats = new HashMap<String, String>(); for (String directive : directives) { directive = directive.trim(); @@ -165,6 +173,16 @@ public class LombokTestSource { continue; } + if (lc.startsWith("format:")) { + String formatLine = directive.substring(7).trim(); + int idx = formatLine.indexOf('='); + if (idx == -1) throw new IllegalArgumentException("To add a format directive, use: \"//FORMAT: javaLangAsFQN = skip\""); + String key = formatLine.substring(0, idx).trim(); + String value = formatLine.substring(idx + 1).trim(); + formats.put(key.toLowerCase(), value); + continue; + } + Assert.fail("Directive line \"" + directive + "\" in '" + file.getAbsolutePath() + "' invalid: unrecognized directive."); throw new RuntimeException(); } @@ -180,6 +198,7 @@ public class LombokTestSource { }; this.configuration = new BubblingConfigurationResolver(Collections.singleton(StringConfigurationSource.forString(conf, reporter, file.getAbsolutePath()))); + this.formatPreferences = Collections.unmodifiableMap(formats); } 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 1482c865..8ec41ef1 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -25,6 +25,7 @@ import java.io.File; import java.io.StringWriter; import java.util.Collection; import java.util.Locale; +import java.util.Map; import lombok.delombok.Delombok; import lombok.javac.CapturingDiagnosticListener; @@ -34,10 +35,11 @@ public class RunTestsViaDelombok extends AbstractRunTests { private Delombok delombok = new Delombok(); @Override - public void transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding) throws Throwable { + public void transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding, Map<String, String> formatPreferences) throws Throwable { delombok.setVerbose(false); delombok.setForceProcess(true); delombok.setCharset(encoding == null ? "UTF-8" : encoding); + delombok.setFormatPreferences(formatPreferences); delombok.setDiagnosticsListener(new CapturingDiagnosticListener(file, messages)); diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 74fe6e92..1571f401 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -93,7 +93,7 @@ public class RunTestsViaEcj extends AbstractRunTests { } @Override - public void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding) throws Throwable { + public void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences) throws Throwable { final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>(); final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>(); ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() { |