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