Skip to content

Commit

Permalink
Remove uses of FixtureFactory from android package
Browse files Browse the repository at this point in the history
Bug: 183235980
Test: m nothing
Change-Id: I72898ada020ee1a73fd534c61afb5c22fa00c1e5
  • Loading branch information
paulduffin committed Mar 22, 2021
1 parent ff2aa69 commit 30ac3e7
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 117 deletions.
2 changes: 0 additions & 2 deletions android/android_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ import (
func TestMain(m *testing.M) {
os.Exit(m.Run())
}

var emptyTestFixtureFactory = NewFixtureFactory(nil)
4 changes: 2 additions & 2 deletions android/androidmk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ func customModuleFactory() Module {
// bp module and then returns the config and the custom module called "foo".
func buildContextAndCustomModuleFoo(t *testing.T, bp string) (*TestContext, *customModule) {
t.Helper()
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
// Enable androidmk Singleton
PrepareForTestWithAndroidMk,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("custom", customModuleFactory)
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)

module := result.ModuleForTests("foo", "").Module().(*customModule)
return result.TestContext, module
Expand Down
8 changes: 4 additions & 4 deletions android/arch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,12 @@ func TestArchMutator(t *testing.T) {

for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
prepareForArchTest,
// Test specific preparer
OptionalFixturePreparer(tt.preparer),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)
ctx := result.TestContext

if g, w := enabledVariants(ctx, "foo"), tt.fooVariants; !reflect.DeepEqual(w, g) {
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestArchMutatorNativeBridge(t *testing.T) {

for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
prepareForArchTest,
// Test specific preparer
OptionalFixturePreparer(tt.preparer),
Expand All @@ -455,7 +455,7 @@ func TestArchMutatorNativeBridge(t *testing.T) {
}
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)

ctx := result.TestContext

Expand Down
4 changes: 2 additions & 2 deletions android/csuite_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
)

func TestCSuiteConfig(t *testing.T) {
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
PrepareForTestWithArchMutator,
FixtureRegisterWithContext(registerCSuiteBuildComponents),
FixtureWithRootAndroidBp(`
csuite_config { name: "plain"}
csuite_config { name: "with_manifest", test_config: "manifest.xml" }
`),
)
).RunTest(t)

variants := result.ModuleVariantsForTests("plain")
if len(variants) > 1 {
Expand Down
8 changes: 4 additions & 4 deletions android/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ func TestDefaults(t *testing.T) {
}
`

result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
prepareForDefaultsTest,
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)

foo := result.Module("foo", "").(*defaultsTestModule)

Expand Down Expand Up @@ -114,11 +114,11 @@ func TestDefaultsAllowMissingDependencies(t *testing.T) {
}
`

result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
prepareForDefaultsTest,
PrepareForTestWithAllowMissingDependencies,
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)

missingDefaults := result.ModuleForTests("missing_defaults", "").Output("out")
missingTransitiveDefaults := result.ModuleForTests("missing_transitive_defaults", "").Output("out")
Expand Down
4 changes: 2 additions & 2 deletions android/deptag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func TestInstallDependencyTag(t *testing.T) {
}
`

result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
PrepareForTestWithArchMutator,
FixtureWithRootAndroidBp(bp),
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("test_module", testInstallDependencyTagModuleFactory)
}),
)
).RunTest(t)

config := result.Config

Expand Down
15 changes: 8 additions & 7 deletions android/license_kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ var licenseKindTests = []struct {
func TestLicenseKind(t *testing.T) {
for _, test := range licenseKindTests {
t.Run(test.name, func(t *testing.T) {
licenseTestFixtureFactory.
Extend(
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("mock_license", newMockLicenseModule)
}),
test.fs.AddToFixture(),
).ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
GroupFixturePreparers(
prepareForLicenseTest,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("mock_license", newMockLicenseModule)
}),
test.fs.AddToFixture(),
).
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
RunTest(t)
})
}
Expand Down
5 changes: 3 additions & 2 deletions android/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

// Common test set up for license tests.
var licenseTestFixtureFactory = emptyTestFixtureFactory.Extend(
var prepareForLicenseTest = GroupFixturePreparers(
// General preparers in alphabetical order.
PrepareForTestWithDefaults,
prepareForTestWithLicenses,
Expand Down Expand Up @@ -179,7 +179,8 @@ func TestLicense(t *testing.T) {
for _, test := range licenseTests {
t.Run(test.name, func(t *testing.T) {
// Customize the common license text fixture factory.
licenseTestFixtureFactory.Extend(
GroupFixturePreparers(
prepareForLicenseTest,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("rule", newMockRuleModule)
}),
Expand Down
3 changes: 2 additions & 1 deletion android/licenses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ func TestLicenses(t *testing.T) {
for _, test := range licensesTests {
t.Run(test.name, func(t *testing.T) {
// Customize the common license text fixture factory.
result := licenseTestFixtureFactory.Extend(
result := GroupFixturePreparers(
prepareForLicenseTest,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("mock_bad_module", newMockLicensesBadModule)
ctx.RegisterModuleType("mock_library", newMockLicensesLibraryModule)
Expand Down
12 changes: 4 additions & 8 deletions android/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,9 @@ func TestErrorDependsOnDisabledModule(t *testing.T) {
}
`

emptyTestFixtureFactory.
prepareForModuleTests.
ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern(`module "foo": depends on disabled module "bar"`)).
RunTest(t,
prepareForModuleTests,
FixtureWithRootAndroidBp(bp))
RunTestWithBp(t, bp)
}

func TestValidateCorrectBuildParams(t *testing.T) {
Expand Down Expand Up @@ -268,9 +266,7 @@ func TestDistErrorChecking(t *testing.T) {
"\\QAndroid.bp:18:17: module \"foo\": dists[1].suffix: Suffix may not contain a '/' character.\\E",
}

emptyTestFixtureFactory.
prepareForModuleTests.
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(expectedErrs)).
RunTest(t,
prepareForModuleTests,
FixtureWithRootAndroidBp(bp))
RunTestWithBp(t, bp)
}
16 changes: 8 additions & 8 deletions android/mutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestMutatorAddMissingDependencies(t *testing.T) {
}
`

result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
PrepareForTestWithAllowMissingDependencies,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
Expand All @@ -74,7 +74,7 @@ func TestMutatorAddMissingDependencies(t *testing.T) {
})
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)

foo := result.ModuleForTests("foo", "").Module().(*mutatorTestModule)

Expand All @@ -90,7 +90,7 @@ func TestModuleString(t *testing.T) {

var moduleStrings []string

emptyTestFixtureFactory.RunTest(t,
GroupFixturePreparers(
FixtureRegisterWithContext(func(ctx RegistrationContext) {

ctx.PreArchMutators(func(ctx RegisterMutatorsContext) {
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestModuleString(t *testing.T) {
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)

want := []string{
// Initial name.
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestFinalDepsPhase(t *testing.T) {

finalGot := map[string]int{}

emptyTestFixtureFactory.RunTest(t,
GroupFixturePreparers(
FixtureRegisterWithContext(func(ctx RegistrationContext) {
dep1Tag := struct {
blueprint.BaseDependencyTag
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestFinalDepsPhase(t *testing.T) {
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)

finalWant := map[string]int{
"common_dep_1{variant:a}": 1,
Expand All @@ -249,7 +249,7 @@ func TestNoCreateVariationsInFinalDeps(t *testing.T) {
}
}

emptyTestFixtureFactory.RunTest(t,
GroupFixturePreparers(
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.FinalDepsMutators(func(ctx RegisterMutatorsContext) {
ctx.BottomUp("vars", func(ctx BottomUpMutatorContext) {
Expand All @@ -265,5 +265,5 @@ func TestNoCreateVariationsInFinalDeps(t *testing.T) {
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
}),
FixtureWithRootAndroidBp(`test {name: "foo"}`),
)
).RunTest(t)
}
26 changes: 13 additions & 13 deletions android/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,21 +633,21 @@ func mockFiles(bps map[string]string) (files map[string][]byte) {
}

func setupTestFromFiles(t *testing.T, bps MockFS) (ctx *TestContext, errs []error) {
result := emptyTestFixtureFactory.
result := GroupFixturePreparers(
FixtureModifyContext(func(ctx *TestContext) {
ctx.RegisterModuleType("test_module", newTestModule)
ctx.RegisterModuleType("soong_namespace", NamespaceFactory)
ctx.Context.RegisterModuleType("blueprint_test_module", newBlueprintTestModule)
ctx.PreArchMutators(RegisterNamespaceMutator)
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
ctx.BottomUp("rename", renameMutator)
})
}),
bps.AddToFixture(),
).
// Ignore errors for now so tests can check them later.
ExtendWithErrorHandler(FixtureIgnoreErrors).
RunTest(t,
FixtureModifyContext(func(ctx *TestContext) {
ctx.RegisterModuleType("test_module", newTestModule)
ctx.RegisterModuleType("soong_namespace", NamespaceFactory)
ctx.Context.RegisterModuleType("blueprint_test_module", newBlueprintTestModule)
ctx.PreArchMutators(RegisterNamespaceMutator)
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
ctx.BottomUp("rename", renameMutator)
})
}),
bps.AddToFixture(),
)
RunTest(t)

return result.TestContext, result.Errs
}
Expand Down
23 changes: 11 additions & 12 deletions android/neverallow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,17 @@ var prepareForNeverAllowTest = GroupFixturePreparers(
func TestNeverallow(t *testing.T) {
for _, test := range neverallowTests {
t.Run(test.name, func(t *testing.T) {
emptyTestFixtureFactory.
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
RunTest(t,
prepareForNeverAllowTest,
FixtureModifyConfig(func(config Config) {
// If the test has its own rules then use them instead of the default ones.
if test.rules != nil {
SetTestNeverallowRules(config, test.rules)
}
}),
test.fs.AddToFixture(),
)
GroupFixturePreparers(
prepareForNeverAllowTest,
FixtureModifyConfig(func(config Config) {
// If the test has its own rules then use them instead of the default ones.
if test.rules != nil {
SetTestNeverallowRules(config, test.rules)
}
}),
test.fs.AddToFixture(),
).ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
RunTest(t)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions android/ninja_deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func TestNinjaDeps(t *testing.T) {
"test_ninja_deps/exists": nil,
}

result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterSingletonType("test_ninja_deps_singleton", testNinjaDepsSingletonFactory)
ctx.RegisterSingletonType("ninja_deps_singleton", ninjaDepsSingletonFactory)
}),
fs.AddToFixture(),
)
).RunTest(t)

// Verify that the ninja file has a dependency on the test_ninja_deps directory.
if g, w := result.NinjaDeps, "test_ninja_deps"; !InList(w, g) {
Expand Down
12 changes: 6 additions & 6 deletions android/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ var packageTests = []struct {
func TestPackage(t *testing.T) {
for _, test := range packageTests {
t.Run(test.name, func(t *testing.T) {
emptyTestFixtureFactory.
GroupFixturePreparers(
PrepareForTestWithArchMutator,
PrepareForTestWithPackageModule,
test.fs.AddToFixture(),
).
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
RunTest(t,
PrepareForTestWithArchMutator,
PrepareForTestWithPackageModule,
test.fs.AddToFixture(),
)
RunTest(t)
})
}
}
4 changes: 2 additions & 2 deletions android/packaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ func runPackagingTest(t *testing.T, multitarget bool, bp string, expected []stri
moduleFactory = packageTestModuleFactory
}

result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
PrepareForTestWithArchMutator,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("component", componentTestModuleFactory)
ctx.RegisterModuleType("package_module", moduleFactory)
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)

p := result.Module("package", archVariant).(*packageTestModule)
actual := p.entries
Expand Down
4 changes: 2 additions & 2 deletions android/path_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ func TestPathDepsMutator(t *testing.T) {
}
`

result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
PrepareForTestWithArchMutator,
PrepareForTestWithFilegroup,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("test", pathDepsMutatorTestModuleFactory)
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)

m := result.Module("foo", "android_arm64_armv8-a").(*pathDepsMutatorTestModule)

Expand Down
Loading

0 comments on commit 30ac3e7

Please sign in to comment.