Search in sources :

Example 31 with Result

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

the class DiagnosticKindTest method testSuggestion.

@Test
public void testSuggestion() throws Exception {
    compilerBuilder.report(ScannerSupplier.fromBugCheckerClasses(SuggestionChecker.class));
    ErrorProneTestCompiler compiler = compilerBuilder.build();
    Result result = compiler.compile(Arrays.asList(compiler.fileManager().forSourceLines("Test.java", TEST_CODE)));
    assertThat(diagnosticHelper.getDiagnostics()).hasSize(1);
    assertThat(diagnosticHelper.getDiagnostics().get(0).getKind()).isEqualTo(Diagnostic.Kind.NOTE);
    assertThat(diagnosticHelper.getDiagnostics().get(0).toString()).contains("Note:");
    assertThat(result).isEqualTo(Result.OK);
}
Also used : Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 32 with Result

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

the class ErrorProneCompilerIntegrationTest method ignoreGeneratedSuperInvocations.

// TODO(cushon) - how can we distinguish between synthetic super() calls and real ones?
@Ignore
@Test
public void ignoreGeneratedSuperInvocations() throws Exception {
    compilerBuilder.report(ScannerSupplier.fromBugCheckerClasses(SuperCallMatcher.class));
    compiler = compilerBuilder.build();
    Result exitCode = compiler.compile(Arrays.asList(compiler.fileManager().forSourceLines("Test.java", "public class Test {", "  public Test() {}", "}")));
    Matcher<? super Iterable<Diagnostic<? extends JavaFileObject>>> matcher = not(hasItem(diagnosticMessage(containsString("[SuperCallMatcher]"))));
    assertTrue("Warning should be found. " + diagnosticHelper.describe(), matcher.matches(diagnosticHelper.getDiagnostics()));
    assertThat(outputStream.toString(), exitCode, is(Result.OK));
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Diagnostic(javax.tools.Diagnostic) Result(com.sun.tools.javac.main.Main.Result) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 33 with Result

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

the class ErrorProneCompilerIntegrationTest method unhandledExceptionsAreReportedWithoutBugParadeLink.

@Test
public void unhandledExceptionsAreReportedWithoutBugParadeLink() throws Exception {
    compilerBuilder.report(ScannerSupplier.fromBugCheckerClasses(Throwing.class));
    compiler = compilerBuilder.build();
    Result exitCode = compiler.compile(compiler.fileManager().forResources(getClass(), "testdata/MultipleTopLevelClassesWithErrors.java", "testdata/ExtendedMultipleTopLevelClassesWithErrors.java"));
    assertThat(outputStream.toString(), exitCode, is(Result.ERROR));
    Matcher<? super Iterable<Diagnostic<? extends JavaFileObject>>> matcher = hasItem(diagnosticMessage(CoreMatchers.<String>allOf(containsString("IllegalStateException: test123"), containsString("unhandled exception was thrown by the Error Prone"))));
    assertTrue("Error should be reported. " + diagnosticHelper.describe(), matcher.matches(diagnosticHelper.getDiagnostics()));
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Diagnostic(javax.tools.Diagnostic) Matchers.containsString(org.hamcrest.Matchers.containsString) Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 34 with Result

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

the class ErrorProneCompilerIntegrationTest method compilePolicy_byfile.

@Test
public void compilePolicy_byfile() throws Exception {
    Result exitCode = compiler.compile(new String[] { "-XDcompilePolicy=byfile" }, Arrays.asList(compiler.fileManager().forSourceLines("Test.java", "class Test {}")));
    outputStream.flush();
    assertThat(exitCode).named(outputStream.toString()).isEqualTo(Result.OK);
}
Also used : Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 35 with Result

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

the class ErrorProneCompilerIntegrationTest method flagEnablesCheck.

@Test
public void flagEnablesCheck() throws Exception {
    String[] testFile = { "public class Test {", "  public Test() {", "    if (true);", "  }", "}" };
    Result exitCode = compiler.compile(Arrays.asList(compiler.fileManager().forSourceLines("Test.java", testFile)));
    outputStream.flush();
    assertThat(diagnosticHelper.getDiagnostics()).isEmpty();
    assertThat(outputStream.toString(), exitCode, is(Result.OK));
    String[] args = { "-Xep:EmptyIf" };
    exitCode = compiler.compile(args, Arrays.asList(compiler.fileManager().forSourceLines("Test.java", testFile)));
    outputStream.flush();
    Matcher<? super Iterable<Diagnostic<? extends JavaFileObject>>> matcher = hasItem(diagnosticMessage(containsString("[EmptyIf]")));
    assertTrue("Error should be found. " + diagnosticHelper.describe(), matcher.matches(diagnosticHelper.getDiagnostics()));
    assertThat(outputStream.toString(), exitCode, is(Result.ERROR));
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Diagnostic(javax.tools.Diagnostic) Matchers.containsString(org.hamcrest.Matchers.containsString) 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