Search in sources :

Example 6 with Result

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);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 7 with Result

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");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 8 with Result

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]");
}
Also used : Path(java.nio.file.Path) StringWriter(java.io.StringWriter) Result(com.sun.tools.javac.main.Main.Result) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 9 with Result

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));
}
Also used : Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Example 10 with Result

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();
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Diagnostic(javax.tools.Diagnostic) Matchers.containsString(org.hamcrest.Matchers.containsString) Result(com.sun.tools.javac.main.Main.Result) Test(org.junit.Test)

Aggregations

Result (com.sun.tools.javac.main.Main.Result)36 Test (org.junit.Test)34 JavaFileObject (javax.tools.JavaFileObject)20 Diagnostic (javax.tools.Diagnostic)10 Matchers.containsString (org.hamcrest.Matchers.containsString)7 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)2 Path (java.nio.file.Path)2 ImmutableList (com.google.common.collect.ImmutableList)1 LookForCheckNameInDiagnostic (com.google.errorprone.DiagnosticTestHelper.LookForCheckNameInDiagnostic)1 InvalidCommandLineOptionException (com.google.errorprone.InvalidCommandLineOptionException)1 BadShiftAmount (com.google.errorprone.bugpatterns.BadShiftAmount)1 BugChecker (com.google.errorprone.bugpatterns.BugChecker)1 NonAtomicVolatileUpdate (com.google.errorprone.bugpatterns.NonAtomicVolatileUpdate)1 Main (com.sun.tools.javac.main.Main)1 IOError (java.io.IOError)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 List (java.util.List)1 JarEntry (java.util.jar.JarEntry)1