Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jayconrod authored and fmeum committed Jan 2, 2024
1 parent 160ef8d commit 15ff159
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions tests/integration/gopackagesdriver/gopackagesdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ go_library(
)
go_test(
name = "hello_test",
srcs = [
"hello_test.go",
"hello_external_test.go",
],
embed = [":hello"],
name = "hello_test",
srcs = [
"hello_test.go",
"hello_external_test.go",
],
embed = [":hello"],
)
go_library(
name = "incompatible",
srcs = ["incompatible.go"],
importpath = "example.com/incompatible",
target_compatible_with = ["@platforms//:incompatible"],
)
-- hello.go --
Expand All @@ -59,7 +66,11 @@ package hello_test
import "testing"
func TestHelloExternal(t *testing.T) {}
`,
-- incompatible.go --
//go:build ignore
package hello
`,
})
}

Expand Down Expand Up @@ -186,6 +197,35 @@ func TestExternalTests(t *testing.T) {
}
}

// TestIncompatible checks that a target that can be queried but not analyzed
// does not appear in .Roots.
func TestIncompatible(t *testing.T) {
reader := strings.NewReader("{}")
out, _, err := bazel_testing.BazelOutputWithInput(reader, "run", "@io_bazel_rules_go//go/tools/gopackagesdriver", "--", "./...")
if err != nil {
t.Fatalf("error running bazel: %v", err)
}
var resp response
if err := json.Unmarshal(out, &resp); err != nil {
t.Fatalf("unmarshaling response: %v", err)
}

helloLabel := "@@//:hello"
incompatibleLabel := "@@//:incompatible"
var foundHello bool
for _, root := range resp.Roots {
if root == helloLabel {
foundHello = true
}
if root == incompatibleLabel {
t.Errorf("response contains root %s", incompatibleLabel)
}
}
if !foundHello {
t.Errorf("response does not contain root %s; roots were %s", helloLabel, strings.Join(resp.Roots, ", "))
}
}

func assertSuffixesInList(t *testing.T, list []string, expectedSuffixes ...string) {
for _, suffix := range expectedSuffixes {
itemFound := false
Expand Down

0 comments on commit 15ff159

Please sign in to comment.