go/packages: propagate PATH in TestConfigEnvDoesNotInheritProcessEnv The packages.Load call first selects a driver to use. In this case it is invariably going to be the go list command, since GOPACKAGESDRIVER is being set to off in Config.Env. In some environments, such as openbsd/amd64, the go command might not be able to run properly if the PATH environment variable isn't passed on to it. There may be room for improvement there, but that's outside of the scope of this test. Fixes golang/go#79907. Change-Id: I6734713f0b2670007078d990325797b075f6f8fc Cq-Include-Trybots: luci.golang.try:x_tools-gotip-openbsd-amd64 Reviewed-on: https://go-review.googlesource.com/c/tools/+/789500 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index 681e0f7..7d6cffa 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go
@@ -3019,6 +3019,9 @@ } } +// TestConfigEnvDoesNotInheritProcessEnv tests that when Config.Env is non-nil +// and doesn't contain os.Environ(), packages.Load doesn't inherit the process +// environment. func TestConfigEnvDoesNotInheritProcessEnv(t *testing.T) { testenv.NeedsGoPackages(t) @@ -3044,6 +3047,7 @@ Dir: dir, Mode: packages.NeedFiles, Env: []string{ + "PATH=" + os.Getenv("PATH"), "GOCACHE=" + t.TempDir(), "GOPACKAGESDRIVER=off", "GOWORK=off",