Skip to content

Commit

Permalink
go/packages: add GOROOT env to avoid TestTarget failure in OpenBSD
Browse files Browse the repository at this point in the history
When running tests in OpenBSD if 'go' is
built with -trimpath, the TestTarget will always fail.
Because when invoked without proper environments, 'go' itself
fails to find the GOROOT path.

Fixes golang/go#70891
  • Loading branch information
linsite committed Dec 27, 2024
1 parent 6d4eee4 commit 9807469
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion go/packages/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3361,9 +3361,12 @@ func main() {
`)
gopath := filepath.Join(dir, "gopath")

// See https://golang.org/issue/70891.
// OpenBSD hasn't a /proc filesystem. When running with a -trimpath
// built go, it will always fail without a GOROOT.
pkgs, err := packages.Load(&packages.Config{
Mode: packages.NeedName | packages.NeedTarget,
Env: []string{"GOPATH=" + gopath, "GO111MODULE=off"},
Env: []string{"GOPATH=" + gopath, "GO111MODULE=off", "GOROOT=" + os.Getenv("GOROOT")},
}, filepath.Join(gopath, "src", "..."))
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 9807469

Please sign in to comment.