...
1
15
16 package gazellebinarytest
17
18 import (
19 "os"
20 "os/exec"
21 "testing"
22
23 "github.com/bazelbuild/bazel-gazelle/testtools"
24 "github.com/bazelbuild/rules_go/go/tools/bazel"
25 )
26
27 func TestGazelleBinary(t *testing.T) {
28 gazellePath, ok := bazel.FindBinary("internal/gazellebinarytest", "gazelle_go_x")
29 if !ok {
30 t.Fatal("could not find gazelle binary")
31 }
32
33 files := []testtools.FileSpec{
34 {Path: "WORKSPACE"},
35 {Path: "BUILD.bazel", Content: "# gazelle:prefix example.com/test"},
36 {Path: "foo.go", Content: "package foo"},
37 {Path: "foo.proto", Content: `syntax = "proto3";`},
38 }
39 dir, cleanup := testtools.CreateFiles(t, files)
40 defer cleanup()
41
42 cmd := exec.Command(gazellePath)
43 cmd.Stdout = os.Stdout
44 cmd.Stderr = os.Stderr
45 cmd.Dir = dir
46 if err := cmd.Run(); err != nil {
47 t.Fatal(err)
48 }
49
50 testtools.CheckFiles(t, dir, []testtools.FileSpec{{
51 Path: "BUILD.bazel",
52 Content: `
53 load("@io_bazel_rules_go//go:def.bzl", "go_library")
54
55 # gazelle:prefix example.com/test
56
57 go_library(
58 name = "test",
59 srcs = ["foo.go"],
60 importpath = "example.com/test",
61 visibility = ["//visibility:public"],
62 )
63
64 x_library(name = "x_default_library")
65 `,
66 }})
67 }
68
View as plain text