From cec8171420763a7a33f210be7bd45e22d3b38831 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 13 Jul 2017 14:43:27 -0700 Subject: Add integration testing infrastructure Fix mutator registration for tests to allow different tests in the same package to register different mutators. Allow tests to track the resulting ModuleBuildParams objects to use in assertions, and provide helpers for getting them. For example: config := android.TestConfig(buildDir) ctx := android.NewTestContext() ctx.RegisterModuleType(...) ctx.MockFileSystem(...) ctx.ParseBlueprintsFile("Android.bp") ctx.PrepareBuildActions(config) ctx.Register() // Get the Inputs value passed to the javac rule for the foo module inputs := ctx.ModuleForTests("foo".Rule("javac").Inputs Test: java_test.go Change-Id: I10c82967f5f3586d2c176f169906b571ed82fc73 --- python/python_test.go | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'python/python_test.go') diff --git a/python/python_test.go b/python/python_test.go index 57aaa344d..4c30d95be 100644 --- a/python/python_test.go +++ b/python/python_test.go @@ -26,8 +26,6 @@ import ( "testing" "android/soong/android" - - "github.com/google/blueprint" ) type pyBinary struct { @@ -306,17 +304,17 @@ var ( func TestPythonModule(t *testing.T) { config, buildDir := setupBuildEnv(t) defer tearDownBuildEnv(buildDir) - android.TestPreDepsMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("version_split", versionSplitMutator()).Parallel() - }) for _, d := range data { t.Run(d.desc, func(t *testing.T) { - ctx := blueprint.NewContext() - android.RegisterTestMutators(ctx) + ctx := android.NewTestContext() + ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { + ctx.BottomUp("version_split", versionSplitMutator()).Parallel() + }) ctx.RegisterModuleType("python_library_host", android.ModuleFactoryAdaptor(PythonLibraryHostFactory)) ctx.RegisterModuleType("python_binary_host", android.ModuleFactoryAdaptor(PythonBinaryHostFactory)) + ctx.Register() ctx.MockFileSystem(d.mockFiles) _, testErrs := ctx.ParseBlueprintsFiles(bpFile) fail(t, testErrs) @@ -360,15 +358,12 @@ func expectErrors(t *testing.T, actErrs []error, expErrs []string) (testErrs []e return } -func expectModule(t *testing.T, ctx *blueprint.Context, buildDir, name, variant string, +func expectModule(t *testing.T, ctx *android.TestContext, buildDir, name, variant string, expPyRunfiles, expDepsPyRunfiles []string, expParSpec string, expDepsParSpecs []string) (testErrs []error) { - module := findModule(ctx, name, variant) - if module == nil { - t.Fatalf("failed to find module %s!", name) - } + module := ctx.ModuleForTests(name, variant) - base, baseOk := module.(*pythonBaseModule) + base, baseOk := module.Module().(*pythonBaseModule) if !baseOk { t.Fatalf("%s is not Python module!", name) } @@ -438,16 +433,6 @@ func tearDownBuildEnv(buildDir string) { os.RemoveAll(buildDir) } -func findModule(ctx *blueprint.Context, name, variant string) blueprint.Module { - var ret blueprint.Module - ctx.VisitAllModules(func(m blueprint.Module) { - if ctx.ModuleName(m) == name && ctx.ModuleSubDir(m) == variant { - ret = m - } - }) - return ret -} - func fail(t *testing.T, errs []error) { if len(errs) > 0 { for _, err := range errs { -- cgit v1.2.3-59-g8ed1b