aboutsummaryrefslogtreecommitdiffstats
path: root/context_test.go
diff options
context:
space:
mode:
authorjgennis <jgennis@gmail.com>2015-10-10 00:53:42 -0700
committerjgennis <jgennis@gmail.com>2015-10-10 00:53:42 -0700
commit45021dcbbdf762b57878704adc1443e96169ea2e (patch)
tree6f476cf8bcc5c817c19d685dd401f255835fa6d5 /context_test.go
parente12c78095755517799fe022b70fdf93d6896dcab (diff)
parentf995846a4b19fa37f7e572788f1a64dd6a82061c (diff)
downloadandroid_build_blueprint-45021dcbbdf762b57878704adc1443e96169ea2e.tar.gz
android_build_blueprint-45021dcbbdf762b57878704adc1443e96169ea2e.tar.bz2
android_build_blueprint-45021dcbbdf762b57878704adc1443e96169ea2e.zip
Merge pull request #61 from yuchenericwu2/master
Add walkDeps to context and module_ctx.
Diffstat (limited to 'context_test.go')
-rw-r--r--context_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/context_test.go b/context_test.go
index 1c4303b..8877be9 100644
--- a/context_test.go
+++ b/context_test.go
@@ -19,6 +19,10 @@ import (
"testing"
)
+type Walker interface {
+ Walk() bool
+}
+
type fooModule struct {
properties struct {
Foo string
@@ -37,6 +41,10 @@ func (f *fooModule) Foo() string {
return f.properties.Foo
}
+func (f *fooModule) Walk() bool {
+ return true
+}
+
type barModule struct {
properties struct {
Bar bool
@@ -55,6 +63,10 @@ func (b *barModule) Bar() bool {
return b.properties.Bar
}
+func (b *barModule) Walk() bool {
+ return false
+}
+
func TestContextParse(t *testing.T) {
ctx := NewContext()
ctx.RegisterModuleType("foo_module", newFooModule)
@@ -99,3 +111,30 @@ func TestContextParse(t *testing.T) {
}
}
+
+// |---B===D - represents a non-walkable edge
+// A = represents a walkable edge
+// |===C---E===G
+// | | A should not be visited because it's the root node.
+// |===F===| B, D and E should not be walked.
+func TestWalkDeps(t *testing.T) {
+ ctx := NewContext()
+ ctx.RegisterModuleType("foo_module", newFooModule)
+ ctx.RegisterModuleType("bar_module", newBarModule)
+ ctx.ParseBlueprintsFiles("context_test_Blueprints")
+ ctx.ResolveDependencies(nil)
+
+ var output string
+ topModule := ctx.moduleGroups["A"].modules[0]
+ ctx.walkDeps(topModule,
+ func(module, parent Module) bool {
+ if module.(Walker).Walk() {
+ output += ctx.ModuleName(module)
+ return true
+ }
+ return false
+ })
+ if output != "CFG" {
+ t.Fatalf("unexpected walkDeps behaviour: %s\nshould be: CFG", output)
+ }
+}