Skip to content

Commit 773b2c2

Browse files
test(protos): update test to use helper macro.
1 parent 78f824f commit 773b2c2

File tree

2 files changed

+14
-40
lines changed

2 files changed

+14
-40
lines changed

language/proto/BUILD.bazel

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
22
load("//language/proto/gen:def.bzl", "known_imports")
3-
3+
load("//internal/generationtest:generation_test.bzl", "gazelle_generation_test")
44
# gazelle:exclude testdata*
55

66
known_imports(
@@ -88,7 +88,6 @@ go_test(
8888
"//testtools",
8989
"//walk",
9090
"@com_github_bazelbuild_buildtools//build:go_default_library",
91-
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
9291
],
9392
)
9493

@@ -126,3 +125,16 @@ alias(
126125
actual = ":proto",
127126
visibility = ["//visibility:public"],
128127
)
128+
129+
filegroup(
130+
name = "generation_test_data",
131+
srcs = glob([
132+
"testdata_full_gen_test/**",
133+
]),
134+
)
135+
136+
gazelle_generation_test(
137+
name = "generation_test",
138+
gazelle_binary = "//:gazelle_local",
139+
test_data = ":generation_test_data",
140+
)

language/proto/generate_test.go

-38
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/bazelbuild/bazel-gazelle/rule"
3232
"github.com/bazelbuild/bazel-gazelle/testtools"
3333
"github.com/bazelbuild/bazel-gazelle/walk"
34-
"github.com/bazelbuild/rules_go/go/tools/bazel"
3534

3635
bzl "github.com/bazelbuild/buildtools/build"
3736
)
@@ -361,40 +360,3 @@ func testConfig(t *testing.T, repoRoot string) (*config.Config, language.Languag
361360
cexts = append(cexts, lang)
362361
return c, lang, cexts
363362
}
364-
365-
// TestFullGeneration runs the gazelle binary on a few example
366-
// workspaces and confirms that the generated BUILD files match expectation.
367-
func TestFullGeneration(t *testing.T) {
368-
tests := map[string][]bazel.RunfileEntry{}
369-
runfiles, err := bazel.ListRunfiles()
370-
if err != nil {
371-
t.Fatalf("bazel.ListRunfiles() error: %v", err)
372-
}
373-
testDataDirectory := "testdata_full_gen_test"
374-
testDataPath := filepath.Join("language", "proto", testDataDirectory, "")
375-
for _, f := range runfiles {
376-
if strings.HasPrefix(f.ShortPath, testDataPath) {
377-
relativePath := strings.TrimPrefix(f.ShortPath, testDataPath)
378-
parts := strings.SplitN(relativePath, "/", 3)
379-
if len(parts) < 3 {
380-
// This file is not a part of a testcase since it must be in a dir that
381-
// is the test case and then have a path inside of that.
382-
continue
383-
}
384-
385-
tests[parts[1]] = append(tests[parts[1]], f)
386-
}
387-
}
388-
if len(tests) == 0 {
389-
t.Fatal("no tests found")
390-
}
391-
392-
testArgs := testtools.NewTestGazelleGenerationArgs()
393-
for testName, files := range tests {
394-
testArgs.Name = testName
395-
testArgs.TestDataPath = testDataPath
396-
testArgs.GazelleBinaryDir = ""
397-
testArgs.GazelleBinaryName = "gazelle_local"
398-
testtools.TestGazelleGenerationOnPath(t, testArgs, files)
399-
}
400-
}

0 commit comments

Comments
 (0)