diff options
author | 2025-02-11 14:58:07 -0800 | |
---|---|---|
committer | 2025-02-12 10:36:48 -0800 | |
commit | 90607e9056f6ff4cec2447fdd7a8b252d67ffde7 (patch) | |
tree | d4e244bc76e8e13a8438bcd921fd9003bce46730 /java/testing.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/testing.go')
-rw-r--r-- | java/testing.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/java/testing.go b/java/testing.go index b3e552658..35319ae58 100644 --- a/java/testing.go +++ b/java/testing.go @@ -605,7 +605,7 @@ func gatherRequiredDepsForTest() string { func getModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string) []string { t.Helper() - module := ctx.ModuleForTests(name, variant).Module() + module := ctx.ModuleForTests(t, name, variant).Module() deps := []string{} ctx.VisitDirectDeps(module, func(m blueprint.Module) { deps = append(deps, m.Name()) @@ -636,7 +636,7 @@ func CheckModuleHasDependency(t *testing.T, ctx *android.TestContext, name, vari // CheckModuleHasDependency returns true if the module depends on the expected dependency. func CheckModuleHasDependencyWithTag(t *testing.T, ctx *android.TestContext, name, variant string, desiredTag blueprint.DependencyTag, expected string) bool { - module := ctx.ModuleForTests(name, variant).Module() + module := ctx.ModuleForTests(t, name, variant).Module() found := false ctx.VisitDirectDepsWithTags(module, func(m blueprint.Module, tag blueprint.DependencyTag) { if tag == desiredTag && m.Name() == expected { @@ -672,7 +672,7 @@ func CheckClasspathFragmentProtoContentInfoProvider(t *testing.T, result *androi // name of the apex, or platform is it is not part of an apex and <module> is the module name. func CheckPlatformBootclasspathDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) { t.Helper() - platformBootclasspath := ctx.ModuleForTests(name, variant).Module().(*platformBootclasspathModule) + platformBootclasspath := ctx.ModuleForTests(t, name, variant).Module().(*platformBootclasspathModule) modules := []android.Module{} ctx.VisitDirectDeps(platformBootclasspath, func(m blueprint.Module) { modules = append(modules, m.(android.Module)) @@ -747,7 +747,7 @@ func CheckHiddenAPIRuleInputs(t *testing.T, message string, expected string, hid // Check that the merged file create by platform_compat_config_singleton has the correct inputs. func CheckMergedCompatConfigInputs(t *testing.T, result *android.TestResult, message string, expectedPaths ...string) { - sourceGlobalCompatConfig := result.SingletonForTests("platform_compat_config_singleton") + sourceGlobalCompatConfig := result.SingletonForTests(t, "platform_compat_config_singleton") allOutputs := sourceGlobalCompatConfig.AllOutputs() android.AssertIntEquals(t, message+": output len", 1, len(allOutputs)) output := sourceGlobalCompatConfig.Output(allOutputs[0]) |