aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2010-07-20 23:51:47 +0200
committerRoel Spilker <r.spilker@gmail.com>2010-07-20 23:51:47 +0200
commitced6843970d270d5edce04f885cf4625cb0a9d86 (patch)
treece10f5b83731810e94baccedba8315a573c6d39f
parent58f5f68f0534503281d0be5aff408b1d183096c7 (diff)
downloadlombok-ced6843970d270d5edce04f885cf4625cb0a9d86.tar.gz
lombok-ced6843970d270d5edce04f885cf4625cb0a9d86.tar.bz2
lombok-ced6843970d270d5edce04f885cf4625cb0a9d86.zip
Added support for checking compiler messages (errors & warnings)
-rw-r--r--test/core/src/lombok/DirectoryRunner.java11
-rw-r--r--test/core/src/lombok/RunTestsViaDelombok.java60
2 files changed, 59 insertions, 12 deletions
diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java
index 1c8cfb2e..db474ff0 100644
--- a/test/core/src/lombok/DirectoryRunner.java
+++ b/test/core/src/lombok/DirectoryRunner.java
@@ -2,6 +2,7 @@ package lombok;
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
@@ -16,6 +17,12 @@ import org.junit.runner.notification.RunNotifier;
public class DirectoryRunner extends Runner {
+ private static final FileFilter JAVA_FILE_FILTER = new FileFilter() {
+ @Override public boolean accept(File file) {
+ return file.isFile() && file.getName().endsWith(".java");
+ }
+ };
+
private final Description description;
private final Map<String, Description> tests = new TreeMap<String, Description>();
private final Throwable failure;
@@ -41,7 +48,7 @@ public class DirectoryRunner extends Runner {
Method afterMethod = testClass.getDeclaredMethod("getAfterDirectory");
afterDirectory = (File) afterMethod.invoke(null);
- for (File file : beforeDirectory.listFiles()) {
+ for (File file : beforeDirectory.listFiles(JAVA_FILE_FILTER)) {
Description testDescription = Description.createTestDescription(testClass, file.getName());
description.addChild(testDescription);
tests.put(file.getName(), testDescription);
@@ -82,7 +89,7 @@ public class DirectoryRunner extends Runner {
if (mustIgnore(file)) {
return false;
}
- RunTestsViaDelombok.compareFile(afterDirectory, file);
+ RunTestsViaDelombok.compareFile(beforeDirectory, afterDirectory, file);
return true;
}
diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java
index f2aedfa3..37ff8f69 100644
--- a/test/core/src/lombok/RunTestsViaDelombok.java
+++ b/test/core/src/lombok/RunTestsViaDelombok.java
@@ -25,42 +25,63 @@ import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileFilter;
+import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
+
+import javax.tools.Diagnostic;
+import javax.tools.DiagnosticListener;
+import javax.tools.JavaFileObject;
import lombok.delombok.Delombok;
public class RunTestsViaDelombok {
+ private static final FileFilter JAVA_FILE_FILTER = new FileFilter() {
+ @Override public boolean accept(File file) {
+ return file.isFile() && file.getName().endsWith(".java");
+ }
+ };
+
private static Delombok delombok = new Delombok();
private static volatile boolean printErrors = false;
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
public static void runComparison(File beforeDir, File afterDir) throws Throwable {
- File[] listFiles = beforeDir.listFiles();
+ File[] listFiles = beforeDir.listFiles(JAVA_FILE_FILTER);
for (File file : listFiles) {
- compareFile(afterDir, file);
+ compareFile(beforeDir, afterDir, file);
}
}
- public static void compareFile(File afterDir, File file) throws Throwable {
+ public static void compareFile(File beforeDir, File afterDir, File file) throws Throwable {
delombok.setVerbose(false);
delombok.setForceProcess(true);
delombok.setCharset("UTF-8");
+
+ final StringBuilder messages = new StringBuilder();
+ delombok.setDiagnosticsListener(new DiagnosticListener<JavaFileObject>() {
+ @Override public void report(Diagnostic<? extends JavaFileObject> d) {
+ messages.append(String.format("%d:%d %s %s\n", d.getLineNumber(), d.getColumnNumber(), d.getKind(), d.getMessage(Locale.ENGLISH)));
+ }
+ });
+
StringWriter writer = new StringWriter();
delombok.delombok(file.getAbsolutePath(), writer);
- compare(file.getName(), readAfter(afterDir, file), writer.toString());
+ compare(file.getName(), readFile(afterDir, file, false), writer.toString(), readFile(beforeDir, file, true), messages.toString());
}
public static void printErrors(boolean print) {
printErrors = print;
}
- private static void compare(String name, String expectedFile, String actualFile) throws Throwable {
+ private static void compare(String name, String expectedFile, String actualFile, String expectedMessages, String actualMessages) throws Throwable {
try {
compareContent(name, expectedFile, actualFile);
}
@@ -76,10 +97,24 @@ public class RunTestsViaDelombok {
}
throw e;
}
+ try {
+ compareContent(name, expectedMessages, actualMessages);
+ }
+ catch (Throwable e) {
+ if (printErrors) {
+ System.out.println("***** " + name + " *****");
+ System.out.println(e.getMessage());
+ System.out.println("**** Expected ******");
+ System.out.println(expectedMessages);
+ System.out.println("**** Actual ******");
+ System.out.println(actualMessages);
+ System.out.println("*******************");
+ }
+ throw e;
+ }
}
-
- private static void compareContent(String name, String expectedFile,
- String actualFile) {
+
+ private static void compareContent(String name, String expectedFile, String actualFile) {
String[] expectedLines = expectedFile.split("(\\r?\\n)");
String[] actualLines = actualFile.split("(\\r?\\n)");
if (actualLines[0].startsWith("// Generated by delombok at ")) {
@@ -101,8 +136,13 @@ public class RunTestsViaDelombok {
}
}
- private static String readAfter(File afterDir, File file) throws IOException {
- BufferedReader reader = new BufferedReader(new FileReader(new File(afterDir, file.getName())));
+ private static String readFile(File afterDir, File file, boolean messages) throws IOException {
+ BufferedReader reader;
+ try {
+ reader = new BufferedReader(new FileReader(new File(afterDir, file.getName() + (messages ? ".messages" : ""))));
+ } catch (FileNotFoundException e) {
+ return "";
+ }
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {