From ef067e114241e1464760e2d632618d9d0d95ffd8 Mon Sep 17 00:00:00 2001 From: Werner Dietl Date: Sun, 11 Aug 2024 15:50:00 -0400 Subject: [PATCH] Check `compileTestJava` sources with Error Prone (#851) --- build.gradle | 3 +- .../AinferTestAnnotatedTypeFactory.java | 7 +++-- .../lubglb/I18nFormatterLubGlbChecker.java | 3 -- .../framework/test/junit/RangeTest.java | 29 ++++++++++--------- .../testchecker/lubglb/LubGlbChecker.java | 3 -- .../supportedquals/SupportedQualsChecker.java | 2 +- .../testchecker/util/FactoryTestChecker.java | 2 +- .../ViewpointTestViewpointAdapter.java | 2 +- 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/build.gradle b/build.gradle index bf1b7340a96..4119f8bace5 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/checker/src/test/java/org/checkerframework/checker/testchecker/ainfer/AinferTestAnnotatedTypeFactory.java b/checker/src/test/java/org/checkerframework/checker/testchecker/ainfer/AinferTestAnnotatedTypeFactory.java index 385f1d9b6fc..4ba8d643131 100644 --- a/checker/src/test/java/org/checkerframework/checker/testchecker/ainfer/AinferTestAnnotatedTypeFactory.java +++ b/checker/src/test/java/org/checkerframework/checker/testchecker/ainfer/AinferTestAnnotatedTypeFactory.java @@ -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 = @@ -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. diff --git a/checker/src/test/java/org/checkerframework/checker/testchecker/lubglb/I18nFormatterLubGlbChecker.java b/checker/src/test/java/org/checkerframework/checker/testchecker/lubglb/I18nFormatterLubGlbChecker.java index 720be2ccebb..851e1ad3830 100644 --- a/checker/src/test/java/org/checkerframework/checker/testchecker/lubglb/I18nFormatterLubGlbChecker.java +++ b/checker/src/test/java/org/checkerframework/checker/testchecker/lubglb/I18nFormatterLubGlbChecker.java @@ -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 diff --git a/framework/src/test/java/org/checkerframework/framework/test/junit/RangeTest.java b/framework/src/test/java/org/checkerframework/framework/test/junit/RangeTest.java index 8e8af4208bb..25143bb7c05 100644 --- a/framework/src/test/java/org/checkerframework/framework/test/junit/RangeTest.java +++ b/framework/src/test/java/org/checkerframework/framework/test/junit/RangeTest.java @@ -111,7 +111,7 @@ public RangeTest() { } /** The element is a member of the range. */ - class RangeAndElement { + static class RangeAndElement { Range range; long element; @@ -124,7 +124,7 @@ class RangeAndElement { } } - class RangeAndTwoElements { + static class RangeAndTwoElements { Range range; long a; long b; @@ -138,6 +138,7 @@ RangeAndElementIterator rangeAndElements() { return new RangeAndElementIterator(); } + @SuppressWarnings("IterableAndIterator") // TODO class RangeAndElementIterator implements Iterator, Iterable { // This is the index of the range that is currently being examined. // It is in [0..ranges.length]. @@ -191,6 +192,7 @@ public Iterator iterator() { } } + @SuppressWarnings("IterableAndIterator") // TODO class ValuesInRangeIterator implements Iterator, Iterable { Range range; @@ -199,6 +201,7 @@ class ValuesInRangeIterator implements Iterator, Iterable { long nextValue; boolean nextValueValid = false; + @SuppressWarnings("StaticAssignmentInConstructor") public ValuesInRangeIterator(Range range) { this.range = range; Range.ignoreOverflow = false; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/framework/src/test/java/org/checkerframework/framework/testchecker/lubglb/LubGlbChecker.java b/framework/src/test/java/org/checkerframework/framework/testchecker/lubglb/LubGlbChecker.java index 3f613d6ea33..0531afc6dcf 100644 --- a/framework/src/test/java/org/checkerframework/framework/testchecker/lubglb/LubGlbChecker.java +++ b/framework/src/test/java/org/checkerframework/framework/testchecker/lubglb/LubGlbChecker.java @@ -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); diff --git a/framework/src/test/java/org/checkerframework/framework/testchecker/supportedquals/SupportedQualsChecker.java b/framework/src/test/java/org/checkerframework/framework/testchecker/supportedquals/SupportedQualsChecker.java index b906c462a0a..b0f4fcd5295 100644 --- a/framework/src/test/java/org/checkerframework/framework/testchecker/supportedquals/SupportedQualsChecker.java +++ b/framework/src/test/java/org/checkerframework/framework/testchecker/supportedquals/SupportedQualsChecker.java @@ -27,7 +27,7 @@ protected SupportedQualsAnnotatedTypeFactory createTypeFactory() { }; } - class SupportedQualsAnnotatedTypeFactory extends BaseAnnotatedTypeFactory { + static class SupportedQualsAnnotatedTypeFactory extends BaseAnnotatedTypeFactory { public SupportedQualsAnnotatedTypeFactory(BaseTypeChecker checker) { super(checker); postInit(); diff --git a/framework/src/test/java/org/checkerframework/framework/testchecker/util/FactoryTestChecker.java b/framework/src/test/java/org/checkerframework/framework/testchecker/util/FactoryTestChecker.java index f62bad5825d..0af7172d61c 100644 --- a/framework/src/test/java/org/checkerframework/framework/testchecker/util/FactoryTestChecker.java +++ b/framework/src/test/java/org/checkerframework/framework/testchecker/util/FactoryTestChecker.java @@ -173,7 +173,7 @@ private Map buildExpected(CompilationUnitTree tree) { } reader.close(); } catch (IOException e) { - e.printStackTrace(); + throw new BugInCF("Unexpected IOException!", e); } return expected; } diff --git a/framework/src/test/java/viewpointtest/ViewpointTestViewpointAdapter.java b/framework/src/test/java/viewpointtest/ViewpointTestViewpointAdapter.java index 9da9504eead..bf4f491edba 100644 --- a/framework/src/test/java/viewpointtest/ViewpointTestViewpointAdapter.java +++ b/framework/src/test/java/viewpointtest/ViewpointTestViewpointAdapter.java @@ -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);