aboutsummaryrefslogtreecommitdiff
path: root/test/core
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2013-03-18 23:56:57 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2013-03-18 23:56:57 +0100
commit0ecc23766f18418f28d09291455777d59537ccc3 (patch)
treed10dd239589872230c31e87a9e88a1017b610d40 /test/core
parent5ec852b35b9f6e0f330098a302ce0d655f792ff7 (diff)
downloadlombok-0ecc23766f18418f28d09291455777d59537ccc3.tar.gz
lombok-0ecc23766f18418f28d09291455777d59537ccc3.tar.bz2
lombok-0ecc23766f18418f28d09291455777d59537ccc3.zip
Added a //version option to test files to restrict them to specific versions.
Diffstat (limited to 'test/core')
-rw-r--r--test/core/src/lombok/AbstractRunTests.java2
-rw-r--r--test/core/src/lombok/DirectoryRunner.java74
2 files changed, 73 insertions, 3 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java
index a3f52cdd..d278c5f3 100644
--- a/test/core/src/lombok/AbstractRunTests.java
+++ b/test/core/src/lombok/AbstractRunTests.java
@@ -72,7 +72,7 @@ public abstract class AbstractRunTests {
StringReader r = new StringReader(expectedFile);
BufferedReader br = new BufferedReader(r);
String firstLine = br.readLine();
- if (firstLine != null && firstLine.startsWith("//ignore")) return false;
+ if (firstLine != null && (firstLine.startsWith("//ignore") || params.shouldIgnoreBasedOnVersion(firstLine))) return false;
compare(
file.getName(),
diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java
index 191a7b63..a3b4de00 100644
--- a/test/core/src/lombok/DirectoryRunner.java
+++ b/test/core/src/lombok/DirectoryRunner.java
@@ -29,15 +29,43 @@ 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 org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
+import com.sun.tools.javac.main.JavaCompiler;
+
public class DirectoryRunner extends Runner {
public enum Compiler {
- DELOMBOK, JAVAC, ECJ;
+ DELOMBOK {
+ @Override public int getVersion() {
+ Matcher m = VERSION_PARSER.matcher(JavaCompiler.version());
+ if (m.matches()) {
+ int major = Integer.parseInt(m.group(1));
+ int minor = Integer.parseInt(m.group(2));
+ if (major == 1) return minor;
+ }
+
+ return 6;
+ }
+ },
+ JAVAC {
+ @Override public int getVersion() {
+ return DELOMBOK.getVersion();
+ }
+ },
+ ECJ {
+ @Override public int getVersion() {
+ return 6;
+ }
+ };
+
+ private static final Pattern VERSION_PARSER = Pattern.compile("^(\\d+)\\.(\\d+).*$");
+ public abstract int getVersion();
}
public static abstract class TestParams {
@@ -46,10 +74,52 @@ public class DirectoryRunner extends Runner {
public abstract File getBeforeDirectory();
public abstract File getAfterDirectory();
public abstract File getMessagesDirectory();
+ /** Version of the JDK dialect that the compiler can understand; for example, if you return '7', you should know what try-with-resources is. */
+ public int getVersion() {
+ return getCompiler().getVersion();
+ }
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() {
@@ -135,6 +205,6 @@ public class DirectoryRunner extends Runner {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
reader.close();
- return line != null && line.startsWith("//ignore");
+ return line != null && (line.startsWith("//ignore") || params.shouldIgnoreBasedOnVersion(line));
}
}