From 653eb56883a6be109ee7e767fae920cae70f569d Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 11 Mar 2013 22:06:09 +0100 Subject: changed the pattern for writing dependencies to the various lib/ directories to be organization-name.jar instead of just name.jar, in order to account for the ever lovely and wonderful apache's crazy decision to call the entirely separate log4j v2.0 also 'log4j'. This does mean you'll have to 'ant clean'. --- test/core/src/lombok/RunTestsViaEcj.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test/core') diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 0bf97213..ca443620 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -129,10 +129,11 @@ public class RunTestsViaEcj extends AbstractRunTests { } } classpath.add("dist/lombok.jar"); - classpath.add("lib/test/commons-logging.jar"); - classpath.add("lib/test/slf4j-api.jar"); - classpath.add("lib/test/slf4j-ext.jar"); - classpath.add("lib/test/log4j.jar"); + classpath.add("lib/test/commons-logging-commons-logging.jar"); + classpath.add("lib/test/org.slf4j-slf4j-api.jar"); + classpath.add("lib/test/org.slf4j-slf4j-ext.jar"); + classpath.add("lib/test/log4j-log4j.jar"); + classpath.add("lib/test/org.apache.logging.log4j-log4j-api.jar"); return new FileSystem(classpath.toArray(new String[0]), new String[] {file.getAbsolutePath()}, "UTF-8"); } } -- cgit From 0ecc23766f18418f28d09291455777d59537ccc3 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 18 Mar 2013 23:56:57 +0100 Subject: Added a //version option to test files to restrict them to specific versions. --- test/core/src/lombok/AbstractRunTests.java | 2 +- test/core/src/lombok/DirectoryRunner.java | 74 +++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 3 deletions(-) (limited to 'test/core') 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)); } } -- cgit