aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/core/src/lombok/AbstractRunTests.java38
-rw-r--r--test/core/src/lombok/CompilerMessageMatcher.java14
-rw-r--r--test/transform/resource/after-delombok/MixGetterVal.java2
-rw-r--r--test/transform/resource/after-delombok/ValInTryWithResources.java1
-rw-r--r--test/transform/resource/after-ecj/MixGetterVal.java2
-rw-r--r--test/transform/resource/before/MixGetterVal.java2
-rw-r--r--test/transform/resource/messages-idempotent/ValErrors.java.messages2
7 files changed, 53 insertions, 8 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java
index 34f6cbf4..2a04d21a 100644
--- a/test/core/src/lombok/AbstractRunTests.java
+++ b/test/core/src/lombok/AbstractRunTests.java
@@ -56,12 +56,15 @@ 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() || !sourceDirectives.versionWithinLimit(params.getVersion())) return false;
+ if (sourceDirectives.isIgnore()) return false;
+ if (!sourceDirectives.versionWithinLimit(params.getVersion())) return false;
+ if (!sourceDirectives.versionWithinLimit(getClasspathVersion())) return false;
String fileName = file.getName();
LombokTestSource expected = LombokTestSource.read(params.getAfterDirectory(), params.getMessagesDirectory(), fileName);
- if (expected.isIgnore() || !expected.versionWithinLimit(params.getVersion())) return false;
+ if (expected.isIgnore()) return false;
+ if (!expected.versionWithinLimit(params.getVersion())) return false;
LinkedHashSet<CompilerMessage> messages = new LinkedHashSet<CompilerMessage>();
StringWriter writer = new StringWriter();
@@ -78,6 +81,22 @@ public abstract class AbstractRunTests {
return true;
}
+ private static int getClasspathVersion() {
+ try {
+ Class.forName("java.lang.AutoCloseable");
+ } catch (ClassNotFoundException e) {
+ return 6;
+ }
+
+ try {
+ Class.forName("java.util.stream.Stream");
+ } catch (ClassNotFoundException e) {
+ return 7;
+ }
+
+ return 8;
+ }
+
protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file) throws Throwable;
protected String readFile(File file) throws IOException {
@@ -176,24 +195,31 @@ public abstract class AbstractRunTests {
}
}
+ @SuppressWarnings("null") /* eclipse bug; it falsely thinks stuffAc will always be null or some such hogwash. */
private static void compareMessages(String name, LombokImmutableList<CompilerMessageMatcher> expected, LinkedHashSet<CompilerMessage> actual) {
Iterator<CompilerMessageMatcher> expectedIterator = expected.iterator();
Iterator<CompilerMessage> actualIterator = actual.iterator();
+ CompilerMessage stuffAc = null;
while (true) {
boolean exHasNext = expectedIterator.hasNext();
- boolean acHasNext = actualIterator.hasNext();
+ boolean acHasNext = stuffAc != null || actualIterator.hasNext();
if (!exHasNext && !acHasNext) break;
if (exHasNext && acHasNext) {
CompilerMessageMatcher cmm = expectedIterator.next();
- CompilerMessage cm = actualIterator.next();
+ CompilerMessage cm = stuffAc == null ? actualIterator.next() : stuffAc;
if (cmm.matches(cm)) continue;
+ if (cmm.isOptional()) stuffAc = cm;
fail(String.format("[%s] Expected message '%s' but got message '%s'", name, cmm, cm));
throw new AssertionError("fail should have aborted already.");
}
- if (exHasNext) fail(String.format("[%s] Expected message '%s' but ran out of actual messages", name, expectedIterator.next()));
+
+ while (expectedIterator.hasNext()) {
+ if (expectedIterator.next().isOptional()) continue;
+ fail(String.format("[%s] Expected message '%s' but ran out of actual messages", name, expectedIterator.next()));
+ }
if (acHasNext) fail(String.format("[%s] Unexpected message: %s", name, actualIterator.next()));
- throw new AssertionError("fail should have aborted already.");
+ break;
}
}
diff --git a/test/core/src/lombok/CompilerMessageMatcher.java b/test/core/src/lombok/CompilerMessageMatcher.java
index cffad88a..0d6c0889 100644
--- a/test/core/src/lombok/CompilerMessageMatcher.java
+++ b/test/core/src/lombok/CompilerMessageMatcher.java
@@ -37,9 +37,14 @@ public class CompilerMessageMatcher {
/** Line Number (starting at 1) */
private final List<Integer> lineNumbers = new ArrayList<Integer>();
private final List<List<String>> messages = new ArrayList<List<String>>();
+ private boolean optional;
private CompilerMessageMatcher() {}
+ public boolean isOptional() {
+ return optional;
+ }
+
public static CompilerMessageMatcher asCompilerMessageMatcher(CompilerMessage message) {
CompilerMessageMatcher cmm = new CompilerMessageMatcher();
cmm.lineNumbers.add((int) message.getLine());
@@ -50,7 +55,7 @@ public class CompilerMessageMatcher {
@Override public String toString() {
StringBuilder out = new StringBuilder();
for (int i = 0; i < lineNumbers.size(); i++) {
- out.append(lineNumbers.get(i));
+ out.append(lineNumbers.get(i)).append(" ");
for (String part : messages.get(i)) out.append(part).append(" ");
if (out.length() > 0) out.setLength(out.length() - 1);
out.append(" |||| ");
@@ -87,10 +92,17 @@ public class CompilerMessageMatcher {
private static CompilerMessageMatcher read(String line) {
line = line.trim();
if (line.isEmpty()) return null;
+ boolean optional = false;
+
+ if (line.startsWith("OPTIONAL ")) {
+ line = line.substring(9);
+ optional = true;
+ }
String[] parts = line.split("\\s*\\|\\|\\|\\|\\s*");
CompilerMessageMatcher cmm = new CompilerMessageMatcher();
+ cmm.optional = optional;
for (String part : parts) {
Matcher m = PATTERN.matcher(part);
if (!m.matches()) throw new IllegalArgumentException("Typo in test file: " + line);
diff --git a/test/transform/resource/after-delombok/MixGetterVal.java b/test/transform/resource/after-delombok/MixGetterVal.java
index 7662608b..abc60d56 100644
--- a/test/transform/resource/after-delombok/MixGetterVal.java
+++ b/test/transform/resource/after-delombok/MixGetterVal.java
@@ -5,6 +5,8 @@ class MixGetterVal {
public void test() {
final int y = x;
m(y);
+ final int a = getX();
+ m(a);
}
@java.lang.SuppressWarnings("all")
public int getX() {
diff --git a/test/transform/resource/after-delombok/ValInTryWithResources.java b/test/transform/resource/after-delombok/ValInTryWithResources.java
index 42bd3193..e1041928 100644
--- a/test/transform/resource/after-delombok/ValInTryWithResources.java
+++ b/test/transform/resource/after-delombok/ValInTryWithResources.java
@@ -1,3 +1,4 @@
+//version 7:
import java.io.IOException;
public class ValInTryWithResources {
public void whyTryInsteadOfCleanup() throws IOException {
diff --git a/test/transform/resource/after-ecj/MixGetterVal.java b/test/transform/resource/after-ecj/MixGetterVal.java
index 45fcf989..d9809703 100644
--- a/test/transform/resource/after-ecj/MixGetterVal.java
+++ b/test/transform/resource/after-ecj/MixGetterVal.java
@@ -10,6 +10,8 @@ class MixGetterVal {
public void test() {
final @val int y = x;
m(y);
+ final @val int a = getX();
+ m(a);
}
public @java.lang.SuppressWarnings("all") int getX() {
return this.x;
diff --git a/test/transform/resource/before/MixGetterVal.java b/test/transform/resource/before/MixGetterVal.java
index f80d2927..3f06b1a8 100644
--- a/test/transform/resource/before/MixGetterVal.java
+++ b/test/transform/resource/before/MixGetterVal.java
@@ -8,5 +8,7 @@ class MixGetterVal {
public void test() {
val y = x;
m(y);
+ val a = getX();
+ m(a);
}
}
diff --git a/test/transform/resource/messages-idempotent/ValErrors.java.messages b/test/transform/resource/messages-idempotent/ValErrors.java.messages
index c2432c6a..f61d3a33 100644
--- a/test/transform/resource/messages-idempotent/ValErrors.java.messages
+++ b/test/transform/resource/messages-idempotent/ValErrors.java.messages
@@ -1,3 +1,3 @@
3 cannot find symbol
6 cannot find symbol
-6 illegal initializer for <none>
+OPTIONAL 6 illegal initializer for <none>