Search in sources :

Example 6 with ErrorProneOptions

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

the class ScannerSupplierTest method applyOverridesEnablesCheck.

@Test
public void applyOverridesEnablesCheck() throws Exception {
    ScannerSupplier ss = ScannerSupplier.fromBugCheckerClasses(ArrayEquals.class, BadShiftAmount.class, StaticQualifiedUsingExpression.class).filter(// disables all checks
    Predicates.alwaysFalse());
    ErrorProneOptions epOptions = ErrorProneOptions.processArgs(ImmutableList.of("-Xep:ArrayEquals", "-Xep:BadShiftAmount"));
    assertScanner(ss.applyOverrides(epOptions)).hasEnabledChecks(ArrayEquals.class, BadShiftAmount.class);
}
Also used : ErrorProneOptions(com.google.errorprone.ErrorProneOptions) ArrayEquals(com.google.errorprone.bugpatterns.ArrayEquals) UnsuppressibleArrayEquals(com.google.errorprone.ErrorProneJavaCompilerTest.UnsuppressibleArrayEquals) BadShiftAmount(com.google.errorprone.bugpatterns.BadShiftAmount) StaticQualifiedUsingExpression(com.google.errorprone.bugpatterns.StaticQualifiedUsingExpression) ErrorProneJavaCompilerTest(com.google.errorprone.ErrorProneJavaCompilerTest) Test(org.junit.Test)

Example 7 with ErrorProneOptions

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

the class ScannerSupplierTest method applyOverridesThrowsExceptionWhenDemotingNonDisablableCheck.

@Test
public void applyOverridesThrowsExceptionWhenDemotingNonDisablableCheck() throws Exception {
    ScannerSupplier ss = ScannerSupplier.fromBugCheckerClasses(ErrorProneJavaCompilerTest.UnsuppressibleArrayEquals.class);
    ErrorProneOptions epOptions = ErrorProneOptions.processArgs(ImmutableList.of("-Xep:ArrayEquals:WARN"));
    InvalidCommandLineOptionException exception = expectThrows(InvalidCommandLineOptionException.class, () -> ss.applyOverrides(epOptions));
    assertThat(exception.getMessage()).contains("may not be demoted to a warning");
}
Also used : ErrorProneOptions(com.google.errorprone.ErrorProneOptions) InvalidCommandLineOptionException(com.google.errorprone.InvalidCommandLineOptionException) ErrorProneJavaCompilerTest(com.google.errorprone.ErrorProneJavaCompilerTest) ErrorProneJavaCompilerTest(com.google.errorprone.ErrorProneJavaCompilerTest) Test(org.junit.Test)

Example 8 with ErrorProneOptions

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

the class ScannerSupplierTest method applyOverridesSetsSeverity.

@Test
public void applyOverridesSetsSeverity() throws Exception {
    ScannerSupplier ss = ScannerSupplier.fromBugCheckerClasses(BadShiftAmount.class, ChainingConstructorIgnoresParameter.class, StringEquality.class);
    ErrorProneOptions epOptions = ErrorProneOptions.processArgs(ImmutableList.of("-Xep:ChainingConstructorIgnoresParameter:WARN", "-Xep:StringEquality:ERROR"));
    ScannerSupplier overriddenScannerSupplier = ss.applyOverrides(epOptions);
    Map<String, SeverityLevel> expected = ImmutableMap.of("BadShiftAmount", SeverityLevel.ERROR, "ChainingConstructorIgnoresParameter", SeverityLevel.WARNING, "StringEquality", SeverityLevel.ERROR);
    assertScanner(overriddenScannerSupplier).hasSeverities(expected);
}
Also used : SeverityLevel(com.google.errorprone.BugPattern.SeverityLevel) ErrorProneOptions(com.google.errorprone.ErrorProneOptions) ErrorProneJavaCompilerTest(com.google.errorprone.ErrorProneJavaCompilerTest) Test(org.junit.Test)

Example 9 with ErrorProneOptions

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

the class ScannerSupplierTest method applyOverridesEnableAllChecks.

@Test
public void applyOverridesEnableAllChecks() throws Exception {
    ScannerSupplier ss = ScannerSupplier.fromBugCheckerClasses(ArrayEquals.class, BadShiftAmount.class, StaticQualifiedUsingExpression.class).filter(// disables all checks
    Predicates.alwaysFalse());
    // assert empty scanner has no enabled checks
    assertScanner(ss).hasEnabledChecks();
    ErrorProneOptions epOptions = ErrorProneOptions.processArgs(ImmutableList.of("-XepAllDisabledChecksAsWarnings"));
    assertScanner(ss.applyOverrides(epOptions)).hasEnabledChecks(ArrayEquals.class, BadShiftAmount.class, StaticQualifiedUsingExpression.class);
    epOptions = ErrorProneOptions.processArgs(ImmutableList.of("-XepAllDisabledChecksAsWarnings", "-Xep:ArrayEquals:OFF"));
    assertScanner(ss.applyOverrides(epOptions)).hasEnabledChecks(BadShiftAmount.class, StaticQualifiedUsingExpression.class);
    // The 'AllDisabledChecksAsWarnings' flag doesn't populate through to additional plugins
    assertScanner(ss.applyOverrides(epOptions).plus(ScannerSupplier.fromBugCheckerClasses(DivZero.class).filter(t -> false))).hasEnabledChecks(BadShiftAmount.class, StaticQualifiedUsingExpression.class);
}
Also used : RunWith(org.junit.runner.RunWith) BadShiftAmount(com.google.errorprone.bugpatterns.BadShiftAmount) Supplier(java.util.function.Supplier) RestrictedApiChecker(com.google.errorprone.bugpatterns.RestrictedApiChecker) ImmutableList(com.google.common.collect.ImmutableList) BugCheckerInfo(com.google.errorprone.BugCheckerInfo) DivZero(com.google.errorprone.bugpatterns.DivZero) Map(java.util.Map) LongLiteralLowerCaseSuffix(com.google.errorprone.bugpatterns.LongLiteralLowerCaseSuffix) Predicates(com.google.common.base.Predicates) ChainingConstructorIgnoresParameter(com.google.errorprone.bugpatterns.ChainingConstructorIgnoresParameter) ArrayEquals(com.google.errorprone.bugpatterns.ArrayEquals) EqualsIncompatibleType(com.google.errorprone.bugpatterns.EqualsIncompatibleType) InvalidCommandLineOptionException(com.google.errorprone.InvalidCommandLineOptionException) Truth.assertAbout(com.google.common.truth.Truth.assertAbout) Assert.expectThrows(org.junit.Assert.expectThrows) UnsuppressibleArrayEquals(com.google.errorprone.ErrorProneJavaCompilerTest.UnsuppressibleArrayEquals) ImmutableMap(com.google.common.collect.ImmutableMap) ErrorProneJavaCompilerTest(com.google.errorprone.ErrorProneJavaCompilerTest) BugChecker(com.google.errorprone.bugpatterns.BugChecker) PreconditionsCheckNotNull(com.google.errorprone.bugpatterns.PreconditionsCheckNotNull) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BuiltInCheckerSuppliers.getSuppliers(com.google.errorprone.scanner.BuiltInCheckerSuppliers.getSuppliers) Subject(com.google.common.truth.Subject) SubjectFactory(com.google.common.truth.SubjectFactory) StaticQualifiedUsingExpression(com.google.errorprone.bugpatterns.StaticQualifiedUsingExpression) DepAnn(com.google.errorprone.bugpatterns.DepAnn) FailureStrategy(com.google.common.truth.FailureStrategy) ErrorProneOptions(com.google.errorprone.ErrorProneOptions) StringEquality(com.google.errorprone.bugpatterns.StringEquality) Collections(java.util.Collections) SeverityLevel(com.google.errorprone.BugPattern.SeverityLevel) ErrorProneOptions(com.google.errorprone.ErrorProneOptions) ArrayEquals(com.google.errorprone.bugpatterns.ArrayEquals) UnsuppressibleArrayEquals(com.google.errorprone.ErrorProneJavaCompilerTest.UnsuppressibleArrayEquals) BadShiftAmount(com.google.errorprone.bugpatterns.BadShiftAmount) StaticQualifiedUsingExpression(com.google.errorprone.bugpatterns.StaticQualifiedUsingExpression) ErrorProneJavaCompilerTest(com.google.errorprone.ErrorProneJavaCompilerTest) Test(org.junit.Test)

Example 10 with ErrorProneOptions

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

the class ScannerSupplierTest method applyOverridesWorksOnEmptySeverityMap.

@Test
@SuppressWarnings("unchecked")
public void applyOverridesWorksOnEmptySeverityMap() throws Exception {
    ScannerSupplier ss = ScannerSupplier.fromBugCheckerClasses(ChainingConstructorIgnoresParameter.class, DepAnn.class, LongLiteralLowerCaseSuffix.class);
    ErrorProneOptions epOptions = ErrorProneOptions.processArgs(Collections.emptyList());
    assertScanner(ss.applyOverrides(epOptions)).hasEnabledChecks(ChainingConstructorIgnoresParameter.class, DepAnn.class, LongLiteralLowerCaseSuffix.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