Search in sources :

Example 21 with Result

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

the class ErrorProneCompilerIntegrationTest method fileWithError.

@Test
public void fileWithError() throws Exception {
    Result exitCode = compiler.compile(compiler.fileManager().forResources(BadShiftAmount.class, "testdata/BadShiftAmountPositiveCases.java"));
    assertThat(outputStream.toString(), exitCode, is(Result.ERROR));
    Matcher<? super Iterable<Diagnostic<? extends JavaFileObject>>> matcher = hasItem(diagnosticMessage(containsString("[BadShiftAmount]")));
    assertTrue("Error should be found. " + diagnosticHelper.describe(), matcher.matches(diagnosticHelper.getDiagnostics()));
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Diagnostic(javax.tools.Diagnostic) BadShiftAmount(com.google.errorprone.bugpatterns.BadShiftAmount) Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 22 with Result

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

the class ErrorProneCompilerIntegrationTest method ignoreGeneratedConstructors.

@Test
public void ignoreGeneratedConstructors() throws Exception {
    compilerBuilder.report(ScannerSupplier.fromBugCheckerClasses(ConstructorMatcher.class));
    compiler = compilerBuilder.build();
    Result exitCode = compiler.compile(Arrays.asList(compiler.fileManager().forSourceLines("Test.java", "public class Test {}")));
    Matcher<? super Iterable<Diagnostic<? extends JavaFileObject>>> matcher = not(hasItem(diagnosticMessage(containsString("[ConstructorMatcher]"))));
    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) Test(org.junit.Test)

Example 23 with Result

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

the class ErrorProneCompilerIntegrationTest method compilePolicy_simple.

@Test
public void compilePolicy_simple() throws Exception {
    Result exitCode = compiler.compile(new String[] { "-XDcompilePolicy=simple" }, 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 24 with Result

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

the class ErrorProneCompilerIntegrationTest method fileWithMultipleTopLevelClassesExtendsWithError.

/**
   * Regression test for a bug in which multiple top-level classes may cause
   * NullPointerExceptions in the matchers.
   */
@Test
public void fileWithMultipleTopLevelClassesExtendsWithError() throws Exception {
    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(containsString("[SelfAssignment]")));
    assertTrue("Warning should be found. " + diagnosticHelper.describe(), matcher.matches(diagnosticHelper.getDiagnostics()));
    assertThat(diagnosticHelper.getDiagnostics()).hasSize(4);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Diagnostic(javax.tools.Diagnostic) Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 25 with Result

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

the class ErrorProneCompilerIntegrationTest method fileWithWarning.

@Test
public void fileWithWarning() throws Exception {
    compilerBuilder.report(ScannerSupplier.fromBugCheckerClasses(NonAtomicVolatileUpdate.class));
    compiler = compilerBuilder.build();
    Result exitCode = compiler.compile(compiler.fileManager().forResources(NonAtomicVolatileUpdate.class, "testdata/NonAtomicVolatileUpdatePositiveCases.java"));
    assertThat(outputStream.toString(), exitCode, is(Result.OK));
    Matcher<? super Iterable<Diagnostic<? extends JavaFileObject>>> matcher = hasItem(diagnosticMessage(containsString("[NonAtomicVolatileUpdate]")));
    assertTrue("Warning should be found. " + diagnosticHelper.describe(), matcher.matches(diagnosticHelper.getDiagnostics()));
}
Also used : NonAtomicVolatileUpdate(com.google.errorprone.bugpatterns.NonAtomicVolatileUpdate) JavaFileObject(javax.tools.JavaFileObject) Diagnostic(javax.tools.Diagnostic) 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