Skip to content

Commit

Permalink
Check compileTestJava sources with Error Prone (#851)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmdietl authored Aug 11, 2024
1 parent eb0cedc commit ef067e1
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 27 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,7 @@ allprojects {
}

// Error Prone depends on checker-qual.jar, so don't run it on that project to avoid a circular dependency.
// TODO: enable Error Prone on test classes.
if (compilationTask.name.equals('compileJava') && !project.name.startsWith('checker-qual')) {
if ((compilationTask.name.equals('compileJava') || compilationTask.name.equals('compileTestJava')) && !project.name.startsWith('checker-qual')) {
// Error Prone must be available in the annotation processor path
options.annotationProcessorPath = configurations.errorprone
// Enable Error Prone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public class AinferTestAnnotatedTypeFactory extends BaseAnnotatedTypeFactory {
private final AnnotationMirror SIBLING1 =
new AnnotationBuilder(processingEnv, AinferSibling1.class).build();

private final AnnotationMirror TREAT_AS_SIBLING1 =
new AnnotationBuilder(processingEnv, AinferTreatAsSibling1.class).build();
// NO-AFU
// private final AnnotationMirror TREAT_AS_SIBLING1 =
// new AnnotationBuilder(processingEnv, AinferTreatAsSibling1.class).build();

/** The AinferSiblingWithFields.value field/element. */
private final ExecutableElement siblingWithFieldsValueElement =
Expand Down Expand Up @@ -124,7 +125,7 @@ public TreeAnnotator createTreeAnnotator() {
new AinferTestTreeAnnotator(this));
}

protected class AinferTestTreeAnnotator extends TreeAnnotator {
protected static class AinferTestTreeAnnotator extends TreeAnnotator {

/**
* Create a new AinferTestTreeAnnotator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ public void initChecker() {
cc[0] = I18nConversionCategory.NUMBER;
AnnotationMirror i18nFormatNumberAnno = treeUtil.categoriesToFormatAnnotation(cc);

QualifierHierarchy qh =
((BaseTypeVisitor<?>) visitor).getTypeFactory().getQualifierHierarchy();

// ** GLB tests **

// GLB of UNUSED and others
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public RangeTest() {
}

/** The element is a member of the range. */
class RangeAndElement {
static class RangeAndElement {
Range range;
long element;

Expand All @@ -124,7 +124,7 @@ class RangeAndElement {
}
}

class RangeAndTwoElements {
static class RangeAndTwoElements {
Range range;
long a;
long b;
Expand All @@ -138,6 +138,7 @@ RangeAndElementIterator rangeAndElements() {
return new RangeAndElementIterator();
}

@SuppressWarnings("IterableAndIterator") // TODO
class RangeAndElementIterator implements Iterator<RangeAndElement>, Iterable<RangeAndElement> {
// This is the index of the range that is currently being examined.
// It is in [0..ranges.length].
Expand Down Expand Up @@ -191,6 +192,7 @@ public Iterator<RangeAndElement> iterator() {
}
}

@SuppressWarnings("IterableAndIterator") // TODO
class ValuesInRangeIterator implements Iterator<Long>, Iterable<Long> {

Range range;
Expand All @@ -199,6 +201,7 @@ class ValuesInRangeIterator implements Iterator<Long>, Iterable<Long> {
long nextValue;
boolean nextValueValid = false;

@SuppressWarnings("StaticAssignmentInConstructor")
public ValuesInRangeIterator(Range range) {
this.range = range;
Range.ignoreOverflow = false;
Expand Down Expand Up @@ -251,8 +254,8 @@ public void testIntRange() {
== (Math.abs(range.to) - 1) / Integer.MIN_VALUE) {
// filter out test data that would cause Range.intRange to return INT_EVERYTHING
int intValue = (int) value;
assert range.contains(value) && result.contains(intValue)
|| !range.contains(value) && !result.contains(intValue)
assert (range.contains(value) && result.contains(intValue))
|| (!range.contains(value) && !result.contains(intValue))
: String.format(
"Range.intRange failure: %s => %s; witness = %s",
range, result, intValue);
Expand All @@ -273,8 +276,8 @@ public void testShortRange() {
// filter out test data that would cause Range.shortRange to return
// SHORT_EVERYTHING
short shortValue = (short) value;
assert range.contains(value) && result.contains(shortValue)
|| !range.contains(value) && !result.contains(shortValue)
assert (range.contains(value) && result.contains(shortValue))
|| (!range.contains(value) && !result.contains(shortValue))
: String.format(
"Range.shortRange failure: %s => %s; witness = %s",
range, result, shortValue);
Expand All @@ -297,8 +300,8 @@ public void testCharRange() {
// CHAR_EVERYTHING
// char range interval is a right shift of the short range interval
char charValue = (char) value;
assert range.contains(value) && result.contains(charValue)
|| !range.contains(value) && !result.contains(charValue)
assert (range.contains(value) && result.contains(charValue))
|| (!range.contains(value) && !result.contains(charValue))
: String.format(
"Range.byteRange failure: %s => %s; witness = %s",
range, result, charValue);
Expand All @@ -319,8 +322,8 @@ public void testByteRange() {
// filter out test data that would cause Range.ByteRange to return
// BYTE_EVERYTHING
byte byteValue = (byte) value;
assert range.contains(value) && result.contains(byteValue)
|| !range.contains(value) && !result.contains(byteValue)
assert (range.contains(value) && result.contains(byteValue))
|| (!range.contains(value) && !result.contains(byteValue))
: String.format(
"Range.byteRange failure: %s => %s; witness = %s",
range, result, byteValue);
Expand Down Expand Up @@ -369,7 +372,7 @@ public void testIntersect() {
Range result = range1.intersect(range2);
for (long value : values) {
assert ((range1.contains(value) && range2.contains(value))
== (result.contains(value)))
== result.contains(value))
: String.format(
"Range.intersect failure: %s %s => %s; witness = %s",
range1, range2, result, value);
Expand Down Expand Up @@ -663,9 +666,9 @@ public void testEqualTo() {
for (Range range2 : ranges) {
for (long value : values) {
Range result = range1.refineEqualTo(range2);
assert (value < range2.from || value > range2.to
assert (value < range2.from || value > range2.to)
? !result.contains(value)
: range1.contains(value) == result.contains(value))
: (range1.contains(value) == result.contains(value))
: String.format(
"Range.refineEqualTo failure: %s %s %s; witness = %s",
range1, range2, result, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public void initChecker() {
F = AnnotationBuilder.fromClass(elements, LubglbF.class);
POLY = AnnotationBuilder.fromClass(elements, PolyLubglb.class);

QualifierHierarchy qh =
((BaseTypeVisitor<?>) visitor).getTypeFactory().getQualifierHierarchy();

lubAssert(D, E, C);
lubAssert(E, D, C);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected SupportedQualsAnnotatedTypeFactory createTypeFactory() {
};
}

class SupportedQualsAnnotatedTypeFactory extends BaseAnnotatedTypeFactory {
static class SupportedQualsAnnotatedTypeFactory extends BaseAnnotatedTypeFactory {
public SupportedQualsAnnotatedTypeFactory(BaseTypeChecker checker) {
super(checker);
postInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private Map<TreeSpec, String> buildExpected(CompilationUnitTree tree) {
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
throw new BugInCF("Unexpected IOException!", e);
}
return expected;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ViewpointTestViewpointAdapter extends AbstractViewpointAdapter {
/**
* The class constructor.
*
* @param atypeFactory
* @param atypeFactory the type factory to use
*/
public ViewpointTestViewpointAdapter(AnnotatedTypeFactory atypeFactory) {
super(atypeFactory);
Expand Down

0 comments on commit ef067e1

Please sign in to comment.