blob: 3d8f6ee526cc41d30f5b2d734bbb95950bbe7af8 [file] [log] [blame]
Colin Cross8e0c5112015-01-23 14:15:10 -08001// Copyright 2014 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Jamie Gennis1bc967e2014-05-27 16:34:41 -070015package blueprint
16
17import (
18 "bytes"
19 "testing"
20)
21
22type fooModule struct {
23 properties struct {
24 Foo string
25 }
26}
27
Jamie Gennis68540da2014-10-06 09:10:40 -070028func newFooModule() (Module, []interface{}) {
Jamie Gennis1bc967e2014-05-27 16:34:41 -070029 m := &fooModule{}
Jamie Gennis68540da2014-10-06 09:10:40 -070030 return m, []interface{}{&m.properties}
Jamie Gennis1bc967e2014-05-27 16:34:41 -070031}
32
33func (f *fooModule) GenerateBuildActions(ModuleContext) {
34}
35
36func (f *fooModule) Foo() string {
37 return f.properties.Foo
38}
39
40type barModule struct {
41 properties struct {
42 Bar bool
43 }
44}
45
Jamie Gennis68540da2014-10-06 09:10:40 -070046func newBarModule() (Module, []interface{}) {
Jamie Gennis1bc967e2014-05-27 16:34:41 -070047 m := &barModule{}
Jamie Gennis68540da2014-10-06 09:10:40 -070048 return m, []interface{}{&m.properties}
Jamie Gennis1bc967e2014-05-27 16:34:41 -070049}
50
51func (b *barModule) GenerateBuildActions(ModuleContext) {
52}
53
54func (b *barModule) Bar() bool {
55 return b.properties.Bar
56}
57
58func TestContextParse(t *testing.T) {
59 ctx := NewContext()
Jamie Gennis68540da2014-10-06 09:10:40 -070060 ctx.RegisterModuleType("foo_module", newFooModule)
61 ctx.RegisterModuleType("bar_module", newBarModule)
Jamie Gennis1bc967e2014-05-27 16:34:41 -070062
63 r := bytes.NewBufferString(`
64 foo_module {
65 name: "MyFooModule",
66 deps: ["MyBarModule"],
67 }
68
69 bar_module {
70 name: "MyBarModule",
71 }
72 `)
73
Colin Cross7ad621c2015-01-07 16:22:45 -080074 _, _, errs, _ := ctx.parse(".", "Blueprint", r, nil)
Jamie Gennis1bc967e2014-05-27 16:34:41 -070075 if len(errs) > 0 {
76 t.Errorf("unexpected parse errors:")
77 for _, err := range errs {
78 t.Errorf(" %s", err)
79 }
80 t.FailNow()
81 }
82
Jamie Gennis68540da2014-10-06 09:10:40 -070083 errs = ctx.resolveDependencies(nil)
Jamie Gennis1bc967e2014-05-27 16:34:41 -070084 if len(errs) > 0 {
85 t.Errorf("unexpected dep errors:")
86 for _, err := range errs {
87 t.Errorf(" %s", err)
88 }
89 t.FailNow()
90 }
91
Colin Cross691a60d2015-01-07 18:08:56 -080092 errs = ctx.updateDependencies()
Jamie Gennis1bc967e2014-05-27 16:34:41 -070093 if len(errs) > 0 {
94 t.Errorf("unexpected dep cycle errors:")
95 for _, err := range errs {
96 t.Errorf(" %s", err)
97 }
98 t.FailNow()
99 }
100
101}