Add tests for android:replace_instead_of_append

Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ideb739b3f1a6a5854453db7d51bdee73a3979fd4
This commit is contained in:
Cole Faust 2024-04-03 17:04:57 -07:00
parent 683316a2b0
commit 02dd6e5640
2 changed files with 86 additions and 14 deletions

View file

@ -980,7 +980,7 @@ func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.S
panic(fmt.Errorf("unexpected tag format %q", field.Tag)) panic(fmt.Errorf("unexpected tag format %q", field.Tag))
} }
// these tags don't need to be present in the runtime generated struct type. // these tags don't need to be present in the runtime generated struct type.
values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend", "path"}) values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend", "path", "replace_instead_of_append"})
if len(values) > 0 { if len(values) > 0 {
panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name)) panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name))
} }

View file

@ -368,14 +368,62 @@ func TestSelects(t *testing.T) {
my_bool: proptools.BoolPtr(true), my_bool: proptools.BoolPtr(true),
}, },
}, },
{
name: "defaults with lists are appended",
bp: `
my_module_type {
name: "foo",
defaults: ["bar"],
my_string_list: select(soong_config_variable("my_namespace", "my_variable"), {
"a": ["a1"],
default: ["b1"],
}),
}
my_defaults {
name: "bar",
my_string_list: select(soong_config_variable("my_namespace", "my_variable2"), {
"a": ["a2"],
default: ["b2"],
}),
}
`,
provider: selectsTestProvider{
my_string_list: &[]string{"b2", "b1"},
},
},
{
name: "Replacing string list",
bp: `
my_module_type {
name: "foo",
defaults: ["bar"],
replacing_string_list: select(soong_config_variable("my_namespace", "my_variable"), {
"a": ["a1"],
default: ["b1"],
}),
}
my_defaults {
name: "bar",
replacing_string_list: select(soong_config_variable("my_namespace", "my_variable2"), {
"a": ["a2"],
default: ["b2"],
}),
}
`,
provider: selectsTestProvider{
replacing_string_list: &[]string{"b1"},
},
},
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
fixtures := GroupFixturePreparers( fixtures := GroupFixturePreparers(
PrepareForTestWithDefaults,
PrepareForTestWithArchMutator, PrepareForTestWithArchMutator,
FixtureRegisterWithContext(func(ctx RegistrationContext) { FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("my_module_type", newSelectsMockModule) ctx.RegisterModuleType("my_module_type", newSelectsMockModule)
ctx.RegisterModuleType("my_defaults", newSelectsMockModuleDefaults)
}), }),
FixtureModifyProductVariables(func(variables FixtureProductVariables) { FixtureModifyProductVariables(func(variables FixtureProductVariables) {
variables.VendorVars = tc.vendorVars variables.VendorVars = tc.vendorVars
@ -402,6 +450,7 @@ type selectsTestProvider struct {
my_string *string my_string *string
my_string_list *[]string my_string_list *[]string
my_paths *[]string my_paths *[]string
replacing_string_list *[]string
} }
func (p *selectsTestProvider) String() string { func (p *selectsTestProvider) String() string {
@ -418,7 +467,8 @@ func (p *selectsTestProvider) String() string {
my_string: %s, my_string: %s,
my_string_list: %s, my_string_list: %s,
my_paths: %s, my_paths: %s,
}`, myBoolStr, myStringStr, p.my_string_list, p.my_paths) replacing_string_list %s,
}`, myBoolStr, myStringStr, p.my_string_list, p.my_paths, p.replacing_string_list)
} }
var selectsTestProviderKey = blueprint.NewProvider[selectsTestProvider]() var selectsTestProviderKey = blueprint.NewProvider[selectsTestProvider]()
@ -428,6 +478,7 @@ type selectsMockModuleProperties struct {
My_string proptools.Configurable[string] My_string proptools.Configurable[string]
My_string_list proptools.Configurable[[]string] My_string_list proptools.Configurable[[]string]
My_paths proptools.Configurable[[]string] `android:"path"` My_paths proptools.Configurable[[]string] `android:"path"`
Replacing_string_list proptools.Configurable[[]string] `android:"replace_instead_of_append,arch_variant"`
} }
type selectsMockModule struct { type selectsMockModule struct {
@ -442,6 +493,7 @@ func (p *selectsMockModule) GenerateAndroidBuildActions(ctx ModuleContext) {
my_string: p.properties.My_string.Evaluate(ctx), my_string: p.properties.My_string.Evaluate(ctx),
my_string_list: p.properties.My_string_list.Evaluate(ctx), my_string_list: p.properties.My_string_list.Evaluate(ctx),
my_paths: p.properties.My_paths.Evaluate(ctx), my_paths: p.properties.My_paths.Evaluate(ctx),
replacing_string_list: p.properties.Replacing_string_list.Evaluate(ctx),
}) })
} }
@ -452,3 +504,23 @@ func newSelectsMockModule() Module {
InitDefaultableModule(m) InitDefaultableModule(m)
return m return m
} }
type selectsMockModuleDefaults struct {
ModuleBase
DefaultsModuleBase
}
func (d *selectsMockModuleDefaults) GenerateAndroidBuildActions(ctx ModuleContext) {
}
func newSelectsMockModuleDefaults() Module {
module := &selectsMockModuleDefaults{}
module.AddProperties(
&selectsMockModuleProperties{},
)
InitDefaultsModule(module)
return module
}