Commit 24e5fae9 authored by Russ Cox's avatar Russ Cox

cmd/go: fix tests from x/vgo repo

This CL fixes up tests from the x/vgo repo that are failing
on some of the builders.
It will be submitted together with CL 123576.

Change-Id: I6bec81a93ad4f7116e8edc8c15beafa25747530c
Reviewed-on: https://go-review.googlesource.com/123580
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent f7248f05
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
...@@ -57,7 +58,7 @@ func Unzip(dir, zipfile, prefix string, maxSize int64) error { ...@@ -57,7 +58,7 @@ func Unzip(dir, zipfile, prefix string, maxSize int64) error {
if zf.Name == prefix || strings.HasSuffix(zf.Name, "/") { if zf.Name == prefix || strings.HasSuffix(zf.Name, "/") {
continue continue
} }
if filepath.Clean(zf.Name) != zf.Name || strings.HasPrefix(zf.Name[len(prefix)+1:], "/") { if path.Clean(zf.Name) != zf.Name || strings.HasPrefix(zf.Name[len(prefix)+1:], "/") {
return fmt.Errorf("unzip %v: invalid file name %s", zipfile, zf.Name) return fmt.Errorf("unzip %v: invalid file name %s", zipfile, zf.Name)
} }
s := int64(zf.UncompressedSize64) s := int64(zf.UncompressedSize64)
......
...@@ -6,8 +6,10 @@ package main_test ...@@ -6,8 +6,10 @@ package main_test
import ( import (
"bytes" "bytes"
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"sort" "sort"
...@@ -81,48 +83,48 @@ func TestModGO111MODULE(t *testing.T) { ...@@ -81,48 +83,48 @@ func TestModGO111MODULE(t *testing.T) {
// In GOPATH/src with go.mod. // In GOPATH/src with go.mod.
tg.cd(tg.path("gp/src/x/y/z")) tg.cd(tg.path("gp/src/x/y/z"))
tg.setenv("GO111MODULE", "auto") tg.setenv("GO111MODULE", "auto")
tg.run("env", "-json") tg.run("env", "GOMOD")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled") tg.grepStdoutNot(`go.mod`, "expected module mode disabled")
tg.cd(tg.path("gp/src/x/y/z/w")) tg.cd(tg.path("gp/src/x/y/z/w"))
tg.run("env", "-json") tg.run("env", "GOMOD")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled") tg.grepStdoutNot(`go.mod`, "expected module mode disabled")
tg.setenv("GO111MODULE", "off") tg.setenv("GO111MODULE", "off")
tg.run("env", "-json") tg.run("env", "GOMOD")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled") tg.grepStdoutNot(`go.mod`, "expected module mode disabled")
tg.setenv("GO111MODULE", "on") tg.setenv("GO111MODULE", "on")
tg.run("env", "-json") tg.run("env", "GOMOD")
tg.grepStdout(`"GOMOD": ".*z[/\\]go.mod"`, "expected module mode enabled") tg.grepStdout(`.*z[/\\]go.mod$`, "expected module mode enabled")
// In GOPATH/src without go.mod. // In GOPATH/src without go.mod.
tg.cd(tg.path("gp/src/x/y")) tg.cd(tg.path("gp/src/x/y"))
tg.setenv("GO111MODULE", "auto") tg.setenv("GO111MODULE", "auto")
tg.run("env", "-json") tg.run("env", "GOMOD")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled") tg.grepStdoutNot(`go.mod`, "expected module mode disabled")
tg.setenv("GO111MODULE", "off") tg.setenv("GO111MODULE", "off")
tg.run("env", "-json") tg.run("env", "GOMOD")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled") tg.grepStdoutNot(`go.mod`, "expected module mode disabled")
tg.setenv("GO111MODULE", "on") tg.setenv("GO111MODULE", "on")
tg.runFail("env", "-json") tg.runFail("env", "GOMOD")
tg.grepStderr(`cannot find main module root`, "expected module mode failure") tg.grepStderr(`cannot find main module root`, "expected module mode failure")
// Outside GOPATH/src with go.mod. // Outside GOPATH/src with go.mod.
tg.cd(tg.path("gp/foo")) tg.cd(tg.path("gp/foo"))
tg.setenv("GO111MODULE", "auto") tg.setenv("GO111MODULE", "auto")
tg.run("env", "-json") tg.run("env", "GOMOD")
tg.grepStdout(`"GOMOD": ".*foo[/\\]go.mod"`, "expected module mode enabled") tg.grepStdout(`.*foo[/\\]go.mod$`, "expected module mode enabled")
tg.cd(tg.path("gp/foo/bar/baz")) tg.cd(tg.path("gp/foo/bar/baz"))
tg.run("env", "-json") tg.run("env", "GOMOD")
tg.grepStdout(`"GOMOD": ".*foo[/\\]go.mod"`, "expected module mode enabled") tg.grepStdout(`.*foo[/\\]go.mod$`, "expected module mode enabled")
tg.setenv("GO111MODULE", "off") tg.setenv("GO111MODULE", "off")
tg.run("env", "-json") tg.run("env", "GOMOD")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled") tg.grepStdoutNot(`go.mod`, "expected module mode disabled")
} }
func TestModVersionsInGOPATHMode(t *testing.T) { func TestModVersionsInGOPATHMode(t *testing.T) {
...@@ -933,6 +935,11 @@ func TestModList(t *testing.T) { ...@@ -933,6 +935,11 @@ func TestModList(t *testing.T) {
} }
func TestModInitLegacy(t *testing.T) { func TestModInitLegacy(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
if _, err := exec.LookPath("git"); err != nil {
t.Skip("skipping because git binary not found")
}
tg := testGoModules(t) tg := testGoModules(t)
defer tg.cleanup() defer tg.cleanup()
...@@ -1035,6 +1042,11 @@ func TestModRequireExcluded(t *testing.T) { ...@@ -1035,6 +1042,11 @@ func TestModRequireExcluded(t *testing.T) {
} }
func TestModInitLegacy2(t *testing.T) { func TestModInitLegacy2(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
if _, err := exec.LookPath("git"); err != nil {
t.Skip("skipping because git binary not found")
}
tg := testGoModules(t) tg := testGoModules(t)
defer tg.cleanup() defer tg.cleanup()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment