Skip to content

Commit

Permalink
Use text blocks in turbine integration tests
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 673953961
  • Loading branch information
cushon authored and Javac Team committed Sep 25, 2024
1 parent 5a874b7 commit 877c472
Show file tree
Hide file tree
Showing 14 changed files with 2,161 additions and 2,042 deletions.
1,983 changes: 989 additions & 994 deletions javatests/com/google/turbine/binder/BinderErrorTest.java

Large diffs are not rendered by default.

204 changes: 127 additions & 77 deletions javatests/com/google/turbine/deps/DependenciesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ public void excluded() throws Exception {
new LibraryBuilder()
.setClasspath(liba)
.addSourceLines(
"B.java", //
"class B {",
" public static final A a = new A();",
"}")
"B.java",
"""
class B {
public static final A a = new A();
}
""")
.compileToJar("libb.jar");
DepsProto.Dependencies deps =
new DepsBuilder()
Expand All @@ -167,10 +169,12 @@ public void transitive() throws Exception {
Path liba =
new LibraryBuilder()
.addSourceLines(
"A.java", //
"class A {",
" public static final class Y {}",
"}")
"A.java",
"""
class A {
public static final class Y {}
}
""")
.compileToJar("liba.jar");
Path libb =
new LibraryBuilder()
Expand All @@ -181,10 +185,12 @@ public void transitive() throws Exception {
new DepsBuilder()
.setClasspath(liba, libb)
.addSourceLines(
"Test.java", //
"class Test extends B {",
" public static class X extends Y {}",
"}")
"Test.java",
"""
class Test extends B {
public static class X extends Y {}
}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -197,35 +203,49 @@ public void closure() throws Exception {
new LibraryBuilder()
.addSourceLines(
"i/I.java",
"package i;", //
"public interface I {}")
"""
package i;
public interface I {}
""")
.compileToJar("libi.jar");
Path liba =
new LibraryBuilder()
.setClasspath(libi)
.addSourceLines(
"a/A.java", //
"package a;",
"import i.I;",
"public class A implements I {}")
"a/A.java",
"""
package a;
import i.I;
public class A implements I {}
""")
.compileToJar("liba.jar");
Path libb =
new LibraryBuilder()
.setClasspath(liba, libi)
.addSourceLines(
"b/B.java", //
"package b;",
"import a.A;",
"public class B extends A {}")
"b/B.java",
"""
package b;
import a.A;
public class B extends A {}
""")
.compileToJar("libb.jar");
{
DepsProto.Dependencies deps =
new DepsBuilder()
.setClasspath(liba, libb, libi)
.addSourceLines(
"Test.java", //
"import b.B;",
"class Test extends B {}")
"Test.java",
"""
import b.B;
class Test extends B {}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -242,9 +262,12 @@ public void closure() throws Exception {
new DepsBuilder()
.setClasspath(liba, libb)
.addSourceLines(
"Test.java", //
"import b.B;",
"class Test extends B {}")
"Test.java",
"""
import b.B;
class Test extends B {}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand Down Expand Up @@ -298,34 +321,46 @@ public void packageInfo() throws Exception {
new LibraryBuilder()
.addSourceLines(
"p/Anno.java",
"package p;",
"import java.lang.annotation.Retention;",
"import static java.lang.annotation.RetentionPolicy.RUNTIME;",
"@Retention(RUNTIME)",
"@interface Anno {}")
"""
package p;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Retention(RUNTIME)
@interface Anno {}
""")
.addSourceLines(
"p/package-info.java", //
"@Anno",
"package p;")
"p/package-info.java",
"""
@Anno
package p;
""")
.compileToJar("libpackage-info.jar");
Path libp =
new LibraryBuilder()
.setClasspath(libpackageInfo)
.addSourceLines(
"p/P.java", //
"package p;",
"public class P {}")
"p/P.java",
"""
package p;
public class P {}
""")
.compileToJar("libp.jar");
{
DepsProto.Dependencies deps =
new DepsBuilder()
.setClasspath(libp, libpackageInfo)
.addSourceLines(
"Test.java", //
"import p.P;",
"class Test {",
" P p;",
"}")
"Test.java",
"""
import p.P;
class Test {
P p;
}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -345,12 +380,14 @@ public void annotations_recursive() throws Exception {
new DepsBuilder()
.setClasspath(libA, libB)
.addSourceLines(
"Test.java", //
"import a.A;",
"import b.B;",
"@A(B.class)",
"class Test {",
"}")
"Test.java",
"""
import a.A;
import b.B;
@A(B.class)
class Test {}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -365,13 +402,16 @@ public void annotations_field() throws Exception {
new DepsBuilder()
.setClasspath(libA, libB)
.addSourceLines(
"Test.java", //
"import a.A;",
"import b.B;",
"class Test {",
" @A(B.class)",
" int x;",
"}")
"Test.java",
"""
import a.A;
import b.B;
class Test {
@A(B.class)
int x;
}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -386,13 +426,16 @@ public void annotations_method() throws Exception {
new DepsBuilder()
.setClasspath(libA, libB)
.addSourceLines(
"Test.java", //
"import a.A;",
"import b.B;",
"class Test {",
" @A(B.class)",
" void f() {}",
"}")
"Test.java",
"""
import a.A;
import b.B;
class Test {
@A(B.class)
void f() {}
}
""")
.run();
assertThat(depsMap(deps))
.containsExactly(
Expand All @@ -403,26 +446,33 @@ private Path libB() throws Exception {
return new LibraryBuilder()
.addSourceLines(
"b/B.java",
"package b;",
"import java.lang.annotation.Retention;",
"import static java.lang.annotation.RetentionPolicy.RUNTIME;",
"@Retention(RUNTIME)",
"public @interface B {",
"}")
"""
package b;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Retention(RUNTIME)
public @interface B {}
""")
.compileToJar("libb.jar");
}

private Path libA() throws Exception {
return new LibraryBuilder()
.addSourceLines(
"a/A.java",
"package a;",
"import java.lang.annotation.Retention;",
"import static java.lang.annotation.RetentionPolicy.RUNTIME;",
"@Retention(RUNTIME)",
"public @interface A {",
" Class<?> value() default Object.class;",
"}")
"""
package a;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Retention(RUNTIME)
public @interface A {
Class<?> value() default Object.class;
}
""")
.compileToJar("liba.jar");
}

Expand Down
Loading

0 comments on commit 877c472

Please sign in to comment.