Extract method to process bp file for androidmk_test.go
Test: m nothing
Bug: 174226317
Change-Id: Ifc9ee5088fe766d971718fc112d1e95719a2b825
diff --git a/android/androidmk_test.go b/android/androidmk_test.go
index 80df6a7..bcaf5d7 100644
--- a/android/androidmk_test.go
+++ b/android/androidmk_test.go
@@ -67,16 +67,10 @@
return module
}
-func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testing.T) {
- bp := `
- custom {
- name: "foo",
- required: ["bar"],
- host_required: ["baz"],
- target_required: ["qux"],
- }
- `
-
+// buildConfigAndCustomModuleFoo creates a config object, processes the supplied
+// bp module and then returns the config and the custom module called "foo".
+func buildConfigAndCustomModuleFoo(t *testing.T, bp string) (Config, *customModule) {
+ t.Helper()
config := TestConfig(buildDir, nil, bp, nil)
config.katiEnabled = true // Enable androidmk Singleton
@@ -90,7 +84,21 @@
_, errs = ctx.PrepareBuildActions(config)
FailIfErrored(t, errs)
- m := ctx.ModuleForTests("foo", "").Module().(*customModule)
+ module := ctx.ModuleForTests("foo", "").Module().(*customModule)
+ return config, module
+}
+
+func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testing.T) {
+ bp := `
+ custom {
+ name: "foo",
+ required: ["bar"],
+ host_required: ["baz"],
+ target_required: ["qux"],
+ }
+ `
+
+ _, m := buildConfigAndCustomModuleFoo(t, bp)
assertEqual := func(expected interface{}, actual interface{}) {
if !reflect.DeepEqual(expected, actual) {
@@ -257,20 +265,7 @@
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
- config := TestConfig(buildDir, nil, testCase.bp, nil)
- config.katiEnabled = true // Enable androidmk Singleton
-
- ctx := NewTestContext(config)
- ctx.RegisterSingletonType("androidmk", AndroidMkSingleton)
- ctx.RegisterModuleType("custom", customModuleFactory)
- ctx.Register()
-
- _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
- FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- FailIfErrored(t, errs)
-
- module := ctx.ModuleForTests("foo", "").Module().(*customModule)
+ config, module := buildConfigAndCustomModuleFoo(t, testCase.bp)
entries := AndroidMkEntriesForTest(t, config, "", module)
if len(entries) != 1 {
t.Errorf("Expected a single AndroidMk entry, got %d", len(entries))