Skip to content

Commit

Permalink
Don't hard code the build paths in the cross test (bazel-contrib#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthehat authored Jan 29, 2018
1 parent 535e17b commit 53f410c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
32 changes: 15 additions & 17 deletions tests/core/cross/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,25 @@ test_suite(
name = "cross",
)

go_source(
name = "cross_src",
srcs = ["main.go"],
)

go_binary(
name = "windows",
basename = "cross",
embed = [":cross_src"],
name = "windows_cross",
srcs = ["main.go"],
goarch = "amd64",
goos = "windows",
pure = "on",
)

go_binary(
name = "linux",
basename = "cross",
embed = [":cross_src"],
name = "linux_cross",
srcs = ["main.go"],
goarch = "amd64",
goos = "linux",
pure = "on",
)

go_binary(
name = "darwin",
basename = "cross",
embed = [":cross_src"],
name = "darwin_cross",
srcs = ["main.go"],
goarch = "amd64",
goos = "darwin",
pure = "on",
Expand All @@ -40,9 +32,15 @@ go_test(
name = "cross_test",
size = "small",
srcs = ["cross_test.go"],
rundir = ".",
data = [
":darwin",
":linux",
":windows",
":darwin_cross",
":linux_cross",
":windows_cross",
],
args = [
"-darwin", "$(location :darwin_cross)",
"-linux", "$(location :linux_cross)",
"-windows", "$(location :windows_cross)",
]
)
19 changes: 12 additions & 7 deletions tests/core/cross/cross_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package cross_test

import (
"flag"
"os"
"os/exec"
"path/filepath"
Expand All @@ -24,24 +25,28 @@ import (
)

type check struct {
file string
file *string
info []string
}

var darwin = flag.String("darwin", "", "The darwin binary")
var linux = flag.String("linux", "", "The linux binary")
var windows = flag.String("windows", "", "The windows binary")

var checks = []check{
{"darwin_amd64_pure_stripped/cross", []string{
{darwin, []string{
"Mach-O",
"64-bit",
"executable",
"x86_64",
}},
{"linux_amd64_pure_stripped/cross", []string{
{linux, []string{
"ELF",
"64-bit",
"executable",
"x86-64",
}},
{"windows_amd64_pure_stripped/cross.exe", []string{
{windows, []string{
"PE32+",
"Windows",
"executable",
Expand All @@ -52,10 +57,10 @@ var checks = []check{

func TestCross(t *testing.T) {
for _, c := range checks {
if _, err := os.Stat(c.file); os.IsNotExist(err) {
t.Fatalf("Missing binary %v", c.file)
if _, err := os.Stat(*c.file); os.IsNotExist(err) {
t.Fatalf("Missing binary %v", *c.file)
}
file, err := filepath.EvalSymlinks(c.file)
file, err := filepath.EvalSymlinks(*c.file)
if err != nil {
t.Fatalf("Invalid filename %v", file)
}
Expand Down

0 comments on commit 53f410c

Please sign in to comment.