aboutsummaryrefslogtreecommitdiff
path: root/test/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/src')
-rw-r--r--test/core/src/lombok/AbstractRunTests.java69
-rw-r--r--test/core/src/lombok/DirectoryRunner.java59
-rw-r--r--test/core/src/lombok/LombokTestSource.java208
-rw-r--r--test/core/src/lombok/RunTestsViaDelombok.java7
-rw-r--r--test/core/src/lombok/RunTestsViaEcj.java7
5 files changed, 241 insertions, 109 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java
index 2f3f0988..91f22502 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,18 @@ 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 lombok.core.LombokImmutableList;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
public abstract class AbstractRunTests {
@@ -50,43 +47,24 @@ public abstract class AbstractRunTests {
}
public boolean compareFile(DirectoryRunner.TestParams params, File file) throws Throwable {
+ LombokTestSource sourceDirectives = LombokTestSource.readDirectives(file);
+ if (sourceDirectives.isIgnore()) 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.
- }
- }
+ transformCode(messages, writer, file, sourceDirectives.getConfLines());
- 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(),
- expectedFile,
- writer.toString(),
- expectedMessages,
- messages,
- params.printErrors());
+ compare(file.getName(), expected, writer.toString(), messages, params.printErrors());
return true;
}
- protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file) throws Throwable;
+ protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, LombokImmutableList<String> confLines) throws Throwable;
protected String readFile(File file) throws IOException {
BufferedReader reader;
@@ -105,11 +83,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 +114,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) throws Throwable {
+ if (expected.getContent() != null) 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 +140,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 +162,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();
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..e4174c08
--- /dev/null
+++ b/test/core/src/lombok/LombokTestSource.java
@@ -0,0 +1,208 @@
+/*
+ * 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.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.junit.Assert;
+
+import lombok.core.LombokImmutableList;
+
+public class LombokTestSource {
+ private final File file;
+ private final String content;
+ private final LombokImmutableList<CompilerMessageMatcher> messages;
+ private final boolean ignore;
+ private final int versionLowerLimit, versionUpperLimit;
+ private final LombokImmutableList<String> confLines;
+
+ 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 LombokImmutableList<String> getConfLines() {
+ return confLines;
+ }
+
+ 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 LombokTestSource(File file, String content, List<CompilerMessageMatcher> messages, List<String> directives) {
+ this.file = file;
+ this.content = content;
+ this.messages = messages == null ? LombokImmutableList.<CompilerMessageMatcher>of() : LombokImmutableList.copyOf(messages);
+
+ List<String> conf = new ArrayList<String>();
+ int versionLower = 0;
+ int versionUpper = Integer.MAX_VALUE;
+ boolean ignore = false;
+
+ for (String directive : directives) {
+ directive = directive.trim();
+ String lc = directive.toLowerCase();
+ if (lc.equals("ignore")) {
+ ignore = true;
+ continue;
+ }
+
+ if (lc.startsWith("version ")) {
+ int[] limits = parseVersionLimit(lc.substring(7).trim());
+ if (limits == null) {
+ Assert.fail("Directive line \"" + directive + "\" in '" + file.getAbsolutePath() + "' invalid: version must be followed by a single integer.");
+ throw new RuntimeException();
+ }
+ versionLower = limits[0];
+ versionUpper = limits[1];
+ continue;
+ }
+
+ if (lc.startsWith("conf:")) {
+ String confLine = directive.substring(5).trim();
+ conf.add(confLine);
+ continue;
+ }
+
+ Assert.fail("Directive line \"" + directive + "\" in '" + file.getAbsolutePath() + "' invalid: unrecognized directive.");
+ throw new RuntimeException();
+ }
+
+ this.versionLowerLimit = versionLower;
+ this.versionUpperLimit = versionUpper;
+ this.ignore = ignore;
+ this.confLines = LombokImmutableList.copyOf(conf);
+ }
+
+ public static LombokTestSource readDirectives(File file) throws IOException {
+ List<String> directives = new ArrayList<String>();
+
+ {
+ @Cleanup val rawIn = new FileInputStream(file);
+ BufferedReader in = new BufferedReader(new InputStreamReader(rawIn, "UTF-8"));
+ for (String i = in.readLine(); i != null; i = in.readLine()) {
+ if (i.isEmpty()) continue;
+
+ if (i.startsWith("//")) {
+ directives.add(i.substring(2));
+ } else {
+ break;
+ }
+ }
+ in.close();
+ rawIn.close();
+ }
+
+ return new LombokTestSource(file, "", null, directives);
+ }
+
+ public static LombokTestSource read(File sourceFolder, File messagesFolder, String fileName) throws IOException {
+ StringBuilder content = null;
+ List<String> directives = new ArrayList<String>();
+
+ File sourceFile = new File(sourceFolder, fileName);
+ if (sourceFile.exists()) {
+ @Cleanup val rawIn = new FileInputStream(sourceFile);
+ BufferedReader in = new BufferedReader(new InputStreamReader(rawIn, "UTF-8"));
+ for (String i = in.readLine(); i != null; i = in.readLine()) {
+ if (content != null) {
+ content.append(i).append("\n");
+ continue;
+ }
+
+ if (i.isEmpty()) continue;
+
+ if (i.startsWith("//")) {
+ directives.add(i.substring(2));
+ } else {
+ content = new StringBuilder();
+ content.append(i).append("\n");
+ }
+ }
+ in.close();
+ rawIn.close();
+ } else {
+ content = new StringBuilder();
+ }
+
+ List<CompilerMessageMatcher> messages = null;
+ if (messagesFolder != null) {
+ File messagesFile = new File(messagesFolder, fileName);
+ @Cleanup val rawIn = new FileInputStream(messagesFile);
+ messages = CompilerMessageMatcher.readAll(rawIn);
+ rawIn.close();
+ }
+
+ return new LombokTestSource(sourceFile, content.toString(), messages, directives);
+ }
+}
diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java
index 17665173..f19ad15d 100644
--- a/test/core/src/lombok/RunTestsViaDelombok.java
+++ b/test/core/src/lombok/RunTestsViaDelombok.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
@@ -26,6 +26,7 @@ import java.io.StringWriter;
import java.util.Collection;
import java.util.Locale;
+import lombok.core.LombokImmutableList;
import lombok.delombok.Delombok;
import lombok.javac.CapturingDiagnosticListener;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
@@ -34,13 +35,15 @@ public class RunTestsViaDelombok extends AbstractRunTests {
private Delombok delombok = new Delombok();
@Override
- public void transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file) throws Throwable {
+ public void transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, LombokImmutableList<String> confLines) throws Throwable {
delombok.setVerbose(false);
delombok.setForceProcess(true);
delombok.setCharset("UTF-8");
delombok.setDiagnosticsListener(new CapturingDiagnosticListener(file, messages));
+ // TODO: Create a configuration based on confLines and set this up so that this compile run will use them.
+
delombok.addFile(file.getAbsoluteFile().getParentFile(), file.getName());
delombok.setSourcepath(file.getAbsoluteFile().getParent());
String bcp = System.getProperty("delombok.bootclasspath");
diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java
index 586c124a..36f9be49 100644
--- a/test/core/src/lombok/RunTestsViaEcj.java
+++ b/test/core/src/lombok/RunTestsViaEcj.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2013 The Project Lombok Authors.
+ * Copyright (C) 2010-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
@@ -33,6 +33,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
+import lombok.core.LombokImmutableList;
import lombok.eclipse.Eclipse;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
@@ -87,7 +88,7 @@ public class RunTestsViaEcj extends AbstractRunTests {
}
@Override
- public void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file) throws Throwable {
+ public void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, LombokImmutableList<String> confLines) throws Throwable {
final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>();
final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>();
ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() {
@@ -106,6 +107,8 @@ public class RunTestsViaEcj extends AbstractRunTests {
}
};
+ // TODO: Create a configuration based on confLines and set this up so that this compile run will use them.
+
ecjCompiler.compile(new ICompilationUnit[] {sourceUnit});
CompilationResult compilationResult = compilationResult_.get();