diff options
author | 2021-03-16 23:36:24 +0000 | |
---|---|---|
committer | 2021-03-18 12:17:05 +0000 | |
commit | 4bb2b219d6d41dc5ddc1474d62e3571540d4e953 (patch) | |
tree | ccc453b55bb9cb074c2b1ec5b2df600e15c6b349 /android/variable_test.go | |
parent | 791302b4129f441f7d466e3b64a77f62bf5576cc (diff) |
Convert android/variable_test.go to test fixtures
Bug: 182885307
Test: m nothing
Change-Id: I51d3651244b110bf41cb0e4c331ac663bf816f84
Diffstat (limited to 'android/variable_test.go')
-rw-r--r-- | android/variable_test.go | 87 |
1 files changed, 38 insertions, 49 deletions
diff --git a/android/variable_test.go b/android/variable_test.go index 393fe0172..d16e45880 100644 --- a/android/variable_test.go +++ b/android/variable_test.go @@ -181,32 +181,30 @@ func TestProductVariables(t *testing.T) { name: "baz", } ` - config := TestConfig(buildDir, nil, bp, nil) - config.TestProductVariables.Eng = proptools.BoolPtr(true) - ctx := NewTestContext(config) - // A module type that has a srcs property but not a cflags property. - ctx.RegisterModuleType("module1", testProductVariableModuleFactoryFactory(&struct { - Srcs []string - }{})) - // A module type that has a cflags property but not a srcs property. - ctx.RegisterModuleType("module2", testProductVariableModuleFactoryFactory(&struct { - Cflags []string - }{})) - // A module type that does not have any properties that match product_variables. - ctx.RegisterModuleType("module3", testProductVariableModuleFactoryFactory(&struct { - Foo []string - }{})) - ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { - ctx.BottomUp("variable", VariableMutator).Parallel() - }) - - ctx.Register() - - _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) - FailIfErrored(t, errs) - _, errs = ctx.PrepareBuildActions(config) - FailIfErrored(t, errs) + emptyTestFixtureFactory.RunTest(t, + FixtureModifyProductVariables(func(variables FixtureProductVariables) { + variables.Eng = proptools.BoolPtr(true) + }), + FixtureRegisterWithContext(func(ctx RegistrationContext) { + // A module type that has a srcs property but not a cflags property. + ctx.RegisterModuleType("module1", testProductVariableModuleFactoryFactory(&struct { + Srcs []string + }{})) + // A module type that has a cflags property but not a srcs property. + ctx.RegisterModuleType("module2", testProductVariableModuleFactoryFactory(&struct { + Cflags []string + }{})) + // A module type that does not have any properties that match product_variables. + ctx.RegisterModuleType("module3", testProductVariableModuleFactoryFactory(&struct { + Foo []string + }{})) + ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { + ctx.BottomUp("variable", VariableMutator).Parallel() + }) + }), + FixtureWithRootAndroidBp(bp), + ) } var testProductVariableDefaultsProperties = struct { @@ -290,32 +288,23 @@ func TestProductVariablesDefaults(t *testing.T) { } ` - config := TestConfig(buildDir, nil, bp, nil) - config.TestProductVariables.Eng = boolPtr(true) - - ctx := NewTestContext(config) - - ctx.RegisterModuleType("test", productVariablesDefaultsTestModuleFactory) - ctx.RegisterModuleType("defaults", productVariablesDefaultsTestDefaultsFactory) - - ctx.PreArchMutators(RegisterDefaultsPreArchMutators) - ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { - ctx.BottomUp("variable", VariableMutator).Parallel() - }) - - ctx.Register() - - _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) - FailIfErrored(t, errs) - _, errs = ctx.PrepareBuildActions(config) - FailIfErrored(t, errs) - - foo := ctx.ModuleForTests("foo", "").Module().(*productVariablesDefaultsTestModule) + result := emptyTestFixtureFactory.RunTest(t, + FixtureModifyProductVariables(func(variables FixtureProductVariables) { + variables.Eng = boolPtr(true) + }), + PrepareForTestWithDefaults, + PrepareForTestWithVariables, + FixtureRegisterWithContext(func(ctx RegistrationContext) { + ctx.RegisterModuleType("test", productVariablesDefaultsTestModuleFactory) + ctx.RegisterModuleType("defaults", productVariablesDefaultsTestDefaultsFactory) + }), + FixtureWithRootAndroidBp(bp), + ) + + foo := result.ModuleForTests("foo", "").Module().(*productVariablesDefaultsTestModule) want := []string{"defaults", "module", "product_variable_defaults", "product_variable_module"} - if g, w := foo.properties.Foo, want; !reflect.DeepEqual(g, w) { - t.Errorf("expected foo %q, got %q", w, g) - } + AssertDeepEquals(t, "foo", want, foo.properties.Foo) } func BenchmarkSliceToTypeArray(b *testing.B) { |