Convert android/mutator_test.go to test fixtures

Bug: 182885307
Test: m nothing
Change-Id: Id7eb915af21ccde5acf1d4a0ec339e0672bc3d57
diff --git a/android/mutator_test.go b/android/mutator_test.go
index 1c395c7..46d26d1 100644
--- a/android/mutator_test.go
+++ b/android/mutator_test.go
@@ -16,12 +16,10 @@
 
 import (
 	"fmt"
-	"reflect"
 	"strings"
 	"testing"
 
 	"github.com/google/blueprint"
-	"github.com/google/blueprint/proptools"
 )
 
 type mutatorTestModule struct {
@@ -67,28 +65,20 @@
 		}
 	`
 
-	config := TestConfig(buildDir, nil, bp, nil)
-	config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
+	result := emptyTestFixtureFactory.RunTest(t,
+		PrepareForTestWithAllowMissingDependencies,
+		FixtureRegisterWithContext(func(ctx RegistrationContext) {
+			ctx.RegisterModuleType("test", mutatorTestModuleFactory)
+			ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
+				ctx.TopDown("add_missing_dependencies", addMissingDependenciesMutator)
+			})
+		}),
+		FixtureWithRootAndroidBp(bp),
+	)
 
-	ctx := NewTestContext(config)
-	ctx.SetAllowMissingDependencies(true)
+	foo := result.ModuleForTests("foo", "").Module().(*mutatorTestModule)
 
-	ctx.RegisterModuleType("test", mutatorTestModuleFactory)
-	ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
-		ctx.TopDown("add_missing_dependencies", addMissingDependenciesMutator)
-	})
-
-	ctx.Register()
-	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
-	FailIfErrored(t, errs)
-	_, errs = ctx.PrepareBuildActions(config)
-	FailIfErrored(t, errs)
-
-	foo := ctx.ModuleForTests("foo", "").Module().(*mutatorTestModule)
-
-	if g, w := foo.missingDeps, []string{"added_missing_dep", "regular_missing_dep"}; !reflect.DeepEqual(g, w) {
-		t.Errorf("want foo missing deps %q, got %q", w, g)
-	}
+	AssertDeepEquals(t, "foo missing deps", []string{"added_missing_dep", "regular_missing_dep"}, foo.missingDeps)
 }
 
 func TestModuleString(t *testing.T) {
@@ -98,52 +88,47 @@
 		}
 	`
 
-	config := TestConfig(buildDir, nil, bp, nil)
-
-	ctx := NewTestContext(config)
-
 	var moduleStrings []string
 
-	ctx.PreArchMutators(func(ctx RegisterMutatorsContext) {
-		ctx.BottomUp("pre_arch", func(ctx BottomUpMutatorContext) {
-			moduleStrings = append(moduleStrings, ctx.Module().String())
-			ctx.CreateVariations("a", "b")
-		})
-		ctx.TopDown("rename_top_down", func(ctx TopDownMutatorContext) {
-			moduleStrings = append(moduleStrings, ctx.Module().String())
-			ctx.Rename(ctx.Module().base().Name() + "_renamed1")
-		})
-	})
+	emptyTestFixtureFactory.RunTest(t,
+		FixtureRegisterWithContext(func(ctx RegistrationContext) {
 
-	ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
-		ctx.BottomUp("pre_deps", func(ctx BottomUpMutatorContext) {
-			moduleStrings = append(moduleStrings, ctx.Module().String())
-			ctx.CreateVariations("c", "d")
-		})
-	})
+			ctx.PreArchMutators(func(ctx RegisterMutatorsContext) {
+				ctx.BottomUp("pre_arch", func(ctx BottomUpMutatorContext) {
+					moduleStrings = append(moduleStrings, ctx.Module().String())
+					ctx.CreateVariations("a", "b")
+				})
+				ctx.TopDown("rename_top_down", func(ctx TopDownMutatorContext) {
+					moduleStrings = append(moduleStrings, ctx.Module().String())
+					ctx.Rename(ctx.Module().base().Name() + "_renamed1")
+				})
+			})
 
-	ctx.PostDepsMutators(func(ctx RegisterMutatorsContext) {
-		ctx.BottomUp("post_deps", func(ctx BottomUpMutatorContext) {
-			moduleStrings = append(moduleStrings, ctx.Module().String())
-			ctx.CreateLocalVariations("e", "f")
-		})
-		ctx.BottomUp("rename_bottom_up", func(ctx BottomUpMutatorContext) {
-			moduleStrings = append(moduleStrings, ctx.Module().String())
-			ctx.Rename(ctx.Module().base().Name() + "_renamed2")
-		})
-		ctx.BottomUp("final", func(ctx BottomUpMutatorContext) {
-			moduleStrings = append(moduleStrings, ctx.Module().String())
-		})
-	})
+			ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
+				ctx.BottomUp("pre_deps", func(ctx BottomUpMutatorContext) {
+					moduleStrings = append(moduleStrings, ctx.Module().String())
+					ctx.CreateVariations("c", "d")
+				})
+			})
 
-	ctx.RegisterModuleType("test", mutatorTestModuleFactory)
+			ctx.PostDepsMutators(func(ctx RegisterMutatorsContext) {
+				ctx.BottomUp("post_deps", func(ctx BottomUpMutatorContext) {
+					moduleStrings = append(moduleStrings, ctx.Module().String())
+					ctx.CreateLocalVariations("e", "f")
+				})
+				ctx.BottomUp("rename_bottom_up", func(ctx BottomUpMutatorContext) {
+					moduleStrings = append(moduleStrings, ctx.Module().String())
+					ctx.Rename(ctx.Module().base().Name() + "_renamed2")
+				})
+				ctx.BottomUp("final", func(ctx BottomUpMutatorContext) {
+					moduleStrings = append(moduleStrings, ctx.Module().String())
+				})
+			})
 
-	ctx.Register()
-
-	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
-	FailIfErrored(t, errs)
-	_, errs = ctx.PrepareBuildActions(config)
-	FailIfErrored(t, errs)
+			ctx.RegisterModuleType("test", mutatorTestModuleFactory)
+		}),
+		FixtureWithRootAndroidBp(bp),
+	)
 
 	want := []string{
 		// Initial name.
@@ -184,9 +169,7 @@
 		"foo_renamed2{pre_arch:b,pre_deps:d,post_deps:f}",
 	}
 
-	if !reflect.DeepEqual(moduleStrings, want) {
-		t.Errorf("want module String() values:\n%q\ngot:\n%q", want, moduleStrings)
-	}
+	AssertDeepEquals(t, "module String() values", want, moduleStrings)
 }
 
 func TestFinalDepsPhase(t *testing.T) {
@@ -202,52 +185,46 @@
 		}
 	`
 
-	config := TestConfig(buildDir, nil, bp, nil)
-
-	ctx := NewTestContext(config)
-
 	finalGot := map[string]int{}
 
-	dep1Tag := struct {
-		blueprint.BaseDependencyTag
-	}{}
-	dep2Tag := struct {
-		blueprint.BaseDependencyTag
-	}{}
+	emptyTestFixtureFactory.RunTest(t,
+		FixtureRegisterWithContext(func(ctx RegistrationContext) {
+			dep1Tag := struct {
+				blueprint.BaseDependencyTag
+			}{}
+			dep2Tag := struct {
+				blueprint.BaseDependencyTag
+			}{}
 
-	ctx.PostDepsMutators(func(ctx RegisterMutatorsContext) {
-		ctx.BottomUp("far_deps_1", func(ctx BottomUpMutatorContext) {
-			if !strings.HasPrefix(ctx.ModuleName(), "common_dep") {
-				ctx.AddFarVariationDependencies([]blueprint.Variation{}, dep1Tag, "common_dep_1")
-			}
-		})
-		ctx.BottomUp("variant", func(ctx BottomUpMutatorContext) {
-			ctx.CreateLocalVariations("a", "b")
-		})
-	})
-
-	ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
-		ctx.BottomUp("far_deps_2", func(ctx BottomUpMutatorContext) {
-			if !strings.HasPrefix(ctx.ModuleName(), "common_dep") {
-				ctx.AddFarVariationDependencies([]blueprint.Variation{}, dep2Tag, "common_dep_2")
-			}
-		})
-		ctx.BottomUp("final", func(ctx BottomUpMutatorContext) {
-			finalGot[ctx.Module().String()] += 1
-			ctx.VisitDirectDeps(func(mod Module) {
-				finalGot[fmt.Sprintf("%s -> %s", ctx.Module().String(), mod)] += 1
+			ctx.PostDepsMutators(func(ctx RegisterMutatorsContext) {
+				ctx.BottomUp("far_deps_1", func(ctx BottomUpMutatorContext) {
+					if !strings.HasPrefix(ctx.ModuleName(), "common_dep") {
+						ctx.AddFarVariationDependencies([]blueprint.Variation{}, dep1Tag, "common_dep_1")
+					}
+				})
+				ctx.BottomUp("variant", func(ctx BottomUpMutatorContext) {
+					ctx.CreateLocalVariations("a", "b")
+				})
 			})
-		})
-	})
 
-	ctx.RegisterModuleType("test", mutatorTestModuleFactory)
+			ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
+				ctx.BottomUp("far_deps_2", func(ctx BottomUpMutatorContext) {
+					if !strings.HasPrefix(ctx.ModuleName(), "common_dep") {
+						ctx.AddFarVariationDependencies([]blueprint.Variation{}, dep2Tag, "common_dep_2")
+					}
+				})
+				ctx.BottomUp("final", func(ctx BottomUpMutatorContext) {
+					finalGot[ctx.Module().String()] += 1
+					ctx.VisitDirectDeps(func(mod Module) {
+						finalGot[fmt.Sprintf("%s -> %s", ctx.Module().String(), mod)] += 1
+					})
+				})
+			})
 
-	ctx.Register()
-
-	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
-	FailIfErrored(t, errs)
-	_, errs = ctx.PrepareBuildActions(config)
-	FailIfErrored(t, errs)
+			ctx.RegisterModuleType("test", mutatorTestModuleFactory)
+		}),
+		FixtureWithRootAndroidBp(bp),
+	)
 
 	finalWant := map[string]int{
 		"common_dep_1{variant:a}":                   1,
@@ -262,37 +239,31 @@
 		"foo{variant:b} -> common_dep_2{variant:a}": 1,
 	}
 
-	if !reflect.DeepEqual(finalWant, finalGot) {
-		t.Errorf("want:\n%q\ngot:\n%q", finalWant, finalGot)
-	}
+	AssertDeepEquals(t, "final", finalWant, finalGot)
 }
 
 func TestNoCreateVariationsInFinalDeps(t *testing.T) {
-	config := TestConfig(buildDir, nil, `test {name: "foo"}`, nil)
-	ctx := NewTestContext(config)
-
 	checkErr := func() {
 		if err := recover(); err == nil || !strings.Contains(fmt.Sprintf("%s", err), "not allowed in FinalDepsMutators") {
 			panic("Expected FinalDepsMutators consistency check to fail")
 		}
 	}
 
-	ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
-		ctx.BottomUp("vars", func(ctx BottomUpMutatorContext) {
-			defer checkErr()
-			ctx.CreateVariations("a", "b")
-		})
-		ctx.BottomUp("local_vars", func(ctx BottomUpMutatorContext) {
-			defer checkErr()
-			ctx.CreateLocalVariations("a", "b")
-		})
-	})
+	emptyTestFixtureFactory.RunTest(t,
+		FixtureRegisterWithContext(func(ctx RegistrationContext) {
+			ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
+				ctx.BottomUp("vars", func(ctx BottomUpMutatorContext) {
+					defer checkErr()
+					ctx.CreateVariations("a", "b")
+				})
+				ctx.BottomUp("local_vars", func(ctx BottomUpMutatorContext) {
+					defer checkErr()
+					ctx.CreateLocalVariations("a", "b")
+				})
+			})
 
-	ctx.RegisterModuleType("test", mutatorTestModuleFactory)
-	ctx.Register()
-
-	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
-	FailIfErrored(t, errs)
-	_, errs = ctx.PrepareBuildActions(config)
-	FailIfErrored(t, errs)
+			ctx.RegisterModuleType("test", mutatorTestModuleFactory)
+		}),
+		FixtureWithRootAndroidBp(`test {name: "foo"}`),
+	)
 }