use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class DiagnosticKindTest method testWarning.
@Test
public void testWarning() throws Exception {
compilerBuilder.report(ScannerSupplier.fromBugCheckerClasses(WarningChecker.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.WARNING);
assertThat(diagnosticHelper.getDiagnostics().get(0).toString()).contains("warning:");
assertThat(result).isEqualTo(Result.OK);
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class DiagnosticKindTest method testError.
@Test
public void testError() throws Exception {
compilerBuilder.report(ScannerSupplier.fromBugCheckerClasses(ErrorChecker.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.ERROR);
assertThat(diagnosticHelper.getDiagnostics().get(0).toString()).contains("error:");
assertThat(result).isEqualTo(Result.ERROR);
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class ErrorProneCompilerIntegrationTest method fileWithMultipleTopLevelClassesExtends.
@Test
public void fileWithMultipleTopLevelClassesExtends() throws Exception {
Result exitCode = compiler.compile(compiler.fileManager().forResources(getClass(), "testdata/MultipleTopLevelClassesWithNoErrors.java", "testdata/ExtendedMultipleTopLevelClassesWithNoErrors.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 reportReadyForAnalysisOnce.
/**
* Test that if javac does dataflow on a class twice error-prone only analyses it once.
*/
@Test
public void reportReadyForAnalysisOnce() throws Exception {
Result exitCode = compiler.compile(compiler.fileManager().forResources(getClass(), "testdata/FlowConstants.java", "testdata/FlowSub.java", // subclass is desugared, once normally).
"testdata/FlowSuper.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 plugin.
@Test
public void plugin() throws Exception {
Path base = tmpFolder.newFolder().toPath();
Path source = base.resolve("test/Test.java");
Files.createDirectories(source.getParent());
Files.write(source, Arrays.asList(//
"package test;", "public class Test {", " int f() { return 42; }", "}"), UTF_8);
Path jar = base.resolve("libproc.jar");
try (JarOutputStream jos = new JarOutputStream(Files.newOutputStream(jar))) {
jos.putNextEntry(new JarEntry("META-INF/services/" + BugChecker.class.getName()));
jos.write((CPSChecker.class.getName() + "\n").getBytes(UTF_8));
String classFile = CPSChecker.class.getName().replace('.', '/') + ".class";
jos.putNextEntry(new JarEntry(classFile));
ByteStreams.copy(getClass().getClassLoader().getResourceAsStream(classFile), jos);
}
// no plugins
{
List<String> args = ImmutableList.of(source.toAbsolutePath().toString(), "-processorpath", File.pathSeparator);
StringWriter out = new StringWriter();
Result result = ErrorProneCompiler.compile(args.toArray(new String[0]), new PrintWriter(out, true));
assertThat(result).isEqualTo(Result.OK);
}
// with plugins
{
List<String> args = ImmutableList.of(source.toAbsolutePath().toString(), "-processorpath", jar.toAbsolutePath().toString());
StringWriter out = new StringWriter();
Result result = ErrorProneCompiler.compile(args.toArray(new String[0]), new PrintWriter(out, true));
assertThat(out.toString()).contains("Using 'return' is considered harmful");
assertThat(result).isEqualTo(Result.ERROR);
}
}
Aggregations