From 3600b80e6f911d5346aceedaa9bfec36b3a8675c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thi=C3=A9baud=20Weksteen?= Date: Thu, 27 Aug 2020 15:50:24 +0200 Subject: [PATCH] Return all rules when TestingModule.Rule fails Similarly to Output, we return the list of Rules that have been generated for TestingModule. This helps debugging failing tests. Test: m nothing Change-Id: I3542f4e4632f94fb84208c2e48e629271a373fd4 --- android/testing.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/android/testing.go b/android/testing.go index 8a9134c75..8ea4168d1 100644 --- a/android/testing.go +++ b/android/testing.go @@ -187,19 +187,21 @@ func newTestingBuildParams(provider testBuildProvider, bparams BuildParams) Test } } -func maybeBuildParamsFromRule(provider testBuildProvider, rule string) TestingBuildParams { +func maybeBuildParamsFromRule(provider testBuildProvider, rule string) (TestingBuildParams, []string) { + var searchedRules []string for _, p := range provider.BuildParamsForTests() { + searchedRules = append(searchedRules, p.Rule.String()) if strings.Contains(p.Rule.String(), rule) { - return newTestingBuildParams(provider, p) + return newTestingBuildParams(provider, p), searchedRules } } - return TestingBuildParams{} + return TestingBuildParams{}, searchedRules } func buildParamsFromRule(provider testBuildProvider, rule string) TestingBuildParams { - p := maybeBuildParamsFromRule(provider, rule) + p, searchRules := maybeBuildParamsFromRule(provider, rule) if p.Rule == nil { - panic(fmt.Errorf("couldn't find rule %q", rule)) + panic(fmt.Errorf("couldn't find rule %q.\nall rules: %v", rule, searchRules)) } return p } @@ -275,7 +277,8 @@ func (m TestingModule) Module() Module { // MaybeRule finds a call to ctx.Build with BuildParams.Rule set to a rule with the given name. Returns an empty // BuildParams if no rule is found. func (m TestingModule) MaybeRule(rule string) TestingBuildParams { - return maybeBuildParamsFromRule(m.module, rule) + r, _ := maybeBuildParamsFromRule(m.module, rule) + return r } // Rule finds a call to ctx.Build with BuildParams.Rule set to a rule with the given name. Panics if no rule is found. @@ -328,7 +331,8 @@ func (s TestingSingleton) Singleton() Singleton { // MaybeRule finds a call to ctx.Build with BuildParams.Rule set to a rule with the given name. Returns an empty // BuildParams if no rule is found. func (s TestingSingleton) MaybeRule(rule string) TestingBuildParams { - return maybeBuildParamsFromRule(s.provider, rule) + r, _ := maybeBuildParamsFromRule(s.provider, rule) + return r } // Rule finds a call to ctx.Build with BuildParams.Rule set to a rule with the given name. Panics if no rule is found.