go/packages: pass TestConfigDefaultEnv on Plan 9

Change-Id: Ice0d44c97dc76bf0ebfe433577d55eb6763cb6d3
Reviewed-on: https://go-review.googlesource.com/c/132601
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Fazlul Shahriar 2018-09-01 00:14:33 -04:00 committed by Brad Fitzpatrick
parent fc0741f0ff
commit 5b8b0ce6cc
1 changed files with 32 additions and 15 deletions

View File

@ -1414,23 +1414,40 @@ func testPatternPassthrough(t *testing.T, exporter packagestest.Exporter) {
func TestConfigDefaultEnv(t *testing.T) { packagestest.TestAll(t, testConfigDefaultEnv) }
func testConfigDefaultEnv(t *testing.T, exporter packagestest.Exporter) {
if runtime.GOOS == "windows" {
const driverJSON = `{
"Roots": ["gopackagesdriver"],
"Packages": [{"ID": "gopackagesdriver", "Name": "gopackagesdriver"}]
}`
var (
pathKey string
driverScript packagestest.Writer
)
switch runtime.GOOS {
case "windows":
// TODO(jayconrod): write an equivalent batch script for windows.
// Hint: "type" can be used to read a file to stdout.
t.Skip("test requires sh")
case "plan9":
pathKey = "path"
driverScript = packagestest.Script(`#!/bin/rc
cat <<'EOF'
` + driverJSON + `
EOF
`)
default:
pathKey = "PATH"
driverScript = packagestest.Script(`#!/bin/sh
cat - <<'EOF'
` + driverJSON + `
EOF
`)
}
exported := packagestest.Export(t, exporter, []packagestest.Module{{
Name: "golang.org/fake",
Files: map[string]interface{}{
"bin/gopackagesdriver": packagestest.Script(`#!/bin/sh
cat - <<'EOF'
{
"Roots": ["gopackagesdriver"],
"Packages": [{"ID": "gopackagesdriver", "Name": "gopackagesdriver"}]
}
EOF
`),
"bin/gopackagesdriver": driverScript,
"golist/golist.go": "package golist",
}}})
defer exported.Cleanup()
@ -1440,7 +1457,7 @@ EOF
t.Fatal(err)
}
path, ok := os.LookupEnv("PATH")
path, ok := os.LookupEnv(pathKey)
var pathWithDriver string
if ok {
pathWithDriver = binDir + string(os.PathListSeparator) + path
@ -1472,9 +1489,9 @@ EOF
},
} {
t.Run(test.desc, func(t *testing.T) {
oldPath := os.Getenv("PATH")
os.Setenv("PATH", test.path)
defer os.Setenv("PATH", oldPath)
oldPath := os.Getenv(pathKey)
os.Setenv(pathKey, test.path)
defer os.Setenv(pathKey, oldPath)
exported.Config.Env = append(coreEnv, "GOPACKAGESDRIVER="+test.driver)
pkgs, err := packages.Load(exported.Config, "golist")
if err != nil {