mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 08:18:29 +00:00
[test-directives] another update to the 'test directives' system; test files now can start with directives (configuration keys, 'ignore', and java language version limits), and the test directory runner now has a framework to handle these. All existing tests pass at this point.
This commit is contained in:
1 parent
f6da35e4c4
commit
c65ec96943
3 files changed
+25
-13
No files matched your search
@@ -53,14 +53,13 @@ public abstract class AbstractRunTests {
|
||||
String fileName = file.getName();
|
||||
LombokTestSource expected = LombokTestSource.read(params.getAfterDirectory(), params.getMessagesDirectory(), fileName);
|
||||
|
||||
if (expected.isIgnore() || expected.versionWithinLimit(params.getVersion())) return false;
|
||||
if (expected.isIgnore() || !expected.versionWithinLimit(params.getVersion())) return false;
|
||||
|
||||
LinkedHashSet<CompilerMessage> messages = new LinkedHashSet<CompilerMessage>();
|
||||
StringWriter writer = new StringWriter();
|
||||
transformCode(messages, writer, file, sourceDirectives.getConfLines());
|
||||
|
||||
compare(file.getName(), expected, writer.toString(), messages, params.printErrors());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -186,15 +185,21 @@ public abstract class AbstractRunTests {
|
||||
private static void compareContent(String name, String expectedFile, String actualFile) {
|
||||
String[] expectedLines = expectedFile.split("(\\r?\\n)");
|
||||
String[] actualLines = actualFile.split("(\\r?\\n)");
|
||||
if (expectedLines[0].startsWith("// Generated by delombok at ")) {
|
||||
expectedLines[0] = "";
|
||||
|
||||
for (int i = 0; i < expectedLines.length; i++) {
|
||||
if (expectedLines[i].isEmpty() || expectedLines[i].startsWith("//")) expectedLines[i] = "";
|
||||
else break;
|
||||
}
|
||||
if (actualLines[0].startsWith("// Generated by delombok at ")) {
|
||||
actualLines[0] = "";
|
||||
for (int i = 0; i < actualLines.length; i++) {
|
||||
if (actualLines[i].isEmpty() || actualLines[i].startsWith("//")) actualLines[i] = "";
|
||||
else break;
|
||||
}
|
||||
expectedLines = removeBlanks(expectedLines);
|
||||
actualLines = removeBlanks(actualLines);
|
||||
|
||||
int size = Math.min(expectedLines.length, actualLines.length);
|
||||
if (size == 0) return;
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
String expected = expectedLines[i];
|
||||
String actual = actualLines[i];
|
||||
|
||||
@@ -24,6 +24,7 @@ package lombok;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
@@ -99,6 +100,7 @@ public class LombokTestSource {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final Pattern IGNORE_PATTERN = Pattern.compile("^\\s*ignore\\s*(?:[:-].*)?$", Pattern.CASE_INSENSITIVE);
|
||||
private LombokTestSource(File file, String content, List<CompilerMessageMatcher> messages, List<String> directives) {
|
||||
this.file = file;
|
||||
this.content = content;
|
||||
@@ -112,7 +114,7 @@ public class LombokTestSource {
|
||||
for (String directive : directives) {
|
||||
directive = directive.trim();
|
||||
String lc = directive.toLowerCase();
|
||||
if (lc.equals("ignore")) {
|
||||
if (IGNORE_PATTERN.matcher(directive).matches()) {
|
||||
ignore = true;
|
||||
continue;
|
||||
}
|
||||
@@ -191,16 +193,20 @@ public class LombokTestSource {
|
||||
}
|
||||
in.close();
|
||||
rawIn.close();
|
||||
} else {
|
||||
content = new StringBuilder();
|
||||
}
|
||||
|
||||
if (content == null) 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();
|
||||
File messagesFile = new File(messagesFolder, fileName + ".messages");
|
||||
try {
|
||||
@Cleanup val rawIn = new FileInputStream(messagesFile);
|
||||
messages = CompilerMessageMatcher.readAll(rawIn);
|
||||
rawIn.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
messages = null;
|
||||
}
|
||||
}
|
||||
|
||||
return new LombokTestSource(sourceFile, content.toString(), messages, directives);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
//ignore: This is a J7 feature that isn't turned on in the ecj variant we use to run the tests. We need to update that ecj at some point and enable this test.
|
||||
Reference in new issue
Block a user