]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/go/go_test.go
[dev.boringcrypto] all: merge master into dev.boringcrypto
[gostls13.git] / src / cmd / go / go_test.go
index bee9384d76c237d56f5c785a3b0cbf890366706a..e762687e0876dce538c23e70a78d94643357160b 100644 (file)
@@ -29,6 +29,7 @@ import (
 
        "cmd/go/internal/cache"
        "cmd/go/internal/cfg"
+       "cmd/go/internal/robustio"
        "cmd/internal/sys"
 )
 
@@ -685,7 +686,7 @@ func (tg *testgoData) creatingTemp(path string) {
        if tg.wd != "" && !filepath.IsAbs(path) {
                path = filepath.Join(tg.pwd(), path)
        }
-       tg.must(os.RemoveAll(path))
+       tg.must(robustio.RemoveAll(path))
        tg.temps = append(tg.temps, path)
 }
 
@@ -887,7 +888,7 @@ func removeAll(dir string) error {
                }
                return nil
        })
-       return os.RemoveAll(dir)
+       return robustio.RemoveAll(dir)
 }
 
 // failSSH puts an ssh executable in the PATH that always fails.
@@ -1181,7 +1182,7 @@ func testMove(t *testing.T, vcs, url, base, config string) {
        case "svn":
                // SVN doesn't believe in text files so we can't just edit the config.
                // Check out a different repo into the wrong place.
-               tg.must(os.RemoveAll(tg.path("src/code.google.com/p/rsc-svn")))
+               tg.must(robustio.RemoveAll(tg.path("src/code.google.com/p/rsc-svn")))
                tg.run("get", "-d", "-u", "code.google.com/p/rsc-svn2/trunk")
                tg.must(os.Rename(tg.path("src/code.google.com/p/rsc-svn2"), tg.path("src/code.google.com/p/rsc-svn")))
        default:
@@ -1222,10 +1223,12 @@ func TestInternalCache(t *testing.T) {
 }
 
 func TestMoveGit(t *testing.T) {
+       testenv.MustHaveExecPath(t, "git")
        testMove(t, "git", "rsc.io/pdf", "pdf", "rsc.io/pdf/.git/config")
 }
 
 func TestMoveHG(t *testing.T) {
+       testenv.MustHaveExecPath(t, "hg")
        testMove(t, "hg", "vcs-test.golang.org/go/custom-hg-hello", "custom-hg-hello", "vcs-test.golang.org/go/custom-hg-hello/.hg/hgrc")
 }
 
@@ -1287,9 +1290,7 @@ func TestImportCycle(t *testing.T) {
 // cmd/go: custom import path checking should not apply to Go packages without import comment.
 func TestIssue10952(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
-       if _, err := exec.LookPath("git"); err != nil {
-               t.Skip("skipping because git binary not found")
-       }
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1305,9 +1306,7 @@ func TestIssue10952(t *testing.T) {
 
 func TestIssue16471(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
-       if _, err := exec.LookPath("git"); err != nil {
-               t.Skip("skipping because git binary not found")
-       }
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1323,9 +1322,7 @@ func TestIssue16471(t *testing.T) {
 // Test git clone URL that uses SCP-like syntax and custom import path checking.
 func TestIssue11457(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
-       if _, err := exec.LookPath("git"); err != nil {
-               t.Skip("skipping because git binary not found")
-       }
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1350,9 +1347,7 @@ func TestIssue11457(t *testing.T) {
 
 func TestGetGitDefaultBranch(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
-       if _, err := exec.LookPath("git"); err != nil {
-               t.Skip("skipping because git binary not found")
-       }
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1378,9 +1373,7 @@ func TestGetGitDefaultBranch(t *testing.T) {
 // Security issue. Don't disable. See golang.org/issue/22125.
 func TestAccidentalGitCheckout(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
-       if _, err := exec.LookPath("git"); err != nil {
-               t.Skip("skipping because git binary not found")
-       }
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1653,6 +1646,7 @@ func TestInstallToGOBINCommandLinePackage(t *testing.T) {
 
 func TestGoGetNonPkg(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1669,6 +1663,7 @@ func TestGoGetNonPkg(t *testing.T) {
 
 func TestGoGetTestOnlyPkg(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1699,7 +1694,7 @@ func TestInstalls(t *testing.T) {
        goarch := strings.TrimSpace(tg.getStdout())
        tg.setenv("GOARCH", goarch)
        fixbin := filepath.Join(goroot, "pkg", "tool", goos+"_"+goarch, "fix") + exeSuffix
-       tg.must(os.RemoveAll(fixbin))
+       tg.must(robustio.RemoveAll(fixbin))
        tg.run("install", "cmd/fix")
        tg.wantExecutable(fixbin, "did not install cmd/fix to $GOROOT/pkg/tool")
        tg.must(os.Remove(fixbin))
@@ -2058,6 +2053,7 @@ func TestDefaultGOPATH(t *testing.T) {
 
 func TestDefaultGOPATHGet(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -2070,13 +2066,13 @@ func TestDefaultGOPATHGet(t *testing.T) {
        tg.grepStderr("created GOPATH="+regexp.QuoteMeta(tg.path("home/go"))+"; see 'go help gopath'", "did not create GOPATH")
 
        // no warning if directory already exists
-       tg.must(os.RemoveAll(tg.path("home/go")))
+       tg.must(robustio.RemoveAll(tg.path("home/go")))
        tg.tempDir("home/go")
        tg.run("get", "github.com/golang/example/hello")
        tg.grepStderrNot(".", "expected no output on standard error")
 
        // error if $HOME/go is a file
-       tg.must(os.RemoveAll(tg.path("home/go")))
+       tg.must(robustio.RemoveAll(tg.path("home/go")))
        tg.tempFile("home/go", "")
        tg.runFail("get", "github.com/golang/example/hello")
        tg.grepStderr(`mkdir .*[/\\]go: .*(not a directory|cannot find the path)`, "expected error because $HOME/go is a file")
@@ -2439,6 +2435,7 @@ func TestSymlinkWarning(t *testing.T) {
 // Issue 8181.
 func TestGoGetDashTIssue8181(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -2453,6 +2450,7 @@ func TestGoGetDashTIssue8181(t *testing.T) {
 func TestIssue11307(t *testing.T) {
        // go get -u was not working except in checkout directory
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -2875,7 +2873,7 @@ func TestCgoDependsOnSyscall(t *testing.T) {
        files, err := filepath.Glob(filepath.Join(runtime.GOROOT(), "pkg", "*_race"))
        tg.must(err)
        for _, file := range files {
-               tg.check(os.RemoveAll(file))
+               tg.check(robustio.RemoveAll(file))
        }
        tg.tempFile("src/foo/foo.go", `
                package foo
@@ -2931,6 +2929,7 @@ func TestCgoPkgConfig(t *testing.T) {
 
        tg.run("env", "PKG_CONFIG")
        pkgConfig := strings.TrimSpace(tg.getStdout())
+       testenv.MustHaveExecPath(t, pkgConfig)
        if out, err := exec.Command(pkgConfig, "--atleast-pkgconfig-version", "0.24").CombinedOutput(); err != nil {
                t.Skipf("%s --atleast-pkgconfig-version 0.24: %v\n%s", pkgConfig, err, out)
        }
@@ -3033,9 +3032,7 @@ func TestIssue7573(t *testing.T) {
        if !canCgo {
                t.Skip("skipping because cgo not enabled")
        }
-       if _, err := exec.LookPath("gccgo"); err != nil {
-               t.Skip("skipping because no gccgo compiler found")
-       }
+       testenv.MustHaveExecPath(t, "gccgo")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -3324,6 +3321,7 @@ func TestGoGenerateBadImports(t *testing.T) {
 
 func TestGoGetCustomDomainWildcard(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -3335,6 +3333,7 @@ func TestGoGetCustomDomainWildcard(t *testing.T) {
 
 func TestGoGetInternalWildcard(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -3407,6 +3406,7 @@ func TestVetWithOnlyCgoFiles(t *testing.T) {
 // Issue 9767, 19769.
 func TestGoGetDotSlashDownload(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -3662,6 +3662,7 @@ func TestImportLocal(t *testing.T) {
 func TestGoGetInsecure(t *testing.T) {
        test := func(t *testing.T, modules bool) {
                testenv.MustHaveExternalNetwork(t)
+               testenv.MustHaveExecPath(t, "git")
 
                tg := testgo(t)
                defer tg.cleanup()
@@ -3702,6 +3703,7 @@ func TestGoGetInsecure(t *testing.T) {
 
 func TestGoGetUpdateInsecure(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -3726,6 +3728,7 @@ func TestGoGetUpdateInsecure(t *testing.T) {
 
 func TestGoGetUpdateUnknownProtocol(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -3760,6 +3763,7 @@ func TestGoGetUpdateUnknownProtocol(t *testing.T) {
 
 func TestGoGetInsecureCustomDomain(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -3862,6 +3866,7 @@ func TestGoGetUpdate(t *testing.T) {
        // former dependencies, not current ones.
 
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -3889,6 +3894,7 @@ func TestGoGetUpdate(t *testing.T) {
 // Issue #20512.
 func TestGoGetRace(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
        if !canRace {
                t.Skip("skipping because race detector not supported")
        }
@@ -3905,6 +3911,7 @@ func TestGoGetDomainRoot(t *testing.T) {
        // go get foo.io (not foo.io/subdir) was not working consistently.
 
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -3919,10 +3926,10 @@ func TestGoGetDomainRoot(t *testing.T) {
        tg.run("get", "go-get-issue-9357.appspot.com")
        tg.run("get", "-u", "go-get-issue-9357.appspot.com")
 
-       tg.must(os.RemoveAll(tg.path("src/go-get-issue-9357.appspot.com")))
+       tg.must(robustio.RemoveAll(tg.path("src/go-get-issue-9357.appspot.com")))
        tg.run("get", "go-get-issue-9357.appspot.com")
 
-       tg.must(os.RemoveAll(tg.path("src/go-get-issue-9357.appspot.com")))
+       tg.must(robustio.RemoveAll(tg.path("src/go-get-issue-9357.appspot.com")))
        tg.run("get", "-u", "go-get-issue-9357.appspot.com")
 }
 
@@ -4303,6 +4310,7 @@ func TestGenerateUsesBuildContext(t *testing.T) {
 // Issue 14450: go get -u .../ tried to import not downloaded package
 func TestGoGetUpdateWithWildcard(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
+       testenv.MustHaveExecPath(t, "git")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -4514,8 +4522,9 @@ func TestLinkXImportPathEscape(t *testing.T) {
        tg := testgo(t)
        defer tg.cleanup()
        tg.parallel()
+       tg.makeTempdir()
        tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
-       exe := "./linkx" + exeSuffix
+       exe := tg.path("linkx" + exeSuffix)
        tg.creatingTemp(exe)
        tg.run("build", "-o", exe, "-ldflags", "-X=my.pkg.Text=linkXworked", "my.pkg/main")
        out, err := exec.Command(exe).CombinedOutput()
@@ -4751,7 +4760,7 @@ func TestExecutableGOROOT(t *testing.T) {
                check(t, symGoTool, newRoot)
        })
 
-       tg.must(os.RemoveAll(tg.path("new/pkg")))
+       tg.must(robustio.RemoveAll(tg.path("new/pkg")))
 
        // Binaries built in the new tree should report the
        // new tree when they call runtime.GOROOT.
@@ -5051,9 +5060,8 @@ func TestExecBuildX(t *testing.T) {
                t.Skip("skipping because cgo not enabled")
        }
 
-       if runtime.GOOS == "plan9" || runtime.GOOS == "windows" {
-               t.Skipf("skipping because unix shell is not supported on %s", runtime.GOOS)
-       }
+       testenv.MustHaveExecPath(t, "/usr/bin/env")
+       testenv.MustHaveExecPath(t, "bash")
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -5103,7 +5111,7 @@ func TestExecBuildX(t *testing.T) {
        if len(matches) == 0 {
                t.Fatal("no WORK directory")
        }
-       tg.must(os.RemoveAll(matches[1]))
+       tg.must(robustio.RemoveAll(matches[1]))
 }
 
 func TestParallelNumber(t *testing.T) {
@@ -5134,9 +5142,10 @@ func TestUpxCompression(t *testing.T) {
                t.Skipf("skipping upx test on %s/%s", runtime.GOOS, runtime.GOARCH)
        }
 
+       testenv.MustHaveExecPath(t, "upx")
        out, err := exec.Command("upx", "--version").CombinedOutput()
        if err != nil {
-               t.Skip("skipping because upx is not available")
+               t.Fatalf("upx --version failed: %v", err)
        }
 
        // upx --version prints `upx <version>` in the first line of output:
@@ -5145,13 +5154,13 @@ func TestUpxCompression(t *testing.T) {
        re := regexp.MustCompile(`([[:digit:]]+)\.([[:digit:]]+)`)
        upxVersion := re.FindStringSubmatch(string(out))
        if len(upxVersion) != 3 {
-               t.Errorf("bad upx version string: %s", upxVersion)
+               t.Fatalf("bad upx version string: %s", upxVersion)
        }
 
        major, err1 := strconv.Atoi(upxVersion[1])
        minor, err2 := strconv.Atoi(upxVersion[2])
        if err1 != nil || err2 != nil {
-               t.Errorf("bad upx version string: %s", upxVersion[0])
+               t.Fatalf("bad upx version string: %s", upxVersion[0])
        }
 
        // Anything below 3.94 is known not to work with go binaries
@@ -5204,26 +5213,29 @@ func TestQEMUUserMode(t *testing.T) {
        src, obj := tg.path("main.go"), tg.path("main")
 
        for _, arch := range testArchs {
-               out, err := exec.Command("qemu-"+arch.qemu, "--version").CombinedOutput()
-               if err != nil {
-                       t.Logf("Skipping %s test (qemu-%s not available)", arch.g, arch.qemu)
-                       continue
-               }
+               arch := arch
+               t.Run(arch.g, func(t *testing.T) {
+                       qemu := "qemu-" + arch.qemu
+                       testenv.MustHaveExecPath(t, qemu)
 
-               tg.setenv("GOARCH", arch.g)
-               tg.run("build", "-o", obj, src)
+                       out, err := exec.Command(qemu, "--version").CombinedOutput()
+                       if err != nil {
+                               t.Fatalf("%s --version failed: %v", qemu, err)
+                       }
 
-               out, err = exec.Command("qemu-"+arch.qemu, obj).CombinedOutput()
-               if err != nil {
-                       t.Logf("qemu-%s output:\n%s\n", arch.qemu, out)
-                       t.Errorf("qemu-%s failed with %v", arch.qemu, err)
-                       continue
-               }
-               if want := "hello qemu-user"; string(out) != want {
-                       t.Errorf("bad output from qemu-%s:\ngot %s; want %s", arch.qemu, out, want)
-               }
-       }
+                       tg.setenv("GOARCH", arch.g)
+                       tg.run("build", "-o", obj, src)
 
+                       out, err = exec.Command(qemu, obj).CombinedOutput()
+                       if err != nil {
+                               t.Logf("%s output:\n%s\n", qemu, out)
+                               t.Fatalf("%s failed with %v", qemu, err)
+                       }
+                       if want := "hello qemu-user"; string(out) != want {
+                               t.Errorf("bad output from %s:\ngot %s; want %s", qemu, out, want)
+                       }
+               })
+       }
 }
 
 func TestCacheListStale(t *testing.T) {