Remove uses of FixtureFactory from android package

Bug: 183235980
Test: m nothing
Change-Id: I72898ada020ee1a73fd534c61afb5c22fa00c1e5
This commit is contained in:
Paul Duffin 2021-03-20 00:36:14 +00:00
parent ff2aa69a86
commit 30ac3e7ca7
24 changed files with 108 additions and 117 deletions

View file

@ -22,5 +22,3 @@ import (
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
var emptyTestFixtureFactory = NewFixtureFactory(nil)

View file

@ -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

View file

@ -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) {
@ -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),
@ -455,7 +455,7 @@ func TestArchMutatorNativeBridge(t *testing.T) {
}
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)
ctx := result.TestContext

View file

@ -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 {

View file

@ -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)
@ -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")

View file

@ -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

View file

@ -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)
})
}

View file

@ -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,
@ -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)
}),

View file

@ -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)

View file

@ -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) {
@ -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)
}

View file

@ -65,7 +65,7 @@ func TestMutatorAddMissingDependencies(t *testing.T) {
}
`
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
PrepareForTestWithAllowMissingDependencies,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
@ -74,7 +74,7 @@ func TestMutatorAddMissingDependencies(t *testing.T) {
})
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)
foo := result.ModuleForTests("foo", "").Module().(*mutatorTestModule)
@ -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) {
@ -128,7 +128,7 @@ func TestModuleString(t *testing.T) {
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)
want := []string{
// Initial name.
@ -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
@ -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,
@ -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) {
@ -265,5 +265,5 @@ func TestNoCreateVariationsInFinalDeps(t *testing.T) {
ctx.RegisterModuleType("test", mutatorTestModuleFactory)
}),
FixtureWithRootAndroidBp(`test {name: "foo"}`),
)
).RunTest(t)
}

View file

@ -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
}

View file

@ -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)
})
}
}

View file

@ -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) {

View file

@ -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)
})
}
}

View file

@ -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

View file

@ -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)

View file

@ -1005,14 +1005,14 @@ func testPathForModuleSrc(t *testing.T, tests []pathForModuleSrcTestCase) {
"foo/src_special/$": nil,
}
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
ctx.RegisterModuleType("output_file_provider", pathForModuleSrcOutputFileProviderModuleFactory)
ctx.RegisterModuleType("filegroup", FileGroupFactory)
}),
mockFS.AddToFixture(),
)
).RunTest(t)
m := result.ModuleForTests("foo", "").Module().(*pathForModuleSrcTestModule)
@ -1203,13 +1203,13 @@ func TestPathsForModuleSrc_AllowMissingDependencies(t *testing.T) {
}
`
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
PrepareForTestWithAllowMissingDependencies,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)
foo := result.ModuleForTests("foo", "").Module().(*pathForModuleSrcTestModule)

View file

@ -284,7 +284,7 @@ func TestPrebuilts(t *testing.T) {
t.Errorf("windows is assumed to be disabled by default")
}
result := emptyTestFixtureFactory.Extend(
result := GroupFixturePreparers(
PrepareForTestWithArchMutator,
PrepareForTestWithPrebuilts,
PrepareForTestWithOverrides,

View file

@ -542,11 +542,11 @@ func TestRuleBuilder_Build(t *testing.T) {
}
`
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
prepareForRuleBuilderTest,
FixtureWithRootAndroidBp(bp),
fs.AddToFixture(),
)
).RunTest(t)
check := func(t *testing.T, params TestingBuildParams, wantCommand, wantOutput, wantDepfile string, wantRestat bool, extraImplicits, extraCmdDeps []string) {
t.Helper()
@ -651,10 +651,10 @@ func TestRuleBuilderHashInputs(t *testing.T) {
},
}
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
prepareForRuleBuilderTest,
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)
for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {

View file

@ -56,11 +56,10 @@ func TestSingletonModule(t *testing.T) {
name: "test_singleton_module",
}
`
result := emptyTestFixtureFactory.
RunTest(t,
prepareForSingletonModuleTest,
FixtureWithRootAndroidBp(bp),
)
result := GroupFixturePreparers(
prepareForSingletonModuleTest,
FixtureWithRootAndroidBp(bp),
).RunTest(t)
ops := result.ModuleForTests("test_singleton_module", "").Module().(*testSingletonModule).ops
wantOps := []string{"GenerateAndroidBuildActions", "GenerateSingletonBuildActions", "MakeVars"}
@ -78,19 +77,16 @@ func TestDuplicateSingletonModule(t *testing.T) {
}
`
emptyTestFixtureFactory.
prepareForSingletonModuleTest.
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern([]string{
`\QDuplicate SingletonModule "test_singleton_module", previously used in\E`,
})).RunTest(t,
prepareForSingletonModuleTest,
FixtureWithRootAndroidBp(bp),
)
})).RunTestWithBp(t, bp)
}
func TestUnusedSingletonModule(t *testing.T) {
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
prepareForSingletonModuleTest,
)
).RunTest(t)
singleton := result.SingletonForTests("test_singleton_module").Singleton()
sm := singleton.(*singletonModuleSingletonAdaptor).sm
@ -113,17 +109,16 @@ func TestVariantSingletonModule(t *testing.T) {
}
`
emptyTestFixtureFactory.
GroupFixturePreparers(
prepareForSingletonModuleTest,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
ctx.BottomUp("test_singleton_module_mutator", testVariantSingletonModuleMutator)
})
}),
).
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern([]string{
`\QGenerateAndroidBuildActions already called for variant\E`,
})).
RunTest(t,
prepareForSingletonModuleTest,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
ctx.BottomUp("test_singleton_module_mutator", testVariantSingletonModuleMutator)
})
}),
FixtureWithRootAndroidBp(bp),
)
RunTestWithBp(t, bp)
}

View file

@ -278,7 +278,7 @@ func TestSoongConfigModule(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
tc.preparer,
PrepareForTestWithDefaults,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
@ -291,7 +291,7 @@ func TestSoongConfigModule(t *testing.T) {
}),
fs.AddToFixture(),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)
foo := result.ModuleForTests("foo", "").Module().(*soongConfigTestModule)
AssertDeepEquals(t, "foo cflags", tc.fooExpectedFlags, foo.props.Cflags)

View file

@ -182,7 +182,7 @@ func TestProductVariables(t *testing.T) {
}
`
emptyTestFixtureFactory.RunTest(t,
GroupFixturePreparers(
FixtureModifyProductVariables(func(variables FixtureProductVariables) {
variables.Eng = proptools.BoolPtr(true)
}),
@ -204,7 +204,7 @@ func TestProductVariables(t *testing.T) {
})
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)
}
var testProductVariableDefaultsProperties = struct {
@ -288,7 +288,7 @@ func TestProductVariablesDefaults(t *testing.T) {
}
`
result := emptyTestFixtureFactory.RunTest(t,
result := GroupFixturePreparers(
FixtureModifyProductVariables(func(variables FixtureProductVariables) {
variables.Eng = boolPtr(true)
}),
@ -299,7 +299,7 @@ func TestProductVariablesDefaults(t *testing.T) {
ctx.RegisterModuleType("defaults", productVariablesDefaultsTestDefaultsFactory)
}),
FixtureWithRootAndroidBp(bp),
)
).RunTest(t)
foo := result.ModuleForTests("foo", "").Module().(*productVariablesDefaultsTestModule)

View file

@ -1142,7 +1142,7 @@ var visibilityTests = []struct {
func TestVisibility(t *testing.T) {
for _, test := range visibilityTests {
t.Run(test.name, func(t *testing.T) {
result := emptyTestFixtureFactory.Extend(
result := GroupFixturePreparers(
// General preparers in alphabetical order as test infrastructure will enforce correct
// registration order.
PrepareForTestWithArchMutator,