diff options
author | Colin Cross <ccross@android.com> | 2017-07-13 14:43:27 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2017-07-14 14:19:51 -0700 |
commit | cec8171420763a7a33f210be7bd45e22d3b38831 (patch) | |
tree | 090551693ef9bac520e6977cef72404d27153966 /python | |
parent | eb54da6ebe8b0baf285be7d107c4cf959c3c462e (diff) | |
download | build_soong-cec8171420763a7a33f210be7bd45e22d3b38831.tar.gz build_soong-cec8171420763a7a33f210be7bd45e22d3b38831.tar.bz2 build_soong-cec8171420763a7a33f210be7bd45e22d3b38831.zip |
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
Diffstat (limited to 'python')
-rw-r--r-- | python/python_test.go | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/python/python_test.go b/python/python_test.go index 57aaa344..4c30d95b 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 { |