diff options
Diffstat (limited to 'test/core')
-rw-r--r-- | test/core/src/lombok/AbstractRunTests.java | 7 | ||||
-rw-r--r-- | test/core/src/lombok/DirectoryRunner.java | 10 | ||||
-rw-r--r-- | test/core/src/lombok/LombokTestSource.java | 4 | ||||
-rw-r--r-- | test/core/src/lombok/RunTestsViaDelombok.java | 59 | ||||
-rw-r--r-- | test/core/src/lombok/RunTestsViaEcj.java | 27 |
5 files changed, 86 insertions, 21 deletions
diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java index 448f77ab..51ec41c5 100644 --- a/test/core/src/lombok/AbstractRunTests.java +++ b/test/core/src/lombok/AbstractRunTests.java @@ -48,6 +48,7 @@ import lombok.core.configuration.ConfigurationResolver; import lombok.core.configuration.ConfigurationResolverFactory; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; import lombok.transform.TestLombokFilesIdempotent; +import lombok.transform.TestSourceFiles; public abstract class AbstractRunTests { private final File dumpActualFilesHere; @@ -91,7 +92,9 @@ public abstract class AbstractRunTests { } }); - boolean changed = transformCode(messages, writer, file, sourceDirectives_.getSpecifiedEncoding(), sourceDirectives_.getFormatPreferences(), sourceDirectives_.minVersion()); + boolean checkPositions = !(params instanceof TestLombokFilesIdempotent || params instanceof TestSourceFiles) && !sourceDirectives_.isSkipCompareContent(); + + boolean changed = transformCode(messages, writer, file, sourceDirectives_.getSpecifiedEncoding(), sourceDirectives_.getFormatPreferences(), sourceDirectives_.minVersion(), checkPositions); 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 +104,7 @@ public abstract class AbstractRunTests { }; } - protected abstract boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion) throws Throwable; + protected abstract boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion, boolean checkPositions) 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 93b18039..b041c42e 100644 --- a/test/core/src/lombok/DirectoryRunner.java +++ b/test/core/src/lombok/DirectoryRunner.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -78,6 +78,9 @@ public class DirectoryRunner extends Runner { } public abstract boolean expectChanges(); + public String testNamePrefix() { + return ""; + } } private static final FileFilter JAVA_FILE_FILTER = new FileFilter() { @@ -114,8 +117,7 @@ public class DirectoryRunner extends Runner { Throwable error = null; try { addTests(testClass); - } - catch (Throwable t) { + } catch (Throwable t) { error = t; } this.failure = error; @@ -124,7 +126,7 @@ public class DirectoryRunner extends Runner { private void addTests(Class<?> testClass) throws Exception { for (File file : params.getBeforeDirectory().listFiles(JAVA_FILE_FILTER)) { if (!params.accept(file)) continue; - Description testDescription = Description.createTestDescription(testClass, file.getName()); + Description testDescription = Description.createTestDescription(testClass, this.params.testNamePrefix() + file.getName()); description.addChild(testDescription); tests.put(file.getName(), testDescription); } diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java index 1498e635..0326dee9 100644 --- a/test/core/src/lombok/LombokTestSource.java +++ b/test/core/src/lombok/LombokTestSource.java @@ -374,4 +374,8 @@ public class LombokTestSource { public int minVersion() { return Math.max(6, versionLowerLimit); } + + public int maxVersion() { + return versionUpperLimit; + } } diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index 59287f30..c10ef4d3 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -28,8 +28,10 @@ import java.io.File; import java.io.PrintStream; import java.io.StringWriter; import java.io.UnsupportedEncodingException; +import java.util.ArrayDeque; import java.util.Collection; import java.util.Collections; +import java.util.Deque; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -56,6 +58,7 @@ import com.sun.tools.javac.tree.JCTree.JCIdent; import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; +import com.sun.tools.javac.tree.JCTree.TypeBoundKind; import com.sun.tools.javac.tree.TreeScanner; import lombok.delombok.Delombok; @@ -67,7 +70,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, int version) throws Throwable { + public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding, Map<String, String> formatPreferences, int version, boolean checkPositions) throws Throwable { delombok.setVerbose(true); ChangedChecker cc = new ChangedChecker(); delombok.setFeedback(cc.feedback); @@ -77,7 +80,7 @@ public class RunTestsViaDelombok extends AbstractRunTests { delombok.setDiagnosticsListener(new CapturingDiagnosticListener(file, messages)); - delombok.addAdditionalAnnotationProcessor(new ValidatePositionProcessor()); + if (checkPositions) delombok.addAdditionalAnnotationProcessor(new ValidatePositionProcessor(version)); delombok.addAdditionalAnnotationProcessor(new ValidateTypesProcessor()); delombok.addFile(file.getAbsoluteFile().getParentFile(), file.getName()); @@ -96,22 +99,64 @@ public class RunTestsViaDelombok extends AbstractRunTests { } public static class ValidatePositionProcessor extends TreeProcessor { + private final int version; + + public ValidatePositionProcessor(int version) { + this.version = version; + } + + private String craftFailMsg(String problematicNode, Deque<JCTree> astContext) { + StringBuilder msg = new StringBuilder(problematicNode).append(" position of node not set: "); + for (JCTree t : astContext) { + msg.append("\n ").append(t.getClass().getSimpleName()); + String asStr = t.toString(); + if (asStr.length() < 80) msg.append(": ").append(asStr); + else if (t instanceof JCClassDecl) msg.append(": ").append(((JCClassDecl) t).name); + else if (t instanceof JCMethodDecl) msg.append(": ").append(((JCMethodDecl) t).name); + else if (t instanceof JCVariableDecl) msg.append(": ").append(((JCVariableDecl) t).name); + } + return msg.append("\n-------").toString(); + } + @Override void processCompilationUnit(final JCCompilationUnit unit) { + final Deque<JCTree> astContext = new ArrayDeque<JCTree>(); unit.accept(new TreeScanner() { @Override public void scan(JCTree tree) { if (tree == null) return; if (tree instanceof JCMethodDecl && (((JCMethodDecl) tree).mods.flags & Flags.GENERATEDCONSTR) != 0) return; + astContext.push(tree); try { if (tree instanceof JCModifiers) return; - if (tree.pos == -1) { - fail("Start position of " + tree + " not set"); + if (!Javac.validateDocComment(unit, tree)) { + fail("Start position of doc comment (" + Javac.getDocComment(unit, tree) + ") of " + tree + " not set"); } - if (Javac.getEndPosition(tree, unit) == -1) { - fail("End position of " + tree + " not set"); + + boolean check = true; + if (version < 8 && tree instanceof TypeBoundKind) { + // TypeBoundKind works differently in java6, and as a consequence, + // the position is not set properly. + // Given status of j6/j7, not worth properly testing. + check = false; + } + if (version < 8 && tree instanceof JCIdent) { + // explicit `super()` invocations do not appear to have end pos in j6/7. + if ("super".equals("" + ((JCIdent) tree).name)) check = false; + } + + if (tree instanceof JCVariableDecl && (((JCVariableDecl) tree).mods.flags & Javac.GENERATED_MEMBER) != 0) return; + + if (check && tree.pos == -1) fail(craftFailMsg("Start", astContext)); + + if (check && Javac.getEndPosition(tree, unit) == -1) { + fail(craftFailMsg("End", astContext)); } } finally { - super.scan(tree); + try { + super.scan(tree); + } finally { + astContext.pop(); + } } } diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 1d840a21..afba8c7f 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2020 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -83,6 +83,10 @@ 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_ReportIndirectStaticAccess, "warning"); + warnings.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, "warning"); + warnings.put("org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures", "enabled"); + warnings.put("org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures", "ignore"); int ecjVersion = Eclipse.getEcjCompilerVersion(); warnings.put(CompilerOptions.OPTION_Source, (ecjVersion < 9 ? "1." : "") + ecjVersion); options.set(warnings); @@ -106,8 +110,13 @@ public class RunTestsViaEcj extends AbstractRunTests { }; } + private ICompilationUnit getSourceUnit(File file, String source) { + if (eclipseAvailable()) return new TestCompilationUnitEclipse(file.getName(), source); + return new TestCompilationUnitEcj(file.getName(), source); + } + @Override - public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion) throws Throwable { + public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion, boolean checkPositions) throws Throwable { final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>(); final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>(); ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() { @@ -120,11 +129,7 @@ public class RunTestsViaEcj extends AbstractRunTests { char[] sourceArray = source.toCharArray(); final ICompilationUnit sourceUnit; try { - if (eclipseAvailable()) { - sourceUnit = new TestCompilationUnitEclipse(file.getName(), source); - } else { - sourceUnit = new TestCompilationUnitEcj(file.getName(), source); - } + sourceUnit = getSourceUnit(file, source); } catch (Throwable t) { t.printStackTrace(); return false; @@ -151,7 +156,12 @@ public class RunTestsViaEcj extends AbstractRunTests { CompilationUnitDeclaration cud = compilationUnit_.get(); if (cud == null) result.append("---- No CompilationUnit provided by ecj ----"); - else result.append(cud.toString()); + else { + String output = cud.toString(); + // starting somewhere around ecj16, the print code is a bit too cavalier with printing modifiers. + output = output.replace("non-sealed @val", "@val"); + result.append(output); + } if (eclipseAvailable()) { EclipseDomConversion.toDomAst(cud, sourceArray); @@ -226,6 +236,7 @@ public class RunTestsViaEcj extends AbstractRunTests { } if (new File("bin/main").exists()) classpath.add("bin/main"); classpath.add("dist/lombok.jar"); + classpath.add("build/teststubs"); 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()) { |