Skip to content

Commit 9bb9bc1

Browse files
committed
go/packages: add GOROOT env to avoid TestTarget failure in OpenBSD
Fixes #70891, 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.
1 parent 6d4eee4 commit 9bb9bc1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

go/packages/packages_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3361,9 +3361,12 @@ func main() {
33613361
`)
33623362
gopath := filepath.Join(dir, "gopath")
33633363

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

0 commit comments

Comments
 (0)