aboutsummaryrefslogtreecommitdiff
path: root/test/core/src/lombok
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/src/lombok')
-rw-r--r--test/core/src/lombok/AbstractRunTests.java21
-rw-r--r--test/core/src/lombok/DirectoryRunner.java67
-rw-r--r--test/core/src/lombok/RunTestsViaEcj.java19
3 files changed, 87 insertions, 20 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java
index a3f52cdd..2f3f0988 100644
--- a/test/core/src/lombok/AbstractRunTests.java
+++ b/test/core/src/lombok/AbstractRunTests.java
@@ -43,7 +43,6 @@ import java.util.List;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
public abstract class AbstractRunTests {
- protected static final String LINE_SEPARATOR = System.getProperty("line.separator");
private final File dumpActualFilesHere;
public AbstractRunTests() {
@@ -69,10 +68,12 @@ 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 (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;
+ }
compare(
file.getName(),
@@ -92,20 +93,20 @@ public abstract class AbstractRunTests {
try {
reader = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException e) {
- return "";
+ return null;
}
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
- result.append(LINE_SEPARATOR);
+ result.append("\n");
}
reader.close();
return result.toString();
}
private String readFile(File dir, File file, boolean messages) throws IOException {
- if (dir == null) return "";
+ if (dir == null) return null;
return readFile(new File(dir, file.getName() + (messages ? ".messages" : "")));
}
@@ -141,7 +142,9 @@ public abstract class AbstractRunTests {
}
private void compare(String name, String expectedFile, String actualFile, List<CompilerMessageMatcher> expectedMessages, LinkedHashSet<CompilerMessage> actualMessages, boolean printErrors) throws Throwable {
- try {
+ if (expectedFile == null && expectedMessages.isEmpty()) expectedFile = "";
+
+ if (expectedFile != null) try {
compareContent(name, expectedFile, actualFile);
} catch (Throwable e) {
if (printErrors) {
diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java
index 191a7b63..5325c1e3 100644
--- a/test/core/src/lombok/DirectoryRunner.java
+++ b/test/core/src/lombok/DirectoryRunner.java
@@ -29,6 +29,11 @@ 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;
import org.junit.runner.Description;
import org.junit.runner.Runner;
@@ -37,7 +42,23 @@ import org.junit.runner.notification.RunNotifier;
public class DirectoryRunner extends Runner {
public enum Compiler {
- DELOMBOK, JAVAC, ECJ;
+ DELOMBOK {
+ @Override public int getVersion() {
+ return Javac.getJavaCompilerVersion();
+ }
+ },
+ JAVAC {
+ @Override public int getVersion() {
+ return DELOMBOK.getVersion();
+ }
+ },
+ ECJ {
+ @Override public int getVersion() {
+ return Eclipse.getEcjCompilerVersion();
+ }
+ };
+
+ public abstract int getVersion();
}
public static abstract class TestParams {
@@ -46,10 +67,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 +198,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..f7294f1f 100644
--- a/test/core/src/lombok/RunTestsViaEcj.java
+++ b/test/core/src/lombok/RunTestsViaEcj.java
@@ -33,6 +33,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
+import lombok.eclipse.Eclipse;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
@@ -43,7 +44,6 @@ import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
-import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
@@ -51,9 +51,10 @@ import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
public class RunTestsViaEcj extends AbstractRunTests {
protected CompilerOptions ecjCompilerOptions() {
CompilerOptions options = new CompilerOptions();
- options.complianceLevel = ClassFileConstants.JDK1_6;
- options.sourceLevel = ClassFileConstants.JDK1_6;
- options.targetJDK = ClassFileConstants.JDK1_6;
+ options.complianceLevel = Eclipse.getLatestEcjCompilerVersionConstant();
+ options.sourceLevel = Eclipse.getLatestEcjCompilerVersionConstant();
+ options.targetJDK = Eclipse.getLatestEcjCompilerVersionConstant();
+ options.docCommentSupport = false;
options.parseLiteralExpressionsAsConstants = true;
options.inlineJsrBytecode = true;
options.reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable = false;
@@ -64,7 +65,6 @@ public class RunTestsViaEcj extends AbstractRunTests {
options.reportUnusedParameterWhenOverridingConcrete = false;
options.reportDeadCodeInTrivialIfStatement = false;
options.generateClassFiles = false;
- options.docCommentSupport = false;
Map<String, String> warnings = new HashMap<String, String>();
warnings.put(CompilerOptions.OPTION_ReportUnusedLocal, "ignore");
warnings.put(CompilerOptions.OPTION_ReportUnusedLabel, "ignore");
@@ -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");
}
}