Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use text blocks for more Error Prone test outputs #4575

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,12 @@ public void ignoreGeneratedSuperInvocations() {
compiler.compile(
Arrays.asList(
forSourceLines(
"Test.java", //
"public class Test {",
" public Test() {}",
"}")));
"Test.java",
"""
public class Test {
public Test() {}
}
""")));

assertWithMessage("[SuperCallMatcher]")
.that(diagnosticHelper.getDiagnostics())
Expand All @@ -301,10 +303,12 @@ public void invalidFlagCausesCmdErrResult() {
args,
Arrays.asList(
forSourceLines(
"Test.java", //
"public class Test {",
" public Test() {}",
"}"))));
"Test.java",
"""
public class Test {
public Test() {}
}
"""))));
}

@Test
Expand Down Expand Up @@ -494,12 +498,14 @@ public void crashSourcePosition() {
Arrays.asList(
forSourceLines(
"test/Test.java",
"package Test;",
"class Test {",
" void f() {",
" return;",
" }",
"}")));
"""
package Test;
class Test {
void f() {
return;
}
}
""")));
assertWithMessage(outputStream.toString()).that(exitCode).isEqualTo(Result.ERROR);
assertThat(diagnosticHelper.getDiagnostics()).hasSize(1);
Diagnostic<? extends JavaFileObject> diag =
Expand Down Expand Up @@ -530,9 +536,11 @@ public void compilePolicy_byfile() {
new String[] {"-XDcompilePolicy=byfile"},
Arrays.asList(
forSourceLines(
"Test.java", //
"package test;",
"class Test {}")));
"Test.java",
"""
package test;
class Test {}
""")));
outputStream.flush();
assertWithMessage(outputStream.toString()).that(exitCode).isEqualTo(Result.OK);
}
Expand All @@ -544,9 +552,11 @@ public void compilePolicy_simple() {
new String[] {"-XDcompilePolicy=simple"},
Arrays.asList(
forSourceLines(
"Test.java", //
"package test;",
"class Test {}")));
"Test.java",
"""
package test;
class Test {}
""")));
outputStream.flush();
assertWithMessage(outputStream.toString()).that(exitCode).isEqualTo(Result.OK);
}
Expand All @@ -573,10 +583,12 @@ public void compilationWithError() {
Arrays.asList(
forSourceLines(
"Test.java",
"package test;",
"public class Test {",
" Object f() { return new NoSuch(); }",
"}")));
"""
package test;
public class Test {
Object f() { return new NoSuch(); }
}
""")));
outputStream.flush();
String output = diagnosticHelper.getDiagnostics().toString();
assertThat(output).contains("error: cannot find symbol");
Expand Down Expand Up @@ -616,10 +628,12 @@ public void checkerWithFlags() {
Arrays.asList(
forSourceLines(
"Test.java",
"package test;",
"public class Test {",
" Object f() { return \"XYLOPHONE\"; }",
"}"));
"""
package test;
public class Test {
Object f() { return "XYLOPHONE"; }
}
"""));

compilerBuilder.report(ScannerSupplier.fromBugCheckerClasses(ForbiddenString.class));
compiler = compilerBuilder.build();
Expand All @@ -636,10 +650,12 @@ public void flagsAreResetOnNextCompilation() {
Arrays.asList(
forSourceLines(
"Test.java",
"package test;",
"public class Test {",
" Object f() { return \"BANANAS\"; }",
"}"));
"""
package test;
public class Test {
Object f() { return "BANANAS"; }
}
"""));

// First compile forbids "bananas", should fail.
compilerBuilder.report(ScannerSupplier.fromBugCheckerClasses(ForbiddenString.class));
Expand Down
Loading
Loading