Make TestModule.Output print a list of all outputs on error

Debugging when writing tests using TestModule.Outputs is
unnecessarily hard, it panics when an incorrect output path
is given but doesn't provide any help to figure out why.
Follow the pattern used by TestContext.ModuleForTests
and print the list of valid output paths on failure.

Test: m checkbuild
Change-Id: I50e8e2dfc2070bd538d47cf6495a489f727b1564
This commit is contained in:
Colin Cross
2017-12-05 09:26:15 -08:00
parent 809d3f8f63
commit 9cf27db425

View File

@@ -136,6 +136,7 @@ func (m TestingModule) Description(desc string) BuildParams {
}
func (m TestingModule) Output(file string) BuildParams {
var searchedOutputs []string
for _, p := range m.module.BuildParamsForTests() {
outputs := append(WritablePaths(nil), p.Outputs...)
if p.Output != nil {
@@ -145,7 +146,9 @@ func (m TestingModule) Output(file string) BuildParams {
if f.String() == file || f.Rel() == file {
return p
}
searchedOutputs = append(searchedOutputs, f.Rel())
}
}
panic(fmt.Errorf("couldn't find output %q", file))
panic(fmt.Errorf("couldn't find output %q.\nall outputs: %v",
file, searchedOutputs))
}