Skip to content

Commit

Permalink
Flip shareTestComponents flag to default to true. Update documentatio…
Browse files Browse the repository at this point in the history
…n to match.

RELNOTES=Changes shareTestComponents default value. This is a breaking change for some tests due to changed visibility requirements.
PiperOrigin-RevId: 398356434
  • Loading branch information
groakley authored and Dagger Team committed Sep 22, 2021
1 parent 5964681 commit 7e09cee
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
3 changes: 2 additions & 1 deletion java/dagger/hilt/processor/internal/HiltCompilerOptions.java
Expand Up @@ -108,7 +108,8 @@ private enum BooleanOption {

DISABLE_MODULES_HAVE_INSTALL_IN_CHECK("disableModulesHaveInstallInCheck", false),

SHARE_TEST_COMPONENTS("shareTestComponents", false),
SHARE_TEST_COMPONENTS(
"shareTestComponents", true),

USE_FRAGMENT_GET_CONTEXT_FIX("android.useFragmentGetContextFix", false);

Expand Down
2 changes: 2 additions & 0 deletions javatests/dagger/hilt/android/BUILD
Expand Up @@ -30,6 +30,7 @@ android_library(
"MultiTestRootExternalModules.java",
],
exports_manifest = 1,
javacopts = ["-Adagger.hilt.shareTestComponents=true"],
manifest = "AndroidManifest.xml",
deps = [
"//:android_local_test_exports",
Expand Down Expand Up @@ -169,6 +170,7 @@ android_local_test(
name = "EarlyEntryPointNoEntryPointsDefinedTest",
size = "small",
srcs = ["EarlyEntryPointNoEntryPointsDefinedTest.java"],
javacopts = ["-Adagger.hilt.shareTestComponents=false"], # TODO(b/200821875): Remove explicit flag
manifest_values = {
"minSdkVersion": "14",
},
Expand Down
2 changes: 1 addition & 1 deletion javatests/dagger/hilt/android/ModuleTest.java
Expand Up @@ -79,7 +79,7 @@ static Dep2 provide() {
// constructor exists.
@Module
@InstallIn(SingletonComponent.class)
static final class TestModule3 {
public static final class TestModule3 {
TestModule3() {
this("");
}
Expand Down
15 changes: 9 additions & 6 deletions javatests/dagger/hilt/android/MultiTestRoot1Test.java
Expand Up @@ -150,7 +150,8 @@ static class Foo {
}
}

static class Bar {
// Must be public due to b/183636779
public static class Bar {
final String value;

Bar(String value) {
Expand All @@ -166,7 +167,8 @@ static class Baz {
}
}

static class Qux {}
// Must be public due to b/183636779
public static class Qux {}

@Module
@InstallIn(SingletonComponent.class)
Expand Down Expand Up @@ -277,10 +279,11 @@ public void testMissingMultiTestRoot2EntryPoint() throws Exception {
ClassCastException.class,
() -> EntryPoints.get(getApplicationContext(), MultiTestRoot2Test.BarEntryPoint.class));
assertThat(exception)
.hasMessageThat()
.isEqualTo(
"Cannot cast dagger.hilt.android.DaggerMultiTestRoot1Test_HiltComponents_SingletonC"
+ " to dagger.hilt.android.MultiTestRoot2Test$BarEntryPoint");
.hasMessageThat()
.isEqualTo(
"Cannot cast dagger.hilt.android.internal.testing.root."
+ "DaggerMultiTestRoot1Test_HiltComponents_SingletonC"
+ " to dagger.hilt.android.MultiTestRoot2Test$BarEntryPoint");
}

@Test
Expand Down
15 changes: 9 additions & 6 deletions javatests/dagger/hilt/android/MultiTestRoot2Test.java
Expand Up @@ -121,7 +121,8 @@ static class Foo {
}
}

static class Bar {
// Must be public due to b/183636779
public static class Bar {
final String value;

Bar(String value) {
Expand All @@ -137,7 +138,8 @@ static class Baz {
}
}

static class Qux {}
// Must be public due to b/183636779
public static class Qux {}

@Module
@InstallIn(SingletonComponent.class)
Expand Down Expand Up @@ -255,10 +257,11 @@ public void testMissingMultiTestRoot1EntryPoint() throws Exception {
ClassCastException.class,
() -> EntryPoints.get(getApplicationContext(), MultiTestRoot1Test.BarEntryPoint.class));
assertThat(exception)
.hasMessageThat()
.isEqualTo(
"Cannot cast dagger.hilt.android.DaggerMultiTestRoot2Test_HiltComponents_SingletonC"
+ " to dagger.hilt.android.MultiTestRoot1Test$BarEntryPoint");
.hasMessageThat()
.isEqualTo(
"Cannot cast dagger.hilt.android.internal.testing.root."
+ "DaggerMultiTestRoot2Test_HiltComponents_SingletonC"
+ " to dagger.hilt.android.MultiTestRoot1Test$BarEntryPoint");
}

@Test
Expand Down
Expand Up @@ -21,4 +21,4 @@

/** A Hilt application used to test errors in {@link HiltAndroidRuleTest}. */
@HiltAndroidApp(Application.class)
final class HiltAndroidRuleTestApp extends Hilt_HiltAndroidRuleTestApp {}
public final class HiltAndroidRuleTestApp extends Hilt_HiltAndroidRuleTestApp {}
Expand Up @@ -83,6 +83,7 @@ public void testProdComponents() {
public void testTestComponents() {
Compilation compilation =
compiler()
.withOptions("-Adagger.hilt.shareTestComponents=false")
.compile(
JavaFileObjects.forSourceLines(
"test.MyTest",
Expand Down

0 comments on commit 7e09cee

Please sign in to comment.