[test] Missing after-X files used to be an implicit 'just ignore the content' signal; now you need an explicit directive to allow this behaviour.

[configuration] added tests for @Accessors configuration key implementations.
This commit is contained in:
Reinier Zwitserloot committed 2014-01-20 01:46:01 +01:00
1 parent e5dc6203c8
commit d1899a81e9
11 files changed
+113 -14

No files matched your search

+11 -5
View File
@@ -36,9 +36,12 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import org.junit.Assert;
import lombok.core.AST;
import lombok.core.LombokConfiguration;
import lombok.core.LombokImmutableList;
import lombok.core.configuration.ConfigurationKeysLoader;
import lombok.core.configuration.ConfigurationResolver;
import lombok.core.configuration.ConfigurationResolverFactory;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
@@ -51,8 +54,9 @@ public abstract class AbstractRunTests {
}
public boolean compareFile(DirectoryRunner.TestParams params, File file) throws Throwable {
ConfigurationKeysLoader.LoaderLoader.loadAllConfigurationKeys();
final LombokTestSource sourceDirectives = LombokTestSource.readDirectives(file);
if (sourceDirectives.isIgnore()) return false;
if (sourceDirectives.isIgnore() || !sourceDirectives.versionWithinLimit(params.getVersion())) return false;
String fileName = file.getName();
LombokTestSource expected = LombokTestSource.read(params.getAfterDirectory(), params.getMessagesDirectory(), fileName);
@@ -70,7 +74,7 @@ public abstract class AbstractRunTests {
transformCode(messages, writer, file);
compare(file.getName(), expected, writer.toString(), messages, params.printErrors());
compare(file.getName(), expected, writer.toString(), messages, params.printErrors(), sourceDirectives.isSkipCompareContent() || expected.isSkipCompareContent());
return true;
}
@@ -124,8 +128,8 @@ public abstract class AbstractRunTests {
}
}
private void compare(String name, LombokTestSource expected, String actualFile, LinkedHashSet<CompilerMessage> actualMessages, boolean printErrors) throws Throwable {
if (expected.getContent() != null) try {
private void compare(String name, LombokTestSource expected, String actualFile, LinkedHashSet<CompilerMessage> actualMessages, boolean printErrors, boolean skipCompareContent) throws Throwable {
if (!skipCompareContent) try {
compareContent(name, expected.getContent(), actualFile);
} catch (Throwable e) {
if (printErrors) {
@@ -209,7 +213,9 @@ public abstract class AbstractRunTests {
actualLines = removeBlanks(actualLines);
int size = Math.min(expectedLines.length, actualLines.length);
if (size == 0) return;
if (size == 0 && expectedLines.length + actualLines.length > 0) {
Assert.fail("Missing / empty expected file.");
}
for (int i = 0; i < size; i++) {
String expected = expectedLines[i];
+15 -1
View File
@@ -46,6 +46,7 @@ public class LombokTestSource {
private final String content;
private final LombokImmutableList<CompilerMessageMatcher> messages;
private final boolean ignore;
private final boolean skipCompareContent;
private final int versionLowerLimit, versionUpperLimit;
private final ConfigurationResolver configuration;
@@ -69,6 +70,10 @@ public class LombokTestSource {
return ignore;
}
public boolean isSkipCompareContent() {
return skipCompareContent;
}
public ConfigurationResolver getConfiguration() {
return configuration;
}
@@ -105,7 +110,9 @@ public class LombokTestSource {
return null;
}
private static final Pattern IGNORE_PATTERN = Pattern.compile("^\\s*ignore\\s*(?:[:-].*)?$", Pattern.CASE_INSENSITIVE);
private static final Pattern IGNORE_PATTERN = Pattern.compile("^\\s*ignore\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE);
private static final Pattern SKIP_COMPARE_CONTENT_PATTERN = Pattern.compile("^\\s*skip[- ]?compare[- ]?content\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE);
private LombokTestSource(File file, String content, List<CompilerMessageMatcher> messages, List<String> directives) {
this.file = file;
this.content = content;
@@ -115,6 +122,7 @@ public class LombokTestSource {
int versionLower = 0;
int versionUpper = Integer.MAX_VALUE;
boolean ignore = false;
boolean skipCompareContent = false;
for (String directive : directives) {
directive = directive.trim();
@@ -124,6 +132,11 @@ public class LombokTestSource {
continue;
}
if (SKIP_COMPARE_CONTENT_PATTERN.matcher(directive).matches()) {
skipCompareContent = true;
continue;
}
if (lc.startsWith("version ")) {
int[] limits = parseVersionLimit(lc.substring(7).trim());
if (limits == null) {
@@ -148,6 +161,7 @@ public class LombokTestSource {
this.versionLowerLimit = versionLower;
this.versionUpperLimit = versionUpper;
this.ignore = ignore;
this.skipCompareContent = skipCompareContent;
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 + ")");
@@ -0,0 +1,26 @@
class AccessorsConfiguration {
private String m_FieldName = "";
@java.lang.SuppressWarnings("all")
public String fieldName() {
return this.m_FieldName;
}
@java.lang.SuppressWarnings("all")
public void fieldName(final String m_FieldName) {
this.m_FieldName = m_FieldName;
}
}
class AccessorsConfiguration2 {
private String m_FieldName = "";
@java.lang.SuppressWarnings("all")
public void setM_FieldName(final String m_FieldName) {
this.m_FieldName = m_FieldName;
}
}
class AccessorsConfiguration3 {
private String fFieldName = "";
@java.lang.SuppressWarnings("all")
public AccessorsConfiguration3 setFieldName(final String fFieldName) {
this.fFieldName = fFieldName;
return this;
}
}
@@ -0,0 +1,31 @@
class AccessorsConfiguration {
private @lombok.Getter @lombok.Setter @lombok.experimental.Accessors(fluent = true) String m_FieldName = "";
AccessorsConfiguration() {
super();
}
public @java.lang.SuppressWarnings("all") String fieldName() {
return this.m_FieldName;
}
public @java.lang.SuppressWarnings("all") void fieldName(final String m_FieldName) {
this.m_FieldName = m_FieldName;
}
}
@lombok.experimental.Accessors(prefix = {}) class AccessorsConfiguration2 {
private @lombok.Setter String m_FieldName = "";
AccessorsConfiguration2() {
super();
}
public @java.lang.SuppressWarnings("all") void setM_FieldName(final String m_FieldName) {
this.m_FieldName = m_FieldName;
}
}
@lombok.experimental.Accessors(chain = true) class AccessorsConfiguration3 {
private @lombok.Setter String fFieldName = "";
AccessorsConfiguration3() {
super();
}
public @java.lang.SuppressWarnings("all") AccessorsConfiguration3 setFieldName(final String fFieldName) {
this.fFieldName = fFieldName;
return this;
}
}
@@ -0,0 +1,20 @@
//CONF: lombok.Accessors.prefix += m_
//CONF: lombok.Accessors.prefix += f
//CONF: lombok.Accessors.chain = false
class AccessorsConfiguration {
@lombok.Getter @lombok.Setter @lombok.experimental.Accessors(fluent=true)
private String m_FieldName = "";
}
@lombok.experimental.Accessors(prefix = {})
class AccessorsConfiguration2 {
@lombok.Setter
private String m_FieldName = "";
}
@lombok.experimental.Accessors(chain = true)
class AccessorsConfiguration3 {
@lombok.Setter
private String fFieldName = "";
}
@@ -1,3 +1,4 @@
//skip compare content
@lombok.experimental.Builder
class BuilderInvalidUse {
private int something;
@@ -1,3 +1,4 @@
//skip compare content
//CONF: lombok.Getter.flagUsage = WARNING
//CONF: lombok.experimental.flagUsage = ERROR
public class FlagUsages {
@@ -1,2 +1,2 @@
1 @Getter, @Setter, @Wither, @Data, @ToString, @EqualsAndHashCode, @AllArgsConstructor are not allowed on builder classes.
12 @Value is not allowed on builder classes.
2 @Getter, @Setter, @Wither, @Data, @ToString, @EqualsAndHashCode, @AllArgsConstructor are not allowed on builder classes.
13 @Value is not allowed on builder classes.
@@ -1,2 +1,2 @@
4 Use of @Getter is flagged according to lombok configuration.
6 Use of any lombok.experimental feature is flagged according to lombok configuration.
5 Use of @Getter is flagged according to lombok configuration.
7 Use of any lombok.experimental feature is flagged according to lombok configuration.
@@ -1,2 +1,2 @@
1 @Getter, @Setter, @FieldDefaults, @Wither, @Data, @ToString, @EqualsAndHashCode, @AllArgsConstructor are not allowed on builder classes.
12 @Value is not allowed on builder classes.
2 @Getter, @Setter, @FieldDefaults, @Wither, @Data, @ToString, @EqualsAndHashCode, @AllArgsConstructor are not allowed on builder classes.
13 @Value is not allowed on builder classes.
@@ -1,2 +1,2 @@
4 Use of @Getter is flagged according to lombok configuration.
6 Use of any lombok.experimental feature is flagged according to lombok configuration.
5 Use of @Getter is flagged according to lombok configuration.
7 Use of any lombok.experimental feature is flagged according to lombok configuration.