Pass Config to NewTestContext instead of ctx.Register

Prepare for using Config when adding singletons by passing
Config to NewTestContext and NewContext instead of to ctx.Register.
This will enable a followup change to store SingletonMakeVarsProviders
registered on the Context in the Config, which is necessary to run
multiple tests in parallel without data races.

Test: all soong tests
Change-Id: Id229629a4e42ff4487d317241673837726c075fc
This commit is contained in:
Colin Cross
2020-10-29 17:09:13 -07:00
parent 45e0c95f85
commit ae8600b507
45 changed files with 209 additions and 208 deletions

View File

@@ -70,7 +70,7 @@ func TestMutatorAddMissingDependencies(t *testing.T) {
config := TestConfig(buildDir, nil, bp, nil)
config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
ctx := NewTestContext()
ctx := NewTestContext(config)
ctx.SetAllowMissingDependencies(true)
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
@@ -78,7 +78,7 @@ func TestMutatorAddMissingDependencies(t *testing.T) {
ctx.TopDown("add_missing_dependencies", addMissingDependenciesMutator)
})
ctx.Register(config)
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
@@ -92,7 +92,15 @@ func TestMutatorAddMissingDependencies(t *testing.T) {
}
func TestModuleString(t *testing.T) {
ctx := NewTestContext()
bp := `
test {
name: "foo",
}
`
config := TestConfig(buildDir, nil, bp, nil)
ctx := NewTestContext(config)
var moduleStrings []string
@@ -130,15 +138,7 @@ func TestModuleString(t *testing.T) {
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
bp := `
test {
name: "foo",
}
`
config := TestConfig(buildDir, nil, bp, nil)
ctx.Register(config)
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
@@ -190,7 +190,21 @@ func TestModuleString(t *testing.T) {
}
func TestFinalDepsPhase(t *testing.T) {
ctx := NewTestContext()
bp := `
test {
name: "common_dep_1",
}
test {
name: "common_dep_2",
}
test {
name: "foo",
}
`
config := TestConfig(buildDir, nil, bp, nil)
ctx := NewTestContext(config)
finalGot := map[string]int{}
@@ -228,20 +242,7 @@ func TestFinalDepsPhase(t *testing.T) {
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
bp := `
test {
name: "common_dep_1",
}
test {
name: "common_dep_2",
}
test {
name: "foo",
}
`
config := TestConfig(buildDir, nil, bp, nil)
ctx.Register(config)
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
@@ -267,7 +268,8 @@ func TestFinalDepsPhase(t *testing.T) {
}
func TestNoCreateVariationsInFinalDeps(t *testing.T) {
ctx := NewTestContext()
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") {
@@ -287,8 +289,7 @@ func TestNoCreateVariationsInFinalDeps(t *testing.T) {
})
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
config := TestConfig(buildDir, nil, `test {name: "foo"}`, nil)
ctx.Register(config)
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)