diff options
author | 2021-02-24 01:49:52 +0000 | |
---|---|---|
committer | 2021-02-26 23:01:50 +0000 | |
commit | 358161232cc80d6bd9daf6b0c9fb042d04f41502 (patch) | |
tree | eb5a0a250245f4486aec814cce285a39a30a7266 /android/prebuilt_test.go | |
parent | 30e3e9d21d3898bc1e97917b4a0428fb696d0804 (diff) |
Add test fixture support
Adds the test fixture support and converts a few tests to exercise the
code and show how it works.
Bug: 181070625
Test: m nothing
Change-Id: I0a2b40fff93b6041f9aa8c4ef0aba91da1bc8bf3
Diffstat (limited to 'android/prebuilt_test.go')
-rw-r--r-- | android/prebuilt_test.go | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go index 9ac38750c..164b1bc59 100644 --- a/android/prebuilt_test.go +++ b/android/prebuilt_test.go @@ -262,7 +262,7 @@ var prebuiltsTests = []struct { } func TestPrebuilts(t *testing.T) { - fs := map[string][]byte{ + fs := MockFS{ "prebuilt_file": nil, "source_file": nil, } @@ -277,32 +277,33 @@ func TestPrebuilts(t *testing.T) { deps: [":bar"], }` } - config := TestArchConfig(buildDir, nil, bp, fs) // Add windows to the target list to test the logic when a variant is // disabled by default. if !Windows.DefaultDisabled { t.Errorf("windows is assumed to be disabled by default") } - config.config.Targets[Windows] = []Target{ - {Windows, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", true}, - } - - ctx := NewTestArchContext(config) - registerTestPrebuiltBuildComponents(ctx) - ctx.RegisterModuleType("filegroup", FileGroupFactory) - ctx.Register() - _, errs := ctx.ParseBlueprintsFiles("Android.bp") - FailIfErrored(t, errs) - _, errs = ctx.PrepareBuildActions(config) - FailIfErrored(t, errs) + result := emptyTestFixtureFactory.Extend( + PrepareForTestWithArchMutator, + PrepareForTestWithPrebuilts, + PrepareForTestWithOverrides, + PrepareForTestWithFilegroup, + // Add a Windows target to the configuration. + FixtureModifyConfig(func(config Config) { + config.Targets[Windows] = []Target{ + {Windows, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", true}, + } + }), + fs.AddToFixture(), + FixtureRegisterWithContext(registerTestPrebuiltModules), + ).RunTestWithBp(t, bp) - for _, variant := range ctx.ModuleVariantsForTests("foo") { - foo := ctx.ModuleForTests("foo", variant) + for _, variant := range result.ModuleVariantsForTests("foo") { + foo := result.ModuleForTests("foo", variant) t.Run(foo.Module().Target().Os.String(), func(t *testing.T) { var dependsOnSourceModule, dependsOnPrebuiltModule bool - ctx.VisitDirectDeps(foo.Module(), func(m blueprint.Module) { + result.VisitDirectDeps(foo.Module(), func(m blueprint.Module) { if _, ok := m.(*sourceModule); ok { dependsOnSourceModule = true } @@ -381,14 +382,18 @@ func TestPrebuilts(t *testing.T) { } func registerTestPrebuiltBuildComponents(ctx RegistrationContext) { - ctx.RegisterModuleType("prebuilt", newPrebuiltModule) - ctx.RegisterModuleType("source", newSourceModule) - ctx.RegisterModuleType("override_source", newOverrideSourceModule) + registerTestPrebuiltModules(ctx) RegisterPrebuiltMutators(ctx) ctx.PostDepsMutators(RegisterOverridePostDepsMutators) } +func registerTestPrebuiltModules(ctx RegistrationContext) { + ctx.RegisterModuleType("prebuilt", newPrebuiltModule) + ctx.RegisterModuleType("source", newSourceModule) + ctx.RegisterModuleType("override_source", newOverrideSourceModule) +} + type prebuiltModule struct { ModuleBase prebuilt Prebuilt |