use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class CommandLineFlagTest method cantDisableNondisableableCheck.
@Test
public void cantDisableNondisableableCheck() throws Exception {
ErrorProneTestCompiler compiler = builder.report(ScannerSupplier.fromBugCheckerClasses(NondisableableChecker.class)).build();
List<JavaFileObject> sources = compiler.fileManager().forResources(getClass(), "CommandLineFlagTestFile.java");
Result exitCode = compiler.compile(new String[] { "-Xep:NondisableableChecker:OFF" }, sources);
assertThat(output.toString()).contains("NondisableableChecker may not be disabled");
assertThat(exitCode).isEqualTo(Result.CMDERR);
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class CommandLineFlagTest method cantOverrideByAltname.
@Test
public void cantOverrideByAltname() throws Exception {
ErrorProneTestCompiler compiler = builder.report(ScannerSupplier.fromBugCheckerClasses(DisableableChecker.class)).build();
List<JavaFileObject> sources = compiler.fileManager().forResources(getClass(), "CommandLineFlagTestFile.java");
Result exitCode = compiler.compile(new String[] { "-Xep:foo:OFF" }, sources);
assertThat(exitCode).isEqualTo(Result.CMDERR);
assertThat(output.toString()).contains("foo is not a valid checker name");
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class ErrorProneCompilerIntegrationTest method paramsFiles.
@Test
public void paramsFiles() throws IOException {
Path dir = tmpFolder.newFolder("tmp").toPath();
Path source = dir.resolve("Test.java");
Files.write(source, Joiner.on('\n').join(ImmutableList.of(//
"class Test {", " boolean f(Integer i, String s) {", " return i.equals(s);", " }", "}")).getBytes(UTF_8));
Path params = dir.resolve("params.txt");
Files.write(params, Joiner.on(' ').join(ImmutableList.of("-Xep:EqualsIncompatibleType:ERROR", source.toAbsolutePath().toAbsolutePath().toString())).getBytes(UTF_8));
StringWriter output = new StringWriter();
Result result = ErrorProneCompiler.builder().redirectOutputTo(new PrintWriter(output, true)).build().run(new String[] { "@" + params.toAbsolutePath().toString() });
assertThat(result).isEqualTo(Result.ERROR);
assertThat(output.toString()).contains("[EqualsIncompatibleType]");
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class ErrorProneCompilerIntegrationTest method fileWithMultipleTopLevelClasses.
@Test
public void fileWithMultipleTopLevelClasses() throws Exception {
Result exitCode = compiler.compile(compiler.fileManager().forResources(getClass(), "testdata/MultipleTopLevelClassesWithNoErrors.java"));
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 maturityIsResetOnNextCompilation.
@Test
public void maturityIsResetOnNextCompilation() throws Exception {
String[] testFile = { "public class Test {", " public Test() {", " if (true);", " }", "}" };
String[] args = { "-Xep:EmptyIf" };
Result 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]")));
assertThat(outputStream.toString(), exitCode, is(Result.ERROR));
assertTrue("Error should be found. " + diagnosticHelper.describe(), matcher.matches(diagnosticHelper.getDiagnostics()));
diagnosticHelper.clearDiagnostics();
exitCode = compiler.compile(Arrays.asList(compiler.fileManager().forSourceLines("Test.java", testFile)));
outputStream.flush();
assertThat(outputStream.toString(), exitCode, is(Result.OK));
assertThat(diagnosticHelper.getDiagnostics()).isEmpty();
}
Aggregations