use of com.google.errorprone.DiagnosticTestHelper.LookForCheckNameInDiagnostic 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());
}
}
Aggregations