aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/src/lombok/AbstractRunTests.java2
-rw-r--r--test/core/src/lombok/DirectoryRunner.java74
-rw-r--r--test/core/src/lombok/RunTestsViaEcj.java9
-rw-r--r--test/pretty/resource/after/TryWithResources.java9
-rw-r--r--test/pretty/resource/before/TryWithResources.java9
-rw-r--r--test/transform/resource/after-delombok/LoggerCommons.java1
-rw-r--r--test/transform/resource/after-delombok/LoggerJul.java1
-rw-r--r--test/transform/resource/after-delombok/LoggerLog4j.java1
-rw-r--r--test/transform/resource/after-delombok/LoggerLog4j2.java6
-rw-r--r--test/transform/resource/after-delombok/LoggerSlf4j.java2
-rw-r--r--test/transform/resource/after-delombok/LoggerXSlf4j.java1
-rw-r--r--test/transform/resource/after-ecj/LoggerLog4j2.java17
-rw-r--r--test/transform/resource/before/LoggerLog4j2.java9
13 files changed, 128 insertions, 13 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));
}
}
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");
}
}
diff --git a/test/pretty/resource/after/TryWithResources.java b/test/pretty/resource/after/TryWithResources.java
new file mode 100644
index 00000000..1a8b82e2
--- /dev/null
+++ b/test/pretty/resource/after/TryWithResources.java
@@ -0,0 +1,9 @@
+//version 7:
+import java.io.PrintWriter;
+public class TryWithResources {
+ {
+ try (final PrintWriter pw = new PrintWriter(System.out);) {
+ pw.println();
+ }
+ }
+}
diff --git a/test/pretty/resource/before/TryWithResources.java b/test/pretty/resource/before/TryWithResources.java
new file mode 100644
index 00000000..eb622f2c
--- /dev/null
+++ b/test/pretty/resource/before/TryWithResources.java
@@ -0,0 +1,9 @@
+//version 7:
+import java.io.PrintWriter;
+public class TryWithResources {
+ {
+ try (PrintWriter pw = new PrintWriter(System.out)) {
+ pw.println();
+ }
+ }
+}
diff --git a/test/transform/resource/after-delombok/LoggerCommons.java b/test/transform/resource/after-delombok/LoggerCommons.java
index c2a03815..dfe3e88d 100644
--- a/test/transform/resource/after-delombok/LoggerCommons.java
+++ b/test/transform/resource/after-delombok/LoggerCommons.java
@@ -1,7 +1,6 @@
class LoggerCommons {
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggerCommons.class);
}
-
class LoggerCommonsWithImport {
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggerCommonsWithImport.class);
} \ No newline at end of file
diff --git a/test/transform/resource/after-delombok/LoggerJul.java b/test/transform/resource/after-delombok/LoggerJul.java
index 39cb2aac..b020c540 100644
--- a/test/transform/resource/after-delombok/LoggerJul.java
+++ b/test/transform/resource/after-delombok/LoggerJul.java
@@ -1,7 +1,6 @@
class LoggerJul {
private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(LoggerJul.class.getName());
}
-
class LoggerJulWithImport {
private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(LoggerJulWithImport.class.getName());
} \ No newline at end of file
diff --git a/test/transform/resource/after-delombok/LoggerLog4j.java b/test/transform/resource/after-delombok/LoggerLog4j.java
index 6892a7d8..dfbad89a 100644
--- a/test/transform/resource/after-delombok/LoggerLog4j.java
+++ b/test/transform/resource/after-delombok/LoggerLog4j.java
@@ -1,7 +1,6 @@
class LoggerLog4j {
private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(LoggerLog4j.class);
}
-
class LoggerLog4jWithImport {
private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(LoggerLog4jWithImport.class);
} \ No newline at end of file
diff --git a/test/transform/resource/after-delombok/LoggerLog4j2.java b/test/transform/resource/after-delombok/LoggerLog4j2.java
new file mode 100644
index 00000000..3447a9a5
--- /dev/null
+++ b/test/transform/resource/after-delombok/LoggerLog4j2.java
@@ -0,0 +1,6 @@
+class LoggerLog4j2 {
+ private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(LoggerLog4j2.class);
+}
+class LoggerLog4j2WithImport {
+ private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(LoggerLog4j2WithImport.class);
+} \ No newline at end of file
diff --git a/test/transform/resource/after-delombok/LoggerSlf4j.java b/test/transform/resource/after-delombok/LoggerSlf4j.java
index cb1486ba..4cc7c107 100644
--- a/test/transform/resource/after-delombok/LoggerSlf4j.java
+++ b/test/transform/resource/after-delombok/LoggerSlf4j.java
@@ -1,11 +1,9 @@
class LoggerSlf4j {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4j.class);
}
-
class LoggerSlf4jWithImport {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jWithImport.class);
}
-
class LoggerSlf4jOuter {
static class Inner {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Inner.class);
diff --git a/test/transform/resource/after-delombok/LoggerXSlf4j.java b/test/transform/resource/after-delombok/LoggerXSlf4j.java
index 0239c60b..7d8f3236 100644
--- a/test/transform/resource/after-delombok/LoggerXSlf4j.java
+++ b/test/transform/resource/after-delombok/LoggerXSlf4j.java
@@ -1,7 +1,6 @@
class LoggerXSlf4j {
private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LoggerXSlf4j.class);
}
-
class LoggerXSlf4jWithImport {
private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LoggerXSlf4jWithImport.class);
} \ No newline at end of file
diff --git a/test/transform/resource/after-ecj/LoggerLog4j2.java b/test/transform/resource/after-ecj/LoggerLog4j2.java
new file mode 100644
index 00000000..c1368e5d
--- /dev/null
+++ b/test/transform/resource/after-ecj/LoggerLog4j2.java
@@ -0,0 +1,17 @@
+import lombok.extern.log4j.Log4j2;
+@lombok.extern.log4j.Log4j2 class LoggerLog4j2 {
+ private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(LoggerLog4j2.class);
+ <clinit>() {
+ }
+ LoggerLog4j2() {
+ super();
+ }
+}
+@Log4j2 class LoggerLog4j2WithImport {
+ private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(LoggerLog4j2WithImport.class);
+ <clinit>() {
+ }
+ LoggerLog4j2WithImport() {
+ super();
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/before/LoggerLog4j2.java b/test/transform/resource/before/LoggerLog4j2.java
new file mode 100644
index 00000000..b7ea99ee
--- /dev/null
+++ b/test/transform/resource/before/LoggerLog4j2.java
@@ -0,0 +1,9 @@
+import lombok.extern.log4j.Log4j2;
+
+@lombok.extern.log4j.Log4j2
+class LoggerLog4j2 {
+}
+
+@Log4j2
+class LoggerLog4j2WithImport {
+} \ No newline at end of file