Convert android/soong_config_modules_test.go to test fixtures

Bug: 182885307
Test: m nothing
Change-Id: I53231b820154447e359e48afa47cdf76f0ec6c47
This commit is contained in:
Paul Duffin 2021-03-16 22:45:14 +00:00
parent e8a4ac49fe
commit 791302b412
1 changed files with 36 additions and 34 deletions

View File

@ -15,7 +15,6 @@
package android package android
import ( import (
"reflect"
"testing" "testing"
) )
@ -181,17 +180,23 @@ func TestSoongConfigModule(t *testing.T) {
} }
` `
run := func(t *testing.T, bp string, fs map[string][]byte) { fixtureForVendorVars := func(vars map[string]map[string]string) FixturePreparer {
return FixtureModifyProductVariables(func(variables FixtureProductVariables) {
variables.VendorVars = vars
})
}
run := func(t *testing.T, bp string, fs MockFS) {
testCases := []struct { testCases := []struct {
name string name string
config Config preparer FixturePreparer
fooExpectedFlags []string fooExpectedFlags []string
fooDefaultsExpectedFlags []string fooDefaultsExpectedFlags []string
}{ }{
{ {
name: "withValues", name: "withValues",
config: testConfigWithVendorVars(buildDir, bp, fs, map[string]map[string]string{ preparer: fixtureForVendorVars(map[string]map[string]string{
"acme": map[string]string{ "acme": {
"board": "soc_a", "board": "soc_a",
"size": "42", "size": "42",
"feature1": "true", "feature1": "true",
@ -221,8 +226,8 @@ func TestSoongConfigModule(t *testing.T) {
}, },
{ {
name: "empty_prop_for_string_var", name: "empty_prop_for_string_var",
config: testConfigWithVendorVars(buildDir, bp, fs, map[string]map[string]string{ preparer: fixtureForVendorVars(map[string]map[string]string{
"acme": map[string]string{"board": "soc_c"}}), "acme": {"board": "soc_c"}}),
fooExpectedFlags: []string{ fooExpectedFlags: []string{
"DEFAULT", "DEFAULT",
"-DGENERIC", "-DGENERIC",
@ -237,8 +242,8 @@ func TestSoongConfigModule(t *testing.T) {
}, },
{ {
name: "unused_string_var", name: "unused_string_var",
config: testConfigWithVendorVars(buildDir, bp, fs, map[string]map[string]string{ preparer: fixtureForVendorVars(map[string]map[string]string{
"acme": map[string]string{"board": "soc_d"}}), "acme": {"board": "soc_d"}}),
fooExpectedFlags: []string{ fooExpectedFlags: []string{
"DEFAULT", "DEFAULT",
"-DGENERIC", "-DGENERIC",
@ -255,7 +260,7 @@ func TestSoongConfigModule(t *testing.T) {
{ {
name: "conditions_default", name: "conditions_default",
config: testConfigWithVendorVars(buildDir, bp, fs, map[string]map[string]string{}), preparer: fixtureForVendorVars(map[string]map[string]string{}),
fooExpectedFlags: []string{ fooExpectedFlags: []string{
"DEFAULT", "DEFAULT",
"-DGENERIC", "-DGENERIC",
@ -272,32 +277,29 @@ func TestSoongConfigModule(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
ctx := NewTestContext(tc.config) t.Run(tc.name, func(t *testing.T) {
result := emptyTestFixtureFactory.RunTest(t,
tc.preparer,
PrepareForTestWithDefaults,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("soong_config_module_type_import", soongConfigModuleTypeImportFactory) ctx.RegisterModuleType("soong_config_module_type_import", soongConfigModuleTypeImportFactory)
ctx.RegisterModuleType("soong_config_module_type", soongConfigModuleTypeFactory) ctx.RegisterModuleType("soong_config_module_type", soongConfigModuleTypeFactory)
ctx.RegisterModuleType("soong_config_string_variable", soongConfigStringVariableDummyFactory) ctx.RegisterModuleType("soong_config_string_variable", soongConfigStringVariableDummyFactory)
ctx.RegisterModuleType("soong_config_bool_variable", soongConfigBoolVariableDummyFactory) ctx.RegisterModuleType("soong_config_bool_variable", soongConfigBoolVariableDummyFactory)
ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory) ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory)
ctx.RegisterModuleType("test", soongConfigTestModuleFactory) ctx.RegisterModuleType("test", soongConfigTestModuleFactory)
ctx.PreArchMutators(RegisterDefaultsPreArchMutators) }),
ctx.Register() fs.AddToFixture(),
FixtureWithRootAndroidBp(bp),
)
_, errs := ctx.ParseBlueprintsFiles("Android.bp") foo := result.ModuleForTests("foo", "").Module().(*soongConfigTestModule)
FailIfErrored(t, errs) AssertDeepEquals(t, "foo cflags", tc.fooExpectedFlags, foo.props.Cflags)
_, errs = ctx.PrepareBuildActions(tc.config)
FailIfErrored(t, errs)
foo := ctx.ModuleForTests("foo", "").Module().(*soongConfigTestModule) fooDefaults := result.ModuleForTests("foo_with_defaults", "").Module().(*soongConfigTestModule)
if g, w := foo.props.Cflags, tc.fooExpectedFlags; !reflect.DeepEqual(g, w) { AssertDeepEquals(t, "foo_with_defaults cflags", tc.fooDefaultsExpectedFlags, fooDefaults.props.Cflags)
t.Errorf("%s: wanted foo cflags %q, got %q", tc.name, w, g) })
} }
fooDefaults := ctx.ModuleForTests("foo_with_defaults", "").Module().(*soongConfigTestModule)
if g, w := fooDefaults.props.Cflags, tc.fooDefaultsExpectedFlags; !reflect.DeepEqual(g, w) {
t.Errorf("%s: wanted foo_with_defaults cflags %q, got %q", tc.name, w, g)
}
}
} }
t.Run("single file", func(t *testing.T) { t.Run("single file", func(t *testing.T) {