Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort the args in loadExpr's output #259

Merged
merged 1 commit into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion go/tools/gazelle/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"go/build"
"path/filepath"
"sort"
"strings"

bzl "github.com/bazelbuild/buildifier/build"
Expand Down Expand Up @@ -179,7 +180,9 @@ func (g *Generator) generateLoad(f *bzl.File) bzl.Expr {
return loadExpr(list...)
}

func loadExpr(rules ...string) bzl.Expr {
func loadExpr(rules ...string) *bzl.CallExpr {
sort.Strings(rules)

list := []bzl.Expr{
&bzl.StringExpr{Value: GoRulesBzl},
}
Expand Down
16 changes: 16 additions & 0 deletions go/tools/gazelle/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ func TestGeneratorDotBazel(t *testing.T) {
testGenerator(t, "BUILD.bazel")
}

func TestLoadExprSorted(t *testing.T) {
out := loadExpr("go_library", "another_thing", "sorted_last")
expected := []string{"@io_bazel_rules_go//go:def.bzl", "another_thing", "go_library", "sorted_last"}
var actual []string
for _, item := range out.List {
it, ok := item.(*bzl.StringExpr)
if !ok {
t.Fatalf("loadExpr List: got %T, want *bzl.StringExpr", item)
}
actual = append(actual, it.Value)
}
if !reflect.DeepEqual(actual, expected) {
t.Errorf("loadExpr List strings: want %#v, got %#v", expected, actual)
}
}

func testGenerator(t *testing.T, buildFileName string) {
stub := stubRuleGen{
goFiles: make(map[string][]string),
Expand Down