From e5705f94cd3778a2e0d25060f1e013d0c33bfb90 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 30 Jan 2015 18:17:00 +0100 Subject: * Added config key ‘lombok.addGeneratedAnnotation’. * Added ‘format’ directive for tests. * Updates tests to salt in some more format and config keys. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/core/src/lombok/AbstractRunTests.java | 5 +++-- test/core/src/lombok/LombokTestSource.java | 19 +++++++++++++++++++ test/core/src/lombok/RunTestsViaDelombok.java | 4 +++- test/core/src/lombok/RunTestsViaEcj.java | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) (limited to 'test/core/src/lombok') 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 messages, StringWriter result, File file, String encoding) throws Throwable; + protected abstract void transformCode(Collection messages, StringWriter result, File file, String encoding, Map 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 messages; + private final Map 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 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 formats = new HashMap(); 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 messages, StringWriter result, final File file, String encoding) throws Throwable { + public void transformCode(Collection messages, StringWriter result, final File file, String encoding, Map 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 messages, StringWriter result, File file, String encoding) throws Throwable { + public void transformCode(Collection messages, StringWriter result, File file, String encoding, Map formatPreferences) throws Throwable { final AtomicReference compilationResult_ = new AtomicReference(); final AtomicReference compilationUnit_ = new AtomicReference(); ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() { -- cgit