Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Jeff Gaston | dea7e4d | 2017-11-17 13:29:40 -0800 | [diff] [blame] | 19 | "path/filepath" |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 20 | "regexp" |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 21 | "strings" |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 22 | "testing" |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 23 | |
| 24 | "github.com/google/blueprint" |
| 25 | ) |
| 26 | |
| 27 | func NewTestContext() *TestContext { |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 28 | namespaceExportFilter := func(namespace *Namespace) bool { |
| 29 | return true |
| 30 | } |
Jeff Gaston | b274ed3 | 2017-12-01 17:10:33 -0800 | [diff] [blame] | 31 | |
| 32 | nameResolver := NewNameResolver(namespaceExportFilter) |
| 33 | ctx := &TestContext{ |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 34 | Context: &Context{blueprint.NewContext()}, |
Jeff Gaston | b274ed3 | 2017-12-01 17:10:33 -0800 | [diff] [blame] | 35 | NameResolver: nameResolver, |
| 36 | } |
| 37 | |
| 38 | ctx.SetNameInterface(nameResolver) |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 39 | |
Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 40 | ctx.preArch = append(ctx.preArch, registerLoadHookMutator) |
| 41 | |
Colin Cross | 1b48842 | 2019-03-04 22:33:56 -0800 | [diff] [blame] | 42 | ctx.postDeps = append(ctx.postDeps, registerPathDepsMutator) |
| 43 | |
Jeff Gaston | 088e29e | 2017-11-29 16:47:17 -0800 | [diff] [blame] | 44 | return ctx |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 47 | func NewTestArchContext() *TestContext { |
| 48 | ctx := NewTestContext() |
| 49 | ctx.preDeps = append(ctx.preDeps, registerArchMutator) |
| 50 | return ctx |
| 51 | } |
| 52 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 53 | type TestContext struct { |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 54 | *Context |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 55 | preArch, preDeps, postDeps []RegisterMutatorFunc |
Jeff Gaston | b274ed3 | 2017-12-01 17:10:33 -0800 | [diff] [blame] | 56 | NameResolver *NameResolver |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | func (ctx *TestContext) PreArchMutators(f RegisterMutatorFunc) { |
| 60 | ctx.preArch = append(ctx.preArch, f) |
| 61 | } |
| 62 | |
| 63 | func (ctx *TestContext) PreDepsMutators(f RegisterMutatorFunc) { |
| 64 | ctx.preDeps = append(ctx.preDeps, f) |
| 65 | } |
| 66 | |
| 67 | func (ctx *TestContext) PostDepsMutators(f RegisterMutatorFunc) { |
| 68 | ctx.postDeps = append(ctx.postDeps, f) |
| 69 | } |
| 70 | |
| 71 | func (ctx *TestContext) Register() { |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 72 | registerMutators(ctx.Context.Context, ctx.preArch, ctx.preDeps, ctx.postDeps) |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 73 | |
Colin Cross | 54855dd | 2017-11-28 23:55:23 -0800 | [diff] [blame] | 74 | ctx.RegisterSingletonType("env", SingletonFactoryAdaptor(EnvSingleton)) |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | func (ctx *TestContext) ModuleForTests(name, variant string) TestingModule { |
| 78 | var module Module |
| 79 | ctx.VisitAllModules(func(m blueprint.Module) { |
| 80 | if ctx.ModuleName(m) == name && ctx.ModuleSubDir(m) == variant { |
| 81 | module = m.(Module) |
| 82 | } |
| 83 | }) |
| 84 | |
| 85 | if module == nil { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 86 | // find all the modules that do exist |
| 87 | allModuleNames := []string{} |
| 88 | ctx.VisitAllModules(func(m blueprint.Module) { |
| 89 | allModuleNames = append(allModuleNames, m.(Module).Name()+"("+ctx.ModuleSubDir(m)+")") |
| 90 | }) |
| 91 | |
| 92 | panic(fmt.Errorf("failed to find module %q variant %q."+ |
| 93 | "\nall modules: %v", name, variant, allModuleNames)) |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | return TestingModule{module} |
| 97 | } |
| 98 | |
Jiyong Park | 37b2520 | 2018-07-11 10:49:27 +0900 | [diff] [blame] | 99 | func (ctx *TestContext) ModuleVariantsForTests(name string) []string { |
| 100 | var variants []string |
| 101 | ctx.VisitAllModules(func(m blueprint.Module) { |
| 102 | if ctx.ModuleName(m) == name { |
| 103 | variants = append(variants, ctx.ModuleSubDir(m)) |
| 104 | } |
| 105 | }) |
| 106 | return variants |
| 107 | } |
| 108 | |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 109 | // SingletonForTests returns a TestingSingleton for the singleton registered with the given name. |
| 110 | func (ctx *TestContext) SingletonForTests(name string) TestingSingleton { |
| 111 | allSingletonNames := []string{} |
| 112 | for _, s := range ctx.Singletons() { |
| 113 | n := ctx.SingletonName(s) |
| 114 | if n == name { |
| 115 | return TestingSingleton{ |
| 116 | singleton: s.(*singletonAdaptor).Singleton, |
| 117 | provider: s.(testBuildProvider), |
| 118 | } |
| 119 | } |
| 120 | allSingletonNames = append(allSingletonNames, n) |
| 121 | } |
| 122 | |
| 123 | panic(fmt.Errorf("failed to find singleton %q."+ |
| 124 | "\nall singletons: %v", name, allSingletonNames)) |
| 125 | } |
| 126 | |
Jeff Gaston | dea7e4d | 2017-11-17 13:29:40 -0800 | [diff] [blame] | 127 | // MockFileSystem causes the Context to replace all reads with accesses to the provided map of |
| 128 | // filenames to contents stored as a byte slice. |
| 129 | func (ctx *TestContext) MockFileSystem(files map[string][]byte) { |
| 130 | // no module list file specified; find every file named Blueprints or Android.bp |
| 131 | pathsToParse := []string{} |
| 132 | for candidate := range files { |
| 133 | base := filepath.Base(candidate) |
| 134 | if base == "Blueprints" || base == "Android.bp" { |
| 135 | pathsToParse = append(pathsToParse, candidate) |
| 136 | } |
| 137 | } |
| 138 | if len(pathsToParse) < 1 { |
| 139 | panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", files)) |
| 140 | } |
| 141 | files[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n")) |
| 142 | |
| 143 | ctx.Context.MockFileSystem(files) |
| 144 | } |
| 145 | |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 146 | type testBuildProvider interface { |
| 147 | BuildParamsForTests() []BuildParams |
| 148 | RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams |
| 149 | } |
| 150 | |
| 151 | type TestingBuildParams struct { |
| 152 | BuildParams |
| 153 | RuleParams blueprint.RuleParams |
| 154 | } |
| 155 | |
| 156 | func newTestingBuildParams(provider testBuildProvider, bparams BuildParams) TestingBuildParams { |
| 157 | return TestingBuildParams{ |
| 158 | BuildParams: bparams, |
| 159 | RuleParams: provider.RuleParamsForTests()[bparams.Rule], |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | func maybeBuildParamsFromRule(provider testBuildProvider, rule string) TestingBuildParams { |
| 164 | for _, p := range provider.BuildParamsForTests() { |
| 165 | if strings.Contains(p.Rule.String(), rule) { |
| 166 | return newTestingBuildParams(provider, p) |
| 167 | } |
| 168 | } |
| 169 | return TestingBuildParams{} |
| 170 | } |
| 171 | |
| 172 | func buildParamsFromRule(provider testBuildProvider, rule string) TestingBuildParams { |
| 173 | p := maybeBuildParamsFromRule(provider, rule) |
| 174 | if p.Rule == nil { |
| 175 | panic(fmt.Errorf("couldn't find rule %q", rule)) |
| 176 | } |
| 177 | return p |
| 178 | } |
| 179 | |
| 180 | func maybeBuildParamsFromDescription(provider testBuildProvider, desc string) TestingBuildParams { |
| 181 | for _, p := range provider.BuildParamsForTests() { |
Colin Cross | b88b3c5 | 2019-06-10 15:15:17 -0700 | [diff] [blame] | 182 | if strings.Contains(p.Description, desc) { |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 183 | return newTestingBuildParams(provider, p) |
| 184 | } |
| 185 | } |
| 186 | return TestingBuildParams{} |
| 187 | } |
| 188 | |
| 189 | func buildParamsFromDescription(provider testBuildProvider, desc string) TestingBuildParams { |
| 190 | p := maybeBuildParamsFromDescription(provider, desc) |
| 191 | if p.Rule == nil { |
| 192 | panic(fmt.Errorf("couldn't find description %q", desc)) |
| 193 | } |
| 194 | return p |
| 195 | } |
| 196 | |
| 197 | func maybeBuildParamsFromOutput(provider testBuildProvider, file string) (TestingBuildParams, []string) { |
| 198 | var searchedOutputs []string |
| 199 | for _, p := range provider.BuildParamsForTests() { |
| 200 | outputs := append(WritablePaths(nil), p.Outputs...) |
Colin Cross | 1d2cf04 | 2019-03-29 15:33:06 -0700 | [diff] [blame] | 201 | outputs = append(outputs, p.ImplicitOutputs...) |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 202 | if p.Output != nil { |
| 203 | outputs = append(outputs, p.Output) |
| 204 | } |
| 205 | for _, f := range outputs { |
| 206 | if f.String() == file || f.Rel() == file { |
| 207 | return newTestingBuildParams(provider, p), nil |
| 208 | } |
| 209 | searchedOutputs = append(searchedOutputs, f.Rel()) |
| 210 | } |
| 211 | } |
| 212 | return TestingBuildParams{}, searchedOutputs |
| 213 | } |
| 214 | |
| 215 | func buildParamsFromOutput(provider testBuildProvider, file string) TestingBuildParams { |
| 216 | p, searchedOutputs := maybeBuildParamsFromOutput(provider, file) |
| 217 | if p.Rule == nil { |
| 218 | panic(fmt.Errorf("couldn't find output %q.\nall outputs: %v", |
| 219 | file, searchedOutputs)) |
| 220 | } |
| 221 | return p |
| 222 | } |
| 223 | |
| 224 | func allOutputs(provider testBuildProvider) []string { |
| 225 | var outputFullPaths []string |
| 226 | for _, p := range provider.BuildParamsForTests() { |
| 227 | outputs := append(WritablePaths(nil), p.Outputs...) |
Colin Cross | 1d2cf04 | 2019-03-29 15:33:06 -0700 | [diff] [blame] | 228 | outputs = append(outputs, p.ImplicitOutputs...) |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 229 | if p.Output != nil { |
| 230 | outputs = append(outputs, p.Output) |
| 231 | } |
| 232 | outputFullPaths = append(outputFullPaths, outputs.Strings()...) |
| 233 | } |
| 234 | return outputFullPaths |
| 235 | } |
| 236 | |
Colin Cross | b77ffc4 | 2019-01-05 22:09:19 -0800 | [diff] [blame] | 237 | // TestingModule is wrapper around an android.Module that provides methods to find information about individual |
| 238 | // ctx.Build parameters for verification in tests. |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 239 | type TestingModule struct { |
| 240 | module Module |
| 241 | } |
| 242 | |
Colin Cross | b77ffc4 | 2019-01-05 22:09:19 -0800 | [diff] [blame] | 243 | // Module returns the Module wrapped by the TestingModule. |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 244 | func (m TestingModule) Module() Module { |
| 245 | return m.module |
| 246 | } |
| 247 | |
Colin Cross | b77ffc4 | 2019-01-05 22:09:19 -0800 | [diff] [blame] | 248 | // MaybeRule finds a call to ctx.Build with BuildParams.Rule set to a rule with the given name. Returns an empty |
| 249 | // BuildParams if no rule is found. |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 250 | func (m TestingModule) MaybeRule(rule string) TestingBuildParams { |
| 251 | return maybeBuildParamsFromRule(m.module, rule) |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Colin Cross | b77ffc4 | 2019-01-05 22:09:19 -0800 | [diff] [blame] | 254 | // Rule finds a call to ctx.Build with BuildParams.Rule set to a rule with the given name. Panics if no rule is found. |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 255 | func (m TestingModule) Rule(rule string) TestingBuildParams { |
| 256 | return buildParamsFromRule(m.module, rule) |
Colin Cross | b77ffc4 | 2019-01-05 22:09:19 -0800 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | // MaybeDescription finds a call to ctx.Build with BuildParams.Description set to a the given string. Returns an empty |
| 260 | // BuildParams if no rule is found. |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 261 | func (m TestingModule) MaybeDescription(desc string) TestingBuildParams { |
| 262 | return maybeBuildParamsFromDescription(m.module, desc) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Colin Cross | b77ffc4 | 2019-01-05 22:09:19 -0800 | [diff] [blame] | 265 | // Description finds a call to ctx.Build with BuildParams.Description set to a the given string. Panics if no rule is |
| 266 | // found. |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 267 | func (m TestingModule) Description(desc string) TestingBuildParams { |
| 268 | return buildParamsFromDescription(m.module, desc) |
Colin Cross | b77ffc4 | 2019-01-05 22:09:19 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 271 | // MaybeOutput finds a call to ctx.Build with a BuildParams.Output or BuildParams.Outputs whose String() or Rel() |
Colin Cross | b77ffc4 | 2019-01-05 22:09:19 -0800 | [diff] [blame] | 272 | // value matches the provided string. Returns an empty BuildParams if no rule is found. |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 273 | func (m TestingModule) MaybeOutput(file string) TestingBuildParams { |
| 274 | p, _ := maybeBuildParamsFromOutput(m.module, file) |
Colin Cross | b77ffc4 | 2019-01-05 22:09:19 -0800 | [diff] [blame] | 275 | return p |
| 276 | } |
| 277 | |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 278 | // Output finds a call to ctx.Build with a BuildParams.Output or BuildParams.Outputs whose String() or Rel() |
Colin Cross | b77ffc4 | 2019-01-05 22:09:19 -0800 | [diff] [blame] | 279 | // value matches the provided string. Panics if no rule is found. |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 280 | func (m TestingModule) Output(file string) TestingBuildParams { |
| 281 | return buildParamsFromOutput(m.module, file) |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 282 | } |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 283 | |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 284 | // AllOutputs returns all 'BuildParams.Output's and 'BuildParams.Outputs's in their full path string forms. |
| 285 | func (m TestingModule) AllOutputs() []string { |
Colin Cross | 4c83e5c | 2019-02-25 14:54:28 -0800 | [diff] [blame] | 286 | return allOutputs(m.module) |
| 287 | } |
| 288 | |
| 289 | // TestingSingleton is wrapper around an android.Singleton that provides methods to find information about individual |
| 290 | // ctx.Build parameters for verification in tests. |
| 291 | type TestingSingleton struct { |
| 292 | singleton Singleton |
| 293 | provider testBuildProvider |
| 294 | } |
| 295 | |
| 296 | // Singleton returns the Singleton wrapped by the TestingSingleton. |
| 297 | func (s TestingSingleton) Singleton() Singleton { |
| 298 | return s.singleton |
| 299 | } |
| 300 | |
| 301 | // MaybeRule finds a call to ctx.Build with BuildParams.Rule set to a rule with the given name. Returns an empty |
| 302 | // BuildParams if no rule is found. |
| 303 | func (s TestingSingleton) MaybeRule(rule string) TestingBuildParams { |
| 304 | return maybeBuildParamsFromRule(s.provider, rule) |
| 305 | } |
| 306 | |
| 307 | // Rule finds a call to ctx.Build with BuildParams.Rule set to a rule with the given name. Panics if no rule is found. |
| 308 | func (s TestingSingleton) Rule(rule string) TestingBuildParams { |
| 309 | return buildParamsFromRule(s.provider, rule) |
| 310 | } |
| 311 | |
| 312 | // MaybeDescription finds a call to ctx.Build with BuildParams.Description set to a the given string. Returns an empty |
| 313 | // BuildParams if no rule is found. |
| 314 | func (s TestingSingleton) MaybeDescription(desc string) TestingBuildParams { |
| 315 | return maybeBuildParamsFromDescription(s.provider, desc) |
| 316 | } |
| 317 | |
| 318 | // Description finds a call to ctx.Build with BuildParams.Description set to a the given string. Panics if no rule is |
| 319 | // found. |
| 320 | func (s TestingSingleton) Description(desc string) TestingBuildParams { |
| 321 | return buildParamsFromDescription(s.provider, desc) |
| 322 | } |
| 323 | |
| 324 | // MaybeOutput finds a call to ctx.Build with a BuildParams.Output or BuildParams.Outputs whose String() or Rel() |
| 325 | // value matches the provided string. Returns an empty BuildParams if no rule is found. |
| 326 | func (s TestingSingleton) MaybeOutput(file string) TestingBuildParams { |
| 327 | p, _ := maybeBuildParamsFromOutput(s.provider, file) |
| 328 | return p |
| 329 | } |
| 330 | |
| 331 | // Output finds a call to ctx.Build with a BuildParams.Output or BuildParams.Outputs whose String() or Rel() |
| 332 | // value matches the provided string. Panics if no rule is found. |
| 333 | func (s TestingSingleton) Output(file string) TestingBuildParams { |
| 334 | return buildParamsFromOutput(s.provider, file) |
| 335 | } |
| 336 | |
| 337 | // AllOutputs returns all 'BuildParams.Output's and 'BuildParams.Outputs's in their full path string forms. |
| 338 | func (s TestingSingleton) AllOutputs() []string { |
| 339 | return allOutputs(s.provider) |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 342 | func FailIfErrored(t *testing.T, errs []error) { |
| 343 | t.Helper() |
| 344 | if len(errs) > 0 { |
| 345 | for _, err := range errs { |
| 346 | t.Error(err) |
| 347 | } |
| 348 | t.FailNow() |
| 349 | } |
| 350 | } |
Logan Chien | ee97c3e | 2018-03-12 16:34:26 +0800 | [diff] [blame] | 351 | |
| 352 | func FailIfNoMatchingErrors(t *testing.T, pattern string, errs []error) { |
| 353 | t.Helper() |
| 354 | |
| 355 | matcher, err := regexp.Compile(pattern) |
| 356 | if err != nil { |
| 357 | t.Errorf("failed to compile regular expression %q because %s", pattern, err) |
| 358 | } |
| 359 | |
| 360 | found := false |
| 361 | for _, err := range errs { |
| 362 | if matcher.FindStringIndex(err.Error()) != nil { |
| 363 | found = true |
| 364 | break |
| 365 | } |
| 366 | } |
| 367 | if !found { |
| 368 | t.Errorf("missing the expected error %q (checked %d error(s))", pattern, len(errs)) |
| 369 | for i, err := range errs { |
| 370 | t.Errorf("errs[%d] = %s", i, err) |
| 371 | } |
| 372 | } |
| 373 | } |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 374 | |
Paul Duffin | 91e3819 | 2019-08-05 15:07:57 +0100 | [diff] [blame^] | 375 | func CheckErrorsAgainstExpectations(t *testing.T, errs []error, expectedErrorPatterns []string) { |
| 376 | t.Helper() |
| 377 | |
| 378 | if expectedErrorPatterns == nil { |
| 379 | FailIfErrored(t, errs) |
| 380 | } else { |
| 381 | for _, expectedError := range expectedErrorPatterns { |
| 382 | FailIfNoMatchingErrors(t, expectedError, errs) |
| 383 | } |
| 384 | if len(errs) > len(expectedErrorPatterns) { |
| 385 | t.Errorf("additional errors found, expected %d, found %d", |
| 386 | len(expectedErrorPatterns), len(errs)) |
| 387 | for i, expectedError := range expectedErrorPatterns { |
| 388 | t.Errorf("expectedErrors[%d] = %s", i, expectedError) |
| 389 | } |
| 390 | for i, err := range errs { |
| 391 | t.Errorf("errs[%d] = %s", i, err) |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | } |
| 397 | |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 398 | func AndroidMkEntriesForTest(t *testing.T, config Config, bpPath string, mod blueprint.Module) AndroidMkEntries { |
| 399 | var p AndroidMkEntriesProvider |
| 400 | var ok bool |
| 401 | if p, ok = mod.(AndroidMkEntriesProvider); !ok { |
Roland Levillain | dfe75b3 | 2019-07-23 16:53:32 +0100 | [diff] [blame] | 402 | t.Errorf("module does not implement AndroidMkEntriesProvider: " + mod.Name()) |
Jaewoong Jung | 9aa3ab1 | 2019-04-03 15:47:29 -0700 | [diff] [blame] | 403 | } |
| 404 | entries := p.AndroidMkEntries() |
| 405 | entries.fillInEntries(config, bpPath, mod) |
| 406 | return entries |
| 407 | } |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 408 | |
| 409 | func AndroidMkDataForTest(t *testing.T, config Config, bpPath string, mod blueprint.Module) AndroidMkData { |
| 410 | var p AndroidMkDataProvider |
| 411 | var ok bool |
| 412 | if p, ok = mod.(AndroidMkDataProvider); !ok { |
Roland Levillain | dfe75b3 | 2019-07-23 16:53:32 +0100 | [diff] [blame] | 413 | t.Errorf("module does not implement AndroidMkDataProvider: " + mod.Name()) |
Jooyung Han | 12df5fb | 2019-07-11 16:18:47 +0900 | [diff] [blame] | 414 | } |
| 415 | data := p.AndroidMk() |
| 416 | data.fillInData(config, bpPath, mod) |
| 417 | return data |
| 418 | } |