mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 10:15:53 +00:00
add the capability to the testing framework to verify that delombok actually also handles the changed flag correctly
This commit is contained in:
1 parent
8db1793461
commit
9eb70cb3e2
21 files changed
+84
-25
No files matched your search
@@ -508,7 +508,7 @@ public class Delombok {
|
||||
FormatPreferences fps = new FormatPreferences(formatPrefs);
|
||||
for (JCCompilationUnit unit : roots) {
|
||||
DelombokResult result = new DelombokResult(catcher.getComments(unit), unit, force || options.isChanged(unit), fps);
|
||||
if (verbose) feedback.printf("File: %s [%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged");
|
||||
if (verbose) feedback.printf("File: %s [%s%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged", force && !options.isChanged(unit) ? " (forced)" : "");
|
||||
Writer rawWriter;
|
||||
if (presetWriter != null) rawWriter = createUnicodeEscapeWriter(presetWriter);
|
||||
else if (output == null) rawWriter = createStandardOutWriter();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 + ")");
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
class LoggerSlf4jOnNonType {
|
||||
LoggerSlf4jOnNonType() {
|
||||
super();
|
||||
}
|
||||
@lombok.extern.slf4j.Slf4j void foo() {
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// unchanged
|
||||
/**
|
||||
* Doc on package
|
||||
*/
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// unchanged
|
||||
class TestOperators {
|
||||
int x = 10;
|
||||
public void test() {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// unchanged
|
||||
import lombok.*;
|
||||
class DoNothingDueToTopLevel {
|
||||
void test() {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// unchanged
|
||||
import lombok.val;
|
||||
|
||||
public class ValErrors {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// unchanged
|
||||
import lombok.val;
|
||||
|
||||
public class ValInBasicFor {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// unchanged
|
||||
class WithInnerAnnotation {
|
||||
@interface Inner {
|
||||
int bar() default 42;
|
||||
|
||||
@@ -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 { ... })
|
||||
@@ -1 +1 @@
|
||||
6 'val' is not allowed in old-style for loops
|
||||
7 'val' is not allowed in old-style for loops
|
||||
@@ -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 { ... })
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user