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
This commit is contained in:
@@ -111,6 +111,8 @@ type Module interface {
|
||||
|
||||
AddProperties(props ...interface{})
|
||||
GetProperties() []interface{}
|
||||
|
||||
BuildParamsForTests() []ModuleBuildParams
|
||||
}
|
||||
|
||||
type nameProperties struct {
|
||||
@@ -291,6 +293,9 @@ type ModuleBase struct {
|
||||
hooks hooks
|
||||
|
||||
registerProps []interface{}
|
||||
|
||||
// For tests
|
||||
buildParams []ModuleBuildParams
|
||||
}
|
||||
|
||||
func (a *ModuleBase) AddProperties(props ...interface{}) {
|
||||
@@ -301,6 +306,10 @@ func (a *ModuleBase) GetProperties() []interface{} {
|
||||
return a.registerProps
|
||||
}
|
||||
|
||||
func (a *ModuleBase) BuildParamsForTests() []ModuleBuildParams {
|
||||
return a.buildParams
|
||||
}
|
||||
|
||||
// Name returns the name of the module. It may be overridden by individual module types, for
|
||||
// example prebuilts will prepend prebuilt_ to the name.
|
||||
func (a *ModuleBase) Name() string {
|
||||
@@ -520,6 +529,8 @@ func (a *ModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
a.buildParams = androidCtx.buildParams
|
||||
}
|
||||
|
||||
type androidBaseContextImpl struct {
|
||||
@@ -538,6 +549,9 @@ type androidModuleContext struct {
|
||||
checkbuildFiles Paths
|
||||
missingDeps []string
|
||||
module Module
|
||||
|
||||
// For tests
|
||||
buildParams []ModuleBuildParams
|
||||
}
|
||||
|
||||
func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) {
|
||||
@@ -566,6 +580,10 @@ func (a *androidModuleContext) Build(pctx blueprint.PackageContext, params bluep
|
||||
}
|
||||
|
||||
func (a *androidModuleContext) ModuleBuild(pctx blueprint.PackageContext, params ModuleBuildParams) {
|
||||
if a.config.captureBuild {
|
||||
a.buildParams = append(a.buildParams, params)
|
||||
}
|
||||
|
||||
bparams := blueprint.BuildParams{
|
||||
Rule: params.Rule,
|
||||
Deps: params.Deps,
|
||||
|
Reference in New Issue
Block a user