Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3600b80e authored by Thiébaud Weksteen's avatar Thiébaud Weksteen
Browse files

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
parent 1fde95ac
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -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.