use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class RefasterRuleCompiler method run.
private Result run(String[] argv, Context context) {
try {
argv = prepareCompilation(argv, context);
} catch (InvalidCommandLineOptionException e) {
System.err.println(e.getMessage());
System.err.flush();
return Result.CMDERR;
}
try {
Result compileResult = new Main("RefasterRuleCompiler", new PrintWriter(new OutputStreamWriter(System.err, StandardCharsets.UTF_8))).compile(argv, context);
System.err.flush();
return compileResult;
} catch (InvalidCommandLineOptionException e) {
System.err.println(e.getMessage());
System.err.flush();
return Result.CMDERR;
}
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class CompilationTestHelper method doTest.
/**
* Performs a compilation and checks that the diagnostics and result match the expectations.
*/
// TODO(eaftan): any way to ensure that this is actually called?
public void doTest() {
Preconditions.checkState(!sources.isEmpty(), "No source files to compile");
List<String> allArgs = buildArguments(args);
Result result = compile(sources, allArgs.toArray(new String[allArgs.size()]));
for (Diagnostic<? extends JavaFileObject> diagnostic : diagnosticHelper.getDiagnostics()) {
if (diagnostic.getCode().contains("error.prone.crash")) {
fail(diagnostic.getMessage(Locale.ENGLISH));
}
}
if (expectNoDiagnostics) {
List<Diagnostic<? extends JavaFileObject>> diagnostics = diagnosticHelper.getDiagnostics();
assertWithMessage(String.format("Expected no diagnostics produced, but found %d: %s", diagnostics.size(), diagnostics)).that(diagnostics.size()).isEqualTo(0);
} else {
for (JavaFileObject source : sources) {
try {
diagnosticHelper.assertHasDiagnosticOnAllMatchingLines(source, lookForCheckNameInDiagnostic);
} catch (IOException e) {
throw new IOError(e);
}
}
assertTrue("Unused error keys: " + diagnosticHelper.getUnusedLookupKeys(), diagnosticHelper.getUnusedLookupKeys().isEmpty());
}
if (expectedResult.isPresent()) {
assertWithMessage(String.format("Expected compilation result %s, but was %s", expectedResult.get(), result)).that(result).isEqualTo(expectedResult.get());
}
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class CommandLineFlagTest method canEnableWithOverriddenSeverity.
@Test
public void canEnableWithOverriddenSeverity() throws Exception {
ErrorProneTestCompiler compiler = builder.build();
List<JavaFileObject> sources = compiler.fileManager().forResources(EmptyIfStatement.class, "testdata/EmptyIfStatementPositiveCases.java");
Result exitCode = compiler.compile(sources);
assertThat(exitCode).isEqualTo(Result.OK);
assertThat(diagnosticHelper.getDiagnostics()).isEmpty();
diagnosticHelper.clearDiagnostics();
exitCode = compiler.compile(new String[] { "-Xep:EmptyIf:WARN" }, sources);
assertThat(exitCode).isEqualTo(Result.OK);
assertThat(diagnosticHelper.getDiagnostics()).isNotEmpty();
assertThat(diagnosticHelper.getDiagnostics().toString()).contains("[EmptyIf]");
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class CommandLineFlagTest method canDisable.
@Test
public void canDisable() throws Exception {
ErrorProneTestCompiler compiler = builder.report(ScannerSupplier.fromBugCheckerClasses(DisableableChecker.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:DisableableChecker:OFF" }, sources);
assertThat(exitCode).isEqualTo(Result.OK);
assertThat(diagnosticHelper.getDiagnostics()).isEmpty();
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class CommandLineFlagTest method canEnableWithDefaultSeverity.
// We have to use one of the built-in checkers for the following two tests because there is no
// way to specify a custom checker and have it be off by default.
@Test
public void canEnableWithDefaultSeverity() throws Exception {
ErrorProneTestCompiler compiler = builder.build();
List<JavaFileObject> sources = compiler.fileManager().forResources(EmptyIfStatement.class, "testdata/EmptyIfStatementPositiveCases.java");
Result exitCode = compiler.compile(sources);
assertThat(exitCode).isEqualTo(Result.OK);
assertThat(diagnosticHelper.getDiagnostics()).isEmpty();
exitCode = compiler.compile(new String[] { "-Xep:EmptyIf" }, sources);
assertThat(exitCode).isEqualTo(Result.ERROR);
}
Aggregations