diff options
Diffstat (limited to 'test/core/src/lombok/RunTestsViaDelombok.java')
-rw-r--r-- | test/core/src/lombok/RunTestsViaDelombok.java | 128 |
1 files changed, 8 insertions, 120 deletions
diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index 37ff8f69..7f99b99e 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -1,5 +1,5 @@ /* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. + * Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,17 +21,8 @@ */ package lombok; -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; @@ -40,124 +31,21 @@ 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 class RunTestsViaDelombok extends AbstractRunTests { + private Delombok delombok = new Delombok(); - public static void runComparison(File beforeDir, File afterDir) throws Throwable { - File[] listFiles = beforeDir.listFiles(JAVA_FILE_FILTER); - - for (File file : listFiles) { - compareFile(beforeDir, afterDir, file); - } - } - - public static void compareFile(File beforeDir, File afterDir, File file) throws Throwable { + @Override + public void transformCode(final StringBuilder messages, StringWriter result, 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(), 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, String expectedMessages, String actualMessages) throws Throwable { - try { - compareContent(name, expectedFile, actualFile); - } - catch (Throwable e) { - if (printErrors) { - System.out.println("***** " + name + " *****"); - System.out.println(e.getMessage()); - System.out.println("**** Expected ******"); - System.out.println(expectedFile); - System.out.println("**** Actual ******"); - System.out.println(actualFile); - System.out.println("*******************"); - } - 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) { - String[] expectedLines = expectedFile.split("(\\r?\\n)"); - String[] actualLines = actualFile.split("(\\r?\\n)"); - if (actualLines[0].startsWith("// Generated by delombok at ")) { - actualLines[0] = ""; - } - expectedLines = removeBlanks(expectedLines); - actualLines = removeBlanks(actualLines); - int size = Math.min(expectedLines.length, actualLines.length); - for (int i = 0; i < size; i++) { - String expected = expectedLines[i]; - String actual = actualLines[i]; - assertEquals(String.format("Difference in %s on line %d", name, i + 1), expected, actual); - } - if (expectedLines.length > actualLines.length) { - fail(String.format("Missing line %d in generated %s: %s", size + 1, name, expectedLines[size])); - } - if (expectedLines.length < actualLines.length) { - fail(String.format("Extra line %d in generated %s: %s", size + 1, name, actualLines[size])); - } - } - - 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) { - result.append(line); - result.append(LINE_SEPARATOR); - } - reader.close(); - return result.toString(); - } - - private static String[] removeBlanks(String[] in) { - List<String> out = new ArrayList<String>(); - for (String s : in) { - if (!s.trim().isEmpty()) out.add(s); - } - return out.toArray(new String[0]); + delombok.delombok(file.getAbsolutePath(), result); } -}
\ No newline at end of file +} |