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);
}
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));
}
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()));
}
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);
}
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));
}
Aggregations