Skip to content

Commit

Permalink
cmd/go: fix tests from x/vgo repo
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Bryan C. Mills <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
rsc committed Jul 12, 2018
1 parent f7248f0 commit 24e5fae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/cmd/go/internal/modfetch/unzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -57,7 +58,7 @@ func Unzip(dir, zipfile, prefix string, maxSize int64) error {
if zf.Name == prefix || strings.HasSuffix(zf.Name, "/") {
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)
}
s := int64(zf.UncompressedSize64)
Expand Down
50 changes: 31 additions & 19 deletions src/cmd/go/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package main_test

import (
"bytes"
"internal/testenv"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"sort"
Expand Down Expand Up @@ -81,48 +83,48 @@ func TestModGO111MODULE(t *testing.T) {
// In GOPATH/src with go.mod.
tg.cd(tg.path("gp/src/x/y/z"))
tg.setenv("GO111MODULE", "auto")
tg.run("env", "-json")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled")
tg.run("env", "GOMOD")
tg.grepStdoutNot(`go.mod`, "expected module mode disabled")

tg.cd(tg.path("gp/src/x/y/z/w"))
tg.run("env", "-json")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled")
tg.run("env", "GOMOD")
tg.grepStdoutNot(`go.mod`, "expected module mode disabled")

tg.setenv("GO111MODULE", "off")
tg.run("env", "-json")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled")
tg.run("env", "GOMOD")
tg.grepStdoutNot(`go.mod`, "expected module mode disabled")

tg.setenv("GO111MODULE", "on")
tg.run("env", "-json")
tg.grepStdout(`"GOMOD": ".*z[/\\]go.mod"`, "expected module mode enabled")
tg.run("env", "GOMOD")
tg.grepStdout(`.*z[/\\]go.mod$`, "expected module mode enabled")

// In GOPATH/src without go.mod.
tg.cd(tg.path("gp/src/x/y"))
tg.setenv("GO111MODULE", "auto")
tg.run("env", "-json")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled")
tg.run("env", "GOMOD")
tg.grepStdoutNot(`go.mod`, "expected module mode disabled")

tg.setenv("GO111MODULE", "off")
tg.run("env", "-json")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled")
tg.run("env", "GOMOD")
tg.grepStdoutNot(`go.mod`, "expected module mode disabled")

tg.setenv("GO111MODULE", "on")
tg.runFail("env", "-json")
tg.runFail("env", "GOMOD")
tg.grepStderr(`cannot find main module root`, "expected module mode failure")

// Outside GOPATH/src with go.mod.
tg.cd(tg.path("gp/foo"))
tg.setenv("GO111MODULE", "auto")
tg.run("env", "-json")
tg.grepStdout(`"GOMOD": ".*foo[/\\]go.mod"`, "expected module mode enabled")
tg.run("env", "GOMOD")
tg.grepStdout(`.*foo[/\\]go.mod$`, "expected module mode enabled")

tg.cd(tg.path("gp/foo/bar/baz"))
tg.run("env", "-json")
tg.grepStdout(`"GOMOD": ".*foo[/\\]go.mod"`, "expected module mode enabled")
tg.run("env", "GOMOD")
tg.grepStdout(`.*foo[/\\]go.mod$`, "expected module mode enabled")

tg.setenv("GO111MODULE", "off")
tg.run("env", "-json")
tg.grepStdout(`"GOMOD": ""`, "expected module mode disabled")
tg.run("env", "GOMOD")
tg.grepStdoutNot(`go.mod`, "expected module mode disabled")
}

func TestModVersionsInGOPATHMode(t *testing.T) {
Expand Down Expand Up @@ -933,6 +935,11 @@ func TestModList(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)
defer tg.cleanup()

Expand Down Expand Up @@ -1035,6 +1042,11 @@ func TestModRequireExcluded(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)
defer tg.cleanup()

Expand Down

0 comments on commit 24e5fae

Please sign in to comment.