Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed Apr 19, 2022
1 parent f811aa0 commit 381a257
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/core/go_binary/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ load(":many_deps.bzl", "many_deps")

test_suite(name = "go_binary")

go_bazel_test(
name = "configurable_attribute_test",
srcs = ["configurable_attribute_test.go"],
)

go_binary(
name = "hello",
srcs = ["hello.go"],
Expand Down
60 changes: 60 additions & 0 deletions tests/core/go_binary/configurable_attribute_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2022 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package configurable_attribute_test

import (
"strings"
"testing"

"github.com/bazelbuild/rules_go/go/tools/bazel_testing"
)

func TestMain(m *testing.M) {
bazel_testing.TestMain(m, bazel_testing.Args{
Main: `
-- BUILD.bazel --
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
go_binary(
name = "main",
srcs = ["main.go"],
goos = select({
"//conditions:default": "darwin",
}),
goarch = "amd64",
)
-- main.go --
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
`,
})
}

func TestConfigurableGOOSAttribute(t *testing.T) {
outBytes, err := bazel_testing.BazelOutput("run", "--run_under=file", "//:main")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
out := string(outBytes)
if !strings.Contains(out, "Mach-O 64-bit") {
t.Fatalf("Wanted darwin executable but got: %s", out)
}
}

0 comments on commit 381a257

Please sign in to comment.