Search in sources :

Example 11 with ErrorProneOptions

use of com.google.errorprone.ErrorProneOptions in project error-prone by google.

the class ScannerSupplierTest method applyOverridesDisableErrorsOnlyForEnabledChecks.

@Test
public void applyOverridesDisableErrorsOnlyForEnabledChecks() {
    Supplier<ScannerSupplier> filteredScanner = () -> ScannerSupplier.fromBugCheckerClasses(BadShiftAmount.class, UnsuppressibleArrayEquals.class, EqualsIncompatibleType.class).filter(p -> !p.checkerClass().equals(EqualsIncompatibleType.class));
    ErrorProneOptions epOptions = ErrorProneOptions.processArgs(ImmutableList.of("-XepAllErrorsAsWarnings"));
    assertScanner(filteredScanner.get().applyOverrides(epOptions)).hasEnabledChecks(UnsuppressibleArrayEquals.class, BadShiftAmount.class);
    epOptions = ErrorProneOptions.processArgs(ImmutableList.of("-XepAllErrorsAsWarnings", "-Xep:BadShiftAmount:OFF"));
    assertScanner(filteredScanner.get().applyOverrides(epOptions)).hasEnabledChecks(UnsuppressibleArrayEquals.class);
}
Also used : UnsuppressibleArrayEquals(com.google.errorprone.ErrorProneJavaCompilerTest.UnsuppressibleArrayEquals) ErrorProneOptions(com.google.errorprone.ErrorProneOptions) BadShiftAmount(com.google.errorprone.bugpatterns.BadShiftAmount) EqualsIncompatibleType(com.google.errorprone.bugpatterns.EqualsIncompatibleType) ErrorProneJavaCompilerTest(com.google.errorprone.ErrorProneJavaCompilerTest) Test(org.junit.Test)

Example 12 with ErrorProneOptions

use of com.google.errorprone.ErrorProneOptions in project error-prone by google.

the class ScannerSupplierTest method applyOverridesDisableErrors.

@Test
public void applyOverridesDisableErrors() {
    // BadShiftAmount (error), ArrayEquals (unsuppressible error), StringEquality (warning)
    ScannerSupplier ss = ScannerSupplier.fromBugCheckerClasses(BadShiftAmount.class, UnsuppressibleArrayEquals.class, StringEquality.class);
    ErrorProneOptions epOptions = ErrorProneOptions.processArgs(ImmutableList.of("-XepAllErrorsAsWarnings"));
    assertScanner(ss.applyOverrides(epOptions)).hasSeverities(ImmutableMap.of(// Unsuppressible, not demoted
    "ArrayEquals", // Unsuppressible, not demoted
    SeverityLevel.ERROR, // Demoted from error to warning
    "BadShiftAmount", // Demoted from error to warning
    SeverityLevel.WARNING, "StringEquality", // Already warning, unaffected
    SeverityLevel.WARNING));
    // Flags after AllErrorsAsWarnings flag should override it.
    epOptions = ErrorProneOptions.processArgs(ImmutableList.of("-XepAllErrorsAsWarnings", "-Xep:StringEquality:ERROR"));
    assertScanner(ss.applyOverrides(epOptions)).hasSeverities(ImmutableMap.of("ArrayEquals", SeverityLevel.ERROR, "BadShiftAmount", SeverityLevel.WARNING, "StringEquality", SeverityLevel.ERROR));
    // AllErrorsAsWarnings flag should override all error-level severity flags that come before it.
    epOptions = ErrorProneOptions.processArgs(ImmutableList.of("-Xep:StringEquality:ERROR", "-XepAllErrorsAsWarnings"));
    assertScanner(ss.applyOverrides(epOptions)).hasSeverities(ImmutableMap.of("ArrayEquals", SeverityLevel.ERROR, "BadShiftAmount", SeverityLevel.WARNING, "StringEquality", SeverityLevel.WARNING));
    // AllErrorsAsWarnings only overrides error-level severity flags.
    // That is, checks disabled before the flag are left disabled, not promoted to warnings.
    epOptions = ErrorProneOptions.processArgs(ImmutableList.of("-Xep:BadShiftAmount:OFF", "-XepAllErrorsAsWarnings"));
    assertScanner(ss.applyOverrides(epOptions)).hasSeverities(ImmutableMap.of("ArrayEquals", SeverityLevel.ERROR, "StringEquality", SeverityLevel.WARNING));
    assertScanner(ss.applyOverrides(epOptions)).hasEnabledChecks(UnsuppressibleArrayEquals.class, StringEquality.class);
}
Also used : ErrorProneOptions(com.google.errorprone.ErrorProneOptions) ErrorProneJavaCompilerTest(com.google.errorprone.ErrorProneJavaCompilerTest) Test(org.junit.Test)

Aggregations

ErrorProneOptions (com.google.errorprone.ErrorProneOptions)12 ErrorProneJavaCompilerTest (com.google.errorprone.ErrorProneJavaCompilerTest)11 Test (org.junit.Test)11 InvalidCommandLineOptionException (com.google.errorprone.InvalidCommandLineOptionException)4 SeverityLevel (com.google.errorprone.BugPattern.SeverityLevel)3 UnsuppressibleArrayEquals (com.google.errorprone.ErrorProneJavaCompilerTest.UnsuppressibleArrayEquals)3 BadShiftAmount (com.google.errorprone.bugpatterns.BadShiftAmount)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 BugCheckerInfo (com.google.errorprone.BugCheckerInfo)2 ArrayEquals (com.google.errorprone.bugpatterns.ArrayEquals)2 BugChecker (com.google.errorprone.bugpatterns.BugChecker)2 DivZero (com.google.errorprone.bugpatterns.DivZero)2 EqualsIncompatibleType (com.google.errorprone.bugpatterns.EqualsIncompatibleType)2 StaticQualifiedUsingExpression (com.google.errorprone.bugpatterns.StaticQualifiedUsingExpression)2 Map (java.util.Map)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Predicate (com.google.common.base.Predicate)1 Predicates (com.google.common.base.Predicates)1 Supplier (com.google.common.base.Supplier)1