...
1
15
16 package generationtest
17
18 import (
19 "flag"
20 "path/filepath"
21 "testing"
22 "time"
23
24 "github.com/bazelbuild/bazel-gazelle/testtools"
25 "github.com/bazelbuild/rules_go/go/tools/bazel"
26 )
27
28 var (
29 gazelleBinaryPath = flag.String("gazelle_binary_path", "", "Path to the gazelle binary to test.")
30 buildInSuffix = flag.String("build_in_suffix", ".in", "The suffix on the test input BUILD.bazel files. Defaults to .in. "+
31 " By default, will use files named BUILD.in as the BUILD files before running gazelle.")
32 buildOutSuffix = flag.String("build_out_suffix", ".out", "The suffix on the expected BUILD.bazel files after running gazelle. Defaults to .out. "+
33 " By default, will use files named BUILD.out as the expected results of the gazelle run.")
34 timeout = flag.Duration("timeout", 2*time.Second, "Time to allow the gazelle process to run before killing.")
35 )
36
37
38
39 func TestFullGeneration(t *testing.T) {
40 tests := []*testtools.TestGazelleGenerationArgs{}
41 runfiles, err := bazel.ListRunfiles()
42 if err != nil {
43 t.Fatalf("bazel.ListRunfiles() error: %v", err)
44 }
45
46
47 absoluteGazelleBinary, err := bazel.Runfile(*gazelleBinaryPath)
48 if err != nil {
49 t.Fatalf("Could not convert gazelle binary path %s to absolute path. Error: %v", *gazelleBinaryPath, err)
50 }
51 for _, f := range runfiles {
52
53 if filepath.Base(f.Path) == "WORKSPACE" {
54
55
56 absolutePathToTestDirectory := filepath.Dir(f.Path)
57
58
59 relativePathToTestDirectory := filepath.Dir(f.ShortPath)
60
61
62 name := filepath.Base(absolutePathToTestDirectory)
63
64 tests = append(tests, &testtools.TestGazelleGenerationArgs{
65 Name: name,
66 TestDataPathAbsolute: absolutePathToTestDirectory,
67 TestDataPathRelative: relativePathToTestDirectory,
68 GazelleBinaryPath: absoluteGazelleBinary,
69 BuildInSuffix: *buildInSuffix,
70 BuildOutSuffix: *buildOutSuffix,
71 Timeout: *timeout,
72 })
73 }
74 }
75 if len(tests) == 0 {
76 t.Fatal("no tests found")
77 }
78
79 for _, args := range tests {
80 testtools.TestGazelleGenerationOnPath(t, args)
81 }
82 }
83
View as plain text