Convert android/mutator_test.go to test fixtures
Bug: 182885307 Test: m nothing Change-Id: Id7eb915af21ccde5acf1d4a0ec339e0672bc3d57
This commit is contained in:
@@ -16,12 +16,10 @@ package android
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type mutatorTestModule struct {
|
type mutatorTestModule struct {
|
||||||
@@ -67,28 +65,20 @@ func TestMutatorAddMissingDependencies(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
config := TestConfig(buildDir, nil, bp, nil)
|
result := emptyTestFixtureFactory.RunTest(t,
|
||||||
config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
|
PrepareForTestWithAllowMissingDependencies,
|
||||||
|
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||||
ctx := NewTestContext(config)
|
|
||||||
ctx.SetAllowMissingDependencies(true)
|
|
||||||
|
|
||||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||||
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||||
ctx.TopDown("add_missing_dependencies", addMissingDependenciesMutator)
|
ctx.TopDown("add_missing_dependencies", addMissingDependenciesMutator)
|
||||||
})
|
})
|
||||||
|
}),
|
||||||
|
FixtureWithRootAndroidBp(bp),
|
||||||
|
)
|
||||||
|
|
||||||
ctx.Register()
|
foo := result.ModuleForTests("foo", "").Module().(*mutatorTestModule)
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
||||||
FailIfErrored(t, errs)
|
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
|
||||||
FailIfErrored(t, errs)
|
|
||||||
|
|
||||||
foo := ctx.ModuleForTests("foo", "").Module().(*mutatorTestModule)
|
AssertDeepEquals(t, "foo missing deps", []string{"added_missing_dep", "regular_missing_dep"}, foo.missingDeps)
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestModuleString(t *testing.T) {
|
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
|
var moduleStrings []string
|
||||||
|
|
||||||
|
emptyTestFixtureFactory.RunTest(t,
|
||||||
|
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||||
|
|
||||||
ctx.PreArchMutators(func(ctx RegisterMutatorsContext) {
|
ctx.PreArchMutators(func(ctx RegisterMutatorsContext) {
|
||||||
ctx.BottomUp("pre_arch", func(ctx BottomUpMutatorContext) {
|
ctx.BottomUp("pre_arch", func(ctx BottomUpMutatorContext) {
|
||||||
moduleStrings = append(moduleStrings, ctx.Module().String())
|
moduleStrings = append(moduleStrings, ctx.Module().String())
|
||||||
@@ -137,13 +126,9 @@ func TestModuleString(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||||
|
}),
|
||||||
ctx.Register()
|
FixtureWithRootAndroidBp(bp),
|
||||||
|
)
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
||||||
FailIfErrored(t, errs)
|
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
|
||||||
FailIfErrored(t, errs)
|
|
||||||
|
|
||||||
want := []string{
|
want := []string{
|
||||||
// Initial name.
|
// Initial name.
|
||||||
@@ -184,9 +169,7 @@ func TestModuleString(t *testing.T) {
|
|||||||
"foo_renamed2{pre_arch:b,pre_deps:d,post_deps:f}",
|
"foo_renamed2{pre_arch:b,pre_deps:d,post_deps:f}",
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(moduleStrings, want) {
|
AssertDeepEquals(t, "module String() values", want, moduleStrings)
|
||||||
t.Errorf("want module String() values:\n%q\ngot:\n%q", want, moduleStrings)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFinalDepsPhase(t *testing.T) {
|
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{}
|
finalGot := map[string]int{}
|
||||||
|
|
||||||
|
emptyTestFixtureFactory.RunTest(t,
|
||||||
|
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||||
dep1Tag := struct {
|
dep1Tag := struct {
|
||||||
blueprint.BaseDependencyTag
|
blueprint.BaseDependencyTag
|
||||||
}{}
|
}{}
|
||||||
@@ -241,13 +222,9 @@ func TestFinalDepsPhase(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||||
|
}),
|
||||||
ctx.Register()
|
FixtureWithRootAndroidBp(bp),
|
||||||
|
)
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
||||||
FailIfErrored(t, errs)
|
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
|
||||||
FailIfErrored(t, errs)
|
|
||||||
|
|
||||||
finalWant := map[string]int{
|
finalWant := map[string]int{
|
||||||
"common_dep_1{variant:a}": 1,
|
"common_dep_1{variant:a}": 1,
|
||||||
@@ -262,21 +239,18 @@ func TestFinalDepsPhase(t *testing.T) {
|
|||||||
"foo{variant:b} -> common_dep_2{variant:a}": 1,
|
"foo{variant:b} -> common_dep_2{variant:a}": 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(finalWant, finalGot) {
|
AssertDeepEquals(t, "final", finalWant, finalGot)
|
||||||
t.Errorf("want:\n%q\ngot:\n%q", finalWant, finalGot)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoCreateVariationsInFinalDeps(t *testing.T) {
|
func TestNoCreateVariationsInFinalDeps(t *testing.T) {
|
||||||
config := TestConfig(buildDir, nil, `test {name: "foo"}`, nil)
|
|
||||||
ctx := NewTestContext(config)
|
|
||||||
|
|
||||||
checkErr := func() {
|
checkErr := func() {
|
||||||
if err := recover(); err == nil || !strings.Contains(fmt.Sprintf("%s", err), "not allowed in FinalDepsMutators") {
|
if err := recover(); err == nil || !strings.Contains(fmt.Sprintf("%s", err), "not allowed in FinalDepsMutators") {
|
||||||
panic("Expected FinalDepsMutators consistency check to fail")
|
panic("Expected FinalDepsMutators consistency check to fail")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emptyTestFixtureFactory.RunTest(t,
|
||||||
|
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||||
ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
|
ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||||
ctx.BottomUp("vars", func(ctx BottomUpMutatorContext) {
|
ctx.BottomUp("vars", func(ctx BottomUpMutatorContext) {
|
||||||
defer checkErr()
|
defer checkErr()
|
||||||
@@ -289,10 +263,7 @@ func TestNoCreateVariationsInFinalDeps(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
|
||||||
ctx.Register()
|
}),
|
||||||
|
FixtureWithRootAndroidBp(`test {name: "foo"}`),
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
)
|
||||||
FailIfErrored(t, errs)
|
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
|
||||||
FailIfErrored(t, errs)
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user