diff options
author | 2020-12-16 12:42:02 -0800 | |
---|---|---|
committer | 2021-01-21 14:25:20 -0500 | |
commit | 432bd598ae5964f045e92aa29bc1cbef3dea04dd (patch) | |
tree | 36450b8d276128e4122864005ebcde8c701c5a3c /android/soongconfig/modules_test.go | |
parent | 324234bd0007ebc78843eece46bb7e8d337e8026 (diff) |
Add conditions_default for soong config variables.
Each variable can specify a conditions_default for properties to be used
when the variable is not set, not set to a true value (for bools), or is
set to a value that is not present in the module (for strings).
Test: m nothing
Test: go test soong tests
Change-Id: I76ec026da2369b407f0f530f77760f530e7958fc
Diffstat (limited to 'android/soongconfig/modules_test.go')
-rw-r--r-- | android/soongconfig/modules_test.go | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/android/soongconfig/modules_test.go b/android/soongconfig/modules_test.go index fb0e1899d..b824c7898 100644 --- a/android/soongconfig/modules_test.go +++ b/android/soongconfig/modules_test.go @@ -254,67 +254,75 @@ type properties struct { A *string B bool } -type soongConfigVariables struct { - Bool_var properties - Other_bool_var properties + +type boolVarProps struct { + A *string + B bool + Conditions_default *properties } -type soongConfigProps struct { - Soong_config_variables soongConfigVariables +type soongConfigVars struct { + Bool_var interface{} } func Test_PropertiesToApply(t *testing.T) { - - mt := &ModuleType{ - BaseModuleType: "foo", - ConfigNamespace: "bar", - Variables: []soongConfigVariable{ - newBoolVariable("bool_var"), - newBoolVariable("other_bool_var"), - }, - affectableProperties: []string{ - "a", - "b", - }, + mt, _ := newModuleType(&ModuleTypeProperties{ + Module_type: "foo", + Config_namespace: "bar", + Bool_variables: []string{"bool_var"}, + Properties: []string{"a", "b"}, + }) + boolVarPositive := &properties{ + A: proptools.StringPtr("A"), + B: true, } - props := soongConfigProps{ - Soong_config_variables: soongConfigVariables{ - Bool_var: properties{ - A: proptools.StringPtr("a"), - B: true, - }, - Other_bool_var: properties{ - A: proptools.StringPtr("other"), - B: false, + conditionsDefault := &properties{ + A: proptools.StringPtr("default"), + B: false, + } + actualProps := &struct { + Soong_config_variables soongConfigVars + }{ + Soong_config_variables: soongConfigVars{ + Bool_var: &boolVarProps{ + A: boolVarPositive.A, + B: boolVarPositive.B, + Conditions_default: conditionsDefault, }, }, } + props := reflect.ValueOf(actualProps) testCases := []struct { + name string config SoongConfig wantProps []interface{} }{ { - config: Config(map[string]string{}), + name: "no_vendor_config", + config: Config(map[string]string{}), + wantProps: []interface{}{conditionsDefault}, }, { - config: Config(map[string]string{"bool_var": "y"}), - wantProps: []interface{}{props.Soong_config_variables.Bool_var}, + name: "vendor_config_false", + config: Config(map[string]string{"bool_var": "n"}), + wantProps: []interface{}{conditionsDefault}, }, { - config: Config(map[string]string{"other_bool_var": "y"}), - wantProps: []interface{}{props.Soong_config_variables.Other_bool_var}, + name: "bool_var_true", + config: Config(map[string]string{"bool_var": "y"}), + wantProps: []interface{}{boolVarPositive}, }, } for _, tc := range testCases { - gotProps, err := PropertiesToApply(mt, reflect.ValueOf(&props), tc.config) + gotProps, err := PropertiesToApply(mt, props, tc.config) if err != nil { - t.Errorf("Unexpected error in PropertiesToApply: %s", err) + t.Errorf("%s: Unexpected error in PropertiesToApply: %s", tc.name, err) } if !reflect.DeepEqual(gotProps, tc.wantProps) { - t.Errorf("Expected %s, got %s", tc.wantProps, gotProps) + t.Errorf("%s: Expected %s, got %s", tc.name, tc.wantProps, gotProps) } } } |