From 4c025a95b26e43a32c527d23a8a7ed074723e03b Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Fri, 11 Oct 2019 16:49:23 -0400 Subject: [PATCH] go/packages: make a copy of the config.Env slice in the test. Before this change, we were "saving" config.Env and then appending to it to create a new slice, like so: savedEnv := config.Env ... // for each test case config.Env = append(savedEnv, additionalValue) but we're modifying savedEnv during each env. Even though it might work, it's not doing what we expect. Clean this up. Change-Id: Idcf8199d836241df2b934308863512c566c0c485 Reviewed-on: https://go-review.googlesource.com/c/tools/+/200769 Run-TryBot: Michael Matloob Run-TryBot: Rebecca Stambler Reviewed-by: Rebecca Stambler --- go/packages/packages_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index e5a1b52077..4b094c481e 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go @@ -1951,7 +1951,6 @@ EOF } else { pathWithDriver = binDir } - coreEnv := exported.Config.Env for _, test := range []struct { desc string path string @@ -1979,7 +1978,10 @@ EOF oldPath := os.Getenv(pathKey) os.Setenv(pathKey, test.path) defer os.Setenv(pathKey, oldPath) - exported.Config.Env = append(coreEnv, "GOPACKAGESDRIVER="+test.driver) + // Clone exported.Config + config := exported.Config + config.Env = append([]string{}, exported.Config.Env...) + config.Env = append(config.Env, "GOPACKAGESDRIVER="+test.driver) pkgs, err := packages.Load(exported.Config, "golist") if err != nil { t.Fatal(err)