diff options
-rw-r--r-- | android/testing.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/android/testing.go b/android/testing.go index e79562da..3d5e9d93 100644 --- a/android/testing.go +++ b/android/testing.go @@ -16,6 +16,7 @@ package android import ( "fmt" + "path/filepath" "strings" "github.com/google/blueprint" @@ -78,6 +79,25 @@ func (ctx *TestContext) ModuleForTests(name, variant string) TestingModule { return TestingModule{module} } +// MockFileSystem causes the Context to replace all reads with accesses to the provided map of +// filenames to contents stored as a byte slice. +func (ctx *TestContext) MockFileSystem(files map[string][]byte) { + // no module list file specified; find every file named Blueprints or Android.bp + pathsToParse := []string{} + for candidate := range files { + base := filepath.Base(candidate) + if base == "Blueprints" || base == "Android.bp" { + pathsToParse = append(pathsToParse, candidate) + } + } + if len(pathsToParse) < 1 { + panic(fmt.Sprintf("No Blueprint or Android.bp files found in mock filesystem: %v\n", files)) + } + files[blueprint.MockModuleListFile] = []byte(strings.Join(pathsToParse, "\n")) + + ctx.Context.MockFileSystem(files) +} + type TestingModule struct { module Module } |