Convert android/mutator_test.go to test fixtures

Bug: 182885307
Test: m nothing
Change-Id: Id7eb915af21ccde5acf1d4a0ec339e0672bc3d57
This commit is contained in:
Paul Duffin
2021-03-16 22:35:28 +00:00
parent 485079130d
commit e8a4ac49fe

View File

@@ -16,12 +16,10 @@ package android
import (
"fmt"
"reflect"
"strings"
"testing"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
type mutatorTestModule struct {
@@ -67,28 +65,20 @@ func TestMutatorAddMissingDependencies(t *testing.T) {
}
`
config := TestConfig(buildDir, nil, bp, nil)
config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
ctx := NewTestContext(config)
ctx.SetAllowMissingDependencies(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.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
FailIfErrored(t, errs)
foo := result.ModuleForTests("foo", "").Module().(*mutatorTestModule)
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,12 +88,11 @@ func TestModuleString(t *testing.T) {
}
`
config := TestConfig(buildDir, nil, bp, nil)
ctx := NewTestContext(config)
var moduleStrings []string
emptyTestFixtureFactory.RunTest(t,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.PreArchMutators(func(ctx RegisterMutatorsContext) {
ctx.BottomUp("pre_arch", func(ctx BottomUpMutatorContext) {
moduleStrings = append(moduleStrings, ctx.Module().String())
@@ -137,13 +126,9 @@ func TestModuleString(t *testing.T) {
})
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
FailIfErrored(t, errs)
}),
FixtureWithRootAndroidBp(bp),
)
want := []string{
// Initial name.
@@ -184,9 +169,7 @@ func TestModuleString(t *testing.T) {
"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,12 +185,10 @@ func TestFinalDepsPhase(t *testing.T) {
}
`
config := TestConfig(buildDir, nil, bp, nil)
ctx := NewTestContext(config)
finalGot := map[string]int{}
emptyTestFixtureFactory.RunTest(t,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
dep1Tag := struct {
blueprint.BaseDependencyTag
}{}
@@ -241,13 +222,9 @@ func TestFinalDepsPhase(t *testing.T) {
})
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
FailIfErrored(t, errs)
}),
FixtureWithRootAndroidBp(bp),
)
finalWant := map[string]int{
"common_dep_1{variant:a}": 1,
@@ -262,21 +239,18 @@ func TestFinalDepsPhase(t *testing.T) {
"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")
}
}
emptyTestFixtureFactory.RunTest(t,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
ctx.BottomUp("vars", func(ctx BottomUpMutatorContext) {
defer checkErr()
@@ -289,10 +263,7 @@ func TestNoCreateVariationsInFinalDeps(t *testing.T) {
})
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
FailIfErrored(t, errs)
}),
FixtureWithRootAndroidBp(`test {name: "foo"}`),
)
}