Skip to content

Commit

Permalink
Enable File.Rules() to find targets nested in comprehensions. (bazelb…
Browse files Browse the repository at this point in the history
  • Loading branch information
katre authored and pmbethe09 committed May 31, 2018
1 parent 588d900 commit 82b2160
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
20 changes: 11 additions & 9 deletions build/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ func (f *File) Rules(kind string) []*Rule {
var all []*Rule

for _, stmt := range f.Stmt {
call, ok := stmt.(*CallExpr)
if !ok {
continue
}
rule := f.Rule(call)
if kind != "" && rule.Kind() != kind {
continue
}
all = append(all, rule)
Walk(stmt, func(x Expr, stk []Expr) {
call, ok := x.(*CallExpr)
if !ok {
return
}
rule := f.Rule(call)
if kind != "" && rule.Kind() != kind {
return
}
all = append(all, rule)
});
}

return all
Expand Down
18 changes: 18 additions & 0 deletions build/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ func TestRules(t *testing.T) {
compare(t, f.Rules("foo.bar.baz"), []*Rule{structRule})
}

func TestRulesNested(t *testing.T) {
f := &File{
Stmt: []Expr{
&ListExpr{
List: []Expr{
simpleCall,
structCall,
},
},
},
}

compare(t, f.Rules(""), []*Rule{simpleRule, structRule})
compare(t, f.Rules("java_binary"), []*Rule(nil))
compare(t, f.Rules("java_library"), []*Rule{simpleRule})
compare(t, f.Rules("foo.bar.baz"), []*Rule{structRule})
}

func TestImplicitName(t *testing.T) {
tests := []struct {
path string
Expand Down

0 comments on commit 82b2160

Please sign in to comment.