Skip to content

Commit

Permalink
Use text blocks for more Error Prone test outputs
Browse files Browse the repository at this point in the history
I skipped reformatted these ones, because reformatting would cause some tests to fail, because of examples like

```
// BUG: Diagnostic contains
@OverRide void f() {}
```

```
// BUG: Diagnostic contains
@OverRide
void f() {} // <- the diagnostic is actually on this line
```

PiperOrigin-RevId: 674341306
  • Loading branch information
cushon authored and Error Prone Team committed Sep 13, 2024
1 parent af9fdd2 commit 350815a
Show file tree
Hide file tree
Showing 46 changed files with 12,740 additions and 10,066 deletions.
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

0 comments on commit 350815a

Please sign in to comment.