aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/configuration/resource/configurationRoot/d1/d11/d111/f1.txt0
-rw-r--r--test/configuration/resource/configurationRoot/d1/d11/d111/lombok.config2
-rw-r--r--test/configuration/resource/configurationRoot/d1/d11/lombok.config5
-rw-r--r--test/configuration/resource/configurationRoot/d1/d12/lombok.config3
-rw-r--r--test/configuration/resource/configurationRoot/d1/lombok.config3
-rw-r--r--test/configuration/resource/configurationRoot/err.txt0
-rw-r--r--test/configuration/resource/configurationRoot/out.txt90
-rw-r--r--test/configuration/src/lombok/core/configuration/RunConfigurationTests.java31
-rw-r--r--test/configuration/src/lombok/core/configuration/TestConfiguration.java95
-rw-r--r--test/core/src/lombok/AbstractRunTests.java95
-rw-r--r--test/core/src/lombok/DirectoryRunner.java59
-rw-r--r--test/core/src/lombok/LombokTestSource.java239
-rw-r--r--test/core/src/lombok/RunAllTests.java4
-rw-r--r--test/core/src/lombok/RunTestsViaDelombok.java2
-rw-r--r--test/core/src/lombok/RunTestsViaEcj.java2
-rw-r--r--test/transform/resource/after-delombok/AccessorsConfiguration.java26
-rw-r--r--test/transform/resource/after-delombok/LoggerConfig.java4
-rw-r--r--test/transform/resource/after-delombok/ToStringConfiguration.java32
-rw-r--r--test/transform/resource/after-ecj/AccessorsConfiguration.java31
-rw-r--r--test/transform/resource/after-ecj/LoggerConfig.java6
-rw-r--r--test/transform/resource/after-ecj/ToStringConfiguration.java35
-rw-r--r--test/transform/resource/before/AccessorsConfiguration.java20
-rw-r--r--test/transform/resource/before/BuilderInvalidUse.java1
-rw-r--r--test/transform/resource/before/DelegateOnStatic.java1
-rw-r--r--test/transform/resource/before/FlagUsages.java11
-rw-r--r--test/transform/resource/before/LoggerConfig.java5
-rw-r--r--test/transform/resource/before/ToStringConfiguration.java13
-rw-r--r--test/transform/resource/messages-delombok/BuilderInvalidUse.java.messages4
-rw-r--r--test/transform/resource/messages-delombok/DelegateOnStatic.java.messages4
-rw-r--r--test/transform/resource/messages-delombok/FlagUsages.java.messages2
-rw-r--r--test/transform/resource/messages-ecj/BuilderInvalidUse.java.messages4
-rw-r--r--test/transform/resource/messages-ecj/DelegateOnStatic.java.messages4
-rw-r--r--test/transform/resource/messages-ecj/FlagUsages.java.messages2
33 files changed, 717 insertions, 118 deletions
diff --git a/test/configuration/resource/configurationRoot/d1/d11/d111/f1.txt b/test/configuration/resource/configurationRoot/d1/d11/d111/f1.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/d1/d11/d111/f1.txt
diff --git a/test/configuration/resource/configurationRoot/d1/d11/d111/lombok.config b/test/configuration/resource/configurationRoot/d1/d11/d111/lombok.config
new file mode 100644
index 00000000..abf7eea0
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/d1/d11/d111/lombok.config
@@ -0,0 +1,2 @@
+clear lombok.accessors.chain
+lombok.accessors.prefix += m_ \ No newline at end of file
diff --git a/test/configuration/resource/configurationRoot/d1/d11/lombok.config b/test/configuration/resource/configurationRoot/d1/d11/lombok.config
new file mode 100644
index 00000000..ec53df09
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/d1/d11/lombok.config
@@ -0,0 +1,5 @@
+config.stopBubbling=true
+
+lombok.accessors.chain = false
+lombok.accessors.flagUsage = ERROR
+lombok.accessors.prefix += f \ No newline at end of file
diff --git a/test/configuration/resource/configurationRoot/d1/d12/lombok.config b/test/configuration/resource/configurationRoot/d1/d12/lombok.config
new file mode 100644
index 00000000..327a2d24
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/d1/d12/lombok.config
@@ -0,0 +1,3 @@
+config.stopBubbling=true
+
+lombok.accessors.chain = true \ No newline at end of file
diff --git a/test/configuration/resource/configurationRoot/d1/lombok.config b/test/configuration/resource/configurationRoot/d1/lombok.config
new file mode 100644
index 00000000..4904b4fa
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/d1/lombok.config
@@ -0,0 +1,3 @@
+config.stopBubbling=true
+# this file shouldn't be read
+no error expected \ No newline at end of file
diff --git a/test/configuration/resource/configurationRoot/err.txt b/test/configuration/resource/configurationRoot/err.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/err.txt
diff --git a/test/configuration/resource/configurationRoot/out.txt b/test/configuration/resource/configurationRoot/out.txt
new file mode 100644
index 00000000..625115a4
--- /dev/null
+++ b/test/configuration/resource/configurationRoot/out.txt
@@ -0,0 +1,90 @@
+Configuration for 'BASE/d1/d11'.
+
+# Emit a warning or error if @Accessors is used.
+lombok.accessors.flagUsage = ERROR
+# BASE/d1/lombok.config:
+# <'lombok.accessors.flagUsage' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 3: lombok.accessors.flagUsage = ERROR
+
+# Generate setters that return 'this' instead of 'void'.
+lombok.accessors.chain = false
+# BASE/d1/lombok.config:
+# <'lombok.accessors.chain' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 2: lombok.accessors.chain = false
+
+# Strip this field prefix, like 'f' or 'm_', from the names of generated getters and setters.
+lombok.accessors.prefix += f
+# BASE/d1/lombok.config:
+# <'lombok.accessors.prefix' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 4: lombok.accessors.prefix += f
+
+# Use this name for the generated logger fields (default: 'log')
+clear lombok.log.fieldName
+
+
+Configuration for:
+- BASE/d1/d11/d111
+- BASE/d1/d11/d111/f1.txt
+
+# Emit a warning or error if @Accessors is used.
+lombok.accessors.flagUsage = ERROR
+# BASE/d1/lombok.config:
+# <'lombok.accessors.flagUsage' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 3: lombok.accessors.flagUsage = ERROR
+#
+# BASE/d1/d11/d111/lombok.config:
+# <'lombok.accessors.flagUsage' not mentioned>
+
+# Generate setters that return 'this' instead of 'void'.
+clear lombok.accessors.chain
+# BASE/d1/lombok.config:
+# <'lombok.accessors.chain' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 2: lombok.accessors.chain = false
+#
+# BASE/d1/d11/d111/lombok.config:
+# 1: clear lombok.accessors.chain
+
+# Strip this field prefix, like 'f' or 'm_', from the names of generated getters and setters.
+lombok.accessors.prefix += f
+lombok.accessors.prefix += m_
+# BASE/d1/lombok.config:
+# <'lombok.accessors.prefix' not mentioned>
+#
+# BASE/d1/d11/lombok.config:
+# 4: lombok.accessors.prefix += f
+#
+# BASE/d1/d11/d111/lombok.config:
+# 2: lombok.accessors.prefix += m_
+
+# Use this name for the generated logger fields (default: 'log')
+clear lombok.log.fieldName
+
+
+Configuration for 'BASE/d1/d12'.
+
+# Emit a warning or error if @Accessors is used.
+clear lombok.accessors.flagUsage
+
+# Generate setters that return 'this' instead of 'void'.
+lombok.accessors.chain = true
+# BASE/d1/lombok.config:
+# <'lombok.accessors.chain' not mentioned>
+#
+# BASE/d1/d12/lombok.config:
+# 2: lombok.accessors.chain = true
+
+# Strip this field prefix, like 'f' or 'm_', from the names of generated getters and setters.
+clear lombok.accessors.prefix
+
+# Use this name for the generated logger fields (default: 'log')
+clear lombok.log.fieldName \ No newline at end of file
diff --git a/test/configuration/src/lombok/core/configuration/RunConfigurationTests.java b/test/configuration/src/lombok/core/configuration/RunConfigurationTests.java
new file mode 100644
index 00000000..40e0a7f4
--- /dev/null
+++ b/test/configuration/src/lombok/core/configuration/RunConfigurationTests.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 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.core.configuration;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({TestConfiguration.class})
+public class RunConfigurationTests {
+}
diff --git a/test/configuration/src/lombok/core/configuration/TestConfiguration.java b/test/configuration/src/lombok/core/configuration/TestConfiguration.java
new file mode 100644
index 00000000..d2599334
--- /dev/null
+++ b/test/configuration/src/lombok/core/configuration/TestConfiguration.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2014 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.core.configuration;
+
+import static lombok.ConfigurationKeys.*;
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.regex.Pattern;
+
+import org.junit.Test;
+
+public class TestConfiguration {
+
+ @Test
+ public void testDisplayVerbose() throws Exception {
+
+ @SuppressWarnings("unchecked")
+ Collection<ConfigurationKey<?>> keys = Arrays.asList(ACCESSORS_FLAG_USAGE, ACCESSORS_CHAIN, ACCESSORS_PREFIX, LOG_ANY_FIELD_NAME);
+
+ String baseName = "test/configuration/resource/configurationRoot/";
+ File directory = new File(baseName);
+ String normalizedName = new File(directory.getAbsoluteFile().toURI().normalize()).toString().replace('\\', '/') + "/";
+ Collection<String> paths = Arrays.asList(normalizedName + "d1/d11", normalizedName + "d1/d12", normalizedName + "d1/d11/d111", normalizedName + "d1/d11/d111/f1.txt");
+
+ ByteArrayOutputStream rawOut = new ByteArrayOutputStream();
+ ByteArrayOutputStream rawErr = new ByteArrayOutputStream();
+ PrintStream outStream = new PrintStream(rawOut);
+ PrintStream errStream = new PrintStream(rawErr);
+
+ int result = new ConfigurationApp().redirectOutput(outStream, errStream).display(keys, true, paths, true);
+
+ outStream.flush();
+ errStream.flush();
+
+ String out = new String(rawOut.toByteArray()).replace("\r\n", "\n").replace('\\', '/').replaceAll(Pattern.quote(normalizedName) + "|" + Pattern.quote(baseName), "BASE/").trim();
+ String err = new String(rawErr.toByteArray()).replace("\r\n", "\n").replace('\\', '/').replaceAll(Pattern.quote(normalizedName) + "|" + Pattern.quote(baseName), "BASE/").trim();
+
+ checkContent(directory, out, "out");
+ checkContent(directory, err, "err");
+ assertEquals(0, result);
+ }
+
+ private void checkContent(File dir, String actual, String type) throws Exception {
+ String expected = fileToString(new File(dir, type + ".txt")).trim();
+ if (!expected.equals(actual)) {
+ System.out.printf("**** Expected %s:\n", type);
+ System.out.println(expected);
+ System.out.printf("**** Actual %s:\n", type);
+ System.out.println(actual);
+ System.out.println("****");
+ }
+ assertEquals(expected, actual);
+ }
+
+ static String fileToString(File configFile) throws Exception {
+ byte[] b = new byte[65536];
+ FileInputStream fis = new FileInputStream(configFile);
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ while (true) {
+ int r = fis.read(b);
+ if (r == -1) break;
+ out.write(b, 0, r);
+ }
+ return new String(out.toByteArray(), "UTF-8");
+ } finally {
+ fis.close();
+ }
+ }
+}
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java
index e84aec0d..34f6cbf4 100644
--- a/test/core/src/lombok/AbstractRunTests.java
+++ b/test/core/src/lombok/AbstractRunTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2013 The Project Lombok Authors.
+ * Copyright (C) 2009-2014 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,21 +25,25 @@ import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
+import org.junit.Assert;
+
+import lombok.core.AST;
+import lombok.core.LombokConfiguration;
+import lombok.core.LombokImmutableList;
+import lombok.core.configuration.ConfigurationKeysLoader;
+import lombok.core.configuration.ConfigurationResolver;
+import lombok.core.configuration.ConfigurationResolverFactory;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
public abstract class AbstractRunTests {
@@ -50,39 +54,27 @@ public abstract class AbstractRunTests {
}
public boolean compareFile(DirectoryRunner.TestParams params, File file) throws Throwable {
+ ConfigurationKeysLoader.LoaderLoader.loadAllConfigurationKeys();
+ final LombokTestSource sourceDirectives = LombokTestSource.readDirectives(file);
+ if (sourceDirectives.isIgnore() || !sourceDirectives.versionWithinLimit(params.getVersion())) return false;
+
+ String fileName = file.getName();
+ LombokTestSource expected = LombokTestSource.read(params.getAfterDirectory(), params.getMessagesDirectory(), fileName);
+
+ if (expected.isIgnore() || !expected.versionWithinLimit(params.getVersion())) return false;
+
LinkedHashSet<CompilerMessage> messages = new LinkedHashSet<CompilerMessage>();
StringWriter writer = new StringWriter();
- transformCode(messages, writer, file);
- String expectedFile = readFile(params.getAfterDirectory(), file, false);
- List<CompilerMessageMatcher> expectedMessages = Collections.emptyList();
- if (params.getMessagesDirectory() != null) {
- try {
- InputStream in = new FileInputStream(new File(params.getMessagesDirectory(), file.getName() + ".messages"));
- try {
- expectedMessages = CompilerMessageMatcher.readAll(in);
- } finally {
- in.close();
- }
- } catch (FileNotFoundException ex) {
- // That's okay - then we expect no messages, and expectedMessages already gets initialized to the empty list.
- }
- }
- if (expectedFile != null) {
- StringReader r = new StringReader(expectedFile);
- BufferedReader br = new BufferedReader(r);
- String firstLine = br.readLine();
- if (firstLine != null && (firstLine.startsWith("//ignore") || params.shouldIgnoreBasedOnVersion(firstLine))) return false;
- }
+ LombokConfiguration.overrideConfigurationResolverFactory(new ConfigurationResolverFactory() {
+ @Override public ConfigurationResolver createResolver(AST<?, ?, ?> ast) {
+ return sourceDirectives.getConfiguration();
+ }
+ });
- compare(
- file.getName(),
- expectedFile,
- writer.toString(),
- expectedMessages,
- messages,
- params.printErrors());
+ transformCode(messages, writer, file);
+ compare(file.getName(), expected, writer.toString(), messages, params.printErrors(), sourceDirectives.isSkipCompareContent() || expected.isSkipCompareContent());
return true;
}
@@ -105,11 +97,6 @@ public abstract class AbstractRunTests {
return result.toString();
}
- private String readFile(File dir, File file, boolean messages) throws IOException {
- if (dir == null) return null;
- return readFile(new File(dir, file.getName() + (messages ? ".messages" : "")));
- }
-
private static File findPlaceToDumpActualFiles() {
String location = System.getProperty("lombok.tests.dump_actual_files");
if (location != null) {
@@ -141,17 +128,15 @@ public abstract class AbstractRunTests {
}
}
- private void compare(String name, String expectedFile, String actualFile, List<CompilerMessageMatcher> expectedMessages, LinkedHashSet<CompilerMessage> actualMessages, boolean printErrors) throws Throwable {
- if (expectedFile == null && expectedMessages.isEmpty()) expectedFile = "";
-
- if (expectedFile != null) try {
- compareContent(name, expectedFile, actualFile);
+ private void compare(String name, LombokTestSource expected, String actualFile, LinkedHashSet<CompilerMessage> actualMessages, boolean printErrors, boolean skipCompareContent) throws Throwable {
+ if (!skipCompareContent) try {
+ compareContent(name, expected.getContent(), 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(expected.getContent());
System.out.println("**** Actual ******");
System.out.println(actualFile);
if (actualMessages != null && !actualMessages.isEmpty()) {
@@ -169,13 +154,13 @@ public abstract class AbstractRunTests {
}
try {
- compareMessages(name, expectedMessages, actualMessages);
+ compareMessages(name, expected.getMessages(), actualMessages);
} catch (Throwable e) {
if (printErrors) {
System.out.println("***** " + name + " *****");
System.out.println(e.getMessage());
System.out.println("**** Expected ******");
- for (CompilerMessageMatcher expectedMessage : expectedMessages) {
+ for (CompilerMessageMatcher expectedMessage : expected.getMessages()) {
System.out.println(expectedMessage);
}
System.out.println("**** Actual ******");
@@ -191,7 +176,7 @@ public abstract class AbstractRunTests {
}
}
- private static void compareMessages(String name, List<CompilerMessageMatcher> expected, LinkedHashSet<CompilerMessage> actual) {
+ private static void compareMessages(String name, LombokImmutableList<CompilerMessageMatcher> expected, LinkedHashSet<CompilerMessage> actual) {
Iterator<CompilerMessageMatcher> expectedIterator = expected.iterator();
Iterator<CompilerMessage> actualIterator = actual.iterator();
@@ -215,15 +200,23 @@ public abstract class AbstractRunTests {
private static void compareContent(String name, String expectedFile, String actualFile) {
String[] expectedLines = expectedFile.split("(\\r?\\n)");
String[] actualLines = actualFile.split("(\\r?\\n)");
- if (expectedLines[0].startsWith("// Generated by delombok at ")) {
- expectedLines[0] = "";
+
+ for (int i = 0; i < expectedLines.length; i++) {
+ if (expectedLines[i].isEmpty() || expectedLines[i].startsWith("//")) expectedLines[i] = "";
+ else break;
}
- if (actualLines[0].startsWith("// Generated by delombok at ")) {
- actualLines[0] = "";
+ for (int i = 0; i < actualLines.length; i++) {
+ if (actualLines[i].isEmpty() || actualLines[i].startsWith("//")) actualLines[i] = "";
+ else break;
}
expectedLines = removeBlanks(expectedLines);
actualLines = removeBlanks(actualLines);
+
int size = Math.min(expectedLines.length, actualLines.length);
+ if (size == 0 && expectedLines.length + actualLines.length > 0) {
+ Assert.fail("Missing / empty expected file.");
+ }
+
for (int i = 0; i < size; i++) {
String expected = trimRight(expectedLines[i]);
String actual = trimRight(actualLines[i]);
diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java
index 5325c1e3..9062f523 100644
--- a/test/core/src/lombok/DirectoryRunner.java
+++ b/test/core/src/lombok/DirectoryRunner.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2013 The Project Lombok Authors.
+ * Copyright (C) 2009-2014 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
@@ -21,16 +21,10 @@
*/
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;
import java.util.Map;
import java.util.TreeMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import lombok.eclipse.Eclipse;
import lombok.javac.Javac;
@@ -75,46 +69,8 @@ public class DirectoryRunner extends Runner {
public boolean accept(File file) {
return true;
}
-
- private static final Pattern P1 = Pattern.compile("^(\\d+)$");
- private static final Pattern P2 = Pattern.compile("^\\:(\\d+)$");
- private static final Pattern P3 = Pattern.compile("^(\\d+):$");
- private static final Pattern P4 = Pattern.compile("^(\\d+):(\\d+)$");
-
- public boolean shouldIgnoreBasedOnVersion(String firstLine) {
- int thisVersion = getVersion();
- if (!firstLine.startsWith("//version ")) return false;
-
- String spec = firstLine.substring("//version ".length());
-
- /* Single version: '5' */ {
- Matcher m = P1.matcher(spec);
- if (m.matches()) return Integer.parseInt(m.group(1)) != thisVersion;
- }
-
- /* Upper bound: ':5' (inclusive) */ {
- Matcher m = P2.matcher(spec);
- if (m.matches()) return Integer.parseInt(m.group(1)) < thisVersion;
- }
-
- /* Lower bound '5:' (inclusive) */ {
- Matcher m = P3.matcher(spec);
- if (m.matches()) return Integer.parseInt(m.group(1)) > thisVersion;
- }
-
- /* Range '7:8' (inclusive) */ {
- Matcher m = P4.matcher(spec);
- if (m.matches()) {
- if (Integer.parseInt(m.group(1)) < thisVersion) return true;
- if (Integer.parseInt(m.group(2)) > thisVersion) return true;
- return false;
- }
- }
-
- throw new IllegalArgumentException("Version validity spec not valid: " + spec);
- }
}
-
+
private static final FileFilter JAVA_FILE_FILTER = new FileFilter() {
@Override public boolean accept(File file) {
return file.isFile() && file.getName().endsWith(".java");
@@ -180,9 +136,7 @@ public class DirectoryRunner extends Runner {
private boolean runTest(String fileName) throws Throwable {
File file = new File(params.getBeforeDirectory(), fileName);
- if (mustIgnore(file)) {
- return false;
- }
+
switch (params.getCompiler()) {
case DELOMBOK:
return new RunTestsViaDelombok().compareFile(params, file);
@@ -193,11 +147,4 @@ public class DirectoryRunner extends Runner {
throw new UnsupportedOperationException();
}
}
-
- private boolean mustIgnore(File file) throws FileNotFoundException, IOException {
- BufferedReader reader = new BufferedReader(new FileReader(file));
- String line = reader.readLine();
- reader.close();
- return line != null && (line.startsWith("//ignore") || params.shouldIgnoreBasedOnVersion(line));
- }
}
diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java
new file mode 100644
index 00000000..318c5885
--- /dev/null
+++ b/test/core/src/lombok/LombokTestSource.java
@@ -0,0 +1,239 @@
+/*
+ * Copyright (C) 2014 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;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.junit.Assert;
+
+import lombok.core.LombokImmutableList;
+import lombok.core.configuration.BubblingConfigurationResolver;
+import lombok.core.configuration.ConfigurationProblemReporter;
+import lombok.core.configuration.ConfigurationResolver;
+import lombok.core.configuration.StringConfigurationSource;
+
+public class LombokTestSource {
+ private final File file;
+ private final String content;
+ private final LombokImmutableList<CompilerMessageMatcher> messages;
+ private final boolean ignore;
+ private final boolean skipCompareContent;
+ private final int versionLowerLimit, versionUpperLimit;
+ private final ConfigurationResolver configuration;
+
+ public boolean versionWithinLimit(int version) {
+ return version >= versionLowerLimit && version <= versionUpperLimit;
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public LombokImmutableList<CompilerMessageMatcher> getMessages() {
+ return messages;
+ }
+
+ public boolean isIgnore() {
+ return ignore;
+ }
+
+ public boolean isSkipCompareContent() {
+ return skipCompareContent;
+ }
+
+ public ConfigurationResolver getConfiguration() {
+ return configuration;
+ }
+
+ private static final Pattern VERSION_STYLE_1 = Pattern.compile("^(\\d+)$");
+ private static final Pattern VERSION_STYLE_2 = Pattern.compile("^\\:(\\d+)$");
+ private static final Pattern VERSION_STYLE_3 = Pattern.compile("^(\\d+):$");
+ private static final Pattern VERSION_STYLE_4 = Pattern.compile("^(\\d+):(\\d+)$");
+
+ private int[] parseVersionLimit(String spec) {
+ /* Single version: '5' */ {
+ Matcher m = VERSION_STYLE_1.matcher(spec);
+ if (m.matches()) {
+ int v = Integer.parseInt(m.group(1));
+ return new int[] {v, v};
+ }
+ }
+
+ /* Upper bound: ':5' (inclusive) */ {
+ Matcher m = VERSION_STYLE_2.matcher(spec);
+ if (m.matches()) return new int[] {0, Integer.parseInt(m.group(1))};
+ }
+
+ /* Lower bound '5:' (inclusive) */ {
+ Matcher m = VERSION_STYLE_3.matcher(spec);
+ if (m.matches()) return new int[] {Integer.parseInt(m.group(1)), 0};
+ }
+
+ /* Range '7:8' (inclusive) */ {
+ Matcher m = VERSION_STYLE_4.matcher(spec);
+ if (m.matches()) return new int[] {Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2))};
+ }
+
+ return null;
+ }
+
+ private static final Pattern IGNORE_PATTERN = Pattern.compile("^\\s*ignore\\s*(?:[-:].*)?$", Pattern.CASE