Skip to content

Commit

Permalink
Fix tests with --nolegacy_external_runfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Dec 23, 2023
1 parent 460e9c6 commit e073ab7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
10 changes: 5 additions & 5 deletions go/tools/bazel_testing/bazel_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,15 @@ func extractTxtar(dir, txt string) error {

func parseLocationArg(arg string) (workspace, shortPath string, err error) {
cleanPath := path.Clean(arg)
if !strings.HasPrefix(cleanPath, "external/") {
if !strings.HasPrefix(cleanPath, "../") {
return "", cleanPath, nil
}
i := strings.IndexByte(arg[len("external/"):], '/')
i := strings.IndexByte(arg[len("../"):], '/')
if i < 0 {
return "", "", fmt.Errorf("unexpected file (missing / after external/): %s", arg)
return "", "", fmt.Errorf("unexpected file (missing / after ../): %s", arg)
}
i += len("external/")
workspace = cleanPath[len("external/"):i]
i += len("../")
workspace = cleanPath[len("../"):i]
shortPath = cleanPath[i+1:]
return workspace, shortPath, nil
}
Expand Down
7 changes: 4 additions & 3 deletions go/tools/builders/stdliblist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Test_stdliblist(t *testing.T) {

test_args := []string{
fmt.Sprintf("-out=%s", outJSON),
"-sdk=external/go_sdk",
"-sdk=../go_sdk",
}

if err := stdliblist(test_args); err != nil {
Expand All @@ -40,8 +40,9 @@ func Test_stdliblist(t *testing.T) {
t.Errorf("export file should be prefixed with __BAZEL_OUTPUT_BASE__ :%v", result)
}
for _, gofile := range result.GoFiles {
if !strings.HasPrefix(gofile, "__BAZEL_OUTPUT_BASE__/external/go_sdk") {
t.Errorf("all go files should be prefixed with __BAZEL_OUTPUT_BASE__/external/go_sdk :%v", result)
// The SDK runfiles are prefixed with __BAZEL_OUTPUT_BASE__/../go_sdk, which is cleaned.
if !strings.HasPrefix(gofile, "go_sdk/") {
t.Errorf("all go files should be prefixed with go_sdk/ :%v", result)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/core/go_test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ go_test(
srcs = ["env_test.go"],
data = ["@go_sdk//:lib/time/zoneinfo.zip"],
env = {
"ZONEINFO": "$(execpath @go_sdk//:lib/time/zoneinfo.zip)",
"ZONEINFO": "$(rlocationpath @go_sdk//:lib/time/zoneinfo.zip)",
},
deps = [
"@io_bazel_rules_go//go/tools/bazel",
"//go/runfiles",
],
)

Expand Down
26 changes: 12 additions & 14 deletions tests/core/go_test/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,23 @@
package env_test

import (
"github.com/bazelbuild/rules_go/go/runfiles"
"os"
"testing"

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

func TestEnv(t *testing.T) {
v := os.Getenv("ZONEINFO")
if v == "" {
t.Fatalf("ZONEINFO env var was empty")
}
v := os.Getenv("ZONEINFO")
if v == "" {
t.Fatalf("ZONEINFO env var was empty")
}

path, err := bazel.Runfile(v)
if err != nil {
t.Fatalf("Could not find runfile %v: %v", v, err)
}
path, err := runfiles.Rlocation(v)
if err != nil {
t.Fatalf("Could not find runfile %v: %v", v, err)
}

if _, err := os.Stat(path); err != nil {
t.Fatalf("Could not find file at env var $ZONEINFO (value: %v) at path %v: %v", v, path, err)
}
if _, err := os.Stat(path); err != nil {
t.Fatalf("Could not find file at env var $ZONEINFO (value: %v) at path %v: %v", v, path, err)
}
}

2 changes: 1 addition & 1 deletion tests/core/runfiles/check_runfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var DefaultTestFiles = []TestFile{
{Workspace: "io_bazel_rules_go", Path: "tests/core/runfiles/local_bin", Binary: true},
{Workspace: "runfiles_remote_test", Path: "remote_file.txt"},
{Workspace: "runfiles_remote_test", Path: "remote_group.txt"},
{Workspace: "runfiles_remote_test", Path: "remote_bin", Binary: true},
{Workspace: "runfiles_remote_test", Path: "../runfiles_remote_test/remote_bin", Binary: true},
}

func CheckRunfiles(files []TestFile) error {
Expand Down

0 comments on commit e073ab7

Please sign in to comment.