aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2015-11-17 00:03:33 +0100
committerRoel Spilker <r.spilker@gmail.com>2015-11-17 00:04:39 +0100
commit9eb70cb3e2043b5262e686b4a80da36e5aa88d81 (patch)
treeb2b9d741169e47785eec216c28f34fdaa5b3b1a4 /test
parent8db179346171d47230b88cdd509954391fb49d1c (diff)
downloadlombok-9eb70cb3e2043b5262e686b4a80da36e5aa88d81.tar.gz
lombok-9eb70cb3e2043b5262e686b4a80da36e5aa88d81.tar.bz2
lombok-9eb70cb3e2043b5262e686b4a80da36e5aa88d81.zip
add the capability to the testing framework to verify that delombok actually also handles the changed flag correctly
Diffstat (limited to 'test')
-rw-r--r--test/core/src/lombok/AbstractRunTests.java7
-rw-r--r--test/core/src/lombok/DirectoryRunner.java4
-rw-r--r--test/core/src/lombok/LombokTestSource.java13
-rw-r--r--test/core/src/lombok/RunTestsViaDelombok.java24
-rw-r--r--test/core/src/lombok/RunTestsViaEcj.java4
-rw-r--r--test/transform/resource/after-ecj/LoggerSlf4jOnNonType.java7
-rw-r--r--test/transform/resource/before/JavadocGenerally.java1
-rw-r--r--test/transform/resource/before/TestOperators.java1
-rw-r--r--test/transform/resource/before/TrickyTypeResolution2.java1
-rw-r--r--test/transform/resource/before/ValErrors.java1
-rw-r--r--test/transform/resource/before/ValInBasicFor.java1
-rw-r--r--test/transform/resource/before/WithInnerAnnotation.java1
-rw-r--r--test/transform/resource/messages-delombok/ValErrors.java.messages4
-rw-r--r--test/transform/resource/messages-delombok/ValInBasicFor.java.messages2
-rw-r--r--test/transform/resource/messages-ecj/ValErrors.java.messages4
-rw-r--r--test/transform/resource/messages-ecj/ValInBasicFor.java.messages4
-rw-r--r--test/transform/src/lombok/transform/TestLombokFilesIdempotent.java7
-rw-r--r--test/transform/src/lombok/transform/TestSourceFiles.java7
-rw-r--r--test/transform/src/lombok/transform/TestWithDelombok.java7
-rw-r--r--test/transform/src/lombok/transform/TestWithEcj.java7
20 files changed, 83 insertions, 24 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java
index 4e1c83dd..85c3674f 100644
--- a/test/core/src/lombok/AbstractRunTests.java
+++ b/test/core/src/lombok/AbstractRunTests.java
@@ -76,7 +76,10 @@ public abstract class AbstractRunTests {
}
});
- transformCode(messages, writer, file, sourceDirectives.getSpecifiedEncoding(), sourceDirectives.getFormatPreferences());
+ boolean changed = transformCode(messages, writer, file, sourceDirectives.getSpecifiedEncoding(), sourceDirectives.getFormatPreferences());
+ boolean forceUnchanged = sourceDirectives.forceUnchanged() || sourceDirectives.isSkipCompareContent();
+ if (params.expectChanges() && !forceUnchanged && !changed) messages.add(new CompilerMessage(-1, -1, true, "not flagged modified"));
+ if (!params.expectChanges() && changed) messages.add(new CompilerMessage(-1, -1, true, "unexpected modification"));
compare(file.getName(), expected, writer.toString(), messages, params.printErrors(), sourceDirectives.isSkipCompareContent() || expected.isSkipCompareContent());
return true;
@@ -98,7 +101,7 @@ public abstract class AbstractRunTests {
return 8;
}
- protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences) throws Throwable;
+ protected abstract boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences) throws Throwable;
protected String readFile(File file) throws IOException {
BufferedReader reader;
diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java
index 9062f523..c1758c57 100644
--- a/test/core/src/lombok/DirectoryRunner.java
+++ b/test/core/src/lombok/DirectoryRunner.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2014 The Project Lombok Authors.
+ * Copyright (C) 2009-2015 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
@@ -69,6 +69,8 @@ public class DirectoryRunner extends Runner {
public boolean accept(File file) {
return true;
}
+
+ public abstract boolean expectChanges();
}
private static final FileFilter JAVA_FILE_FILTER = new FileFilter() {
diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java
index 1f3f5e1a..cd7cd166 100644
--- a/test/core/src/lombok/LombokTestSource.java
+++ b/test/core/src/lombok/LombokTestSource.java
@@ -51,6 +51,7 @@ public class LombokTestSource {
private final Map<String, String> formatPreferences;
private final boolean ignore;
private final boolean skipCompareContent;
+ private final boolean unchanged;
private final int versionLowerLimit, versionUpperLimit;
private final ConfigurationResolver configuration;
private final String specifiedEncoding;
@@ -75,6 +76,10 @@ public class LombokTestSource {
return ignore;
}
+ public boolean forceUnchanged() {
+ return unchanged;
+ }
+
public boolean isSkipCompareContent() {
return skipCompareContent;
}
@@ -124,6 +129,7 @@ public class LombokTestSource {
}
private static final Pattern IGNORE_PATTERN = Pattern.compile("^\\s*ignore\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE);
+ private static final Pattern UNCHANGED_PATTERN = Pattern.compile("^\\s*unchanged\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE);
private static final Pattern SKIP_COMPARE_CONTENT_PATTERN = Pattern.compile("^\\s*skip[- ]?compare[- ]?content\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE);
private LombokTestSource(File file, String content, List<CompilerMessageMatcher> messages, List<String> directives) {
@@ -136,6 +142,7 @@ public class LombokTestSource {
int versionUpper = Integer.MAX_VALUE;
boolean ignore = false;
boolean skipCompareContent = false;
+ boolean unchanged = false;
String encoding = null;
Map<String, String> formats = new HashMap<String, String>();
@@ -147,6 +154,11 @@ public class LombokTestSource {
continue;
}
+ if (UNCHANGED_PATTERN.matcher(directive).matches()) {
+ unchanged = true;
+ continue;
+ }
+
if (SKIP_COMPARE_CONTENT_PATTERN.matcher(directive).matches()) {
skipCompareContent = true;
continue;
@@ -194,6 +206,7 @@ public class LombokTestSource {
this.versionUpperLimit = versionUpper;
this.ignore = ignore;
this.skipCompareContent = skipCompareContent;
+ this.unchanged = unchanged;
ConfigurationProblemReporter reporter = new ConfigurationProblemReporter() {
@Override public void report(String sourceDescription, String problem, int lineNumber, CharSequence line) {
Assert.fail("Problem on directive line: " + problem + " at conf line #" + lineNumber + " (" + line + ")");
diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java
index 8ec41ef1..0887de32 100644
--- a/test/core/src/lombok/RunTestsViaDelombok.java
+++ b/test/core/src/lombok/RunTestsViaDelombok.java
@@ -21,8 +21,11 @@
*/
package lombok;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.PrintStream;
import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Locale;
import java.util.Map;
@@ -35,8 +38,10 @@ public class RunTestsViaDelombok extends AbstractRunTests {
private Delombok delombok = new Delombok();
@Override
- public void transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding, Map<String, String> formatPreferences) throws Throwable {
- delombok.setVerbose(false);
+ public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding, Map<String, String> formatPreferences) throws Throwable {
+ delombok.setVerbose(true);
+ ChangedChecker cc = new ChangedChecker();
+ delombok.setFeedback(cc.feedback);
delombok.setForceProcess(true);
delombok.setCharset(encoding == null ? "UTF-8" : encoding);
delombok.setFormatPreferences(formatPreferences);
@@ -52,8 +57,23 @@ public class RunTestsViaDelombok extends AbstractRunTests {
try {
Locale.setDefault(Locale.ENGLISH);
delombok.delombok();
+ return cc.isChanged();
} finally {
Locale.setDefault(originalLocale);
}
}
+
+ static class ChangedChecker {
+ private final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ private final PrintStream feedback;
+
+ ChangedChecker() throws UnsupportedEncodingException {
+ feedback = new PrintStream(bytes, true, "UTF-8");
+ }
+
+ boolean isChanged() throws UnsupportedEncodingException {
+ feedback.flush();
+ return bytes.toString("UTF-8").endsWith("[delomboked]\n");
+ }
+ }
}
diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java
index 272ed8b7..75200223 100644
--- a/test/core/src/lombok/RunTestsViaEcj.java
+++ b/test/core/src/lombok/RunTestsViaEcj.java
@@ -93,7 +93,7 @@ public class RunTestsViaEcj extends AbstractRunTests {
}
@Override
- public void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences) throws Throwable {
+ public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences) throws Throwable {
final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>();
final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>();
ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() {
@@ -125,6 +125,8 @@ public class RunTestsViaEcj extends AbstractRunTests {
if (cud == null) result.append("---- NO CompilationUnit provided by ecj ----");
else result.append(cud.toString());
+
+ return true;
}
private FileSystem createFileSystem(File file) {
diff --git a/test/transform/resource/after-ecj/LoggerSlf4jOnNonType.java b/test/transform/resource/after-ecj/LoggerSlf4jOnNonType.java
deleted file mode 100644
index f0c2ee58..00000000
--- a/test/transform/resource/after-ecj/LoggerSlf4jOnNonType.java
+++ /dev/null
@@ -1,7 +0,0 @@
-class LoggerSlf4jOnNonType {
- LoggerSlf4jOnNonType() {
- super();
- }
- @lombok.extern.slf4j.Slf4j void foo() {
- }
-} \ No newline at end of file
diff --git a/test/transform/resource/before/JavadocGenerally.java b/test/transform/resource/before/JavadocGenerally.java
index ee015acf..e47de44d 100644
--- a/test/transform/resource/before/JavadocGenerally.java
+++ b/test/transform/resource/before/JavadocGenerally.java
@@ -1,3 +1,4 @@
+// unchanged
/**
* Doc on package
*/
diff --git a/test/transform/resource/before/TestOperators.java b/test/transform/resource/before/TestOperators.java
index 566bedfc..de384122 100644
--- a/test/transform/resource/before/TestOperators.java
+++ b/test/transform/resource/before/TestOperators.java
@@ -1,3 +1,4 @@
+// unchanged
class TestOperators {
int x = 10;
public void test() {
diff --git a/test/transform/resource/before/TrickyTypeResolution2.java b/test/transform/resource/before/TrickyTypeResolution2.java
index 00f2ac39..6dfddee0 100644
--- a/test/transform/resource/before/TrickyTypeResolution2.java
+++ b/test/transform/resource/before/TrickyTypeResolution2.java
@@ -1,3 +1,4 @@
+// unchanged
import lombok.*;
class DoNothingDueToTopLevel {
void test() {
diff --git a/test/transform/resource/before/ValErrors.java b/test/transform/resource/before/ValErrors.java
index 96181638..87383719 100644
--- a/test/transform/resource/before/ValErrors.java
+++ b/test/transform/resource/before/ValErrors.java
@@ -1,3 +1,4 @@
+// unchanged
import lombok.val;
public class ValErrors {
diff --git a/test/transform/resource/before/ValInBasicFor.java b/test/transform/resource/before/ValInBasicFor.java
index 1f132b8f..a109bcd3 100644
--- a/test/transform/resource/before/ValInBasicFor.java
+++ b/test/transform/resource/before/ValInBasicFor.java
@@ -1,3 +1,4 @@
+// unchanged
import lombok.val;
public class ValInBasicFor {
diff --git a/test/transform/resource/before/WithInnerAnnotation.java b/test/transform/resource/before/WithInnerAnnotation.java
index a8decfeb..dca1f269 100644
--- a/test/transform/resource/before/WithInnerAnnotation.java
+++ b/test/transform/resource/before/WithInnerAnnotation.java
@@ -1,3 +1,4 @@
+// unchanged
class WithInnerAnnotation {
@interface Inner {
int bar() default 42;
diff --git a/test/transform/resource/messages-delombok/ValErrors.java.messages b/test/transform/resource/messages-delombok/ValErrors.java.messages
index bb33c6de..0777143b 100644
--- a/test/transform/resource/messages-delombok/ValErrors.java.messages
+++ b/test/transform/resource/messages-delombok/ValErrors.java.messages
@@ -1,2 +1,2 @@
-5 Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved
-9 'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })
+6 Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved
+10 'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })
diff --git a/test/transform/resource/messages-delombok/ValInBasicFor.java.messages b/test/transform/resource/messages-delombok/ValInBasicFor.java.messages
index 7166b550..60f8f70c 100644
--- a/test/transform/resource/messages-delombok/ValInBasicFor.java.messages
+++ b/test/transform/resource/messages-delombok/ValInBasicFor.java.messages
@@ -1 +1 @@
-6 'val' is not allowed in old-style for loops
+7 'val' is not allowed in old-style for loops
diff --git a/test/transform/resource/messages-ecj/ValErrors.java.messages b/test/transform/resource/messages-ecj/ValErrors.java.messages
index 6d53ddd6..c4c76901 100644
--- a/test/transform/resource/messages-ecj/ValErrors.java.messages
+++ b/test/transform/resource/messages-ecj/ValErrors.java.messages
@@ -1,2 +1,2 @@
-5 d cannot be resolved to a variable
-9 'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })
+6 d cannot be resolved to a variable
+10 'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })
diff --git a/test/transform/resource/messages-ecj/ValInBasicFor.java.messages b/test/transform/resource/messages-ecj/ValInBasicFor.java.messages
index c75e20f2..b32eabe4 100644
--- a/test/transform/resource/messages-ecj/ValInBasicFor.java.messages
+++ b/test/transform/resource/messages-ecj/ValInBasicFor.java.messages
@@ -1,2 +1,2 @@
-6 'val' is not allowed in old-style for loops
-6 Type mismatch: cannot convert from int to val
+7 'val' is not allowed in old-style for loops
+7 Type mismatch: cannot convert from int to val
diff --git a/test/transform/src/lombok/transform/TestLombokFilesIdempotent.java b/test/transform/src/lombok/transform/TestLombokFilesIdempotent.java
index d2909943..754a4237 100644
--- a/test/transform/src/lombok/transform/TestLombokFilesIdempotent.java
+++ b/test/transform/src/lombok/transform/TestLombokFilesIdempotent.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2010 The Project Lombok Authors.
+ * Copyright (C) 2009-2015 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
@@ -53,4 +53,9 @@ public class TestLombokFilesIdempotent extends DirectoryRunner.TestParams {
public boolean printErrors() {
return true;
}
+
+ @Override
+ public boolean expectChanges() {
+ return false;
+ }
}
diff --git a/test/transform/src/lombok/transform/TestSourceFiles.java b/test/transform/src/lombok/transform/TestSourceFiles.java
index c3ac0a68..17be133e 100644
--- a/test/transform/src/lombok/transform/TestSourceFiles.java
+++ b/test/transform/src/lombok/transform/TestSourceFiles.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2010 The Project Lombok Authors.
+ * Copyright (C) 2009-2015 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
@@ -53,4 +53,9 @@ public class TestSourceFiles extends DirectoryRunner.TestParams {
public File getMessagesDirectory() {
return null;
}
+
+ @Override
+ public boolean expectChanges() {
+ return false;
+ }
}
diff --git a/test/transform/src/lombok/transform/TestWithDelombok.java b/test/transform/src/lombok/transform/TestWithDelombok.java
index bd8d9d09..9f4cf94a 100644
--- a/test/transform/src/lombok/transform/TestWithDelombok.java
+++ b/test/transform/src/lombok/transform/TestWithDelombok.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2010 The Project Lombok Authors.
+ * Copyright (C) 2009-2015 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
@@ -53,4 +53,9 @@ public class TestWithDelombok extends DirectoryRunner.TestParams {
public File getMessagesDirectory() {
return new File("test/transform/resource/messages-delombok");
}
+
+ @Override
+ public boolean expectChanges() {
+ return true;
+ }
}
diff --git a/test/transform/src/lombok/transform/TestWithEcj.java b/test/transform/src/lombok/transform/TestWithEcj.java
index 0a4057dd..3df8dc8b 100644
--- a/test/transform/src/lombok/transform/TestWithEcj.java
+++ b/test/transform/src/lombok/transform/TestWithEcj.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2012 The Project Lombok Authors.
+ * Copyright (C) 2009-2015 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
@@ -57,4 +57,9 @@ public class TestWithEcj extends DirectoryRunner.TestParams {
public File getMessagesDirectory() {
return new File("test/transform/resource/messages-ecj");
}
+
+ @Override
+ public boolean expectChanges() {
+ return true;
+ }
}