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