diff options
author | 2025-02-11 14:58:07 -0800 | |
---|---|---|
committer | 2025-02-12 10:36:48 -0800 | |
commit | 90607e9056f6ff4cec2447fdd7a8b252d67ffde7 (patch) | |
tree | d4e244bc76e8e13a8438bcd921fd9003bce46730 /java/dex_test.go | |
parent | d8db8faba62a3cb77f75294e96deda9e53c15786 (diff) |
Don't panic in ModuleForTests and friends
Panicking in ModuleForTests and similar test helper functions was
a mistake. Go's test runner stops running tests as soon as any
test panics, which means debugging multiple tests panicking requires
rerunning all the tests after fixing each panic to find the next
one. Pass the *testing.T into ModuleForTests and friends so that
it can call t.Fatalf instead.
Test: all soong tests pass
Change-Id: I5d0f2424eaf04fb795079e6d1e4b9469d8c7033c
Diffstat (limited to 'java/dex_test.go')
-rw-r--r-- | java/dex_test.go | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/java/dex_test.go b/java/dex_test.go index 4e515b403..2126e42e8 100644 --- a/java/dex_test.go +++ b/java/dex_test.go @@ -60,11 +60,11 @@ func TestR8(t *testing.T) { } `) - app := result.ModuleForTests("app", "android_common") - stableApp := result.ModuleForTests("stable_app", "android_common") - corePlatformApp := result.ModuleForTests("core_platform_app", "android_common") - lib := result.ModuleForTests("lib", "android_common") - staticLib := result.ModuleForTests("static_lib", "android_common") + app := result.ModuleForTests(t, "app", "android_common") + stableApp := result.ModuleForTests(t, "stable_app", "android_common") + corePlatformApp := result.ModuleForTests(t, "core_platform_app", "android_common") + lib := result.ModuleForTests(t, "lib", "android_common") + staticLib := result.ModuleForTests(t, "static_lib", "android_common") appJavac := app.Rule("javac") appR8 := app.Rule("r8") @@ -210,14 +210,14 @@ func TestR8TransitiveDeps(t *testing.T) { result := fixturePreparer.RunTestWithBp(t, bp) getHeaderJar := func(name string) android.Path { - mod := result.ModuleForTests(name, "android_common") + mod := result.ModuleForTests(t, name, "android_common") return mod.Output("turbine-combined/" + name + ".jar").Output } - appR8 := result.ModuleForTests("app", "android_common").Rule("r8") - overrideAppR8 := result.ModuleForTests("app", "android_common_override_app").Rule("r8") + appR8 := result.ModuleForTests(t, "app", "android_common").Rule("r8") + overrideAppR8 := result.ModuleForTests(t, "app", "android_common_override_app").Rule("r8") appHeader := getHeaderJar("app") - overrideAppHeader := result.ModuleForTests("app", "android_common_override_app").Output("turbine-combined/app.jar").Output + overrideAppHeader := result.ModuleForTests(t, "app", "android_common_override_app").Output("turbine-combined/app.jar").Output libHeader := getHeaderJar("lib") transitiveLibHeader := getHeaderJar("transitive_lib") transitiveLib2Header := getHeaderJar("transitive_lib_2") @@ -226,7 +226,7 @@ func TestR8TransitiveDeps(t *testing.T) { repeatedDepHeader := getHeaderJar("repeated_dep") usesLibHeader := getHeaderJar("uses_lib") optionalUsesLibHeader := getHeaderJar("optional_uses_lib") - prebuiltLibHeader := result.ModuleForTests("prebuilt_lib", "android_common").Output("combined/lib.jar").Output + prebuiltLibHeader := result.ModuleForTests(t, "prebuilt_lib", "android_common").Output("combined/lib.jar").Output for _, rule := range []android.TestingBuildParams{appR8, overrideAppR8} { android.AssertStringDoesNotContain(t, "expected no app header jar in app r8 classpath", @@ -278,7 +278,7 @@ func TestR8Flags(t *testing.T) { } `) - app := result.ModuleForTests("app", "android_common") + app := result.ModuleForTests(t, "app", "android_common") appR8 := app.Rule("r8") android.AssertStringDoesContain(t, "expected -dontshrink in app r8 flags", appR8.Args["r8Flags"], "-dontshrink") @@ -323,10 +323,10 @@ func TestD8(t *testing.T) { } `) - foo := result.ModuleForTests("foo", "android_common") - lib := result.ModuleForTests("lib", "android_common") - app := result.ModuleForTests("app", "android_common") - staticLib := result.ModuleForTests("static_lib", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") + lib := result.ModuleForTests(t, "lib", "android_common") + app := result.ModuleForTests(t, "app", "android_common") + staticLib := result.ModuleForTests(t, "static_lib", "android_common") fooJavac := foo.Rule("javac") fooD8 := foo.Rule("d8") @@ -398,7 +398,7 @@ func TestProguardFlagsInheritanceStatic(t *testing.T) { } `) - app := result.ModuleForTests("app", "android_common") + app := result.ModuleForTests(t, "app", "android_common") appR8 := app.Rule("r8") android.AssertStringDoesContain(t, "expected primary_lib's proguard flags from direct dep", appR8.Args["r8Flags"], "primary.flags") @@ -647,7 +647,7 @@ func TestProguardFlagsInheritance(t *testing.T) { tc.transitiveDepExportsFlagsFiles, ), ) - appR8 := result.ModuleForTests("app", "android_common").Rule("r8") + appR8 := result.ModuleForTests(t, "app", "android_common").Rule("r8") shouldHaveDepFlags := android.InList(directDepFlagsFileName, tc.expectedFlagsFiles) if shouldHaveDepFlags { @@ -689,7 +689,7 @@ func TestProguardFlagsInheritanceAppImport(t *testing.T) { PrepareForTestWithJavaDefaultModules, ).RunTestWithBp(t, bp) - appR8 := result.ModuleForTests("app", "android_common").Rule("r8") + appR8 := result.ModuleForTests(t, "app", "android_common").Rule("r8") android.AssertStringDoesContain(t, "expected aarimports's proguard flags", appR8.Args["r8Flags"], "proguard.txt") } @@ -709,7 +709,7 @@ func TestR8FlagsArtProfile(t *testing.T) { } `) - app := result.ModuleForTests("app", "android_common") + app := result.ModuleForTests(t, "app", "android_common") appR8 := app.Rule("r8") android.AssertStringDoesContain(t, "expected --art-profile in app r8 flags", appR8.Args["r8Flags"], "--art-profile") @@ -847,7 +847,7 @@ func TestDebugReleaseFlags(t *testing.T) { dexRuleKey = "d8" } dexFlagsKey := dexRuleKey + "Flags" - appDex := result.ModuleForTests("app", "android_common").Rule(dexRuleKey) + appDex := result.ModuleForTests(t, "app", "android_common").Rule(dexRuleKey) android.AssertStringDoesContain(t, "expected flag in dex flags", appDex.Args[dexFlagsKey], tc.expectedFlags) |