From 5f9f15be072872cd57b4d5d305865ce8c592ee9d Mon Sep 17 00:00:00 2001 From: "Artem V. Navrotskiy" Date: Fri, 29 Apr 2022 10:55:53 +0300 Subject: [PATCH] Add lost `x_defs` on test execution regression test --- tests/core/go_test/x_defs/BUILD.bazel | 50 +++++++++++++++++++++++++++ tests/core/go_test/x_defs/bar.go | 10 ++++++ tests/core/go_test/x_defs/baz.go | 6 ++++ tests/core/go_test/x_defs/foo.go | 1 + tests/core/go_test/x_defs/foo_test.go | 28 +++++++++++++++ tests/core/go_test/x_defs/qux.go | 3 ++ tests/core/go_test_x_defs/BUILD.bazel | 48 +++++++++++++++++++++++++ 7 files changed, 146 insertions(+) create mode 100644 tests/core/go_test/x_defs/BUILD.bazel create mode 100644 tests/core/go_test/x_defs/bar.go create mode 100644 tests/core/go_test/x_defs/baz.go create mode 100644 tests/core/go_test/x_defs/foo.go create mode 100644 tests/core/go_test/x_defs/foo_test.go create mode 100644 tests/core/go_test/x_defs/qux.go create mode 100644 tests/core/go_test_x_defs/BUILD.bazel diff --git a/tests/core/go_test/x_defs/BUILD.bazel b/tests/core/go_test/x_defs/BUILD.bazel new file mode 100644 index 0000000000..279e4a6ca7 --- /dev/null +++ b/tests/core/go_test/x_defs/BUILD.bazel @@ -0,0 +1,50 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +test_suite( + name = "x_defs", +) + +go_test( + name = "foo_test", + srcs = ["foo_test.go"], + embed = [":foo"], + importpath = "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/foo", + pure = "on", + deps = [":bar"], +) + +go_library( + name = "bar", + srcs = ["bar.go"], + importpath = "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/bar", + visibility = ["//visibility:public"], + x_defs = {"Bar": "Bar"}, + deps = [ + ":baz", + ":foo", + ], +) + +go_library( + name = "baz", + srcs = ["baz.go"], + importpath = "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/baz", + visibility = ["//visibility:public"], + x_defs = {"Baz": "Baz"}, + deps = [":qux"], +) + +go_library( + name = "foo", + srcs = ["foo.go"], + importpath = "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/foo", + visibility = ["//visibility:public"], +) + +go_library( + name = "qux", + srcs = ["qux.go"], + importpath = "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/qux", + visibility = ["//visibility:public"], + x_defs = {"Qux": "Qux"}, +) diff --git a/tests/core/go_test/x_defs/bar.go b/tests/core/go_test/x_defs/bar.go new file mode 100644 index 0000000000..1d0081a4c7 --- /dev/null +++ b/tests/core/go_test/x_defs/bar.go @@ -0,0 +1,10 @@ +package bar + +import ( + "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/baz" + _ "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/foo" +) + +var Bar string +var Qux = baz.Qux +var Baz = baz.Baz diff --git a/tests/core/go_test/x_defs/baz.go b/tests/core/go_test/x_defs/baz.go new file mode 100644 index 0000000000..9d4334f7d4 --- /dev/null +++ b/tests/core/go_test/x_defs/baz.go @@ -0,0 +1,6 @@ +package baz + +import "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/qux" + +var Baz string +var Qux = qux.Qux diff --git a/tests/core/go_test/x_defs/foo.go b/tests/core/go_test/x_defs/foo.go new file mode 100644 index 0000000000..f52652b1ba --- /dev/null +++ b/tests/core/go_test/x_defs/foo.go @@ -0,0 +1 @@ +package foo diff --git a/tests/core/go_test/x_defs/foo_test.go b/tests/core/go_test/x_defs/foo_test.go new file mode 100644 index 0000000000..dc940509df --- /dev/null +++ b/tests/core/go_test/x_defs/foo_test.go @@ -0,0 +1,28 @@ +package foo_test + +import ( + "testing" + + "github.com/bazelbuild/rules_go/tests/core/go_test/x_defs/bar" +) + +func TestBar(t *testing.T) { + Equal(t, "Bar", bar.Bar) +} + +func TestBaz(t *testing.T) { + Equal(t, "Baz", bar.Baz) +} + +func TestQux(t *testing.T) { + Equal(t, "Qux", bar.Qux) +} + +func Equal(t *testing.T, expected string, actual string) bool { + if expected != actual { + t.Errorf("Not equal: \n"+ + "expected: %s\n"+ + "actual : %s", expected, actual) + } + return true +} diff --git a/tests/core/go_test/x_defs/qux.go b/tests/core/go_test/x_defs/qux.go new file mode 100644 index 0000000000..4983170cce --- /dev/null +++ b/tests/core/go_test/x_defs/qux.go @@ -0,0 +1,3 @@ +package qux + +var Qux string diff --git a/tests/core/go_test_x_defs/BUILD.bazel b/tests/core/go_test_x_defs/BUILD.bazel new file mode 100644 index 0000000000..709c5e28a6 --- /dev/null +++ b/tests/core/go_test_x_defs/BUILD.bazel @@ -0,0 +1,48 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "bar", + srcs = ["bar.go"], + importpath = "github.com/bozaro/rules_go_xdefs/bar", + visibility = ["//visibility:public"], + x_defs = {"Bar": "Bar"}, + deps = [ + "//baz", + "//foo", + ], +) + +go_library( + name = "baz", + srcs = ["baz.go"], + importpath = "github.com/bozaro/rules_go_xdefs/baz", + visibility = ["//visibility:public"], + x_defs = {"Baz": "Baz"}, + deps = ["//qux"], +) +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "foo", + srcs = ["foo.go"], + importpath = "github.com/bozaro/rules_go_xdefs/foo", + visibility = ["//visibility:public"], +) + +go_test( + name = "foo_test", + srcs = ["foo_test.go"], + embed = [":foo"], + importpath = "github.com/bozaro/rules_go_xdefs/foo", + pure = "on", + deps = ["//bar"], +) +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "qux", + srcs = ["qux.go"], + importpath = "github.com/bozaro/rules_go_xdefs/qux", + visibility = ["//visibility:public"], + x_defs = {"Qux": "Qux"}, +)