Merge "Detect empty apex in ConfiguredJarList" am: b8887127ba
am: 6664c04ce9
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1574743 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I42edc356e4a6cc4ec548c36a023a4fee6d5d94dd
This commit is contained in:
@@ -1624,21 +1624,33 @@ func splitListOfPairsIntoPairOfLists(list []string) ([]string, []string, error)
|
||||
func splitConfiguredJarPair(str string) (string, string, error) {
|
||||
pair := strings.SplitN(str, ":", 2)
|
||||
if len(pair) == 2 {
|
||||
return pair[0], pair[1], nil
|
||||
apex := pair[0]
|
||||
jar := pair[1]
|
||||
if apex == "" {
|
||||
return apex, jar, fmt.Errorf("invalid apex '%s' in <apex>:<jar> pair '%s', expected format: <apex>:<jar>", apex, str)
|
||||
}
|
||||
return apex, jar, nil
|
||||
} else {
|
||||
return "error-apex", "error-jar", fmt.Errorf("malformed (apex, jar) pair: '%s', expected format: <apex>:<jar>", str)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateTestConfiguredJarList is a function to create ConfiguredJarList for
|
||||
// tests.
|
||||
// CreateTestConfiguredJarList is a function to create ConfiguredJarList for tests.
|
||||
func CreateTestConfiguredJarList(list []string) ConfiguredJarList {
|
||||
apexes, jars, err := splitListOfPairsIntoPairOfLists(list)
|
||||
// Create the ConfiguredJarList in as similar way as it is created at runtime by marshalling to
|
||||
// a json list of strings and then unmarshalling into a ConfiguredJarList instance.
|
||||
b, err := json.Marshal(list)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return ConfiguredJarList{apexes, jars}
|
||||
var jarList ConfiguredJarList
|
||||
err = json.Unmarshal(b, &jarList)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return jarList
|
||||
}
|
||||
|
||||
// EmptyConfiguredJarList returns an empty jar list.
|
||||
|
@@ -100,6 +100,22 @@ func TestConfiguredJarList(t *testing.T) {
|
||||
assertStringEquals(t, "apex1:jarA", list1.String())
|
||||
})
|
||||
|
||||
t.Run("create invalid - missing apex", func(t *testing.T) {
|
||||
defer func() {
|
||||
err := recover().(error)
|
||||
assertStringEquals(t, "malformed (apex, jar) pair: 'jarA', expected format: <apex>:<jar>", err.Error())
|
||||
}()
|
||||
CreateTestConfiguredJarList([]string{"jarA"})
|
||||
})
|
||||
|
||||
t.Run("create invalid - empty apex", func(t *testing.T) {
|
||||
defer func() {
|
||||
err := recover().(error)
|
||||
assertStringEquals(t, "invalid apex '' in <apex>:<jar> pair ':jarA', expected format: <apex>:<jar>", err.Error())
|
||||
}()
|
||||
CreateTestConfiguredJarList([]string{":jarA"})
|
||||
})
|
||||
|
||||
list2 := list1.Append("apex2", "jarB")
|
||||
t.Run("append", func(t *testing.T) {
|
||||
assertStringEquals(t, "apex1:jarA,apex2:jarB", list2.String())
|
||||
|
@@ -65,7 +65,7 @@ func TestHiddenAPISingleton(t *testing.T) {
|
||||
srcs: ["a.java"],
|
||||
compile_dex: true,
|
||||
}
|
||||
`, []string{":foo"}, nil)
|
||||
`, []string{"platform:foo"}, nil)
|
||||
|
||||
hiddenAPI := ctx.SingletonForTests("hiddenapi")
|
||||
hiddenapiRule := hiddenAPI.Rule("hiddenapi")
|
||||
@@ -82,7 +82,7 @@ func TestHiddenAPISingletonWithPrebuilt(t *testing.T) {
|
||||
jars: ["a.jar"],
|
||||
compile_dex: true,
|
||||
}
|
||||
`, []string{":foo"}, nil)
|
||||
`, []string{"platform:foo"}, nil)
|
||||
|
||||
hiddenAPI := ctx.SingletonForTests("hiddenapi")
|
||||
hiddenapiRule := hiddenAPI.Rule("hiddenapi")
|
||||
@@ -106,7 +106,7 @@ func TestHiddenAPISingletonWithPrebuiltUseSource(t *testing.T) {
|
||||
compile_dex: true,
|
||||
prefer: false,
|
||||
}
|
||||
`, []string{":foo"}, nil)
|
||||
`, []string{"platform:foo"}, nil)
|
||||
|
||||
hiddenAPI := ctx.SingletonForTests("hiddenapi")
|
||||
hiddenapiRule := hiddenAPI.Rule("hiddenapi")
|
||||
@@ -135,7 +135,7 @@ func TestHiddenAPISingletonWithPrebuiltOverrideSource(t *testing.T) {
|
||||
compile_dex: true,
|
||||
prefer: true,
|
||||
}
|
||||
`, []string{":foo"}, nil)
|
||||
`, []string{"platform:foo"}, nil)
|
||||
|
||||
hiddenAPI := ctx.SingletonForTests("hiddenapi")
|
||||
hiddenapiRule := hiddenAPI.Rule("hiddenapi")
|
||||
@@ -236,7 +236,7 @@ func TestHiddenAPISingletonWithPrebuiltCsvFile(t *testing.T) {
|
||||
jars: ["a.jar"],
|
||||
compile_dex: true,
|
||||
}
|
||||
`, []string{":foo"}, &prebuiltHiddenApiDir)
|
||||
`, []string{"platform:foo"}, &prebuiltHiddenApiDir)
|
||||
|
||||
expectedCpInput := prebuiltHiddenApiDir + "/hiddenapi-flags.csv"
|
||||
expectedCpOutput := buildDir + "/hiddenapi/hiddenapi-flags.csv"
|
||||
|
Reference in New Issue
Block a user