From f2de0a28e70ff284fe6fac626c39df66f4bf3e89 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 27 Nov 2009 17:36:03 +0100 Subject: Improved error reporting --- test/core/src/lombok/TestViaDelombok.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/core/src/lombok/TestViaDelombok.java b/test/core/src/lombok/TestViaDelombok.java index e8070723..f9ea95f2 100644 --- a/test/core/src/lombok/TestViaDelombok.java +++ b/test/core/src/lombok/TestViaDelombok.java @@ -64,7 +64,7 @@ public class TestViaDelombok { String expected = expectedLines[i]; String actual = actualLines[i]; if (!expected.equals(actual)) { - fail(String.format("Difference in line %s(%d):\n`%s`\n`%s`\n", name, i, expected, actual)); + fail(String.format("Difference in line %s(%d):\nExpected `%s`\nGot `%s`\n", name, i, expected, actual)); } } if (expectedLines.length > actualLines.length) { -- cgit From 645a0b06c76ce6fbad8d48afe0161b21d04046bb Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 27 Nov 2009 17:37:26 +0100 Subject: Removed empty () for annotation without parameters --- src/delombok/lombok/delombok/PrettyCommentsPrinter.java | 8 +++++--- test/delombok/resource/after/Annotation.java | 7 +++++++ test/delombok/resource/before/Annotation.java | 7 +++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 test/delombok/resource/after/Annotation.java create mode 100644 test/delombok/resource/before/Annotation.java (limited to 'test') diff --git a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java index 611dd417..785826f1 100644 --- a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java +++ b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java @@ -1358,9 +1358,11 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { try { print("@"); printExpr(tree.annotationType); - print("("); - printExprs(tree.args); - print(")"); + if (tree.args.nonEmpty()) { + print("("); + printExprs(tree.args); + print(")"); + } } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/test/delombok/resource/after/Annotation.java b/test/delombok/resource/after/Annotation.java new file mode 100644 index 00000000..38eddbf7 --- /dev/null +++ b/test/delombok/resource/after/Annotation.java @@ -0,0 +1,7 @@ +@SuppressWarnings("all") +class Annotation { + @Override + public String toString() { + return super.toString(); + } +} diff --git a/test/delombok/resource/before/Annotation.java b/test/delombok/resource/before/Annotation.java new file mode 100644 index 00000000..38eddbf7 --- /dev/null +++ b/test/delombok/resource/before/Annotation.java @@ -0,0 +1,7 @@ +@SuppressWarnings("all") +class Annotation { + @Override + public String toString() { + return super.toString(); + } +} -- cgit From e67e9e14dcc0f3754c3a42e6b4d039a7aa04db1a Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Sat, 28 Nov 2009 00:15:58 +0100 Subject: Added support for running unit tests using the method name to determine the file to test --- test/core/src/lombok/ReflectionFileTester.java | 60 ++++++++++++++++++++++ test/core/src/lombok/TestViaDelombok.java | 28 +++++----- test/delombok/resource/after/ForLoop.java | 2 - test/delombok/resource/after/WithComments.java | 1 - .../src/lombok/delombok/TestSourceFiles.java | 35 ++++++++++--- 5 files changed, 103 insertions(+), 23 deletions(-) create mode 100644 test/core/src/lombok/ReflectionFileTester.java (limited to 'test') diff --git a/test/core/src/lombok/ReflectionFileTester.java b/test/core/src/lombok/ReflectionFileTester.java new file mode 100644 index 00000000..32de9c54 --- /dev/null +++ b/test/core/src/lombok/ReflectionFileTester.java @@ -0,0 +1,60 @@ +package lombok; + +import java.io.File; +import java.lang.reflect.Method; + +import org.junit.Test; + +public class ReflectionFileTester { + + private final File before; + private final File after; + + public ReflectionFileTester(String beforePath, String afterPath) { + before = new File(beforePath); + after = new File(afterPath); + if (!before.isDirectory()) { + throw new IllegalArgumentException(beforePath + " is not a directory"); + } + if (!after.isDirectory()) { + throw new IllegalArgumentException(afterPath + " is not a directory"); + } + } + + public boolean verify(Class clazz) { + boolean result = true; + for (File f : before.listFiles()) { + String fileName = f.getName(); + if (!fileName.endsWith(".java")) { + continue; + } + String methodName = "test" + fileName.substring(0, fileName.length() - 5); + try { + Method method = clazz.getDeclaredMethod(methodName); + if (method.getAnnotation(Test.class) == null) { + result = false; + System.err.printf("Class %s method %s is not a @Test method\n", clazz.getName(), methodName); + } + } + catch (NoSuchMethodException e) { + result = false; + System.err.printf("Class %s has no method %s\n", clazz.getName(), methodName); + } + } + return result; + } + + public void test() throws Exception { + StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); + if (stackTrace.length < 3) { + throw new Error("No stacktrace available"); + } + String methodName = stackTrace[2].getMethodName(); + if (!methodName.startsWith("test")) { + throw new IllegalStateException("test() should be called from a methos that starts with 'test'"); + } + String fileName = methodName.substring(4).concat(".java"); + File testFile = new File(before, fileName); + TestViaDelombok.compareFile(after, testFile); + } +} diff --git a/test/core/src/lombok/TestViaDelombok.java b/test/core/src/lombok/TestViaDelombok.java index f9ea95f2..a3e97098 100644 --- a/test/core/src/lombok/TestViaDelombok.java +++ b/test/core/src/lombok/TestViaDelombok.java @@ -21,7 +21,7 @@ */ package lombok; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.io.BufferedReader; import java.io.File; @@ -42,14 +42,18 @@ public class TestViaDelombok { File[] listFiles = beforeDir.listFiles(); for (File file : listFiles) { - delombok.setVerbose(false); - delombok.setForceProcess(true); - delombok.setCharset("UTF-8"); - StringWriter writer = new StringWriter(); - delombok.delombok(file.getAbsolutePath(), writer); - compare(file.getName(), readAfter(afterDir, file), writer.toString()); + compareFile(afterDir, file); } } + + public static void compareFile(File afterDir, File file) throws IOException { + delombok.setVerbose(false); + delombok.setForceProcess(true); + delombok.setCharset("UTF-8"); + StringWriter writer = new StringWriter(); + delombok.delombok(file.getAbsolutePath(), writer); + compare(file.getName(), readAfter(afterDir, file), writer.toString()); + } private static void compare(String name, String expectedFile, String actualFile) { String[] expectedLines = expectedFile.split("(\\r?\\n)"); @@ -63,15 +67,13 @@ public class TestViaDelombok { for (int i = 0; i < size; i++) { String expected = expectedLines[i]; String actual = actualLines[i]; - if (!expected.equals(actual)) { - fail(String.format("Difference in line %s(%d):\nExpected `%s`\nGot `%s`\n", name, i, expected, actual)); - } + assertEquals(String.format("Difference in %s on line %d", name, i + 1), expected, actual); } if (expectedLines.length > actualLines.length) { - fail(String.format("Missing line %s(%d): %s\n", name, size, expectedLines[size])); + 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 %s(%d): %s\n", name, size, actualLines[size])); + fail(String.format("Extra line %d in generated %s: %s", size + 1, name, actualLines[size])); } } @@ -94,4 +96,4 @@ public class TestViaDelombok { } return out.toArray(new String[0]); } -} +} \ No newline at end of file diff --git a/test/delombok/resource/after/ForLoop.java b/test/delombok/resource/after/ForLoop.java index 609549b7..615f6e8a 100644 --- a/test/delombok/resource/after/ForLoop.java +++ b/test/delombok/resource/after/ForLoop.java @@ -1,6 +1,4 @@ - public class ForLoop { - public static void main(String[] args) { // before loop for (int i = 0; i < 10; i++) { diff --git a/test/delombok/resource/after/WithComments.java b/test/delombok/resource/after/WithComments.java index 59cc97c4..684dcc8e 100644 --- a/test/delombok/resource/after/WithComments.java +++ b/test/delombok/resource/after/WithComments.java @@ -1,5 +1,4 @@ // Cool Comments - public class WithComments { // Also inside the body } \ No newline at end of file diff --git a/test/delombok/src/lombok/delombok/TestSourceFiles.java b/test/delombok/src/lombok/delombok/TestSourceFiles.java index a5df5197..fc2a9cab 100644 --- a/test/delombok/src/lombok/delombok/TestSourceFiles.java +++ b/test/delombok/src/lombok/delombok/TestSourceFiles.java @@ -21,18 +21,39 @@ */ package lombok.delombok; -import java.io.File; - -import lombok.TestViaDelombok; +import lombok.ReflectionFileTester; +import org.junit.BeforeClass; import org.junit.Test; public class TestSourceFiles { - private static final File BEFORE_DIR = new File("test/delombok/resource/before"); - private static final File AFTER_DIR = new File("test/delombok/resource/after"); + private static final String AFTER = "test/delombok/resource/after"; + private static final String BEFORE = "test/delombok/resource/before"; + + private static final ReflectionFileTester tester = new ReflectionFileTester(BEFORE, AFTER); + + @BeforeClass + public static void verify() { + tester.verify(TestSourceFiles.class); + } + + @Test + public void testAnnotation() throws Exception { + tester.test(); + } + + @Test + public void testCast() throws Exception { + tester.test(); + } + + @Test + public void testForLoop() throws Exception { + tester.test(); + } @Test - public void testSources() throws Exception { - TestViaDelombok.runComparison(BEFORE_DIR, AFTER_DIR); + public void testWithComments() throws Exception { + tester.test(); } } -- cgit