aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/src/lombok/AbstractRunTests.java4
-rw-r--r--test/core/src/lombok/LombokTestSource.java32
-rw-r--r--test/core/src/lombok/RunTestsViaDelombok.java4
-rw-r--r--test/core/src/lombok/RunTestsViaEcj.java4
-rw-r--r--test/transform/resource/after-delombok/EncodingUsAscii.java9
-rw-r--r--test/transform/resource/after-delombok/EncodingUtf8.java8
-rw-r--r--test/transform/resource/after-ecj/EncodingUsAscii.java1
-rw-r--r--test/transform/resource/after-ecj/EncodingUtf8.java9
-rw-r--r--test/transform/resource/before/EncodingUsAscii.java5
-rw-r--r--test/transform/resource/before/EncodingUtf8.java5
10 files changed, 71 insertions, 10 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java
index a1f535b4..85d4d4f3 100644
--- a/test/core/src/lombok/AbstractRunTests.java
+++ b/test/core/src/lombok/AbstractRunTests.java
@@ -75,7 +75,7 @@ public abstract class AbstractRunTests {
}
});
- transformCode(messages, writer, file);
+ transformCode(messages, writer, file, sourceDirectives.getSpecifiedEncoding());
compare(file.getName(), expected, writer.toString(), messages, params.printErrors(), sourceDirectives.isSkipCompareContent() || expected.isSkipCompareContent());
return true;
@@ -97,7 +97,7 @@ public abstract class AbstractRunTests {
return 8;
}
- protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file) throws Throwable;
+ protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding) throws Throwable;
protected String readFile(File file) throws IOException {
BufferedReader reader;
diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java
index 402001e9..f31d7be7 100644
--- a/test/core/src/lombok/LombokTestSource.java
+++ b/test/core/src/lombok/LombokTestSource.java
@@ -49,7 +49,8 @@ public class LombokTestSource {
private final boolean skipCompareContent;
private final int versionLowerLimit, versionUpperLimit;
private final ConfigurationResolver configuration;
-
+ private final String specifiedEncoding;
+
public boolean versionWithinLimit(int version) {
return version >= versionLowerLimit && version <= versionUpperLimit;
}
@@ -74,6 +75,10 @@ public class LombokTestSource {
return skipCompareContent;
}
+ public String getSpecifiedEncoding() {
+ return specifiedEncoding;
+ }
+
public ConfigurationResolver getConfiguration() {
return configuration;
}
@@ -123,6 +128,7 @@ public class LombokTestSource {
int versionUpper = Integer.MAX_VALUE;
boolean ignore = false;
boolean skipCompareContent = false;
+ String encoding = null;
for (String directive : directives) {
directive = directive.trim();
@@ -154,10 +160,15 @@ public class LombokTestSource {
continue;
}
+ if (lc.startsWith("encoding:")) {
+ encoding = directive.substring(9).trim();
+ continue;
+ }
+
Assert.fail("Directive line \"" + directive + "\" in '" + file.getAbsolutePath() + "' invalid: unrecognized directive.");
throw new RuntimeException();
}
-
+ this.specifiedEncoding = encoding;
this.versionLowerLimit = versionLower;
this.versionUpperLimit = versionUpper;
this.ignore = ignore;
@@ -194,13 +205,17 @@ public class LombokTestSource {
}
public static LombokTestSource read(File sourceFolder, File messagesFolder, String fileName) throws IOException {
+ return read0(sourceFolder, messagesFolder, fileName, "UTF-8");
+ }
+
+ private static LombokTestSource read0(File sourceFolder, File messagesFolder, String fileName, String encoding) 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"));
+ BufferedReader in = new BufferedReader(new InputStreamReader(rawIn, encoding));
for (String i = in.readLine(); i != null; i = in.readLine()) {
if (content != null) {
content.append(i).append("\n");
@@ -234,6 +249,15 @@ public class LombokTestSource {
}
}
- return new LombokTestSource(sourceFile, content.toString(), messages, directives);
+ LombokTestSource source = new LombokTestSource(sourceFile, content.toString(), messages, directives);
+ String specifiedEncoding = source.getSpecifiedEncoding();
+
+ // The source file has an 'encoding' header to test encoding issues. Of course, reading the encoding header
+ // requires knowing the encoding of the file first. In practice we get away with it, because UTF-8 and US-ASCII are compatible enough.
+ // The fix is therefore to read in as UTF-8 initially, and if the file requests that it should be read as another encoding, toss it all
+ // and reread that way.
+
+ if (specifiedEncoding == null || specifiedEncoding.equalsIgnoreCase(encoding)) return source;
+ return read0(sourceFolder, messagesFolder, fileName, specifiedEncoding);
}
}
diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java
index 6a08642b..1482c865 100644
--- a/test/core/src/lombok/RunTestsViaDelombok.java
+++ b/test/core/src/lombok/RunTestsViaDelombok.java
@@ -34,10 +34,10 @@ 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, String encoding) throws Throwable {
delombok.setVerbose(false);
delombok.setForceProcess(true);
- delombok.setCharset("UTF-8");
+ delombok.setCharset(encoding == null ? "UTF-8" : encoding);
delombok.setDiagnosticsListener(new CapturingDiagnosticListener(file, messages));
diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java
index 90dabcde..2b83b296 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) throws Throwable {
+ public void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding) throws Throwable {
final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>();
final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>();
ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() {
@@ -103,7 +103,7 @@ public class RunTestsViaEcj extends AbstractRunTests {
};
String source = readFile(file);
- final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), "UTF-8");
+ final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), encoding == null ? "UTF-8" : encoding);
Compiler ecjCompiler = new Compiler(createFileSystem(file), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) {
@Override protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) {
diff --git a/test/transform/resource/after-delombok/EncodingUsAscii.java b/test/transform/resource/after-delombok/EncodingUsAscii.java
new file mode 100644
index 00000000..a9e6b1a5
--- /dev/null
+++ b/test/transform/resource/after-delombok/EncodingUsAscii.java
@@ -0,0 +1,9 @@
+//ENCODING: US-ASCII
+class EncodingUsAscii {
+ String foo\u0e51\u0e51 = "\016\t\b ";
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public java.lang.String toString() {
+ return "EncodingUsAscii(foo\u0e51\u0e51=" + this.foo\u0e51\u0e51 + ")";
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/after-delombok/EncodingUtf8.java b/test/transform/resource/after-delombok/EncodingUtf8.java
new file mode 100644
index 00000000..9ae3e30a
--- /dev/null
+++ b/test/transform/resource/after-delombok/EncodingUtf8.java
@@ -0,0 +1,8 @@
+class EncodingUtf8 {
+ String foo๑๑ = "\016\t\b ";
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public java.lang.String toString() {
+ return "EncodingUtf8(foo๑๑=" + this.foo๑๑ + ")";
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/after-ecj/EncodingUsAscii.java b/test/transform/resource/after-ecj/EncodingUsAscii.java
new file mode 100644
index 00000000..b66feb0c
--- /dev/null
+++ b/test/transform/resource/after-ecj/EncodingUsAscii.java
@@ -0,0 +1 @@
+//ignore: This test serves to check what happens with 'weird' characters when you use delombok. It's just not relevant for ecj.
diff --git a/test/transform/resource/after-ecj/EncodingUtf8.java b/test/transform/resource/after-ecj/EncodingUtf8.java
new file mode 100644
index 00000000..5a7a1644
--- /dev/null
+++ b/test/transform/resource/after-ecj/EncodingUtf8.java
@@ -0,0 +1,9 @@
+@lombok.ToString class EncodingUtf8 {
+ String foo๑๑ = "\t\b ";
+ EncodingUtf8() {
+ super();
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
+ return (("EncodingUtf8(foo๑๑=" + this.foo๑๑) + ")");
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/before/EncodingUsAscii.java b/test/transform/resource/before/EncodingUsAscii.java
new file mode 100644
index 00000000..dbcd150b
--- /dev/null
+++ b/test/transform/resource/before/EncodingUsAscii.java
@@ -0,0 +1,5 @@
+//ENCODING: US-ASCII
+@lombok.ToString
+class EncodingUsAscii {
+ String foo\u0e51\u0e51 = "\u000e \10 ";
+} \ No newline at end of file
diff --git a/test/transform/resource/before/EncodingUtf8.java b/test/transform/resource/before/EncodingUtf8.java
new file mode 100644
index 00000000..75b0ee00
--- /dev/null
+++ b/test/transform/resource/before/EncodingUtf8.java
@@ -0,0 +1,5 @@
+//ENCODING: UTF-8
+@lombok.ToString
+class EncodingUtf8 {
+ String foo\u0e51๑ = "\u000e \10 ";
+} \ No newline at end of file