use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class ErrorProneCompilerIntegrationTest method invalidFlagCausesCmdErrResult.
@Test
public void invalidFlagCausesCmdErrResult() throws Exception {
String[] args = { "-Xep:" };
Result exitCode = compiler.compile(args, Arrays.asList(compiler.fileManager().forSourceLines("Test.java", "public class Test {", " public Test() {}", "}")));
outputStream.flush();
assertThat(outputStream.toString(), exitCode, is(Result.CMDERR));
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class ErrorProneCompilerIntegrationTest method severityIsResetOnNextCompilation.
@Test
public void severityIsResetOnNextCompilation() throws Exception {
String[] testFile = { "public class Test {", " void doIt (int i) {", " i = i;", " }", "}" };
String[] args = { "-Xep:SelfAssignment:WARN" };
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("[SelfAssignment]")));
assertThat(outputStream.toString(), exitCode, is(Result.OK));
assertTrue("Warning should be found. " + diagnosticHelper.describe(), matcher.matches(diagnosticHelper.getDiagnostics()));
// Should reset to default severity (ERROR)
exitCode = compiler.compile(Arrays.asList(compiler.fileManager().forSourceLines("Test.java", testFile)));
outputStream.flush();
assertThat(outputStream.toString(), exitCode, is(Result.ERROR));
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class ErrorProneCompilerIntegrationTest method cannotSuppressGeneratedError.
@Test
public void cannotSuppressGeneratedError() throws Exception {
String[] generatedFile = { "@javax.annotation.Generated(\"Foo\")", "class Generated {", " public Generated() {", " if (true);", " }", "}" };
String[] args = { "-Xep:EmptyIf:ERROR", "-XepDisableWarningsInGeneratedCode" };
Result exitCode = compiler.compile(args, Arrays.asList(compiler.fileManager().forSourceLines("Generated.java", generatedFile)));
outputStream.flush();
assertThat(diagnosticHelper.getDiagnostics()).hasSize(1);
assertThat(diagnosticHelper.getDiagnostics().get(0).getMessage(Locale.ENGLISH)).contains("[EmptyIf]");
assertThat(outputStream.toString(), exitCode, is(Result.ERROR));
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class CommandLineFlagTest method malformedFlag.
/* Tests for new-style ("-Xep:") flags */
@Test
public void malformedFlag() throws Exception {
ErrorProneTestCompiler compiler = builder.build();
List<String> badArgs = Arrays.asList(// too many parts
"-Xep:Foo:WARN:jfkdlsdf", // no check name
"-Xep:", // nonexistent severity level
"-Xep:Foo:FJDKFJSD");
Result exitCode;
for (String badArg : badArgs) {
exitCode = compiler.compile(new String[] { badArg }, Collections.<JavaFileObject>emptyList());
assertThat(exitCode).isEqualTo(Result.CMDERR);
assertThat(output.toString()).contains("invalid flag");
}
}
use of com.sun.tools.javac.main.Main.Result in project error-prone by google.
the class CommandLineFlagTest method cantOverrideNonexistentCheck.
@Test
public void cantOverrideNonexistentCheck() throws Exception {
ErrorProneTestCompiler compiler = builder.build();
List<JavaFileObject> sources = compiler.fileManager().forResources(getClass(), "CommandLineFlagTestFile.java");
List<String> badOptions = Arrays.asList("-Xep:BogusChecker:ERROR", "-Xep:BogusChecker:WARN", "-Xep:BogusChecker:OFF", "-Xep:BogusChecker");
for (String badOption : badOptions) {
Result exitCode = compiler.compile(new String[] { badOption }, sources);
assertThat(exitCode).isEqualTo(Result.CMDERR);
assertThat(output.toString()).contains("BogusChecker is not a valid checker name");
}
}
Aggregations