From 3cf45e932b26f8e96caeecdae570cf7d9cd5e328 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Sun, 29 Nov 2009 16:44:05 +0100 Subject: Improved comment placement (newlines, whitespace) --- test/delombok/resource/after/Cast.java | 3 +-- test/delombok/resource/after/WithComments.java | 1 + test/delombok/resource/before/WithComments.java | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'test/delombok') diff --git a/test/delombok/resource/after/Cast.java b/test/delombok/resource/after/Cast.java index a1b455f0..95237b0f 100644 --- a/test/delombok/resource/after/Cast.java +++ b/test/delombok/resource/after/Cast.java @@ -1,7 +1,6 @@ import java.util.*; public class Cast { public void test(List list) { - RandomAccess r = (/*before*/ - RandomAccess /*after*/)list; + RandomAccess r = (/*before*/ RandomAccess /*after*/)list; } } \ No newline at end of file diff --git a/test/delombok/resource/after/WithComments.java b/test/delombok/resource/after/WithComments.java index 684dcc8e..e4f078aa 100644 --- a/test/delombok/resource/after/WithComments.java +++ b/test/delombok/resource/after/WithComments.java @@ -1,4 +1,5 @@ // Cool Comments public class WithComments { // Also inside the body +// On start of line } \ No newline at end of file diff --git a/test/delombok/resource/before/WithComments.java b/test/delombok/resource/before/WithComments.java index 22d044b3..f75551ac 100644 --- a/test/delombok/resource/before/WithComments.java +++ b/test/delombok/resource/before/WithComments.java @@ -1,4 +1,5 @@ // Cool Comments public class WithComments { // Also inside the body +// On start of line } -- cgit From c646def5791e3a5c27cf77c373e5ce40017c165c Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Sun, 29 Nov 2009 17:23:19 +0100 Subject: 'ant test' will now run the lombok unit tests. --- build.xml | 4 + buildScripts/test.ant.xml | 79 +++++++++++++ test/core/src/lombok/DirectoryRunner.java | 2 +- test/core/src/lombok/RunTestsViaDelombok.java | 123 +++++++++++++++++++++ test/core/src/lombok/TestViaDelombok.java | 123 --------------------- .../src/lombok/delombok/TestLombokFiles.java | 4 +- 6 files changed, 209 insertions(+), 126 deletions(-) create mode 100644 buildScripts/test.ant.xml create mode 100644 test/core/src/lombok/RunTestsViaDelombok.java delete mode 100644 test/core/src/lombok/TestViaDelombok.java (limited to 'test/delombok') diff --git a/build.xml b/build.xml index 5fead285..006a546b 100644 --- a/build.xml +++ b/build.xml @@ -75,6 +75,10 @@ the common tasks and can be called on to run the main aspects of all the sub-scr + + + + diff --git a/buildScripts/test.ant.xml b/buildScripts/test.ant.xml new file mode 100644 index 00000000..742819c5 --- /dev/null +++ b/buildScripts/test.ant.xml @@ -0,0 +1,79 @@ + + + +This buildfile is part of projectlombok.org. It responsible for running unit tests. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + All tests successful. + + diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java index 40b21aa0..1c8cfb2e 100644 --- a/test/core/src/lombok/DirectoryRunner.java +++ b/test/core/src/lombok/DirectoryRunner.java @@ -82,7 +82,7 @@ public class DirectoryRunner extends Runner { if (mustIgnore(file)) { return false; } - TestViaDelombok.compareFile(afterDirectory, file); + RunTestsViaDelombok.compareFile(afterDirectory, file); return true; } diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java new file mode 100644 index 00000000..f2aedfa3 --- /dev/null +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -0,0 +1,123 @@ +/* + * Copyright © 2009 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 + * 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 static org.junit.Assert.*; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + +import lombok.delombok.Delombok; + +public class RunTestsViaDelombok { + 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(); + + for (File file : listFiles) { + compareFile(afterDir, file); + } + } + + public static void compareFile(File afterDir, File file) throws Throwable { + 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()); + } + + public static void printErrors(boolean print) { + printErrors = print; + } + + private static void compare(String name, String expectedFile, String actualFile) 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; + } + } + + 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 readAfter(File afterDir, File file) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File(afterDir, file.getName()))); + 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 out = new ArrayList(); + for (String s : in) { + if (!s.trim().isEmpty()) out.add(s); + } + return out.toArray(new String[0]); + } +} \ No newline at end of file diff --git a/test/core/src/lombok/TestViaDelombok.java b/test/core/src/lombok/TestViaDelombok.java deleted file mode 100644 index 63a8e1f8..00000000 --- a/test/core/src/lombok/TestViaDelombok.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright © 2009 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 - * 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 static org.junit.Assert.*; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.List; - -import lombok.delombok.Delombok; - -public class TestViaDelombok { - 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(); - - for (File file : listFiles) { - compareFile(afterDir, file); - } - } - - public static void compareFile(File afterDir, File file) throws Throwable { - 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()); - } - - public static void printErrors(boolean print) { - printErrors = print; - } - - private static void compare(String name, String expectedFile, String actualFile) 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; - } - } - - 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 readAfter(File afterDir, File file) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File(afterDir, file.getName()))); - 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 out = new ArrayList(); - for (String s : in) { - if (!s.trim().isEmpty()) out.add(s); - } - return out.toArray(new String[0]); - } -} \ No newline at end of file diff --git a/test/delombok/src/lombok/delombok/TestLombokFiles.java b/test/delombok/src/lombok/delombok/TestLombokFiles.java index 66e3580e..12c16d76 100644 --- a/test/delombok/src/lombok/delombok/TestLombokFiles.java +++ b/test/delombok/src/lombok/delombok/TestLombokFiles.java @@ -24,7 +24,7 @@ package lombok.delombok; import java.io.File; import lombok.DirectoryRunner; -import lombok.TestViaDelombok; +import lombok.RunTestsViaDelombok; import org.junit.runner.RunWith; @@ -32,7 +32,7 @@ import org.junit.runner.RunWith; public class TestLombokFiles { public static File getBeforeDirectory() { - TestViaDelombok.printErrors(true); + RunTestsViaDelombok.printErrors(true); return new File("test/lombok/resource/before"); } -- cgit