aboutsummaryrefslogtreecommitdiff
path: root/test/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/src')
-rw-r--r--test/core/src/lombok/AbstractRunTests.java18
-rw-r--r--test/core/src/lombok/CompilerMessage.java50
-rw-r--r--test/core/src/lombok/CompilerMessageMatcher.java33
-rw-r--r--test/core/src/lombok/DirectoryRunner.java19
-rw-r--r--test/core/src/lombok/RunTestsViaDelombok.java24
-rw-r--r--test/core/src/lombok/RunTestsViaEcj.java6
6 files changed, 64 insertions, 86 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java
index 229d321a..a3f52cdd 100644
--- a/test/core/src/lombok/AbstractRunTests.java
+++ b/test/core/src/lombok/AbstractRunTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2010 The Project Lombok Authors.
+ * Copyright (C) 2009-2013 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -40,6 +40,8 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
+import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
+
public abstract class AbstractRunTests {
protected static final String LINE_SEPARATOR = System.getProperty("line.separator");
private final File dumpActualFilesHere;
@@ -130,7 +132,7 @@ public abstract class AbstractRunTests {
FileOutputStream fos = new FileOutputStream(file);
try {
for (CompilerMessage message : content) {
- fos.write(message.asCompilerMessageMatcher().toString().getBytes("UTF-8"));
+ fos.write(CompilerMessageMatcher.asCompilerMessageMatcher(message).toString().getBytes("UTF-8"));
fos.write('\n');
}
} finally {
@@ -151,7 +153,9 @@ public abstract class AbstractRunTests {
System.out.println(actualFile);
if (actualMessages != null && !actualMessages.isEmpty()) {
System.out.println("**** Actual Errors *****");
- System.out.println(actualMessages);
+ for (CompilerMessage actualMessage : actualMessages) {
+ System.out.println(actualMessage);
+ }
}
System.out.println("*******************");
}
@@ -168,9 +172,13 @@ public abstract class AbstractRunTests {
System.out.println("***** " + name + " *****");
System.out.println(e.getMessage());
System.out.println("**** Expected ******");
- System.out.println(expectedMessages);
+ for (CompilerMessageMatcher expectedMessage : expectedMessages) {
+ System.out.println(expectedMessage);
+ }
System.out.println("**** Actual ******");
- System.out.println(actualMessages);
+ for (CompilerMessage actualMessage : actualMessages) {
+ System.out.println(actualMessage);
+ }
System.out.println("*******************");
}
if (dumpActualFilesHere != null) {
diff --git a/test/core/src/lombok/CompilerMessage.java b/test/core/src/lombok/CompilerMessage.java
deleted file mode 100644
index d04d17f1..00000000
--- a/test/core/src/lombok/CompilerMessage.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package lombok;
-
-public final class CompilerMessage {
- /** Line Number (starting at 1) */
- final long line;
-
- /** Position is either column number, OR position in file starting from the first byte. */
- final long position;
- final boolean isError;
- final String message;
-
- public CompilerMessage(long line, long position, boolean isError, String message) {
- this.line = line;
- this.position = position;
- this.isError = isError;
- this.message = message;
- }
-
- @Override public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + (isError ? 1231 : 1237);
- result = prime * result + (int) (line ^ (line >>> 32));
- result = prime * result + ((message == null) ? 0 : message.hashCode());
- result = prime * result + (int) (position ^ (position >>> 32));
- return result;
- }
-
- @Override public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null) return false;
- if (getClass() != obj.getClass()) return false;
- CompilerMessage other = (CompilerMessage) obj;
- if (isError != other.isError) return false;
- if (line != other.line) return false;
- if (message == null) {
- if (other.message != null) return false;
- } else if (!message.equals(other.message)) return false;
- if (position != other.position) return false;
- return true;
- }
-
- public CompilerMessageMatcher asCompilerMessageMatcher() {
- return new CompilerMessageMatcher(line, position, message);
- }
-
- @Override public String toString() {
- return String.format("%d:%d %s %s", line, position, isError ? "ERROR" : "WARNING", message);
- }
-}
diff --git a/test/core/src/lombok/CompilerMessageMatcher.java b/test/core/src/lombok/CompilerMessageMatcher.java
index b7902395..af12e199 100644
--- a/test/core/src/lombok/CompilerMessageMatcher.java
+++ b/test/core/src/lombok/CompilerMessageMatcher.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright (C) 2012-2013 The Project Lombok Authors.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
package lombok;
import java.io.BufferedReader;
@@ -11,6 +32,8 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
+
public class CompilerMessageMatcher {
/** Line Number (starting at 1) */
private final long line;
@@ -25,6 +48,10 @@ public class CompilerMessageMatcher {
this.messageParts = Arrays.asList(message.split("\\s+"));
}
+ public static CompilerMessageMatcher asCompilerMessageMatcher(CompilerMessage message) {
+ return new CompilerMessageMatcher(message.getLine(), message.getColumnOrPosition(), message.getMessage());
+ }
+
@Override public String toString() {
StringBuilder parts = new StringBuilder();
for (String part : messageParts) parts.append(part).append(" ");
@@ -33,10 +60,10 @@ public class CompilerMessageMatcher {
}
public boolean matches(CompilerMessage message) {
- if (message.line != this.line) return false;
- if (message.position != this.position) return false;
+ if (message.getLine() != this.line) return false;
+ if (message.getColumnOrPosition() != this.position) return false;
for (String token : messageParts) {
- if (!message.message.contains(token)) return false;
+ if (!message.getMessage().contains(token)) return false;
}
return true;
}
diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java
index c896d327..191a7b63 100644
--- a/test/core/src/lombok/DirectoryRunner.java
+++ b/test/core/src/lombok/DirectoryRunner.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2010 The Project Lombok Authors.
+ * Copyright (C) 2009-2013 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -40,12 +40,16 @@ public class DirectoryRunner extends Runner {
DELOMBOK, JAVAC, ECJ;
}
- public interface TestParams {
- Compiler getCompiler();
- boolean printErrors();
- File getBeforeDirectory();
- File getAfterDirectory();
- File getMessagesDirectory();
+ public static abstract class TestParams {
+ public abstract Compiler getCompiler();
+ public abstract boolean printErrors();
+ public abstract File getBeforeDirectory();
+ public abstract File getAfterDirectory();
+ public abstract File getMessagesDirectory();
+
+ public boolean accept(File file) {
+ return true;
+ }
}
private static final FileFilter JAVA_FILE_FILTER = new FileFilter() {
@@ -76,6 +80,7 @@ public class DirectoryRunner extends Runner {
private void addTests(Class<?> testClass) throws Exception {
for (File file : params.getBeforeDirectory().listFiles(JAVA_FILE_FILTER)) {
+ if (!params.accept(file)) continue;
Description testDescription = Description.createTestDescription(testClass, file.getName());
description.addChild(testDescription);
tests.put(file.getName(), testDescription);
diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java
index 16eae8d3..17665173 100644
--- a/test/core/src/lombok/RunTestsViaDelombok.java
+++ b/test/core/src/lombok/RunTestsViaDelombok.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2010 The Project Lombok Authors.
+ * Copyright (C) 2009-2013 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -25,35 +25,21 @@ import java.io.File;
import java.io.StringWriter;
import java.util.Collection;
import java.util.Locale;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.tools.Diagnostic;
-import javax.tools.Diagnostic.Kind;
-import javax.tools.DiagnosticListener;
-import javax.tools.JavaFileObject;
import lombok.delombok.Delombok;
+import lombok.javac.CapturingDiagnosticListener;
+import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
public class RunTestsViaDelombok extends AbstractRunTests {
private Delombok delombok = new Delombok();
@Override
- public void transformCode(final Collection<CompilerMessage> messages, StringWriter result, final File file) throws Throwable {
+ public void transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file) throws Throwable {
delombok.setVerbose(false);
delombok.setForceProcess(true);
delombok.setCharset("UTF-8");
- delombok.setDiagnosticsListener(new DiagnosticListener<JavaFileObject>() {
- @Override public void report(Diagnostic<? extends JavaFileObject> d) {
- String msg = d.getMessage(Locale.ENGLISH);
- Matcher m = Pattern.compile(
- "^" + Pattern.quote(file.getAbsolutePath()) +
- "\\s*:\\s*\\d+\\s*:\\s*(?:warning:\\s*)?(.*)$", Pattern.DOTALL).matcher(msg);
- if (m.matches()) msg = m.group(1);
- messages.add(new CompilerMessage(d.getLineNumber(), d.getColumnNumber(), d.getKind() == Kind.ERROR, msg));
- }
- });
+ delombok.setDiagnosticsListener(new CapturingDiagnosticListener(file, messages));
delombok.addFile(file.getAbsoluteFile().getParentFile(), file.getName());
delombok.setSourcepath(file.getAbsoluteFile().getParent());
diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java
index b081d54a..0bf97213 100644
--- a/test/core/src/lombok/RunTestsViaEcj.java
+++ b/test/core/src/lombok/RunTestsViaEcj.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2012 The Project Lombok Authors.
+ * Copyright (C) 2010-2013 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -33,6 +33,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
+import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
+
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.Compiler;
@@ -110,7 +112,7 @@ public class RunTestsViaEcj extends AbstractRunTests {
CategorizedProblem[] problems = compilationResult.getAllProblems();
if (problems != null) for (CategorizedProblem p : problems) {
- messages.add(new CompilerMessage(p.getSourceLineNumber(), p.getSourceStart(), p.isError(), p.getMessage()));
+ messages.add(new CompilerMessage(p.getSourceLineNumber(), p.getSourceStart(), p.getSourceStart(), p.isError(), p.getMessage()));
}
CompilationUnitDeclaration cud = compilationUnit_.get();