Search in sources :

Example 11 with Result

use of com.sun.tools.javac.main.Main.Result in project error-prone by google.

the class ErrorProneCompilerIntegrationTest method annotationProcessingWorks.

/**
   * Regression test for Issue 188, error-prone doesn't work with annotation processors.
   */
@Test
public void annotationProcessingWorks() throws Exception {
    Result exitCode = compiler.compile(compiler.fileManager().forResources(getClass(), "testdata/UsesAnnotationProcessor.java"), Arrays.asList(new NullAnnotationProcessor()));
    assertThat(outputStream.toString(), exitCode, is(Result.OK));
}
Also used : Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 12 with Result

use of com.sun.tools.javac.main.Main.Result in project error-prone by google.

the class ErrorProneCompilerIntegrationTest method crashSourcePosition.

@Test
public void crashSourcePosition() throws Exception {
    compiler = compilerBuilder.report(ScannerSupplier.fromBugCheckerClasses(CrashOnReturn.class)).build();
    Result exitCode = compiler.compile(Arrays.asList(compiler.fileManager().forSourceLines("test/Test.java", "package Test;", "class Test {", "  void f() {", "    return;", "  }", "}")));
    assertThat(exitCode).named(outputStream.toString()).isEqualTo(Result.ERROR);
    assertThat(diagnosticHelper.getDiagnostics()).hasSize(1);
    Diagnostic<? extends JavaFileObject> diag = Iterables.getOnlyElement(diagnosticHelper.getDiagnostics());
    assertThat(diag.getLineNumber()).isEqualTo(4);
    assertThat(diag.getColumnNumber()).isEqualTo(5);
    assertThat(diag.getSource().toUri().toString()).endsWith("test/Test.java");
    assertThat(diag.getMessage(Locale.ENGLISH)).contains("An unhandled exception was thrown by the Error Prone static analysis plugin");
}
Also used : Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 13 with Result

use of com.sun.tools.javac.main.Main.Result in project error-prone by google.

the class CommandLineFlagTest method canDemoteToWarning.

@Test
public void canDemoteToWarning() throws Exception {
    ErrorProneTestCompiler compiler = builder.report(ScannerSupplier.fromBugCheckerClasses(ErrorChecker.class)).build();
    List<JavaFileObject> sources = compiler.fileManager().forResources(getClass(), "CommandLineFlagTestFile.java");
    Result exitCode = compiler.compile(sources);
    assertThat(exitCode).isEqualTo(Result.ERROR);
    diagnosticHelper.clearDiagnostics();
    exitCode = compiler.compile(new String[] { "-Xep:ErrorChecker:WARN" }, sources);
    assertThat(exitCode).isEqualTo(Result.OK);
    assertThat(diagnosticHelper.getDiagnostics()).isNotEmpty();
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 14 with Result

use of com.sun.tools.javac.main.Main.Result in project error-prone by google.

the class CommandLineFlagTest method canPromoteToError.

@Test
public void canPromoteToError() throws Exception {
    ErrorProneTestCompiler compiler = builder.report(ScannerSupplier.fromBugCheckerClasses(WarningChecker.class)).build();
    List<JavaFileObject> sources = compiler.fileManager().forResources(getClass(), "CommandLineFlagTestFile.java");
    Result exitCode = compiler.compile(sources);
    assertThat(exitCode).isEqualTo(Result.OK);
    assertThat(diagnosticHelper.getDiagnostics()).isNotEmpty();
    exitCode = compiler.compile(new String[] { "-Xep:WarningChecker:ERROR" }, sources);
    assertThat(exitCode).isEqualTo(Result.ERROR);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 15 with Result

use of com.sun.tools.javac.main.Main.Result in project error-prone by google.

the class CommandLineFlagTest method ignoreUnknownChecksFlagAllowsOverridingUnknownCheck.

@Test
public void ignoreUnknownChecksFlagAllowsOverridingUnknownCheck() throws Exception {
    ErrorProneTestCompiler compiler = builder.build();
    List<JavaFileObject> sources = compiler.fileManager().forResources(getClass(), "CommandLineFlagTestFile.java");
    List<String> badOptions = Arrays.asList("-Xep:BogusChecker:ERROR", "-Xep:BogusChecker:WARN", "-Xep:BogusChecker:OFF", "-Xep:BogusChecker");
    for (String badOption : badOptions) {
        Result exitCode = compiler.compile(new String[] { "-XepIgnoreUnknownCheckNames", badOption }, sources);
        assertThat(exitCode).isEqualTo(Result.OK);
    }
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Aggregations

Result (com.sun.tools.javac.main.Main.Result)36 Test (org.junit.Test)34 JavaFileObject (javax.tools.JavaFileObject)20 Diagnostic (javax.tools.Diagnostic)10 Matchers.containsString (org.hamcrest.Matchers.containsString)7 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)2 Path (java.nio.file.Path)2 ImmutableList (com.google.common.collect.ImmutableList)1 LookForCheckNameInDiagnostic (com.google.errorprone.DiagnosticTestHelper.LookForCheckNameInDiagnostic)1 InvalidCommandLineOptionException (com.google.errorprone.InvalidCommandLineOptionException)1 BadShiftAmount (com.google.errorprone.bugpatterns.BadShiftAmount)1 BugChecker (com.google.errorprone.bugpatterns.BugChecker)1 NonAtomicVolatileUpdate (com.google.errorprone.bugpatterns.NonAtomicVolatileUpdate)1 Main (com.sun.tools.javac.main.Main)1 IOError (java.io.IOError)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 List (java.util.List)1 JarEntry (java.util.jar.JarEntry)1