diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2014-05-06 18:43:24 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2014-05-06 18:43:24 +0200 |
commit | e53d93b7cec7f080d401c5d85e4f98b6655de555 (patch) | |
tree | 41379580abd72f88a372adcc1481042700ba690a /test | |
parent | 7079271802176caea4404fc7c80b4656346a2402 (diff) | |
download | lombok-e53d93b7cec7f080d401c5d85e4f98b6655de555.tar.gz lombok-e53d93b7cec7f080d401c5d85e4f98b6655de555.tar.bz2 lombok-e53d93b7cec7f080d401c5d85e4f98b6655de555.zip |
added support for different error messages, where either one will mean the tests pass (new versions of javac, ecj, etc sometimes totally change the message).
Diffstat (limited to 'test')
3 files changed, 40 insertions, 22 deletions
diff --git a/test/core/src/lombok/CompilerMessageMatcher.java b/test/core/src/lombok/CompilerMessageMatcher.java index db288749..cffad88a 100644 --- a/test/core/src/lombok/CompilerMessageMatcher.java +++ b/test/core/src/lombok/CompilerMessageMatcher.java @@ -27,7 +27,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -36,32 +35,41 @@ import lombok.javac.CapturingDiagnosticListener.CompilerMessage; public class CompilerMessageMatcher { /** Line Number (starting at 1) */ - private final long line; + private final List<Integer> lineNumbers = new ArrayList<Integer>(); + private final List<List<String>> messages = new ArrayList<List<String>>(); - private final Collection<String> messageParts; - - public CompilerMessageMatcher(long line, String message) { - this.line = line; - this.messageParts = Arrays.asList(message.split("\\s+")); - } + private CompilerMessageMatcher() {} public static CompilerMessageMatcher asCompilerMessageMatcher(CompilerMessage message) { - return new CompilerMessageMatcher(message.getLine(), message.getMessage()); + CompilerMessageMatcher cmm = new CompilerMessageMatcher(); + cmm.lineNumbers.add((int) message.getLine()); + cmm.messages.add(Arrays.asList(message.getMessage().split("\\s+"))); + return cmm; } @Override public String toString() { - StringBuilder parts = new StringBuilder(); - for (String part : messageParts) parts.append(part).append(" "); - if (parts.length() > 0) parts.setLength(parts.length() - 1); - return String.format("%d %s", line, parts); + StringBuilder out = new StringBuilder(); + for (int i = 0; i < lineNumbers.size(); i++) { + out.append(lineNumbers.get(i)); + for (String part : messages.get(i)) out.append(part).append(" "); + if (out.length() > 0) out.setLength(out.length() - 1); + out.append(" |||| "); + } + if (out.length() > 0) out.setLength(out.length() - 6); + return out.toString(); } public boolean matches(CompilerMessage message) { - if (message.getLine() != this.line) return false; - for (String token : messageParts) { - if (!message.getMessage().contains(token)) return false; + outer: + for (int i = 0; i < lineNumbers.size(); i++) { + if (message.getLine() != lineNumbers.get(i)) continue; + for (String token : messages.get(i)) { + if (!message.getMessage().contains(token)) continue outer; + } + return true; } - return true; + + return false; } public static List<CompilerMessageMatcher> readAll(InputStream rawIn) throws IOException { @@ -75,11 +83,21 @@ public class CompilerMessageMatcher { } private static final Pattern PATTERN = Pattern.compile("^(\\d+) (.*)$"); + private static CompilerMessageMatcher read(String line) { line = line.trim(); if (line.isEmpty()) return null; - Matcher m = PATTERN.matcher(line); - if (!m.matches()) throw new IllegalArgumentException("Typo in test file: " + line); - return new CompilerMessageMatcher(Integer.parseInt(m.group(1)), m.group(2)); + + String[] parts = line.split("\\s*\\|\\|\\|\\|\\s*"); + + CompilerMessageMatcher cmm = new CompilerMessageMatcher(); + for (String part : parts) { + Matcher m = PATTERN.matcher(part); + if (!m.matches()) throw new IllegalArgumentException("Typo in test file: " + line); + cmm.lineNumbers.add(Integer.parseInt(m.group(1))); + cmm.messages.add(Arrays.asList(m.group(2).split("\\s+"))); + } + + return cmm; } } diff --git a/test/transform/resource/messages-delombok/LoggerSlf4jOnNonType.java.messages b/test/transform/resource/messages-delombok/LoggerSlf4jOnNonType.java.messages index 262fbb27..ca4d607f 100644 --- a/test/transform/resource/messages-delombok/LoggerSlf4jOnNonType.java.messages +++ b/test/transform/resource/messages-delombok/LoggerSlf4jOnNonType.java.messages @@ -1 +1 @@ -2 @Log is legal only on types.
\ No newline at end of file +3 @Log is legal only on types. |||| 3 annotation type not applicable to this kind of declaration
\ No newline at end of file diff --git a/test/transform/resource/messages-ecj/LoggerSlf4jOnNonType.java.messages b/test/transform/resource/messages-ecj/LoggerSlf4jOnNonType.java.messages index 81e9b718..3ef2aeb9 100644 --- a/test/transform/resource/messages-ecj/LoggerSlf4jOnNonType.java.messages +++ b/test/transform/resource/messages-ecj/LoggerSlf4jOnNonType.java.messages @@ -1 +1 @@ -2 The annotation @Slf4j is disallowed for this location +3 The annotation @Slf4j is disallowed for this location |