aboutsummaryrefslogtreecommitdiff
path: root/test/core/src/lombok
diff options
context:
space:
mode:
authorRawi01 <Rawi01@users.noreply.github.com>2020-08-31 09:57:29 +0200
committerRawi01 <Rawi01@users.noreply.github.com>2020-08-31 09:57:29 +0200
commit82ac8aad1d0e3e152db4ce328184c40c73700cee (patch)
tree3d5abb9072d43b87f19e5faf88a3d09b6c6da8e4 /test/core/src/lombok
parent3d90a51163354930eeea0e26c2b0a567af8e96be (diff)
parent9148294f78a8e646ee131ca182a9b692bc028fdb (diff)
downloadlombok-82ac8aad1d0e3e152db4ce328184c40c73700cee.tar.gz
lombok-82ac8aad1d0e3e152db4ce328184c40c73700cee.tar.bz2
lombok-82ac8aad1d0e3e152db4ce328184c40c73700cee.zip
Merge branch 'master' into extensionmethod
Conflicts: build.xml
Diffstat (limited to 'test/core/src/lombok')
-rw-r--r--test/core/src/lombok/AbstractRunTests.java24
-rw-r--r--test/core/src/lombok/DirectoryRunner.java20
-rw-r--r--test/core/src/lombok/LombokTestSource.java4
-rw-r--r--test/core/src/lombok/RunTestsViaDelombok.java2
-rw-r--r--test/core/src/lombok/RunTestsViaEcj.java108
-rw-r--r--test/core/src/lombok/TestBase.java (renamed from test/core/src/lombok/RunAllTests.java)6
-rw-r--r--test/core/src/lombok/TestEclipse.java31
-rw-r--r--test/core/src/lombok/TestJavac.java31
8 files changed, 199 insertions, 27 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java
index d223ae03..448f77ab 100644
--- a/test/core/src/lombok/AbstractRunTests.java
+++ b/test/core/src/lombok/AbstractRunTests.java
@@ -91,7 +91,7 @@ public abstract class AbstractRunTests {
}
});
- boolean changed = transformCode(messages, writer, file, sourceDirectives_.getSpecifiedEncoding(), sourceDirectives_.getFormatPreferences());
+ boolean changed = transformCode(messages, writer, file, sourceDirectives_.getSpecifiedEncoding(), sourceDirectives_.getFormatPreferences(), sourceDirectives_.minVersion());
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"));
@@ -101,7 +101,7 @@ public abstract class AbstractRunTests {
};
}
- protected abstract boolean 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, int minVersion) throws Throwable;
protected String readFile(File file) throws IOException {
BufferedReader reader;
@@ -190,6 +190,8 @@ public abstract class AbstractRunTests {
for (CompilerMessage actualMessage : actualMessages) {
System.out.println(actualMessage);
}
+ System.out.println("**** Actual File ******");
+ System.out.println(lineNumber(actualFile));
System.out.println("*******************");
}
if (dumpActualFilesHere != null) {
@@ -199,6 +201,22 @@ public abstract class AbstractRunTests {
}
}
+ private CharSequence lineNumber(String content) {
+ StringBuilder out = new StringBuilder();
+ int pos = 0;
+ int ln = 1;
+ while (true) {
+ out.append(String.format("%4d ", ln));
+ int idx = content.indexOf('\n', pos);
+ if (idx == -1) {
+ return out.append(content.substring(pos));
+ }
+ out.append(content.substring(pos, idx + 1));
+ ln++;
+ pos = idx + 1;
+ }
+ }
+
@SuppressWarnings("null") /* eclipse bug workaround; it falsely thinks stuffAc will always be null. */
private static void compareMessages(String name, LombokImmutableList<CompilerMessageMatcher> expected, LinkedHashSet<CompilerMessage> actual) {
Iterator<CompilerMessageMatcher> expectedIterator = expected.iterator();
@@ -267,7 +285,7 @@ public abstract class AbstractRunTests {
endIdx--;
}
- return in.substring(0, endIdx);
+ return in.substring(0, endIdx + 1);
}
private static String[] removeBlanks(String[] in) {
diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java
index b8b1da43..a174355d 100644
--- a/test/core/src/lombok/DirectoryRunner.java
+++ b/test/core/src/lombok/DirectoryRunner.java
@@ -47,7 +47,7 @@ public class DirectoryRunner extends Runner {
@Override public int getVersion() {
return Javac.getJavaCompilerVersion();
}
- },
+ },
JAVAC {
@Override public int getVersion() {
return DELOMBOK.getVersion();
@@ -82,8 +82,22 @@ public class DirectoryRunner extends Runner {
private static final FileFilter JAVA_FILE_FILTER = new FileFilter() {
@Override public boolean accept(File file) {
- return file.isFile() && file.getName().endsWith(".java") &&
- (DEBUG_FOCUS_ON_FILE.isEmpty() || DEBUG_FOCUS_ON_FILE.contains(file.getName()));
+ if (!file.isFile() || !file.getName().endsWith(".java")) return false;
+ boolean positiveFilter = false;
+ for (String dfof : DEBUG_FOCUS_ON_FILE) {
+ if (dfof.isEmpty()) continue;
+ if (!dfof.endsWith(".java")) dfof = dfof + ".java";
+ boolean invert = dfof.startsWith("!");
+ if (invert) dfof = dfof.substring(1);
+ positiveFilter = positiveFilter || !invert;
+ int starIdx = dfof.indexOf('*');
+ if (starIdx == -1) {
+ if (file.getName().equals(dfof)) return !invert;
+ } else {
+ if (file.getName().startsWith(dfof.substring(0, starIdx)) && file.getName().endsWith(dfof.substring(starIdx + 1))) return !invert;
+ }
+ }
+ return !positiveFilter;
}
};
diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java
index b04f0ba0..57a32333 100644
--- a/test/core/src/lombok/LombokTestSource.java
+++ b/test/core/src/lombok/LombokTestSource.java
@@ -358,4 +358,8 @@ public class LombokTestSource {
if (specifiedEncoding == null || specifiedEncoding.equalsIgnoreCase(encoding)) return source;
return read0(sourceFolder, messagesFolder, fileName, specifiedEncoding);
}
+
+ public int minVersion() {
+ return Math.max(6, versionLowerLimit);
+ }
}
diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java
index 0887de32..ffac8372 100644
--- a/test/core/src/lombok/RunTestsViaDelombok.java
+++ b/test/core/src/lombok/RunTestsViaDelombok.java
@@ -38,7 +38,7 @@ public class RunTestsViaDelombok extends AbstractRunTests {
private Delombok delombok = new Delombok();
@Override
- public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding, Map<String, String> formatPreferences) throws Throwable {
+ public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding, Map<String, String> formatPreferences, int version) throws Throwable {
delombok.setVerbose(true);
ChangedChecker cc = new ChangedChecker();
delombok.setFeedback(cc.feedback);
diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java
index 3efe38f5..739d6316 100644
--- a/test/core/src/lombok/RunTestsViaEcj.java
+++ b/test/core/src/lombok/RunTestsViaEcj.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2014 The Project Lombok Authors.
+ * Copyright (C) 2010-2020 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
@@ -23,25 +23,33 @@ package lombok;
import java.io.File;
import java.io.StringWriter;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
import lombok.eclipse.Eclipse;
import lombok.javac.CapturingDiagnosticListener.CompilerMessage;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.Compiler;
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
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.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
@@ -69,7 +77,8 @@ public class RunTestsViaEcj extends AbstractRunTests {
warnings.put(CompilerOptions.OPTION_ReportUnusedLabel, "ignore");
warnings.put(CompilerOptions.OPTION_ReportUnusedImport, "ignore");
warnings.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, "ignore");
- warnings.put(CompilerOptions.OPTION_Source, "1." + Eclipse.getEcjCompilerVersion());
+ int ecjVersion = Eclipse.getEcjCompilerVersion();
+ warnings.put(CompilerOptions.OPTION_Source, (ecjVersion < 9 ? "1." : "") + ecjVersion);
options.set(warnings);
return options;
}
@@ -92,7 +101,7 @@ public class RunTestsViaEcj extends AbstractRunTests {
}
@Override
- public boolean 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, int minVersion) throws Throwable {
final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>();
final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>();
ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() {
@@ -102,9 +111,10 @@ public class RunTestsViaEcj extends AbstractRunTests {
};
String source = readFile(file);
- final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), encoding == null ? "UTF-8" : encoding);
+ char[] sourceArray = source.toCharArray();
+ final org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(sourceArray, file.getName(), encoding == null ? "UTF-8" : encoding);
- Compiler ecjCompiler = new Compiler(createFileSystem(file), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) {
+ Compiler ecjCompiler = new Compiler(createFileSystem(file, minVersion), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) {
@Override protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) {
if (inUnit == sourceUnit) compilationUnit_.set(parsedUnit);
super.addCompilationUnit(inUnit, parsedUnit);
@@ -125,10 +135,76 @@ public class RunTestsViaEcj extends AbstractRunTests {
if (cud == null) result.append("---- No CompilationUnit provided by ecj ----");
else result.append(cud.toString());
+ if (eclipseAvailable()) {
+ EclipseDomConversion.toDomAst(cud, sourceArray);
+ }
+
return true;
}
- private FileSystem createFileSystem(File file) {
+ private boolean eclipseAvailable() {
+ try {
+ Class.forName("org.eclipse.jdt.core.dom.CompilationUnit");
+ } catch (Throwable t) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private static final String bootRuntimePath = System.getProperty("delombok.bootclasspath");
+
+ private static class EclipseDomConversion {
+ static CompilationUnit toDomAst(CompilationUnitDeclaration cud, final char[] source) {
+ Map<String, String> options = new HashMap<String, String>();
+ options.put(JavaCore.COMPILER_SOURCE, "11");
+ options.put("org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures", "enabled");
+ try {
+ org.eclipse.jdt.internal.core.CompilationUnit ccu = new org.eclipse.jdt.internal.core.CompilationUnit(null, null, null) {
+ @Override public char[] getContents() {
+ return source;
+ }
+ };
+ return AST.convertCompilationUnit(4, cud, options, false, ccu, 0, null);
+ } catch (SecurityException e) {
+ try {
+ debugClasspathConflicts("org/eclipse/jdt/internal/compiler");
+ } catch (Exception e2) {
+ throw Lombok.sneakyThrow(e2);
+ }
+ throw e;
+ }
+ }
+ }
+
+ @SuppressWarnings({"all"})
+ private static void debugClasspathConflicts(String prefixToLookFor) throws Exception {
+ String[] paths = System.getProperty("java.class.path").split(":");
+ for (String p : paths) {
+ Path cp = Paths.get(p);
+ if (Files.isDirectory(cp)) {
+ if (Files.isDirectory(cp.resolve(prefixToLookFor))) System.out.println("** DIR-BASED: " + cp);
+ } else if (Files.isRegularFile(cp)) {
+ JarFile jf = new JarFile(cp.toFile());
+ try {
+ Enumeration<JarEntry> jes = jf.entries();
+ while (jes.hasMoreElements()) {
+ JarEntry je = jes.nextElement();
+ if (je.getName().startsWith(prefixToLookFor)) {
+ System.out.println("** JAR-BASED: " + cp);
+ break;
+ }
+ }
+ } finally {
+ jf.close();
+ }
+ } else {
+ System.out.println("** MISSING: " + cp);
+ }
+ }
+ }
+
+ private FileSystem createFileSystem(File file, int minVersion) {
List<String> classpath = new ArrayList<String>();
for (Iterator<String> i = classpath.iterator(); i.hasNext();) {
if (FileSystem.getClasspath(i.next(), "UTF-8", null) == null) {
@@ -137,16 +213,14 @@ public class RunTestsViaEcj extends AbstractRunTests {
}
if (new File("bin").exists()) classpath.add("bin");
classpath.add("dist/lombok.jar");
- classpath.add("lib/oracleJDK8Environment/rt.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");
- classpath.add("lib/test/org.jboss.logging-jboss-logging.jar");
- classpath.add("lib/test/com.google.guava-guava.jar");
- classpath.add("lib/test/com.google.code.findbugs-findbugs.jar");
- classpath.add("lib/test/com.google.flogger-flogger.jar");
+ if (bootRuntimePath == null || bootRuntimePath.isEmpty()) throw new IllegalStateException("System property delombok.bootclasspath is not set; set it to the rt of java6 or java8");
+ classpath.add(bootRuntimePath);
+ for (File f : new File("lib/test").listFiles()) {
+ String fn = f.getName();
+ if (fn.length() < 4) continue;
+ if (!fn.substring(fn.length() - 4).toLowerCase().equals(".jar")) continue;
+ classpath.add("lib/test/" + fn);
+ }
return new FileSystem(classpath.toArray(new String[0]), new String[] {file.getAbsolutePath()}, "UTF-8");
}
}
diff --git a/test/core/src/lombok/RunAllTests.java b/test/core/src/lombok/TestBase.java
index 1ca76af5..4b0c02f3 100644
--- a/test/core/src/lombok/RunAllTests.java
+++ b/test/core/src/lombok/TestBase.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011-2015 The Project Lombok Authors.
+ * Copyright (C) 2011-2020 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,6 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
-@SuiteClasses({lombok.transform.RunTransformTests.class, lombok.bytecode.RunBytecodeTests.class, lombok.core.configuration.RunConfigurationTests.class, lombok.core.RunCoreTests.class})
-public class RunAllTests {
+@SuiteClasses({lombok.core.configuration.RunConfigurationTests.class, lombok.core.RunCoreTests.class})
+public class TestBase {
}
diff --git a/test/core/src/lombok/TestEclipse.java b/test/core/src/lombok/TestEclipse.java
new file mode 100644
index 00000000..9fe798bc
--- /dev/null
+++ b/test/core/src/lombok/TestEclipse.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2011-2020 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 org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({lombok.transform.TestWithEcj.class})
+public class TestEclipse {
+}
diff --git a/test/core/src/lombok/TestJavac.java b/test/core/src/lombok/TestJavac.java
new file mode 100644
index 00000000..fbc495ad
--- /dev/null
+++ b/test/core/src/lombok/TestJavac.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2011-2020 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 org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({lombok.bytecode.RunBytecodeTests.class, lombok.transform.TestLombokFilesIdempotent.class, lombok.transform.TestSourceFiles.class, lombok.transform.TestWithDelombok.class})
+public class TestJavac {
+}