diff --git a/go/src/cmd/go/testdata/addmod.go b/go/src/cmd/go/testdata/addmod.go new file mode 100644 index 0000000000000000000000000000000000000000..7ef68b3edcc9d5537dc3f6be97878d2dcf498398 --- /dev/null +++ b/go/src/cmd/go/testdata/addmod.go @@ -0,0 +1,154 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore +// +build ignore + +// Addmod adds a module as a txtar archive to the testdata/mod directory. +// +// Usage: +// +// go run addmod.go path@version... +// +// It should only be used for very small modules - we do not want to check +// very large files into testdata/mod. +// +// It is acceptable to edit the archive afterward to remove or shorten files. +// See mod/README for more information. +package main + +import ( + "bytes" + "cmd/go/internal/str" + "flag" + "fmt" + "internal/txtar" + "io/fs" + "log" + "os" + "os/exec" + "path/filepath" + "strings" +) + +func usage() { + fmt.Fprintf(os.Stderr, "usage: go run addmod.go path@version...\n") + os.Exit(2) +} + +var tmpdir string + +func fatalf(format string, args ...any) { + os.RemoveAll(tmpdir) + log.Fatalf(format, args...) +} + +const goCmd = "go" + +func main() { + flag.Usage = usage + flag.Parse() + if flag.NArg() == 0 { + usage() + } + + log.SetPrefix("addmod: ") + log.SetFlags(0) + + var err error + tmpdir, err = os.MkdirTemp("", "addmod-") + if err != nil { + log.Fatal(err) + } + + run := func(command string, args ...string) string { + cmd := exec.Command(command, args...) + cmd.Dir = tmpdir + var stderr bytes.Buffer + cmd.Stderr = &stderr + out, err := cmd.Output() + if err != nil { + fatalf("%s %s: %v\n%s", command, strings.Join(args, " "), err, stderr.Bytes()) + } + return string(out) + } + + gopath := strings.TrimSpace(run("go", "env", "GOPATH")) + if gopath == "" { + fatalf("cannot find GOPATH") + } + + exitCode := 0 + for _, arg := range flag.Args() { + if err := os.WriteFile(filepath.Join(tmpdir, "go.mod"), []byte("module m\n"), 0666); err != nil { + fatalf("%v", err) + } + run(goCmd, "get", "-d", arg) + path := arg + if i := strings.Index(path, "@"); i >= 0 { + path = path[:i] + } + out := run(goCmd, "list", "-m", "-f={{.Path}} {{.Version}} {{.Dir}}", path) + f := strings.Fields(out) + if len(f) != 3 { + log.Printf("go list -m %s: unexpected output %q", arg, out) + exitCode = 1 + continue + } + path, vers, dir := f[0], f[1], f[2] + mod, err := os.ReadFile(filepath.Join(gopath, "pkg/mod/cache/download", path, "@v", vers+".mod")) + if err != nil { + log.Printf("%s: %v", arg, err) + exitCode = 1 + continue + } + info, err := os.ReadFile(filepath.Join(gopath, "pkg/mod/cache/download", path, "@v", vers+".info")) + if err != nil { + log.Printf("%s: %v", arg, err) + exitCode = 1 + continue + } + + a := new(txtar.Archive) + title := arg + if !strings.Contains(arg, "@") { + title += "@" + vers + } + a.Comment = []byte(fmt.Sprintf("module %s\n\n", title)) + a.Files = []txtar.File{ + {Name: ".mod", Data: mod}, + {Name: ".info", Data: info}, + } + dir = filepath.Clean(dir) + err = filepath.WalkDir(dir, func(path string, info fs.DirEntry, err error) error { + if !info.Type().IsRegular() { + return nil + } + name := info.Name() + if name == "go.mod" || strings.HasSuffix(name, ".go") { + data, err := os.ReadFile(path) + if err != nil { + return err + } + a.Files = append(a.Files, txtar.File{Name: str.TrimFilePathPrefix(path, dir), Data: data}) + } + return nil + }) + if err != nil { + log.Printf("%s: %v", arg, err) + exitCode = 1 + continue + } + + data := txtar.Format(a) + target := filepath.Join("mod", strings.ReplaceAll(path, "/", "_")+"_"+vers+".txt") + if err := os.WriteFile(target, data, 0666); err != nil { + log.Printf("%s: %v", arg, err) + exitCode = 1 + continue + } + } + os.RemoveAll(tmpdir) + os.Exit(exitCode) +} diff --git a/go/src/cmd/go/testdata/mod/README b/go/src/cmd/go/testdata/mod/README new file mode 100644 index 0000000000000000000000000000000000000000..43ddf77eff3844b631665485abe511380ae7066a --- /dev/null +++ b/go/src/cmd/go/testdata/mod/README @@ -0,0 +1,36 @@ +This directory holds Go modules served by a Go module proxy +that runs on localhost during tests, both to make tests avoid +requiring specific network servers and also to make them +significantly faster. + +A small go get'able test module can be added here by running + + cd cmd/go/testdata + go run addmod.go path@vers + +where path and vers are the module path and version to add here. + +For interactive experimentation using this set of modules, run: + + cd cmd/go + go test -proxy=localhost:1234 & + export GOPROXY=http://localhost:1234/mod + +and then run go commands as usual. + +Modules saved to this directory should be small: a few kilobytes at most. +It is acceptable to edit the archives created by addmod.go to remove +or shorten files. It is also acceptable to write module archives by hand: +they need not be backed by some public git repo. + +Each module archive is named path_vers.txt, where slashes in path +have been replaced with underscores. The archive must contain +two files ".info" and ".mod", to be served as the info and mod files +in the proxy protocol (see https://research.swtch.com/vgo-module). +The remaining files are served as the content of the module zip file. +The path@vers prefix required of files in the zip file is added +automatically by the proxy: the files in the archive have names without +the prefix, like plain "go.mod", "x.go", and so on. + +See ../addmod.go and ../savedir.go for tools to generate txtar files, +although again it is also fine to write them by hand. diff --git a/go/src/cmd/go/testdata/mod/example.com_ambiguous_a_b_v0.0.0-empty.txt b/go/src/cmd/go/testdata/mod/example.com_ambiguous_a_b_v0.0.0-empty.txt new file mode 100644 index 0000000000000000000000000000000000000000..a86951981e2596a9a088018d0936e2d6f08ee7a1 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_ambiguous_a_b_v0.0.0-empty.txt @@ -0,0 +1,12 @@ +Module example.com/ambiguous/a/b is a suffix of example.com/a. +This version contains no package. +-- .mod -- +module example.com/ambiguous/a/b + +go 1.16 +-- .info -- +{"Version":"v0.0.0-empty"} +-- go.mod -- +module example.com/ambiguous/a/b + +go 1.16 diff --git a/go/src/cmd/go/testdata/mod/example.com_ambiguous_a_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_ambiguous_a_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..bb438262e134bf3d34b3d0af92193fc8966ac2a5 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_ambiguous_a_v1.0.0.txt @@ -0,0 +1,18 @@ +Module example.com/ambiguous/a is a prefix of example.com/a/b. +It contains package example.com/a/b. +-- .mod -- +module example.com/ambiguous/a + +go 1.16 + +require example.com/ambiguous/a/b v0.0.0-empty +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module example.com/ambiguous/a + +go 1.16 + +require example.com/ambiguous/a/b v0.0.0-empty +-- b/b.go -- +package b diff --git a/go/src/cmd/go/testdata/mod/example.com_badchain_a_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_badchain_a_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..d7bf6471b7cdeb6bac3dca177dcb5ffef57901ef --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_badchain_a_v1.0.0.txt @@ -0,0 +1,12 @@ +example.com/badchain/a v1.0.0 + +-- .mod -- +module example.com/badchain/a + +require example.com/badchain/b v1.0.0 +-- .info -- +{"Version":"v1.0.0"} +-- a.go -- +package a + +import _ "example.com/badchain/b" diff --git a/go/src/cmd/go/testdata/mod/example.com_badchain_a_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_badchain_a_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..92190d8ac177a11226b09c435bae3a182727453d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_badchain_a_v1.1.0.txt @@ -0,0 +1,12 @@ +example.com/badchain/a v1.1.0 + +-- .mod -- +module example.com/badchain/a + +require example.com/badchain/b v1.1.0 +-- .info -- +{"Version":"v1.1.0"} +-- a.go -- +package a + +import _ "example.com/badchain/b" diff --git a/go/src/cmd/go/testdata/mod/example.com_badchain_b_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_badchain_b_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..d42b8aab164536e3e5a157dd605f8bfc4d097662 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_badchain_b_v1.0.0.txt @@ -0,0 +1,12 @@ +example.com/badchain/b v1.0.0 + +-- .mod -- +module example.com/badchain/b + +require example.com/badchain/c v1.0.0 +-- .info -- +{"Version":"v1.0.0"} +-- b.go -- +package b + +import _ "example.com/badchain/c" diff --git a/go/src/cmd/go/testdata/mod/example.com_badchain_b_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_badchain_b_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..664818474ce815cb4bc882914c8c5d1e2ffa2263 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_badchain_b_v1.1.0.txt @@ -0,0 +1,12 @@ +example.com/badchain/b v1.1.0 + +-- .mod -- +module example.com/badchain/b + +require example.com/badchain/c v1.1.0 +-- .info -- +{"Version":"v1.1.0"} +-- b.go -- +package b + +import _ "example.com/badchain/c" diff --git a/go/src/cmd/go/testdata/mod/example.com_badchain_c_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_badchain_c_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..9c717cb0e6efcf0fba2b30642a02aa54dee67b89 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_badchain_c_v1.0.0.txt @@ -0,0 +1,8 @@ +example.com/badchain/c v1.0.0 + +-- .mod -- +module example.com/badchain/c +-- .info -- +{"Version":"v1.0.0"} +-- c.go -- +package c diff --git a/go/src/cmd/go/testdata/mod/example.com_badchain_c_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_badchain_c_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..36bc2c67266e0c7906e9fd4e7ba5964b3b1a328b --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_badchain_c_v1.1.0.txt @@ -0,0 +1,8 @@ +example.com/badchain/c v1.1.0 + +-- .mod -- +module badchain.example.com/c +-- .info -- +{"Version":"v1.1.0"} +-- c.go -- +package c diff --git a/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0-exclude.txt b/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0-exclude.txt new file mode 100644 index 0000000000000000000000000000000000000000..c883d8a7744a15626377305cfca13ccfd7fa5d98 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0-exclude.txt @@ -0,0 +1,28 @@ +example.com/cmd contains main packages. + +-- .info -- +{"Version":"v1.0.0-exclude"} +-- .mod -- +module example.com/cmd + +go 1.16 + +exclude rsc.io/quote v1.5.2 +-- go.mod -- +module example.com/cmd + +go 1.16 + +exclude rsc.io/quote v1.5.2 +-- a/a.go -- +package main + +func main() {} +-- b/b.go -- +package main + +func main() {} +-- err/err.go -- +package err + +var X = DoesNotCompile diff --git a/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0-newerself.txt b/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0-newerself.txt new file mode 100644 index 0000000000000000000000000000000000000000..7670f29ffd0024ea106a0de4269ee32ee11a71c7 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0-newerself.txt @@ -0,0 +1,28 @@ +example.com/cmd contains main packages. + +-- .info -- +{"Version":"v1.0.0-newerself"} +-- .mod -- +module example.com/cmd + +go 1.16 + +require example.com/cmd v1.0.0 +-- go.mod -- +module example.com/cmd + +go 1.16 + +require example.com/cmd v1.0.0 +-- a/a.go -- +package main + +func main() {} +-- b/b.go -- +package main + +func main() {} +-- err/err.go -- +package err + +var X = DoesNotCompile diff --git a/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0-replace.txt b/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0-replace.txt new file mode 100644 index 0000000000000000000000000000000000000000..581a496035ec9ee072ca49c929cbd0ca420c893b --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0-replace.txt @@ -0,0 +1,28 @@ +example.com/cmd contains main packages. + +-- .info -- +{"Version":"v1.0.0-replace"} +-- .mod -- +module example.com/cmd + +go 1.16 + +replace rsc.io/quote => rsc.io/quote v1.5.2 +-- go.mod -- +module example.com/cmd + +go 1.16 + +replace rsc.io/quote => rsc.io/quote v1.5.2 +-- a/a.go -- +package main + +func main() {} +-- b/b.go -- +package main + +func main() {} +-- err/err.go -- +package err + +var X = DoesNotCompile diff --git a/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..c1981391a13c74a57b1a326f4cd915b236594208 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_cmd_v1.0.0.txt @@ -0,0 +1,31 @@ +example.com/cmd contains main packages. + +v1.0.0 is the latest non-retracted version. Other versions contain errors or +detectable problems. + +-- .info -- +{"Version":"v1.0.0"} +-- .mod -- +module example.com/cmd + +go 1.16 +-- go.mod -- +module example.com/cmd + +go 1.16 +-- a/a.go -- +package main + +import "fmt" + +func main() { fmt.Println("a@v1.0.0") } +-- b/b.go -- +package main + +import "fmt" + +func main() { fmt.Println("b@v1.0.0") } +-- err/err.go -- +package err + +var X = DoesNotCompile diff --git a/go/src/cmd/go/testdata/mod/example.com_cmd_v1.9.0.txt b/go/src/cmd/go/testdata/mod/example.com_cmd_v1.9.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..9298afb1fb39175e7c936a96785c04f0ebe78c93 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_cmd_v1.9.0.txt @@ -0,0 +1,30 @@ +example.com/cmd contains main packages. + +-- .info -- +{"Version":"v1.9.0"} +-- .mod -- +module example.com/cmd + +go 1.16 + +// this is a bad version +retract v1.9.0 +-- go.mod -- +module example.com/cmd + +go 1.16 + +// this is a bad version +retract v1.9.0 +-- a/a.go -- +package main + +func main() {} +-- b/b.go -- +package main + +func main() {} +-- err/err.go -- +package err + +var X = DoesNotCompile diff --git a/go/src/cmd/go/testdata/mod/example.com_depends_on_generics_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_depends_on_generics_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..80d309552e58bac31a0bc03ab936fc441dfb1dbf --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_depends_on_generics_v1.0.0.txt @@ -0,0 +1,23 @@ +example.com/depends/on/generics v1.0.0 +written by hand + +-- .mod -- +module example.com/depends/on/generics + +go 1.18 + +require example.com/generics v1.0.0 +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module example.com/depends/on/generics + +go 1.18 + +require example.com/generics v1.0.0 +-- main.go -- +package main + +import "example.com/generics" + +func main() {generics.Bar()} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/mod/example.com_deprecated_a_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_deprecated_a_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..252c0b8ddb00be7bf3b3f320b078963ff16d7f50 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_deprecated_a_v1.0.0.txt @@ -0,0 +1,19 @@ +-- .info -- +{"Version":"v1.0.0"} +-- .mod -- +module example.com/deprecated/a + +go 1.17 +-- go.mod -- +module example.com/deprecated/a + +go 1.17 +-- a.go -- +package a + +-- cmd/a/a.go -- +package main + +import "fmt" + +func main() { fmt.Println("a@v1.0.0") } diff --git a/go/src/cmd/go/testdata/mod/example.com_deprecated_a_v1.9.0.txt b/go/src/cmd/go/testdata/mod/example.com_deprecated_a_v1.9.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..bb572958619b763d4cb764cf148fe25f1b721412 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_deprecated_a_v1.9.0.txt @@ -0,0 +1,21 @@ +-- .info -- +{"Version":"v1.9.0"} +-- .mod -- +// Deprecated: in example.com/deprecated/a@v1.9.0 +module example.com/deprecated/a + +go 1.17 +-- go.mod -- +// Deprecated: in example.com/deprecated/a@v1.9.0 +module example.com/deprecated/a + +go 1.17 +-- a.go -- +package a + +-- cmd/a/a.go -- +package main + +import "fmt" + +func main() { fmt.Println("a@v1.9.0") } diff --git a/go/src/cmd/go/testdata/mod/example.com_deprecated_b_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_deprecated_b_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..50006aefb5f3aabeddc1763a1f39f7c74b276252 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_deprecated_b_v1.0.0.txt @@ -0,0 +1,12 @@ +-- .info -- +{"Version":"v1.0.0"} +-- .mod -- +module example.com/deprecated/b + +go 1.17 +-- go.mod -- +module example.com/deprecated/b + +go 1.17 +-- b.go -- +package b diff --git a/go/src/cmd/go/testdata/mod/example.com_deprecated_b_v1.9.0.txt b/go/src/cmd/go/testdata/mod/example.com_deprecated_b_v1.9.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..163d6b543eb7a8ff08f4ad19debf24c4aea21024 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_deprecated_b_v1.9.0.txt @@ -0,0 +1,14 @@ +-- .info -- +{"Version":"v1.9.0"} +-- .mod -- +// Deprecated: in example.com/deprecated/b@v1.9.0 +module example.com/deprecated/b + +go 1.17 +-- go.mod -- +// Deprecated: in example.com/deprecated/b@v1.9.0 +module example.com/deprecated/b + +go 1.17 +-- b.go -- +package b diff --git a/go/src/cmd/go/testdata/mod/example.com_dotgo.go_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_dotgo.go_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..4f7f4d7dd21cf50a507b9bfa56bfc6bf027635b7 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_dotgo.go_v1.0.0.txt @@ -0,0 +1,16 @@ +This module's path ends with ".go". +Based on github.com/nats-io/nats.go. +Used in regression tests for golang.org/issue/32483. + +-- .mod -- +module example.com/dotgo.go + +go 1.13 +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module example.com/dotgo.go + +go 1.13 +-- dotgo.go -- +package dotgo diff --git a/go/src/cmd/go/testdata/mod/example.com_dotname_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_dotname_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..2ada3a3f812af60861577b2383c619fde64c4126 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_dotname_v1.0.0.txt @@ -0,0 +1,12 @@ +-- .info -- +{"Version":"v1.0.0"} +-- .mod -- +module example.com/dotname + +go 1.16 +-- go.mod -- +module example.com/dotname + +go 1.16 +-- .dot/dot.go -- +package dot diff --git a/go/src/cmd/go/testdata/mod/example.com_downgrade_v2.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_downgrade_v2.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..88d50e5bbab8d6578a693e6865674b20b0936f1d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_downgrade_v2.0.0.txt @@ -0,0 +1,9 @@ +example.com/downgrade v2.0.0 +written by hand + +-- .mod -- +module example.com/downgrade + +require rsc.io/quote v1.5.2 +-- .info -- +{"Version":"v2.0.0"} diff --git a/go/src/cmd/go/testdata/mod/example.com_downgrade_v2_v2.0.1.txt b/go/src/cmd/go/testdata/mod/example.com_downgrade_v2_v2.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..a4d665ff1be4f0dab02b1bf4d340538a4d3216e9 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_downgrade_v2_v2.0.1.txt @@ -0,0 +1,13 @@ +example.com/downgrade/v2 v2.0.1 +written by hand + +-- .mod -- +module example.com/downgrade/v2 + +require rsc.io/quote v1.5.2 +-- .info -- +{"Version":"v2.0.1"} +-- go.mod -- +module example.com/downgrade/v2 + +require rsc.io/quote v1.5.2 diff --git a/go/src/cmd/go/testdata/mod/example.com_fuzzfail_v0.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_fuzzfail_v0.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..af005ffb4119080e158cd4b9cd7ce44d0b951112 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_fuzzfail_v0.1.0.txt @@ -0,0 +1,20 @@ +-- .mod -- +module example.com/fuzzfail + +go 1.18 +-- .info -- +{"Version":"v0.1.0"} +-- go.mod -- +module example.com/fuzzfail + +go 1.18 +-- fuzzfail_test.go -- +package fuzzfail + +import "testing" + +func FuzzFail(f *testing.F) { + f.Fuzz(func(t *testing.T, b []byte) { + t.Fatalf("oops: %q", b) + }) +} diff --git a/go/src/cmd/go/testdata/mod/example.com_fuzzfail_v0.2.0.txt b/go/src/cmd/go/testdata/mod/example.com_fuzzfail_v0.2.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..ea599aa61109aa2138746686412c0d035582c2ea --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_fuzzfail_v0.2.0.txt @@ -0,0 +1,23 @@ +-- .mod -- +module example.com/fuzzfail + +go 1.18 +-- .info -- +{"Version":"v0.2.0"} +-- go.mod -- +module example.com/fuzzfail + +go 1.18 +-- fuzzfail_test.go -- +package fuzzfail + +import "testing" + +func FuzzFail(f *testing.F) { + f.Fuzz(func(t *testing.T, b []byte) { + t.Fatalf("oops: %q", b) + }) +} +-- testdata/fuzz/FuzzFail/bbb0c2d22aa1a24617301566dc7486f8b625d38024603ba62757c1124013b49a -- +go test fuzz v1 +[]byte("\x05") diff --git a/go/src/cmd/go/testdata/mod/example.com_generics_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_generics_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..092241e93b20be4ed0accc4a54417277d0aed694 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_generics_v1.0.0.txt @@ -0,0 +1,21 @@ +example.com/generics v1.0.0 +written by hand + +-- .mod -- +module example.com/generics + +go 1.18 +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module example.com/generics + +go 1.18 +-- generics.go -- +package generics + +type Int interface { + ~int +} + +func Bar() {} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/mod/example.com_ignore_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_ignore_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..ed205844229de6c2695454f7e9c50d851b1e6e6c --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_ignore_v1.0.0.txt @@ -0,0 +1,11 @@ +-- .mod -- +module example.com/ignore + +ignore ./foo +-- .info -- +{"Version":"v1.0.0"} + +-- foo/foo.go -- +package foo + +const Bar = "Hello from foo!" \ No newline at end of file diff --git a/go/src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..435578da8d8a5d7da42a1ad0446749e76e399ded --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v1.0.0.txt @@ -0,0 +1,8 @@ +Module example.com/incompatiblewithsub has an incompatible version +and a package in a subdirectory. +-- .info -- +{"Version":"v1.0.0"} +-- .mod -- +module example.com/incompatiblewithsub +-- sub/sub.go -- +package sub diff --git a/go/src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v2.0.0+incompatible.txt b/go/src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v2.0.0+incompatible.txt new file mode 100644 index 0000000000000000000000000000000000000000..198ec1702bdebbcffd3b96ad34328dc40bb9e933 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_incompatiblewithsub_v2.0.0+incompatible.txt @@ -0,0 +1,8 @@ +Module example.com/incompatiblewithsub has an incompatible version +and a package in a subdirectory. +-- .info -- +{"Version":"v2.0.0+incompatible"} +-- .mod -- +module example.com/incompatiblewithsub +-- sub/sub.go -- +package sub diff --git a/go/src/cmd/go/testdata/mod/example.com_invalidpath_v1_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_invalidpath_v1_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..7d9d1303a9043c2a9c7cf6015e2fc66d8da3f226 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_invalidpath_v1_v1.0.0.txt @@ -0,0 +1,13 @@ +example.com/invalidpath/v1 v1.0.0 +written by hand + +-- .mod -- +module example.com/invalidpath/v1 +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module example.com/invalidpath/v1 +-- version.go -- +package version + +const V = "v1.0.0" diff --git a/go/src/cmd/go/testdata/mod/example.com_join_subpkg_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_join_subpkg_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..1ecfa0b6de97248921e6bd89c6f66e138f208ce7 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_join_subpkg_v1.0.0.txt @@ -0,0 +1,9 @@ +Written by hand. +Test case for package moved into a parent module. + +-- .mod -- +module example.com/join/subpkg +-- .info -- +{"Version": "v1.0.0"} +-- x.go -- +package subpkg diff --git a/go/src/cmd/go/testdata/mod/example.com_join_subpkg_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_join_subpkg_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..9eb823adb76c0219b5f03e8674d9609f9ec4e4b2 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_join_subpkg_v1.1.0.txt @@ -0,0 +1,9 @@ +Written by hand. +Test case for package moved into a parent module. + +-- .mod -- +module example.com/join/subpkg + +require example.com/join v1.1.0 +-- .info -- +{"Version": "v1.1.0"} diff --git a/go/src/cmd/go/testdata/mod/example.com_join_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_join_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..84c68b13b6de6238856aab8a1e9547dcf47f9556 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_join_v1.0.0.txt @@ -0,0 +1,7 @@ +Written by hand. +Test case for package moved into a parent module. + +-- .mod -- +module example.com/join +-- .info -- +{"Version": "v1.0.0"} diff --git a/go/src/cmd/go/testdata/mod/example.com_join_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_join_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..5f92036d9e7b248f14a14f4f652f73152a001e0f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_join_v1.1.0.txt @@ -0,0 +1,9 @@ +Written by hand. +Test case for package moved into a parent module. + +-- .mod -- +module example.com/join +-- .info -- +{"Version": "v1.1.0"} +-- subpkg/x.go -- +package subpkg diff --git a/go/src/cmd/go/testdata/mod/example.com_latemigrate_v2_v2.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_latemigrate_v2_v2.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..25bd3d9d8fa2e802965bb851d45453dc2cbf4be5 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_latemigrate_v2_v2.0.0.txt @@ -0,0 +1,14 @@ +example.com/latemigrate/v2 v2.0.0 +written by hand + +This repository migrated to modules in v2.0.1 after v2.0.0 was already tagged. +All versions require rsc.io/quote so we can test downgrades. + +v2.0.0 is technically part of example.com/latemigrate as v2.0.0+incompatible. +Proxies may serve it as part of the version list for example.com/latemigrate/v2. +'go get' must be able to ignore these versions. + +-- .mod -- +module example.com/latemigrate +-- .info -- +{"Version":"v2.0.0"} diff --git a/go/src/cmd/go/testdata/mod/example.com_latemigrate_v2_v2.0.1.txt b/go/src/cmd/go/testdata/mod/example.com_latemigrate_v2_v2.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..be427a3185d693b901302fc0405ebfb4f0079dfb --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_latemigrate_v2_v2.0.1.txt @@ -0,0 +1,20 @@ +example.com/latemigrate/v2 v2.0.1 +written by hand + +This repository migrated to modules in v2.0.1 after v2.0.0 was already tagged. +All versions require rsc.io/quote so we can test downgrades. + +v2.0.1 belongs to example.com/latemigrate/v2. + +-- .mod -- +module example.com/latemigrate/v2 + +require rsc.io/quote v1.3.0 +-- .info -- +{"Version":"v2.0.1"} +-- go.mod -- +module example.com/latemigrate/v2 + +require rsc.io/quote v1.3.0 +-- late.go -- +package late diff --git a/go/src/cmd/go/testdata/mod/example.com_missingpkg_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_missingpkg_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..15f3f69557d1ddf54ae15c86d6fc88e3832f10e1 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_missingpkg_v1.0.0.txt @@ -0,0 +1,11 @@ +The deprecated package is present in this version (which is @latest) but +is deleted in a newer prerelease version. + +-- .mod -- +module example.com/missingpkg +-- .info -- +{"Version":"v1.0.0"} +-- lib.go -- +package lib +-- deprecated/deprecated.go -- +package deprecated diff --git a/go/src/cmd/go/testdata/mod/example.com_missingpkg_v1.0.1-beta.txt b/go/src/cmd/go/testdata/mod/example.com_missingpkg_v1.0.1-beta.txt new file mode 100644 index 0000000000000000000000000000000000000000..44580fe4cbe3900ba21de34bc9562950b3cc1e08 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_missingpkg_v1.0.1-beta.txt @@ -0,0 +1,8 @@ +The deprecated package is deleted in this version. + +-- .mod -- +module example.com/missingpkg +-- .info -- +{"Version":"v1.0.1-beta"} +-- lib.go -- +package lib diff --git a/go/src/cmd/go/testdata/mod/example.com_nest_sub_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_nest_sub_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..90f1459803944054313dec639e713e95f9316773 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_nest_sub_v1.0.0.txt @@ -0,0 +1,12 @@ +Written by hand. +Test case for nested modules without an explicit relationship. +This is nested below the top-level module. + +-- .mod -- +module example.com/nest/sub +-- .info -- +{"Version": "v1.0.0"} +-- go.mod -- +module example.com/nest/sub +-- y/y.go -- +package y diff --git a/go/src/cmd/go/testdata/mod/example.com_nest_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_nest_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..593caf1d90abe48bd1d9476644ac0bab517971af --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_nest_v1.0.0.txt @@ -0,0 +1,12 @@ +Written by hand. +Test case for nested modules without an explicit relationship. +This is the top-level module. + +-- .mod -- +module example.com/nest +-- .info -- +{"Version": "v1.0.0"} +-- go.mod -- +module example.com/nest +-- sub/x/x.go -- +package x diff --git a/go/src/cmd/go/testdata/mod/example.com_nest_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_nest_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..5a01550fd5d075167d7bfce1413bcf2dad1a090b --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_nest_v1.1.0.txt @@ -0,0 +1,12 @@ +Written by hand. +Test case for nested modules without an explicit relationship. +This is the top-level module. + +-- .mod -- +module example.com/nest +-- .info -- +{"Version": "v1.1.0"} +-- go.mod -- +module example.com/nest +-- sub/x/x.go -- +package x diff --git a/go/src/cmd/go/testdata/mod/example.com_newcycle_a_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_newcycle_a_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..829065df9fb96989d2f9aa70e220f1fb75750396 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_newcycle_a_v1.0.0.txt @@ -0,0 +1,10 @@ +example.com/newcycle/a v1.0.0 + +Transitively requires v1.0.1 of itself via example.com/newcycle/b + +-- .mod -- +module example.com/newcycle/a + +require example.com/newcycle/b v1.0.0 +-- .info -- +{"Version":"v1.0.0"} diff --git a/go/src/cmd/go/testdata/mod/example.com_newcycle_a_v1.0.1.txt b/go/src/cmd/go/testdata/mod/example.com_newcycle_a_v1.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..a03f4b49fd5ec51f0c5196f2390163f0d90840ca --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_newcycle_a_v1.0.1.txt @@ -0,0 +1,10 @@ +example.com/newcycle/a v1.0.1 + +Transitively requires itself via example.com/newcycle/b + +-- .mod -- +module example.com/newcycle/a + +require example.com/newcycle/b v1.0.0 +-- .info -- +{"Version":"v1.0.1"} diff --git a/go/src/cmd/go/testdata/mod/example.com_newcycle_b_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_newcycle_b_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..ff9e1f5ea5fa6e769071f37a022f7797cc817253 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_newcycle_b_v1.0.0.txt @@ -0,0 +1,8 @@ +example.com/newcycle/b v1.0.0 + +-- .mod -- +module example.com/newcycle/b + +require example.com/newcycle/a v1.0.1 +-- .info -- +{"Version":"v1.0.0"} diff --git a/go/src/cmd/go/testdata/mod/example.com_noroot_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_noroot_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..aa5febf71056fd75dd32f9c05ade375026e36cb0 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_noroot_v1.0.0.txt @@ -0,0 +1,8 @@ +A module which has no root package. + +-- .mod -- +module example.com/noroot +-- .info -- +{"Version":"v1.0.0"} +-- pkg/pkg.go -- +package pkg diff --git a/go/src/cmd/go/testdata/mod/example.com_noroot_v1.0.1.txt b/go/src/cmd/go/testdata/mod/example.com_noroot_v1.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..9b93717c84f48e36a7b812c6f5c7d3b9b20db1a1 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_noroot_v1.0.1.txt @@ -0,0 +1,8 @@ +A module which has no root package. + +-- .mod -- +module example.com/noroot +-- .info -- +{"Version":"v1.0.1"} +-- pkg/pkg.go -- +package pkg diff --git a/go/src/cmd/go/testdata/mod/example.com_notags_v0.0.0-20190507143103-cc8cbe209b64.txt b/go/src/cmd/go/testdata/mod/example.com_notags_v0.0.0-20190507143103-cc8cbe209b64.txt new file mode 100644 index 0000000000000000000000000000000000000000..259774d542554c675a3c83f056d0be544a1f2b94 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_notags_v0.0.0-20190507143103-cc8cbe209b64.txt @@ -0,0 +1,9 @@ +Written by hand. +The "latest" version of a module without any tags. + +-- .mod -- +module example.com/notags +-- .info -- +{"Version":"v0.0.0-20190507143103-cc8cbe209b64","Time":"2019-05-07T07:31:03-07:00"} +-- notags.go -- +package notags diff --git a/go/src/cmd/go/testdata/mod/example.com_printversion_v0.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_printversion_v0.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..606322ac862fe5c15672a61e71847e3f0d8dd2fc --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_printversion_v0.1.0.txt @@ -0,0 +1,33 @@ +example.com/printversion v0.1.0 + +-- .mod -- +module example.com/printversion +-- .info -- +{"Version":"v0.1.0"} +-- README.txt -- +There is no go.mod file for this version of the module. +-- printversion.go -- +package main + +import ( + "fmt" + "os" + "runtime/debug" + + _ "example.com/version" +) + +func main() { + info, _ := debug.ReadBuildInfo() + fmt.Fprintf(os.Stdout, "path is %s\n", info.Path) + fmt.Fprintf(os.Stdout, "main is %s %s\n", info.Main.Path, info.Main.Version) + if r := info.Main.Replace; r != nil { + fmt.Fprintf(os.Stdout, "\t(replaced by %s %s)\n", r.Path, r.Version) + } + for _, m := range info.Deps { + fmt.Fprintf(os.Stdout, "using %s %s\n", m.Path, m.Version) + if r := m.Replace; r != nil { + fmt.Fprintf(os.Stdout, "\t(replaced by %s %s)\n", r.Path, r.Version) + } + } +} diff --git a/go/src/cmd/go/testdata/mod/example.com_printversion_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_printversion_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..b9b71e953825aef26891a3d9c9d8d51276371189 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_printversion_v1.0.0.txt @@ -0,0 +1,41 @@ +example.com/printversion v1.0.0 + +-- .mod -- +module example.com/printversion + +require example.com/version v1.0.0 +replace example.com/version v1.0.0 => ../oops v0.0.0 +exclude example.com/version v1.1.0 +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module example.com/printversion + +require example.com/version v1.0.0 +replace example.com/version v1.0.0 => ../oops v0.0.0 +exclude example.com/version v1.0.1 +-- printversion.go -- +package main + +import ( + "fmt" + "os" + "runtime/debug" + + _ "example.com/version" +) + +func main() { + info, _ := debug.ReadBuildInfo() + fmt.Fprintf(os.Stdout, "path is %s\n", info.Path) + fmt.Fprintf(os.Stdout, "main is %s %s\n", info.Main.Path, info.Main.Version) + if r := info.Main.Replace; r != nil { + fmt.Fprintf(os.Stdout, "\t(replaced by %s %s)\n", r.Path, r.Version) + } + for _, m := range info.Deps { + fmt.Fprintf(os.Stdout, "using %s %s\n", m.Path, m.Version) + if r := m.Replace; r != nil { + fmt.Fprintf(os.Stdout, "\t(replaced by %s %s)\n", r.Path, r.Version) + } + } +} diff --git a/go/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.0.0-20190430073000-30950c05d534.txt b/go/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.0.0-20190430073000-30950c05d534.txt new file mode 100644 index 0000000000000000000000000000000000000000..047ceb68c5b55caa73e98695cdb48a22754b1bcf --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.0.0-20190430073000-30950c05d534.txt @@ -0,0 +1,13 @@ +example.com/pseudoupgrade v0.0.0-20190429073000-30950c05d534 +written by hand + +-- .mod -- +module example.com/pseudoupgrade + +-- .info -- +{"Version":"v0.0.0-20190430073000-30950c05d534","Name":"v0.0.0-20190430073000-30950c05d534","Short":"30950c05d534","Time":"2019-04-30T07:30:00Z"} + +-- pseudoupgrade.go -- +package pseudoupgrade + +const X = 1 diff --git a/go/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..7ddb0dc724d5ba0ceb1695cab5b10dff222fc173 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.0.txt @@ -0,0 +1,13 @@ +example.com/pseudoupgrade v0.1.0 +written by hand + +-- .mod -- +module example.com/pseudoupgrade + +-- .info -- +{"Version":"v0.1.0","Name":"","Short":"","Time":"2019-04-29T07:30:30Z"} + +-- pseudoupgrade.go -- +package pseudoupgrade + +const X = 1 diff --git a/go/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.1-0.20190429073117-b5426c86b553.txt b/go/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.1-0.20190429073117-b5426c86b553.txt new file mode 100644 index 0000000000000000000000000000000000000000..b3f48bbdab6cec1112aed97240b9e5aa879bd566 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.1-0.20190429073117-b5426c86b553.txt @@ -0,0 +1,13 @@ +example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553 +written by hand + +-- .mod -- +module example.com/pseudoupgrade + +-- .info -- +{"Version":"v0.1.1-0.20190429073117-b5426c86b553","Name":"v0.1.1-0.20190429073117-b5426c86b553","Short":"b5426c86b553","Time":"2019-04-29T07:31:00Z"} + +-- pseudoupgrade.go -- +package pseudoupgrade + +const X = 1 diff --git a/go/src/cmd/go/testdata/mod/example.com_quote_v1.5.2.txt b/go/src/cmd/go/testdata/mod/example.com_quote_v1.5.2.txt new file mode 100644 index 0000000000000000000000000000000000000000..05f7ae28a396a1174b27cb1922908f19f09ea68f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_quote_v1.5.2.txt @@ -0,0 +1,9 @@ +This module is a replacement for rsc.io/quote, but its go.mod file declares +a module path different from its location and the original module. + +-- .mod -- +module rsc.io/Quote + +go 1.14 +-- .info -- +{"Version":"v1.5.2"} diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_ambiguous_nested_v1.9.0-bad.txt b/go/src/cmd/go/testdata/mod/example.com_retract_ambiguous_nested_v1.9.0-bad.txt new file mode 100644 index 0000000000000000000000000000000000000000..f8e623d56f7818f68f6c65dfed6e199f1da2314e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_ambiguous_nested_v1.9.0-bad.txt @@ -0,0 +1,10 @@ +-- .mod -- +module example.com/retract/ambiguous/nested + +go 1.16 + +retract v1.9.0-bad // nested modules are bad +-- .info -- +{"Version":"v1.9.0-bad"} +-- nested.go -- +package nested diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_ambiguous_other_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_ambiguous_other_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ee01391a2423eff055d8aae097cb5d03c93f115 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_ambiguous_other_v1.0.0.txt @@ -0,0 +1,12 @@ +-- .mod -- +module example.com/retract/ambiguous/other + +go 1.16 + +require example.com/retract/ambiguous v1.0.0 +-- .info -- +{"Version":"v1.0.0"} +-- other.go -- +package other + +import _ "example.com/retract/ambiguous/nested" diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_ambiguous_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_ambiguous_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..c8eeb1654f355f6d974806299ea10f47fc2e275a --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_ambiguous_v1.0.0.txt @@ -0,0 +1,9 @@ +-- .mod -- +module example.com/retract/ambiguous + +go 1.16 +-- .info -- +{"Version":"v1.0.0"} +-- nested/nested.go -- +package nested + diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_incompatible_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_incompatible_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..a987685e248b7a45130289660f20e759653b7266 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_incompatible_v1.0.0.txt @@ -0,0 +1,19 @@ +The v1.0.0 release of example.com/retract/incompatible retracts +v2.0.0+incompatible. + +-- .mod -- +module example.com/retract/incompatible + +go 1.16 + +retract v2.0.0+incompatible +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module example.com/retract/incompatible + +go 1.16 + +retract v2.0.0+incompatible +-- incompatible.go -- +package incompatible diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_incompatible_v2.0.0+incompatible.txt b/go/src/cmd/go/testdata/mod/example.com_retract_incompatible_v2.0.0+incompatible.txt new file mode 100644 index 0000000000000000000000000000000000000000..c668dbb7a9411c44d41a481a010601ae3ffe35b2 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_incompatible_v2.0.0+incompatible.txt @@ -0,0 +1,9 @@ +The v1.0.0 release of example.com/retract/incompatible retracts +v2.0.0+incompatible. + +-- .mod -- +module example.com/retract/incompatible +-- .info -- +{"Version":"v2.0.0+incompatible"} +-- incompatible.go -- +package incompatible diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_missingmod_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_missingmod_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..1d8d81071ee0e2ea33867938b9663d9e7cc7978d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_missingmod_v1.0.0.txt @@ -0,0 +1,10 @@ +This version should be retracted, but the go.mod file for the version that would +contain the retraction is not available. +-- .mod -- +module example.com/retract/missingmod + +go 1.14 +-- .info -- +{"Version":"v1.0.0"} +-- missingmod.go -- +package missingmod diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_missingmod_v1.9.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_missingmod_v1.9.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..bba919ec213e211114b8798f48968bbe7b276374 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_missingmod_v1.9.0.txt @@ -0,0 +1,4 @@ +The go.mod file at this version will be loaded to check for retractions +of earlier versions. However, the .mod file is not available. +-- .info -- +{"Version":"v1.9.0"} diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..21d53529842e8e257a5d0e86e2e7ef63e0a1c84d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.0.0.txt @@ -0,0 +1,10 @@ +-- .mod -- +module example.com/retract/newergoversion + +go 1.21 + +-- .info -- +{"Version":"v1.0.0"} + +-- retract.go -- +package newergoversion \ No newline at end of file diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.2.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.2.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..7aa28b90e3ab9b7cd34a59c32e7c6bcfccf3791d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.2.0.txt @@ -0,0 +1,12 @@ +-- .mod -- +module example.com/retract/newergoversion + +go 1.23 + +retract v1.2.0 + +-- .info -- +{"Version":"v1.2.0"} + +-- retract.go -- +package newergoversion diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_noupgrade_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_noupgrade_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..466afc576577c4a54271c9acf6fd2618ce9cfa9d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_noupgrade_v1.0.0.txt @@ -0,0 +1,9 @@ +-- .mod -- +module example.com/retract/noupgrade + +go 1.19 + +retract v1.0.0 // bad + +-- .info -- +{"Version":"v1.0.0"} diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-block.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-block.txt new file mode 100644 index 0000000000000000000000000000000000000000..c4a53e1d80eac4d7c505b836acdaa0c79997aa96 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-block.txt @@ -0,0 +1,6 @@ +-- .mod -- +module example.com/retract/rationale + +go 1.14 +-- .info -- +{"Version":"v1.0.0-block"} diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-blockwithcomment.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-blockwithcomment.txt new file mode 100644 index 0000000000000000000000000000000000000000..92573b62e3679ab6d4207406d09bf58e4e195b30 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-blockwithcomment.txt @@ -0,0 +1,6 @@ +-- .mod -- +module example.com/retract/rationale + +go 1.14 +-- .info -- +{"Version":"v1.0.0-blockwithcomment"} diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-empty.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-empty.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f0894aa8bea1323ce3c4336355f0f93e0746cb0 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-empty.txt @@ -0,0 +1,8 @@ +-- .mod -- +module example.com/retract/rationale + +go 1.14 +-- .info -- +{"Version":"v1.0.0-empty"} +-- empty.go -- +package empty diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-long.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-long.txt new file mode 100644 index 0000000000000000000000000000000000000000..1b5e7534285de0b511458f33a923acf4e408e267 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-long.txt @@ -0,0 +1,8 @@ +-- .mod -- +module example.com/retract/rationale + +go 1.14 +-- .info -- +{"Version":"v1.0.0-long"} +-- empty.go -- +package empty diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-multiline1.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-multiline1.txt new file mode 100644 index 0000000000000000000000000000000000000000..b1ffe27225066d9160687ab7939991b9f6970fb6 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-multiline1.txt @@ -0,0 +1,8 @@ +-- .mod -- +module example.com/retract/rationale + +go 1.14 +-- .info -- +{"Version":"v1.0.0-multiline1"} +-- empty.go -- +package empty diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-multiline2.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-multiline2.txt new file mode 100644 index 0000000000000000000000000000000000000000..72f80b3254106bf084ef6bbd1a0397661abcae8a --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-multiline2.txt @@ -0,0 +1,8 @@ +-- .mod -- +module example.com/retract/rationale + +go 1.14 +-- .info -- +{"Version":"v1.0.0-multiline2"} +-- empty.go -- +package empty diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-order.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-order.txt new file mode 100644 index 0000000000000000000000000000000000000000..1b0450462b0c0962f048d44d5d86857b07c43336 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-order.txt @@ -0,0 +1,6 @@ +-- .mod -- +module example.com/retract/rationale + +go 1.14 +-- .info -- +{"Version":"v1.0.0-order"} diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-unprintable.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-unprintable.txt new file mode 100644 index 0000000000000000000000000000000000000000..949612431e5d17b6071f3cc63afefa430792cb82 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.0-unprintable.txt @@ -0,0 +1,8 @@ +-- .mod -- +module example.com/retract/rationale + +go 1.14 +-- .info -- +{"Version":"v1.0.0-unprintable"} +-- empty.go -- +package empty diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.1-order.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.1-order.txt new file mode 100644 index 0000000000000000000000000000000000000000..3be7d5b56e4b22198954564bff39c7ef499b3a77 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.0.1-order.txt @@ -0,0 +1,6 @@ +-- .mod -- +module example.com/retract/rationale + +go 1.14 +-- .info -- +{"Version":"v1.0.1-order"} diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.9.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.9.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..6975d4ebd4dd93b13159bce97d4e539c851285fc --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rationale_v1.9.0.txt @@ -0,0 +1,48 @@ +Module example.com/retract/description retracts all versions of itself. +The rationale comments have various problems. + +-- .mod -- +module example.com/retract/rationale + +go 1.14 + +retract ( + v1.0.0-empty + + // short description + // more + // + // detail + v1.0.0-multiline1 // suffix + // after not included +) + +// short description +// more +// +// detail +retract v1.0.0-multiline2 // suffix + +// loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong +retract v1.0.0-long + +// Ends with a BEL character. Beep! +retract v1.0.0-unprintable + +// block comment +retract ( + v1.0.0-block + + // inner comment + v1.0.0-blockwithcomment +) + +retract ( + [v1.0.0-order, v1.0.0-order] // degenerate range + v1.0.0-order // single version + + v1.0.1-order // single version + [v1.0.1-order, v1.0.1-order] // degenerate range +) +-- .info -- +{"Version":"v1.9.0"} diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rename_v1.0.0-bad.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rename_v1.0.0-bad.txt new file mode 100644 index 0000000000000000000000000000000000000000..25c4ff1b1f9e2dfa4fd5f28fb2655d76899bf5d1 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rename_v1.0.0-bad.txt @@ -0,0 +1,16 @@ +Module example.com/retract/rename is renamed in a later version. + +This happens frequently when a repository is renamed or when a go.mod file +is added for the first time with a custom module path. +-- .info -- +{"Version":"v1.0.0-bad"} +-- .mod -- +module example.com/retract/rename + +go 1.16 +-- go.mod -- +module example.com/retract/rename + +go 1.16 +-- rename.go -- +package rename diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_rename_v1.9.0-new.txt b/go/src/cmd/go/testdata/mod/example.com_retract_rename_v1.9.0-new.txt new file mode 100644 index 0000000000000000000000000000000000000000..9c08f713c40a6fbf88606de596248aaef57cd837 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_rename_v1.9.0-new.txt @@ -0,0 +1,22 @@ +Module example.com/retract/rename is renamed in this version. + +This happens frequently when a repository is renamed or when a go.mod file +is added for the first time with a custom module path. +-- .info -- +{"Version":"v1.9.0-new"} +-- .mod -- +module example.com/retract/newname + +go 1.16 + +// bad +retract v1.0.0-bad +-- go.mod -- +module example.com/retract/newname + +go 1.16 + +// bad +retract v1.0.0-bad +-- newname.go -- +package newname diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_self_all_v1.9.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_self_all_v1.9.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..4dc486b599801e3ef470df119c3f136ccf1d6659 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_self_all_v1.9.0.txt @@ -0,0 +1,14 @@ +Module example.com/retract/self/prev is a module that retracts its own +latest version. + +No unretracted versions are available. + +-- .mod -- +module example.com/retract/self/all + +go 1.15 + +retract v1.9.0 // bad + +-- .info -- +{"Version":"v1.9.0"} diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_self_prerelease_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_self_prerelease_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..04c28455d76d903fea3cf65e2bea8e9f9acfe900 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_self_prerelease_v1.0.0.txt @@ -0,0 +1,16 @@ +Module example.com/retract/self/prerelease is a module that retracts its own +latest version and all other release version. + +A pre-release version higher than the highest release version is still +available, and that should be matched by @latest. + +-- .mod -- +module example.com/retract/self/prerelease + +go 1.15 + +-- .info -- +{"Version":"v1.0.0"} + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_self_prerelease_v1.9.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_self_prerelease_v1.9.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..7c1c047e69e8b97d955c48521f1a44d7b093af9d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_self_prerelease_v1.9.0.txt @@ -0,0 +1,19 @@ +Module example.com/retract/self/prerelease is a module that retracts its own +latest version and all other release version. + +A pre-release version higher than the highest release version is still +available, and that should be matched by @latest. + +-- .mod -- +module example.com/retract/self/prerelease + +go 1.15 + +retract v1.0.0 // bad +retract v1.9.0 // self + +-- .info -- +{"Version":"v1.9.0"} + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_self_prerelease_v1.9.1-pre.txt b/go/src/cmd/go/testdata/mod/example.com_retract_self_prerelease_v1.9.1-pre.txt new file mode 100644 index 0000000000000000000000000000000000000000..abf44fdae14fcb41ae10bbe9e36d7ea4e8c23645 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_self_prerelease_v1.9.1-pre.txt @@ -0,0 +1,16 @@ +Module example.com/retract/self/prerelease is a module that retracts its own +latest version and all other release version. + +A pre-release version higher than the highest release version is still +available, and that should be matched by @latest. + +-- .mod -- +module example.com/retract/self/prerelease + +go 1.15 + +-- .info -- +{"Version":"v1.9.1-pre"} + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_self_prev_v1.0.0-bad.txt b/go/src/cmd/go/testdata/mod/example.com_retract_self_prev_v1.0.0-bad.txt new file mode 100644 index 0000000000000000000000000000000000000000..095063d69b2d6b23786f2b887a86ff8f3205d2c9 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_self_prev_v1.0.0-bad.txt @@ -0,0 +1,14 @@ +See example.com_retract_self_prev_v1.9.0.txt. + +This version is retracted. + +-- .mod -- +module example.com/retract/self/prev + +go 1.15 + +-- .info -- +{"Version":"v1.0.0-bad"} + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_self_prev_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_self_prev_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..27c3a390655a213a619cb727c71470c687e5fcf7 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_self_prev_v1.1.0.txt @@ -0,0 +1,14 @@ +See example.com_retract_self_pref_v1.9.0.txt. + +This version is the latest (only) non-retracted version. + +-- .mod -- +module example.com/retract/self/prev + +go 1.15 + +-- .info -- +{"Version":"v1.1.0"} + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_self_prev_v1.9.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_self_prev_v1.9.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..03d6168f0d19d0b552c370681d742361a3b5baee --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_self_prev_v1.9.0.txt @@ -0,0 +1,18 @@ +Module example.com/retract/self/prev is a module that retracts its own +latest version, as well as an earlier version. + +A previous unretracted release version, v1.1.0, is still available. + +-- .mod -- +module example.com/retract/self/prev + +go 1.15 + +retract v1.0.0-bad // bad +retract v1.9.0 // self + +-- .info -- +{"Version":"v1.9.0"} + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_self_pseudo_v0.0.0-20200325131415-0123456789ab b/go/src/cmd/go/testdata/mod/example.com_retract_self_pseudo_v0.0.0-20200325131415-0123456789ab new file mode 100644 index 0000000000000000000000000000000000000000..f9ab41e88f9ea342f8c02aae72a3c9ce350dc0d9 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_self_pseudo_v0.0.0-20200325131415-0123456789ab @@ -0,0 +1,20 @@ +See example.com_retract_self_pseudo_v1.9.0.txt. + +This version is not retracted. It should be returned by the proxy's +@latest endpoint. It should match the @latest version query. + +TODO(golang.org/issue/24031): the proxy and proxy.golang.org both return +the highest release version from the @latest endpoint, even if that +version is retracted, so there is no way for the go command to +discover an unretracted pseudo-version. + +-- .mod -- +module example.com/retract/self/pseudo + +go 1.15 + +-- .info -- +{"Version":"v0.0.0-20200325131415-01234567890ab"} + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_self_pseudo_v1.0.0-bad.txt b/go/src/cmd/go/testdata/mod/example.com_retract_self_pseudo_v1.0.0-bad.txt new file mode 100644 index 0000000000000000000000000000000000000000..d47eda05977544b762e592e296df8b49b6718d9e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_self_pseudo_v1.0.0-bad.txt @@ -0,0 +1,14 @@ +See example.com_retract_self_pseudo_v1.9.0.txt. + +This version is retracted. + +-- .mod -- +module example.com/retract/self/pseudo + +go 1.15 + +-- .info -- +{"Version":"v1.0.0-bad"} + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_self_pseudo_v1.9.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_self_pseudo_v1.9.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..db09cc6a5f405d16f2e544aa25ec199f3a0fc98e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_self_pseudo_v1.9.0.txt @@ -0,0 +1,16 @@ +Module example.com/retract/self/pseudo is a module that retracts its own +latest version, as well as an earlier version. + +An unretracted pseudo-version is available. + +-- .mod -- +module example.com/retract/self/pseudo + +go 1.15 + +retract v1.0.0-bad // bad +retract v1.9.0 // self + +-- .info -- +{"Version":"v1.9.0"} + diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_v1.0.0-bad.txt b/go/src/cmd/go/testdata/mod/example.com_retract_v1.0.0-bad.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f996cfc366cf2df450b1efe89c6a0add3c2543f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_v1.0.0-bad.txt @@ -0,0 +1,10 @@ +-- .mod -- +module example.com/retract + +go 1.15 + +-- .info -- +{"Version":"v1.0.0-bad"} + +-- retract.go -- +package retract diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_v1.0.0-good.txt b/go/src/cmd/go/testdata/mod/example.com_retract_v1.0.0-good.txt new file mode 100644 index 0000000000000000000000000000000000000000..78152bba4fad7231e5c7af93869bf31423566a7d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_v1.0.0-good.txt @@ -0,0 +1,10 @@ +-- .mod -- +module example.com/retract + +go 1.15 + +-- .info -- +{"Version":"v1.0.0-good"} + +-- retract.go -- +package retract diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_v1.0.0-unused.txt b/go/src/cmd/go/testdata/mod/example.com_retract_v1.0.0-unused.txt new file mode 100644 index 0000000000000000000000000000000000000000..3bc9e35b7c5f702a2f33021d644fe4030ac3fbf0 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_v1.0.0-unused.txt @@ -0,0 +1,10 @@ +-- .mod -- +module example.com/retract + +go 1.15 + +-- .info -- +{"Version":"v1.0.0-unused"} + +-- retract.go -- +package retract diff --git a/go/src/cmd/go/testdata/mod/example.com_retract_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_retract_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..18d6d832e2ba22505f6655da5d4ac71311ce4fcd --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_retract_v1.1.0.txt @@ -0,0 +1,13 @@ +-- .mod -- +module example.com/retract + +go 1.15 + +retract v1.0.0-bad // bad +retract v1.0.0-unused // bad + +-- .info -- +{"Version":"v1.1.0"} + +-- retract.go -- +package retract diff --git a/go/src/cmd/go/testdata/mod/example.com_split-incompatible_subpkg_v0.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_split-incompatible_subpkg_v0.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..edf5d487885d4293a7178464953ebfa3a9dcd3a5 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_split-incompatible_subpkg_v0.1.0.txt @@ -0,0 +1,14 @@ +Written by hand. +Test case for getting a package that has been moved to a nested module, +with a +incompatible version (and thus no go.mod file) at the root module. + +-- .mod -- +module example.com/split-incompatible/subpkg +-- .info -- +{"Version": "v0.1.0"} +-- go.mod -- +module example.com/split-incompatible/subpkg + +go 1.16 +-- subpkg.go -- +package subpkg diff --git a/go/src/cmd/go/testdata/mod/example.com_split-incompatible_v2.0.0+incompatible.txt b/go/src/cmd/go/testdata/mod/example.com_split-incompatible_v2.0.0+incompatible.txt new file mode 100644 index 0000000000000000000000000000000000000000..00076d74fc2f8868a1e78de129bcbe6a6fbf1d51 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_split-incompatible_v2.0.0+incompatible.txt @@ -0,0 +1,10 @@ +Written by hand. +Test case for getting a package that has been moved to a nested module, +with a +incompatible version (and thus no go.mod file) at the root module. + +-- .mod -- +module example.com/split-incompatible +-- .info -- +{"Version": "v2.0.0+incompatible"} +-- subpkg/subpkg.go -- +package subpkg diff --git a/go/src/cmd/go/testdata/mod/example.com_split-incompatible_v2.1.0-pre+incompatible.txt b/go/src/cmd/go/testdata/mod/example.com_split-incompatible_v2.1.0-pre+incompatible.txt new file mode 100644 index 0000000000000000000000000000000000000000..bb1c1fecc9d2713360069cf593b6df89e6e1c303 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_split-incompatible_v2.1.0-pre+incompatible.txt @@ -0,0 +1,10 @@ +Written by hand. +Test case for getting a package that has been moved to a nested module, +with a +incompatible version (and thus no go.mod file) at the root module. + +-- .mod -- +module example.com/split-incompatible +-- .info -- +{"Version": "v2.1.0-pre+incompatible"} +-- README.txt -- +subpkg has moved to module example.com/split-incompatible/subpkg diff --git a/go/src/cmd/go/testdata/mod/example.com_split_subpkg_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_split_subpkg_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..b197b66398185a59f45822aab4ab1bce687e6127 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_split_subpkg_v1.1.0.txt @@ -0,0 +1,11 @@ +Written by hand. +Test case for getting a package that has been moved to a different module. + +-- .mod -- +module example.com/split/subpkg + +require example.com/split v1.1.0 +-- .info -- +{"Version": "v1.1.0"} +-- x.go -- +package subpkg diff --git a/go/src/cmd/go/testdata/mod/example.com_split_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_split_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..b706e590d98fd52d932a9fc9d9bd6a8af2f0291b --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_split_v1.0.0.txt @@ -0,0 +1,9 @@ +Written by hand. +Test case for getting a package that has been moved to a different module. + +-- .mod -- +module example.com/split +-- .info -- +{"Version": "v1.0.0"} +-- subpkg/x.go -- +package subpkg diff --git a/go/src/cmd/go/testdata/mod/example.com_split_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_split_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..d38971f9b62817c3b206fc1b0558d8a0468b83fe --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_split_v1.1.0.txt @@ -0,0 +1,9 @@ +Written by hand. +Test case for getting a package that has been moved to a different module. + +-- .mod -- +module example.com/split + +require example.com/split/subpkg v1.1.0 +-- .info -- +{"Version": "v1.1.0"} diff --git a/go/src/cmd/go/testdata/mod/example.com_stack_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_stack_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..787b7aedfa40a738e3516a5fe3f2063137e5df68 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_stack_v1.0.0.txt @@ -0,0 +1,18 @@ +Module with a function that prints file name for the top stack frame. +Different versions of this module are identical, but they should return +different file names with -trimpath. +-- .mod -- +module example.com/stack + +go 1.14 +-- .info -- +{"Version":"v1.0.0"} +-- stack.go -- +package stack + +import "runtime" + +func TopFile() string { + _, file, _, _ := runtime.Caller(0) + return file +} diff --git a/go/src/cmd/go/testdata/mod/example.com_stack_v1.0.1.txt b/go/src/cmd/go/testdata/mod/example.com_stack_v1.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..c715dd234f70ed8f18001d04c5829d55fe7956a1 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_stack_v1.0.1.txt @@ -0,0 +1,18 @@ +Module with a function that prints file name for the top stack frame. +Different versions of this module are identical, but they should return +different file names with -trimpath. +-- .mod -- +module example.com/stack + +go 1.14 +-- .info -- +{"Version":"v1.0.1"} +-- stack.go -- +package stack + +import "runtime" + +func TopFile() string { + _, file, _, _ := runtime.Caller(0) + return file +} diff --git a/go/src/cmd/go/testdata/mod/example.com_tools_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_tools_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..22e36b993affb711fb3dec2d25eb8fed287305eb --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_tools_v1.0.0.txt @@ -0,0 +1,12 @@ +-- .info -- +{"Version": "v1.0.0"} +-- .mod -- +module example.com/tools +-- cmd/hello/hello.go -- +package main + +import "fmt" + +func main() { + fmt.Println("hello") +} diff --git a/go/src/cmd/go/testdata/mod/example.com_tools_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_tools_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..91819341a62c3efc388e4331391bdfd3850d1239 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_tools_v1.1.0.txt @@ -0,0 +1,12 @@ +-- .info -- +{"Version": "v1.1.0"} +-- .mod -- +module example.com/tools +-- cmd/hello/hello.go -- +package main + +import "fmt" + +func main() { + fmt.Println("hello v1.1") +} diff --git a/go/src/cmd/go/testdata/mod/example.com_undeprecated_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_undeprecated_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..0e18d5078a69a3ef6599b923c5e1df1d2360b944 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_undeprecated_v1.0.0.txt @@ -0,0 +1,21 @@ +-- .info -- +{"Version":"v1.0.0"} +-- .mod -- +// Deprecated: in v1.0.0 +module example.com/undeprecated + +go 1.17 +-- go.mod -- +// Deprecated: in v1.0.0 +module example.com/undeprecated + +go 1.17 +-- undeprecated.go -- +package undeprecated + +-- cmd/a/a.go -- +package main + +import "fmt" + +func main() { fmt.Println("a@v1.0.0") } diff --git a/go/src/cmd/go/testdata/mod/example.com_undeprecated_v1.0.1.txt b/go/src/cmd/go/testdata/mod/example.com_undeprecated_v1.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..26fe07c5d6579c142db09dd09db215bcccdcaaf7 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_undeprecated_v1.0.1.txt @@ -0,0 +1,21 @@ +-- .info -- +{"Version":"v1.0.1"} +-- .mod -- +// no longer deprecated +module example.com/undeprecated + +go 1.17 +-- go.mod -- +// no longer deprecated +module example.com/undeprecated + +go 1.17 +-- undeprecated.go -- +package undeprecated + +-- cmd/a/a.go -- +package main + +import "fmt" + +func main() { fmt.Println("a@v1.0.1") } diff --git a/go/src/cmd/go/testdata/mod/example.com_usemissingpre_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_usemissingpre_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..5e1c5c815ed73a30f35200301f86c0040d27b40e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_usemissingpre_v1.0.0.txt @@ -0,0 +1,13 @@ +This module requires example.com/missingpkg at a prerelease version, which +is newer than @latest. + +-- .mod -- +module example.com/usemissingpre + +require example.com/missingpkg v1.0.1-beta +-- .info -- +{"Version":"v1.0.0"} +-- use.go -- +package use + +import _ "example.com/missingpkg" diff --git a/go/src/cmd/go/testdata/mod/example.com_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..263287d9e2cf8a713700edc468524a0c671d3ae1 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_v1.0.0.txt @@ -0,0 +1,9 @@ +Written by hand. +Test case for module at root of domain. + +-- .mod -- +module example.com +-- .info -- +{"Version": "v1.0.0"} +-- x.go -- +package x diff --git a/go/src/cmd/go/testdata/mod/example.com_version_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.com_version_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..d8c45b527e9d504591ef9ec2881ac7472620cf66 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_version_v1.0.0.txt @@ -0,0 +1,11 @@ +example.com/version v1.0.0 +written by hand + +-- .mod -- +module example.com/version +-- .info -- +{"Version":"v1.0.0"} +-- version.go -- +package version + +const V = "v1.0.0" diff --git a/go/src/cmd/go/testdata/mod/example.com_version_v1.0.1.txt b/go/src/cmd/go/testdata/mod/example.com_version_v1.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..3bfdb0e4cdcc2fad4895b0d05aac7b312810c85d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_version_v1.0.1.txt @@ -0,0 +1,11 @@ +example.com/version v1.0.1 +written by hand + +-- .mod -- +module example.com/version +-- .info -- +{"Version":"v1.0.1"} +-- version.go -- +package version + +const V = "v1.0.1" diff --git a/go/src/cmd/go/testdata/mod/example.com_version_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.com_version_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..8109a9acc9e53e84d9ce5714a6a3d013b4e37449 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.com_version_v1.1.0.txt @@ -0,0 +1,11 @@ +example.com/version v1.1.0 +written by hand + +-- .mod -- +module example.com/version +-- .info -- +{"Version":"v1.1.0"} +-- version.go -- +package version + +const V = "v1.1.0" diff --git a/go/src/cmd/go/testdata/mod/example.net_ambiguous_nested_v0.1.0.txt b/go/src/cmd/go/testdata/mod/example.net_ambiguous_nested_v0.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..8c9de7a5f4764ff9bd25cb22fee721f842c51001 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.net_ambiguous_nested_v0.1.0.txt @@ -0,0 +1,19 @@ +Written by hand. + +Test module containing a package that is also provided by a nested module tagged +with the same version. + +-- .mod -- +module example.net/ambiguous/nested + +go 1.16 +-- .info -- +{"Version": "v0.1.0"} +-- go.mod -- +module example.net/ambiguous/nested + +go 1.16 +-- pkg/pkg.go -- +// Package pkg exists in both example.net/ambiguous v0.1.0 +// and example.net/ambiguous/nested v0.1.0 +package pkg diff --git a/go/src/cmd/go/testdata/mod/example.net_ambiguous_v0.1.0.txt b/go/src/cmd/go/testdata/mod/example.net_ambiguous_v0.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..8fa6d83346d0f901d812d81f2208c44fc93955f0 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.net_ambiguous_v0.1.0.txt @@ -0,0 +1,19 @@ +Written by hand. + +Test module containing a package that is also provided by a nested module tagged +with the same version. + +-- .mod -- +module example.net/ambiguous + +go 1.16 +-- .info -- +{"Version": "v0.1.0"} +-- go.mod -- +module example.net/ambiguous + +go 1.16 +-- nested/pkg/pkg.go -- +// Package pkg exists in both example.net/ambiguous v0.1.0 +// and example.net/ambiguous/nested v0.1.0 +package pkg diff --git a/go/src/cmd/go/testdata/mod/example.net_ambiguous_v0.2.0.txt b/go/src/cmd/go/testdata/mod/example.net_ambiguous_v0.2.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..7589ad76a311a2a054944b71dafb9dc2e4bf7b61 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.net_ambiguous_v0.2.0.txt @@ -0,0 +1,18 @@ +Written by hand. + +Test module containing a package that is also provided by a nested module tagged +with the same version. + +-- .mod -- +module example.net/ambiguous + +go 1.16 +-- .info -- +{"Version": "v0.2.0"} +-- go.mod -- +module example.net/ambiguous + +go 1.16 +-- nested/pkg/README.txt -- +// Package pkg no longer exists in this module at v0.2.0. +// Find it in module example.net/ambiguous/nested instead. diff --git a/go/src/cmd/go/testdata/mod/example.net_pkgadded_v1.0.0.txt b/go/src/cmd/go/testdata/mod/example.net_pkgadded_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..207e86a73cf4d224bede65f143add33156e904b7 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.net_pkgadded_v1.0.0.txt @@ -0,0 +1,17 @@ +Written by hand. +Test module with a root package added in v1.1.0 +and a subpackage added in v1.2.0. + +-- .mod -- +module example.net/pkgadded + +go 1.16 +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module example.net/pkgadded + +go 1.16 +-- README.txt -- +We will add the package example.net/pkgadded in v1.1.0, +and example.net/pkgadded/subpkg in v1.2.0. diff --git a/go/src/cmd/go/testdata/mod/example.net_pkgadded_v1.1.0.txt b/go/src/cmd/go/testdata/mod/example.net_pkgadded_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..1c88de2dd6ffa773926302c18f756b5940ea90bd --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.net_pkgadded_v1.1.0.txt @@ -0,0 +1,19 @@ +Written by hand. +Test module with a root package added in v1.1.0 +and a subpackage added in v1.2.0. + +-- .mod -- +module example.net/pkgadded + +go 1.16 +-- .info -- +{"Version":"v1.1.0"} +-- go.mod -- +module example.net/pkgadded + +go 1.16 +-- README.txt -- +We will add the package example.net/pkgadded/subpkg in v1.2.0. +-- pkgadded.go -- +// Package pkgadded was added in v1.1.0. +package pkgadded diff --git a/go/src/cmd/go/testdata/mod/example.net_pkgadded_v1.2.0.txt b/go/src/cmd/go/testdata/mod/example.net_pkgadded_v1.2.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..922951ac37ea88b107f85f77d08ea4d0c16a4356 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/example.net_pkgadded_v1.2.0.txt @@ -0,0 +1,20 @@ +Written by hand. +Test module with a root package added in v1.1.0 +and a subpackage added in v1.2.0. + +-- .mod -- +module example.net/pkgadded + +go 1.16 +-- .info -- +{"Version":"v1.2.0"} +-- go.mod -- +module example.net/pkgadded + +go 1.16 +-- pkgadded.go -- +// Package pkgadded was added in v1.1.0. +package pkgadded +-- subpkg/subpkg.go -- +// Package subpkg was added in v1.2.0. +package subpkg diff --git a/go/src/cmd/go/testdata/mod/github.com_dmitshur-test_modtest5_v0.0.0-20190619020302-197a620e0c9a.txt b/go/src/cmd/go/testdata/mod/github.com_dmitshur-test_modtest5_v0.0.0-20190619020302-197a620e0c9a.txt new file mode 100644 index 0000000000000000000000000000000000000000..c2709c161e169124637b6e20687ebad339582ddd --- /dev/null +++ b/go/src/cmd/go/testdata/mod/github.com_dmitshur-test_modtest5_v0.0.0-20190619020302-197a620e0c9a.txt @@ -0,0 +1,10 @@ +module github.com/dmitshur-test/modtest5@v0.0.0-20190619020302-197a620e0c9a + +-- .mod -- +module github.com/dmitshur-test/modtest5 +-- .info -- +{"Version":"v0.0.0-20190619020302-197a620e0c9a","Time":"2019-06-18T19:03:02-07:00"} +-- p.go -- +package p + +const v = 1 diff --git a/go/src/cmd/go/testdata/mod/github.com_dmitshur-test_modtest5_v0.5.0-alpha.0.20190619023908-3da23a9deb9e.txt b/go/src/cmd/go/testdata/mod/github.com_dmitshur-test_modtest5_v0.5.0-alpha.0.20190619023908-3da23a9deb9e.txt new file mode 100644 index 0000000000000000000000000000000000000000..22e47f378ef91398d5c903453bd199c8de54209d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/github.com_dmitshur-test_modtest5_v0.5.0-alpha.0.20190619023908-3da23a9deb9e.txt @@ -0,0 +1,10 @@ +module github.com/dmitshur-test/modtest5@v0.5.0-alpha.0.20190619023908-3da23a9deb9e + +-- .mod -- +module github.com/dmitshur-test/modtest5 +-- .info -- +{"Version":"v0.5.0-alpha.0.20190619023908-3da23a9deb9e","Time":"2019-06-18T19:39:08-07:00"} +-- p.go -- +package p + +const v = 3 diff --git a/go/src/cmd/go/testdata/mod/github.com_dmitshur-test_modtest5_v0.5.0-alpha.txt b/go/src/cmd/go/testdata/mod/github.com_dmitshur-test_modtest5_v0.5.0-alpha.txt new file mode 100644 index 0000000000000000000000000000000000000000..4f088ccd2ca3f6063196e54ef4bcc810a1ac8bb5 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/github.com_dmitshur-test_modtest5_v0.5.0-alpha.txt @@ -0,0 +1,10 @@ +module github.com/dmitshur-test/modtest5@v0.5.0-alpha + +-- .mod -- +module github.com/dmitshur-test/modtest5 +-- .info -- +{"Version":"v0.5.0-alpha","Time":"2019-06-18T19:04:46-07:00"} +-- p.go -- +package p + +const v = 2 diff --git a/go/src/cmd/go/testdata/mod/golang.org_notx_useinternal_v0.1.0.txt b/go/src/cmd/go/testdata/mod/golang.org_notx_useinternal_v0.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..0420a1a4a0aee33062b90750eb7428fe093fb5a4 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_notx_useinternal_v0.1.0.txt @@ -0,0 +1,13 @@ +written by hand — attempts to use a prohibited internal package +(https://golang.org/s/go14internal) + +-- .mod -- +module golang.org/notx/useinternal +-- .info -- +{"Version":"v0.1.0","Name":"","Short":"","Time":"2018-07-25T17:24:00Z"} +-- go.mod -- +module golang.org/notx/useinternal +-- useinternal.go -- +package useinternal + +import _ "golang.org/x/internal/subtle" diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.1.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.1.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..3713de33bde2e7aadfa86a60eec0fc8186df5fc6 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.1.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.18.1.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.18.1.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.3.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.3.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..8eda1eedb0b15ed7b84ee149bb3431055f689906 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.3.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.18.3.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.18.3.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.5.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.5.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..d74ef250f27fb8df55dc46fd0b04424f94f12a28 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.5.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.18.5.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.18.5.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.7.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.7.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..2fc7f85895c0fa539214e40c5dc0c16b9671de68 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.7.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.18.7.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.18.7.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.9.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.9.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..7b0785106d5d44e3182b13cf6cba9d7b5ae560d3 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.9.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.18.9.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.18.9.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..2c80ce5e2a26fe8b001dfcd0ad07143a6efe8136 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.18.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.18.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.18.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.0.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.0.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..215c5477884e6c7e2f6b7c72dd14207362a4d36a --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.0.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.22.0.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.22.0.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.1.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.1.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..ac36e3fe6549561269d31c002672cd8bc20bc84e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.1.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.22.1.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.22.1.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.3.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.3.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..1178a48ab1a7bd2250b14a4e27b271a2fd016e0e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.3.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.22.3.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.22.3.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.5.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.5.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..d330127a79487999d0d80976582d1de1bbe9c5aa --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.5.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.22.5.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.22.5.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.7.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.7.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..a72863b830f4a8f530c315c77c9d7312d3241c4f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.7.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.22.7.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.22.7.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.9.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.9.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..ac558496c27148f8fad8e350dcefd36943d03dfd --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22.9.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.22.9.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.22.9.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22rc1.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22rc1.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..b384f28a83d7876ecd1859b6e71d0b38b13c39dc --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.22rc1.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.22rc1.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.22rc1.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.23.0.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.23.0.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..bbc137768e25927c2a6461a70fcd3dc4acd26852 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.23.0.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.23.0.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.23.0.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.23.5.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.23.5.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..206e8ad2b8ed22ca4809d15e681f5e7cd8889df6 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.23.5.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.23.5.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.23.5.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.23.9.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.23.9.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..7d037764185e614e3a65411b352632fbb449d3b3 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.23.9.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.23.9.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.23.9.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.24rc1.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.24rc1.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..4b61dddaa24920c07169e3ec75197b09127b9af9 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.24rc1.linux-amd64.txt @@ -0,0 +1,8 @@ +golang.org/toolchain v0.0.1-go1.24rc1.linux-amd64 +written by hand +-- .info -- +{"Version":"v0.0.1-go1.24rc1.linux-amd64"} +-- .mod -- +golang.org/toolchain +-- go.mod -- +golang.org/toolchain diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.aix-ppc64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.aix-ppc64.txt new file mode 100644 index 0000000000000000000000000000000000000000..ba40ef33d6eba258d3fbc92b60e3090f1c752880 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.aix-ppc64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.aix-ppc64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.aix-ppc64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-386.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-386.txt new file mode 100644 index 0000000000000000000000000000000000000000..abed143614d2b7235767c17985034695d777303b --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-386.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.android-386 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.android-386"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..34ed03825cbcc2d67422d93012b4c71646ad58cc --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-amd64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.android-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.android-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-arm.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-arm.txt new file mode 100644 index 0000000000000000000000000000000000000000..f399f998979890d97a178656a7135d33b8e205c0 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-arm.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.android-arm + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.android-arm"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-arm64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-arm64.txt new file mode 100644 index 0000000000000000000000000000000000000000..947af20b0f199b30348062731d2e67db112e2fb8 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.android-arm64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.android-arm64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.android-arm64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.darwin-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.darwin-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..19e8c4ab99087690994a3b6d7fc36fb0a6e7bae5 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.darwin-amd64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.darwin-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.darwin-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.darwin-arm64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.darwin-arm64.txt new file mode 100644 index 0000000000000000000000000000000000000000..8da52c69a5dab2857080b435a475f76bbb9d723a --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.darwin-arm64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.darwin-arm64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.darwin-arm64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.dragonfly-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.dragonfly-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..06441291f33304ca80582576c359b7d8a7c4a4ee --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.dragonfly-amd64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.dragonfly-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.dragonfly-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-386.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-386.txt new file mode 100644 index 0000000000000000000000000000000000000000..82cd5a7a30e61d202d29a1de24e92663ace5407b --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-386.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.freebsd-386 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.freebsd-386"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..b0b0d2894da9bb2dcf2896a8e1091f95b4602e58 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-amd64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.freebsd-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.freebsd-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-arm.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-arm.txt new file mode 100644 index 0000000000000000000000000000000000000000..1d4c492b57a9e3b962a869850bd47a27980092ec --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-arm.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.freebsd-arm + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.freebsd-arm"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-arm64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-arm64.txt new file mode 100644 index 0000000000000000000000000000000000000000..b9ec6725b6c57f4cc98d8108c5630f1b61993491 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-arm64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.freebsd-arm64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.freebsd-arm64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-riscv64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-riscv64.txt new file mode 100644 index 0000000000000000000000000000000000000000..80a87862c83ba38211af8bd7814d093509f069aa --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.freebsd-riscv64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.freebsd-riscv64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.freebsd-riscv64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.illumos-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.illumos-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..71ef4ed569e7ace7bc487d8059dbad8556199efd --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.illumos-amd64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.illumos-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.illumos-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.ios-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.ios-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..39e3ce1c24f8fb58f79c2c1449f2b4543b342a7f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.ios-amd64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.ios-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.ios-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.ios-arm64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.ios-arm64.txt new file mode 100644 index 0000000000000000000000000000000000000000..789cbde7a9177ac5f912833742bdd2726475071f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.ios-arm64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.ios-arm64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.ios-arm64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.js-wasm.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.js-wasm.txt new file mode 100644 index 0000000000000000000000000000000000000000..34af7aa9d40dc1e8a49760bfb25e285ba15a4c87 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.js-wasm.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.js-wasm + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.js-wasm"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-386.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-386.txt new file mode 100644 index 0000000000000000000000000000000000000000..62b88000c49ef1c35116c550e5f4fc06f3ef8e06 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-386.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.linux-386 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.linux-386"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..d35dd7d7b4cef1ba3ae9e07d4897fe2c25429b3f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-amd64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.linux-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.linux-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-arm.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-arm.txt new file mode 100644 index 0000000000000000000000000000000000000000..de644691a7208dde1f28611994932774dc4c1838 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-arm.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.linux-arm + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.linux-arm"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-arm64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-arm64.txt new file mode 100644 index 0000000000000000000000000000000000000000..2cd0d9ad46ea8a4ebef6b70cf75e914799745c07 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-arm64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.linux-arm64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.linux-arm64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-loong64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-loong64.txt new file mode 100644 index 0000000000000000000000000000000000000000..fe1b08976f3ff6405d806474f8e0a09caaa86976 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-loong64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.linux-loong64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.linux-loong64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-mips64x.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-mips64x.txt new file mode 100644 index 0000000000000000000000000000000000000000..40c93aee59100eb1518b6bef810de79b298ab851 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-mips64x.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.linux-mips64x + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.linux-mips64x"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-mipsx.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-mipsx.txt new file mode 100644 index 0000000000000000000000000000000000000000..bb5865dc7d9d327b7c18ff5694402b2304e58f34 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-mipsx.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.linux-mipsx + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.linux-mipsx"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-ppc64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-ppc64.txt new file mode 100644 index 0000000000000000000000000000000000000000..c8927f6af91d440dcbe36a35d4738c8d1d0b5924 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-ppc64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.linux-ppc64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.linux-ppc64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-ppc64le.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-ppc64le.txt new file mode 100644 index 0000000000000000000000000000000000000000..f0f012b9df0aa32a28870cdb27b4b0678f13d338 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-ppc64le.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.linux-ppc64le + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.linux-ppc64le"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-riscv64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-riscv64.txt new file mode 100644 index 0000000000000000000000000000000000000000..2c6038b0533e82d4fba0310143ddcfe47eef1ee3 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-riscv64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.linux-riscv64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.linux-riscv64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-s390x.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-s390x.txt new file mode 100644 index 0000000000000000000000000000000000000000..54f5d9ff1b5858ce24371838ed6ec7a544790660 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.linux-s390x.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.linux-s390x + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.linux-s390x"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-386.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-386.txt new file mode 100644 index 0000000000000000000000000000000000000000..cf6738ec658c7ea97f9b82d1030a8f6ae0d53d0f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-386.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.netbsd-386 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.netbsd-386"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..d4e6b93cd1012e03cd9cf93934ea5956b321d571 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-amd64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.netbsd-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.netbsd-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-arm.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-arm.txt new file mode 100644 index 0000000000000000000000000000000000000000..0d776d23c764b1435955c07b75eea0e13bb74ff8 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-arm.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.netbsd-arm + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.netbsd-arm"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-arm64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-arm64.txt new file mode 100644 index 0000000000000000000000000000000000000000..3c22682d07cba36d4715c3189bace86ca0d64552 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.netbsd-arm64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.netbsd-arm64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.netbsd-arm64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-386.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-386.txt new file mode 100644 index 0000000000000000000000000000000000000000..af280c34bdac1fa6934f64689096f1465760513c --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-386.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.openbsd-386 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.openbsd-386"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..a6807639f460154101f5a5e21e55220999fa35dc --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-amd64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.openbsd-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.openbsd-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-arm.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-arm.txt new file mode 100644 index 0000000000000000000000000000000000000000..9b1986b406b65c20802838b57499c090032b6a42 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-arm.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.openbsd-arm + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.openbsd-arm"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-arm64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-arm64.txt new file mode 100644 index 0000000000000000000000000000000000000000..9adffc2de7fb865dd30ebc1a786422d7e5f06489 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-arm64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.openbsd-arm64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.openbsd-arm64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-mips64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-mips64.txt new file mode 100644 index 0000000000000000000000000000000000000000..f9bfb7cd40c9224f93411fc5735a8408cc0d7726 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-mips64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.openbsd-mips64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.openbsd-mips64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-ppc64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-ppc64.txt new file mode 100644 index 0000000000000000000000000000000000000000..0bd75a655083e0716849a01e8a54a236bfcd5570 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-ppc64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.openbsd-ppc64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.openbsd-ppc64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-riscv64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-riscv64.txt new file mode 100644 index 0000000000000000000000000000000000000000..3b012445380fcbab1b2ed38219df7c7a635a0b6e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.openbsd-riscv64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.openbsd-riscv64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.openbsd-riscv64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.plan9-386.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.plan9-386.txt new file mode 100644 index 0000000000000000000000000000000000000000..cf3725216d77256a4ea1e6f0a715d99837afed3e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.plan9-386.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.plan9-386 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.plan9-386"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/rc +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.plan9-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.plan9-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f1e6b9ade9909184ca606710921bbb50c96772b --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.plan9-amd64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.plan9-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.plan9-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/rc +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.plan9-arm.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.plan9-arm.txt new file mode 100644 index 0000000000000000000000000000000000000000..f76a36de84a92dda11b9937d903d3450dc3a65aa --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.plan9-arm.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.plan9-arm + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.plan9-arm"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/rc +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.solaris-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.solaris-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..330a904d4954dc79f136c4929f24444423e9a146 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.solaris-amd64.txt @@ -0,0 +1,15 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.solaris-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.solaris-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go -- +#!/bin/sh +echo go1.999testmod here! +-- bin/gofmt -- +echo i am unused +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.windows-386.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.windows-386.txt new file mode 100644 index 0000000000000000000000000000000000000000..65fff4cd425308318cae4b5d4f5cc25efdd1dad5 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.windows-386.txt @@ -0,0 +1,12 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.windows-386 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.windows-386"} +-- go.mod -- +module golang.org/toolchain +-- bin/go.bat -- +@echo go1.999testmod here! +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.windows-amd64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.windows-amd64.txt new file mode 100644 index 0000000000000000000000000000000000000000..a78e7c8879cc11e72d87acbbd83bf9b306d5ca1f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.windows-amd64.txt @@ -0,0 +1,12 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.windows-amd64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.windows-amd64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go.bat -- +@echo go1.999testmod here! +-- pkg/tool/fake -- +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.windows-arm64.txt b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.windows-arm64.txt new file mode 100644 index 0000000000000000000000000000000000000000..b60ffbe90320836a6793a55af77de2da63ce938f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_toolchain_v0.0.1-go1.999testmod.windows-arm64.txt @@ -0,0 +1,11 @@ +golang.org/toolchain@v0.0.1-go1.999testmod.windows-arm64 + +-- .mod -- +module golang.org/toolchain +-- .info -- +{"Version":"v0.0.1-go1.999testmod.windows-arm64"} +-- go.mod -- +module golang.org/toolchain +-- bin/go.bat -- +@echo go1.999testmod here! +-- lib/wasm/go_js_wasm_exec -- diff --git a/go/src/cmd/go/testdata/mod/golang.org_x_internal_v0.1.0.txt b/go/src/cmd/go/testdata/mod/golang.org_x_internal_v0.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..5737e95cf47fdb761f7d8701924b2b62b29ec74a --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_x_internal_v0.1.0.txt @@ -0,0 +1,43 @@ +written by hand — loosely derived from golang.org/x/crypto/internal/subtle, +but splitting the internal package across a module boundary + +-- .mod -- +module golang.org/x/internal +-- .info -- +{"Version":"v0.1.0","Name":"","Short":"","Time":"2018-07-25T17:24:00Z"} +-- go.mod -- +module golang.org/x/internal +-- subtle/aliasing.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !appengine + +// This is a tiny version of golang.org/x/crypto/internal/subtle. + +package subtle + +import "unsafe" + +func AnyOverlap(x, y []byte) bool { + return len(x) > 0 && len(y) > 0 && + uintptr(unsafe.Pointer(&x[0])) <= uintptr(unsafe.Pointer(&y[len(y)-1])) && + uintptr(unsafe.Pointer(&y[0])) <= uintptr(unsafe.Pointer(&x[len(x)-1])) +} +-- subtle/aliasing_appengine.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build appengine + +package subtle + +import "reflect" + +func AnyOverlap(x, y []byte) bool { + return len(x) > 0 && len(y) > 0 && + reflect.ValueOf(&x[0]).Pointer() <= reflect.ValueOf(&y[len(y)-1]).Pointer() && + reflect.ValueOf(&y[0]).Pointer() <= reflect.ValueOf(&x[len(x)-1]).Pointer() +} diff --git a/go/src/cmd/go/testdata/mod/golang.org_x_text_v0.0.0-20170915032832-14c0d48ead0c.txt b/go/src/cmd/go/testdata/mod/golang.org_x_text_v0.0.0-20170915032832-14c0d48ead0c.txt new file mode 100644 index 0000000000000000000000000000000000000000..f4f50cdedb616ebb822ce89a152f2c09f168fe0a --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_x_text_v0.0.0-20170915032832-14c0d48ead0c.txt @@ -0,0 +1,47 @@ +written by hand - just enough to compile rsc.io/sampler, rsc.io/quote + +-- .mod -- +module golang.org/x/text +-- .info -- +{"Version":"v0.0.0-20170915032832-14c0d48ead0c","Name":"v0.0.0-20170915032832-14c0d48ead0c","Short":"14c0d48ead0c","Time":"2017-09-15T03:28:32Z"} +-- go.mod -- +module golang.org/x/text +-- unused/unused.go -- +package unused +-- language/lang.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This is a tiny version of golang.org/x/text. + +package language + +import "strings" + +type Tag string + +func Make(s string) Tag { return Tag(s) } + +func (t Tag) String() string { return string(t) } + +func NewMatcher(tags []Tag) Matcher { return &matcher{tags} } + +type Matcher interface { + Match(...Tag) (Tag, int, int) +} + +type matcher struct { + tags []Tag +} + +func (m *matcher) Match(prefs ...Tag) (Tag, int, int) { + for _, pref := range prefs { + for _, tag := range m.tags { + if tag == pref || strings.HasPrefix(string(pref), string(tag+"-")) || strings.HasPrefix(string(tag), string(pref+"-")) { + return tag, 0, 0 + } + } + } + return m.tags[0], 0, 0 +} diff --git a/go/src/cmd/go/testdata/mod/golang.org_x_text_v0.3.0.txt b/go/src/cmd/go/testdata/mod/golang.org_x_text_v0.3.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..5561afae8ed2fd52ee24afb4c3b8777cb62e0aba --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_x_text_v0.3.0.txt @@ -0,0 +1,47 @@ +written by hand - just enough to compile rsc.io/sampler, rsc.io/quote + +-- .mod -- +module golang.org/x/text +-- .info -- +{"Version":"v0.3.0","Name":"","Short":"","Time":"2017-09-16T03:28:32Z"} +-- go.mod -- +module golang.org/x/text +-- unused/unused.go -- +package unused +-- language/lang.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This is a tiny version of golang.org/x/text. + +package language + +import "strings" + +type Tag string + +func Make(s string) Tag { return Tag(s) } + +func (t Tag) String() string { return string(t) } + +func NewMatcher(tags []Tag) Matcher { return &matcher{tags} } + +type Matcher interface { + Match(...Tag) (Tag, int, int) +} + +type matcher struct { + tags []Tag +} + +func (m *matcher) Match(prefs ...Tag) (Tag, int, int) { + for _, pref := range prefs { + for _, tag := range m.tags { + if tag == pref || strings.HasPrefix(string(pref), string(tag+"-")) || strings.HasPrefix(string(tag), string(pref+"-")) { + return tag, 0, 0 + } + } + } + return m.tags[0], 0, 0 +} diff --git a/go/src/cmd/go/testdata/mod/golang.org_x_useinternal_v0.1.0.txt b/go/src/cmd/go/testdata/mod/golang.org_x_useinternal_v0.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..3fcba447befe22d4dc35a54684cf49028ecefa9b --- /dev/null +++ b/go/src/cmd/go/testdata/mod/golang.org_x_useinternal_v0.1.0.txt @@ -0,0 +1,13 @@ +written by hand — uses an internal package from another module +(https://golang.org/s/go14internal) + +-- .mod -- +module golang.org/x/useinternal +-- .info -- +{"Version":"v0.1.0","Name":"","Short":"","Time":"2018-07-25T17:24:00Z"} +-- go.mod -- +module golang.org/x/useinternal +-- useinternal.go -- +package useinternal + +import _ "golang.org/x/internal/subtle" diff --git a/go/src/cmd/go/testdata/mod/gopkg.in_dummy.v2-unstable_v2.0.0.txt b/go/src/cmd/go/testdata/mod/gopkg.in_dummy.v2-unstable_v2.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..f174159fd3fddc0e2fdd8728a7f85d6f971abe6a --- /dev/null +++ b/go/src/cmd/go/testdata/mod/gopkg.in_dummy.v2-unstable_v2.0.0.txt @@ -0,0 +1,9 @@ +gopkg.in/dummy.v2-unstable v2.0.0 +written by hand + +-- .mod -- +module gopkg.in/dummy.v2-unstable +-- .info -- +{"Version":"v2.0.0"} +-- dummy.go -- +package dummy diff --git a/go/src/cmd/go/testdata/mod/not-rsc.io_quote_v0.1.0-nomod.txt b/go/src/cmd/go/testdata/mod/not-rsc.io_quote_v0.1.0-nomod.txt new file mode 100644 index 0000000000000000000000000000000000000000..efff08826ad5ddf894f99a74512f63f13ba3cc19 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/not-rsc.io_quote_v0.1.0-nomod.txt @@ -0,0 +1,59 @@ +Constructed by hand. +(derived from rsc.io/quote@e7a685a342, but without an explicit go.mod file.) + +-- .mod -- +module "not-rsc.io/quote" +-- .info -- +{"Version":"v0.1.0-nomod","Time":"2018-02-14T00:51:33Z"} +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +// Hello returns a greeting. +func Hello() string { + return "Hello, world." +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import "testing" + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory. Share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} diff --git a/go/src/cmd/go/testdata/mod/patch.example.com_depofdirectpatch_v1.0.0.txt b/go/src/cmd/go/testdata/mod/patch.example.com_depofdirectpatch_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..40616c668a8a74ce6bdcb1102a66e4d6a3c0493d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/patch.example.com_depofdirectpatch_v1.0.0.txt @@ -0,0 +1,11 @@ +patch.example.com/depofdirectpatch v1.0.0 +written by hand + +-- .mod -- +module patch.example.com/depofdirectpatch +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module patch.example.com/depofdirectpatch +-- depofdirectpatch.go -- +package depofdirectpatch diff --git a/go/src/cmd/go/testdata/mod/patch.example.com_depofdirectpatch_v1.0.1.txt b/go/src/cmd/go/testdata/mod/patch.example.com_depofdirectpatch_v1.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..e075028656e2691feccc438337b67de71d875a00 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/patch.example.com_depofdirectpatch_v1.0.1.txt @@ -0,0 +1,11 @@ +patch.example.com/depofdirectpatch v1.0.1 +written by hand + +-- .mod -- +module patch.example.com/depofdirectpatch +-- .info -- +{"Version":"v1.0.1"} +-- go.mod -- +module patch.example.com/depofdirectpatch +-- depofdirectpatch.go -- +package depofdirectpatch diff --git a/go/src/cmd/go/testdata/mod/patch.example.com_direct_v1.0.0.txt b/go/src/cmd/go/testdata/mod/patch.example.com_direct_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..1e775fb89bc9ac1664a7cd980ea0abaf099ffe71 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/patch.example.com_direct_v1.0.0.txt @@ -0,0 +1,21 @@ +patch.example.com/direct v1.0.0 +written by hand + +-- .mod -- +module patch.example.com/direct + +require ( + patch.example.com/indirect v1.0.0 +) +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module patch.example.com/direct + +require ( + patch.example.com/indirect v1.0.0 +) +-- direct.go -- +package direct + +import _ "patch.example.com/indirect" diff --git a/go/src/cmd/go/testdata/mod/patch.example.com_direct_v1.0.1.txt b/go/src/cmd/go/testdata/mod/patch.example.com_direct_v1.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..64912b7b439b6868a480395ffc923c4dd3a14d1f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/patch.example.com_direct_v1.0.1.txt @@ -0,0 +1,27 @@ +patch.example.com/direct v1.0.1 +written by hand + +-- .mod -- +module patch.example.com/direct + +require ( + patch.example.com/indirect v1.0.0 + patch.example.com/depofdirectpatch v1.0.0 +) +-- .info -- +{"Version":"v1.0.1"} +-- go.mod -- +module patch.example.com/direct + +require ( + patch.example.com/indirect v1.0.0 + patch.example.com/depofdirectpatch v1.0.0 +) +-- direct.go -- +package direct + +import _ "patch.example.com/indirect" +-- usedepofdirectpatch/unused.go -- +package usedepofdirectpatch + +import _ "patch.example.com/depofdirectpatch" diff --git a/go/src/cmd/go/testdata/mod/patch.example.com_direct_v1.1.0.txt b/go/src/cmd/go/testdata/mod/patch.example.com_direct_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..406e3b9f628a76d6ea4c10568cfdc3d11095b82d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/patch.example.com_direct_v1.1.0.txt @@ -0,0 +1,21 @@ +patch.example.com/direct v1.1.0 +written by hand + +-- .mod -- +module patch.example.com/direct + +require ( + patch.example.com/indirect v1.0.0 +) +-- .info -- +{"Version":"v1.1.0"} +-- go.mod -- +module patch.example.com/direct + +require ( + patch.example.com/indirect v1.0.0 +) +-- direct.go -- +package direct + +import _ "patch.example.com/indirect" diff --git a/go/src/cmd/go/testdata/mod/patch.example.com_indirect_v1.0.0.txt b/go/src/cmd/go/testdata/mod/patch.example.com_indirect_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..ea7f5e2d8d0c8fa841f716c06604de327ce3b65f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/patch.example.com_indirect_v1.0.0.txt @@ -0,0 +1,11 @@ +patch.example.com/indirect v1.0.0 +written by hand + +-- .mod -- +module patch.example.com/indirect +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module patch.example.com/indirect +-- direct.go -- +package indirect diff --git a/go/src/cmd/go/testdata/mod/patch.example.com_indirect_v1.0.1.txt b/go/src/cmd/go/testdata/mod/patch.example.com_indirect_v1.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..8c6cf8e7bf94732bfe178d118c4ac4ce0ce0e022 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/patch.example.com_indirect_v1.0.1.txt @@ -0,0 +1,11 @@ +patch.example.com/indirect v1.0.1 +written by hand + +-- .mod -- +module patch.example.com/indirect +-- .info -- +{"Version":"v1.0.1"} +-- go.mod -- +module patch.example.com/indirect +-- direct.go -- +package indirect diff --git a/go/src/cmd/go/testdata/mod/patch.example.com_indirect_v1.1.0.txt b/go/src/cmd/go/testdata/mod/patch.example.com_indirect_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..f7229d417aa8c209f9bc00942891caaa5635441a --- /dev/null +++ b/go/src/cmd/go/testdata/mod/patch.example.com_indirect_v1.1.0.txt @@ -0,0 +1,11 @@ +patch.example.com/indirect v1.1.0 +written by hand + +-- .mod -- +module patch.example.com/indirect +-- .info -- +{"Version":"v1.1.0"} +-- go.mod -- +module patch.example.com/indirect +-- direct.go -- +package indirect diff --git a/go/src/cmd/go/testdata/mod/rsc.io_!c!g!o_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_!c!g!o_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..6276147535b445b33e1ebecc9d154e56186ebd49 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_!c!g!o_v1.0.0.txt @@ -0,0 +1,19 @@ +rsc.io/CGO v1.0.0 + +-- .mod -- +module rsc.io/CGO +-- .info -- +{"Version":"v1.0.0","Name":"","Short":"","Time":"2018-08-01T18:23:45Z"} +-- go.mod -- +module rsc.io/CGO +-- cgo.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package CGO + +// #cgo CFLAGS: -I${SRCDIR} +import "C" + +var V = 0 diff --git a/go/src/cmd/go/testdata/mod/rsc.io_!q!u!o!t!e_v1.5.2.txt b/go/src/cmd/go/testdata/mod/rsc.io_!q!u!o!t!e_v1.5.2.txt new file mode 100644 index 0000000000000000000000000000000000000000..21185c39f3320ed7e5b5926cf18d48bd3a923fdc --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_!q!u!o!t!e_v1.5.2.txt @@ -0,0 +1,88 @@ +rsc.io/QUOTE v1.5.2 + +-- .mod -- +module rsc.io/QUOTE + +require rsc.io/quote v1.5.2 +-- .info -- +{"Version":"v1.5.2","Name":"","Short":"","Time":"2018-07-15T16:25:34Z"} +-- go.mod -- +module rsc.io/QUOTE + +require rsc.io/quote v1.5.2 +-- QUOTE/quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// PACKAGE QUOTE COLLECTS LOUD SAYINGS. +package QUOTE + +import ( + "strings" + + "rsc.io/quote" +) + +// HELLO RETURNS A GREETING. +func HELLO() string { + return strings.ToUpper(quote.Hello()) +} + +// GLASS RETURNS A USEFUL PHRASE FOR WORLD TRAVELERS. +func GLASS() string { + return strings.ToUpper(quote.GLASS()) +} + +// GO RETURNS A GO PROVERB. +func GO() string { + return strings.ToUpper(quote.GO()) +} + +// OPT RETURNS AN OPTIMIZATION TRUTH. +func OPT() string { + return strings.ToUpper(quote.OPT()) +} +-- QUOTE/quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package QUOTE + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHELLO(t *testing.T) { + hello := "HELLO, WORLD" + if out := HELLO(); out != hello { + t.Errorf("HELLO() = %q, want %q", out, hello) + } +} + +func TestGLASS(t *testing.T) { + glass := "I CAN EAT GLASS AND IT DOESN'T HURT ME." + if out := GLASS(); out != glass { + t.Errorf("GLASS() = %q, want %q", out, glass) + } +} + +func TestGO(t *testing.T) { + go1 := "DON'T COMMUNICATE BY SHARING MEMORY, SHARE MEMORY BY COMMUNICATING." + if out := GO(); out != go1 { + t.Errorf("GO() = %q, want %q", out, go1) + } +} + +func TestOPT(t *testing.T) { + opt := "IF A PROGRAM IS TOO SLOW, IT MUST HAVE A LOOP." + if out := OPT(); out != opt { + t.Errorf("OPT() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_!q!u!o!t!e_v1.5.3-!p!r!e.txt b/go/src/cmd/go/testdata/mod/rsc.io_!q!u!o!t!e_v1.5.3-!p!r!e.txt new file mode 100644 index 0000000000000000000000000000000000000000..54bac2df7bb36867c48026adf215aae7cc6a24c6 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_!q!u!o!t!e_v1.5.3-!p!r!e.txt @@ -0,0 +1,88 @@ +rsc.io/QUOTE v1.5.3-PRE (sigh) + +-- .mod -- +module rsc.io/QUOTE + +require rsc.io/quote v1.5.2 +-- .info -- +{"Version":"v1.5.3-PRE","Name":"","Short":"","Time":"2018-07-15T16:25:34Z"} +-- go.mod -- +module rsc.io/QUOTE + +require rsc.io/quote v1.5.2 +-- QUOTE/quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// PACKAGE QUOTE COLLECTS LOUD SAYINGS. +package QUOTE + +import ( + "strings" + + "rsc.io/quote" +) + +// HELLO RETURNS A GREETING. +func HELLO() string { + return strings.ToUpper(quote.Hello()) +} + +// GLASS RETURNS A USEFUL PHRASE FOR WORLD TRAVELERS. +func GLASS() string { + return strings.ToUpper(quote.GLASS()) +} + +// GO RETURNS A GO PROVERB. +func GO() string { + return strings.ToUpper(quote.GO()) +} + +// OPT RETURNS AN OPTIMIZATION TRUTH. +func OPT() string { + return strings.ToUpper(quote.OPT()) +} +-- QUOTE/quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package QUOTE + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHELLO(t *testing.T) { + hello := "HELLO, WORLD" + if out := HELLO(); out != hello { + t.Errorf("HELLO() = %q, want %q", out, hello) + } +} + +func TestGLASS(t *testing.T) { + glass := "I CAN EAT GLASS AND IT DOESN'T HURT ME." + if out := GLASS(); out != glass { + t.Errorf("GLASS() = %q, want %q", out, glass) + } +} + +func TestGO(t *testing.T) { + go1 := "DON'T COMMUNICATE BY SHARING MEMORY, SHARE MEMORY BY COMMUNICATING." + if out := GO(); out != go1 { + t.Errorf("GO() = %q, want %q", out, go1) + } +} + +func TestOPT(t *testing.T) { + opt := "IF A PROGRAM IS TOO SLOW, IT MUST HAVE A LOOP." + if out := OPT(); out != opt { + t.Errorf("OPT() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_badfile1_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_badfile1_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..9d23e7db98cf3a7570713686600e36c97d1642e5 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_badfile1_v1.0.0.txt @@ -0,0 +1,14 @@ +rsc.io/badfile1 v1.0.0 +written by hand +this is part of the badfile test but is a valid zip file. + +-- .mod -- +module rsc.io/badfile1 +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module rsc.io/badfile1 +-- α.go -- +package α +-- .gitignore -- +-- x/y/z/.gitignore -- diff --git a/go/src/cmd/go/testdata/mod/rsc.io_badfile2_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_badfile2_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..58e1e1c103acdb862f82b3781e2bda8fa50a0a59 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_badfile2_v1.0.0.txt @@ -0,0 +1,12 @@ +rsc.io/badfile1 v1.0.0 +written by hand + +-- .mod -- +module rsc.io/badfile2 +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module rsc.io/badfile2 +-- ☺.go -- +package smiley + diff --git a/go/src/cmd/go/testdata/mod/rsc.io_badfile3_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_badfile3_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..a008448c5fd27a32e81d5370536ae621611a089e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_badfile3_v1.0.0.txt @@ -0,0 +1,12 @@ +rsc.io/badfile3 v1.0.0 +written by hand + +-- .mod -- +module rsc.io/badfile3 +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module rsc.io/badfile3 +-- x?y.go -- +package x + diff --git a/go/src/cmd/go/testdata/mod/rsc.io_badfile4_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_badfile4_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..e28844dc632e55a767fcfd11df4e8bfb37e303a5 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_badfile4_v1.0.0.txt @@ -0,0 +1,15 @@ +rsc.io/badfile4 v1.0.0 +written by hand + +-- .mod -- +module rsc.io/badfile4 +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module rsc.io/badfile4 +-- x/Y.go -- +package x +-- x/y.go -- +package x + + diff --git a/go/src/cmd/go/testdata/mod/rsc.io_badfile5_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_badfile5_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..3c7903a3bc0c71b3df20e10062cc301b5730d48d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_badfile5_v1.0.0.txt @@ -0,0 +1,13 @@ +rsc.io/badfile5 v1.0.0 +written by hand + +-- .mod -- +module rsc.io/badfile5 +-- .info -- +{"Version":"v1.0.0"} +-- go.mod -- +module rsc.io/badfile5 +-- x/y/z/w.go -- +package z +-- x/Y/zz/ww.go -- +package zz diff --git a/go/src/cmd/go/testdata/mod/rsc.io_badmod_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_badmod_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..993ceb7a0be72a4ab5a5596357cea171bd72d653 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_badmod_v1.0.0.txt @@ -0,0 +1,11 @@ +rsc.io/badmod v1.0.0 +written by hand + +-- .mod -- +module rsc.io/badmod +hello world +-- .info -- +{"Version":"v1.0.0"} +-- x.go -- +package x + diff --git a/go/src/cmd/go/testdata/mod/rsc.io_badsum_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_badsum_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..d62db2627a0510da485bedf9826c919989d13c2c --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_badsum_v1.0.0.txt @@ -0,0 +1,14 @@ +rsc.io/badsum@v1.0.0 + +This module would match the hard-coded hash for rsc.io/badsum v1.0.0 +in modfetch/notary.go if not for the "break hash" line. + +-- .mod -- +module "rsc.io/badsum" +-- .info -- +{"Version":"v1.0.0","Time":"2018-02-14T00:45:20Z"} +-- go.mod -- +module "rsc.io/badsum" +-- badsum.go -- +package badsum +// break hash diff --git a/go/src/cmd/go/testdata/mod/rsc.io_badsum_v1.0.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_badsum_v1.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..5fea50a01d73c53444616b2e856c6c36acf82dfc --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_badsum_v1.0.1.txt @@ -0,0 +1,14 @@ +rsc.io/badsum@v1.0.1 + +This module would match the hard-coded hash for rsc.io/badsum v1.0.1/go.mod +in modfetch/notary.go if not for the "break hash" line. + +-- .mod -- +module "rsc.io/badsum" +# break hash +-- .info -- +{"Version":"v1.0.1","Time":"2018-02-14T00:45:20Z"} +-- go.mod -- +module "rsc.io/badsum" +-- badsum.go -- +package badsum diff --git a/go/src/cmd/go/testdata/mod/rsc.io_badzip_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_badzip_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..07a38fa6d7d7492fd365c426c43ae2877a7dd544 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_badzip_v1.0.0.txt @@ -0,0 +1,11 @@ +rsc.io/badzip v1.0.0 +written by hand + +-- .mod -- +module rsc.io/badzip +-- .info -- +{"Version":"v1.0.0"} +-- x.go -- +package x +-- /rsc.io/badzip@v1.0.0.txt -- +This file should not be here. diff --git a/go/src/cmd/go/testdata/mod/rsc.io_breaker_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_breaker_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..a103e3f8aa1a926e2095665f1b7bc300a614cdb1 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_breaker_v1.0.0.txt @@ -0,0 +1,11 @@ +rsc.io/breaker v1.0.0 +written by hand + +-- .mod -- +module rsc.io/breaker +-- .info -- +{"Version":"v1.0.0"} +-- breaker.go -- +package breaker + +const X = 1 diff --git a/go/src/cmd/go/testdata/mod/rsc.io_breaker_v2.0.0+incompatible.txt b/go/src/cmd/go/testdata/mod/rsc.io_breaker_v2.0.0+incompatible.txt new file mode 100644 index 0000000000000000000000000000000000000000..59d8bacf07881356e60c8d7a196ffd534d505b6b --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_breaker_v2.0.0+incompatible.txt @@ -0,0 +1,11 @@ +rsc.io/breaker v2.0.0+incompatible +written by hand + +-- .mod -- +module rsc.io/breaker +-- .info -- +{"Version":"v2.0.0+incompatible", "Name": "7307b307f4f0dde421900f8e5126fadac1e13aed", "Short": "7307b307f4f0"} +-- breaker.go -- +package breaker + +const XX = 2 diff --git a/go/src/cmd/go/testdata/mod/rsc.io_breaker_v2.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_breaker_v2.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..59d8bacf07881356e60c8d7a196ffd534d505b6b --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_breaker_v2.0.0.txt @@ -0,0 +1,11 @@ +rsc.io/breaker v2.0.0+incompatible +written by hand + +-- .mod -- +module rsc.io/breaker +-- .info -- +{"Version":"v2.0.0+incompatible", "Name": "7307b307f4f0dde421900f8e5126fadac1e13aed", "Short": "7307b307f4f0"} +-- breaker.go -- +package breaker + +const XX = 2 diff --git a/go/src/cmd/go/testdata/mod/rsc.io_fortune_v0.0.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_fortune_v0.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..644695cba11b6c9034a40466311392522e9cd493 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_fortune_v0.0.1.txt @@ -0,0 +1,21 @@ +rsc.io/fortune 0.0.1 +written by hand + +-- .mod -- +module rsc.io/fortune +go 1.21rc999 + +-- go.mod -- +module rsc.io/fortune +go 1.21rc999 + +-- .info -- +{"Version":"v0.0.1"} +-- fortune.go -- +package main + +import "rsc.io/quote" + +func main() { + println(quote.Hello()) +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_fortune_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_fortune_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..d8a71f3cd9397f993133aeaa9b1ebfffec51a507 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_fortune_v1.0.0.txt @@ -0,0 +1,15 @@ +rsc.io/fortune v1.0.0 +written by hand + +-- .mod -- +module rsc.io/fortune +-- .info -- +{"Version":"v1.0.0"} +-- fortune.go -- +package main + +import "rsc.io/quote" + +func main() { + println(quote.Hello()) +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_fortune_v2_v2.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_fortune_v2_v2.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..3acd6379311f643194e45a712464b4af4aed5fa6 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_fortune_v2_v2.0.0.txt @@ -0,0 +1,21 @@ +rsc.io/fortune v2.0.0 +written by hand + +-- .mod -- +module rsc.io/fortune/v2 +-- .info -- +{"Version":"v2.0.0"} +-- fortune.go -- +package main + +import "rsc.io/quote" + +func main() { + println(quote.Hello()) +} +-- fortune_test.go -- +package main + +import "testing" + +func TestFortuneV2(t *testing.T) {} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_future_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_future_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..d3826a3d436ad7feb790532a8e78ee2de0bb2f0c --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_future_v1.0.0.txt @@ -0,0 +1,16 @@ +rsc.io/future v1.0.0 +written by hand + +-- .mod -- +module rsc.io/future +go 1.999 +-- .info -- +{"Version":"v1.0.0"} +-- main.go -- +package main + +func main() { +} +-- go.mod -- +module rsc.io/future +go 1.999 diff --git a/go/src/cmd/go/testdata/mod/rsc.io_needall_v0.0.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_needall_v0.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a1582a577cb9539928d7271463e6db7e5c3ed2e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_needall_v0.0.1.txt @@ -0,0 +1,25 @@ +rsc.io/needall 0.0.1 +written by hand + +-- .mod -- +module rsc.io/needall +go 1.23 + +require rsc.io/needgo121 v0.0.1 +require rsc.io/needgo122 v0.0.1 +require rsc.io/needgo123 v0.0.1 + +-- go.mod -- +module rsc.io/needall +go 1.23 + +require rsc.io/needgo121 v0.0.1 +require rsc.io/needgo122 v0.0.1 +require rsc.io/needgo123 v0.0.1 + +-- .info -- +{"Version":"v0.0.1"} +-- p.go -- +package p + +func F() {} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_needgo1183_v0.0.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_needgo1183_v0.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..a41296e1c734c1460491fce25b7fd45eb9a02cea --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_needgo1183_v0.0.1.txt @@ -0,0 +1,17 @@ +rsc.io/needgo1183 v0.0.1 +written by hand + +-- .mod -- +module rsc.io/needgo1183 +go 1.18.3 + +-- go.mod -- +module rsc.io/needgo1183 +go 1.18.3 + +-- .info -- +{"Version":"v0.0.1"} +-- p.go -- +package p + +func F() {} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_needgo118_v0.0.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_needgo118_v0.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..805eac7bb2e4f0f55173fd9e6fdcc34de1ba2675 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_needgo118_v0.0.1.txt @@ -0,0 +1,17 @@ +rsc.io/needgo118 0.0.1 +written by hand + +-- .mod -- +module rsc.io/needgo118 +go 1.18 + +-- go.mod -- +module rsc.io/needgo118 +go 1.18 + +-- .info -- +{"Version":"v0.0.1"} +-- p.go -- +package p + +func F() {} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_needgo121_v0.0.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_needgo121_v0.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..5b059609c4e52ba47032b612945eeb61716611f4 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_needgo121_v0.0.1.txt @@ -0,0 +1,17 @@ +rsc.io/needgo121 0.0.1 +written by hand + +-- .mod -- +module rsc.io/needgo121 +go 1.21 + +-- go.mod -- +module rsc.io/needgo121 +go 1.21 + +-- .info -- +{"Version":"v0.0.1"} +-- p.go -- +package p + +func F() {} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_needgo1223_v0.0.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_needgo1223_v0.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..f166a8226e0e4c3b4d07ec1c895741fcbed49bd3 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_needgo1223_v0.0.1.txt @@ -0,0 +1,17 @@ +rsc.io/needgo1223 0.0.1 +written by hand + +-- .mod -- +module rsc.io/needgo1223 +go 1.22.3 + +-- go.mod -- +module rsc.io/needgo1223 +go 1.22.3 + +-- .info -- +{"Version":"v0.0.1"} +-- p.go -- +package p + +func F() {} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_needgo122_v0.0.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_needgo122_v0.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..59116eb6abeadfd530e87f5a887dd9bdd6b5546e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_needgo122_v0.0.1.txt @@ -0,0 +1,17 @@ +rsc.io/needgo122 0.0.1 +written by hand + +-- .mod -- +module rsc.io/needgo122 +go 1.22 + +-- go.mod -- +module rsc.io/needgo122 +go 1.22 + +-- .info -- +{"Version":"v0.0.1"} +-- p.go -- +package p + +func F() {} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_needgo123_v0.0.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_needgo123_v0.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..0ec55714da031e2ff9e30aed55e44fd4e0246201 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_needgo123_v0.0.1.txt @@ -0,0 +1,17 @@ +rsc.io/needgo123 0.0.1 +written by hand + +-- .mod -- +module rsc.io/needgo123 +go 1.23 + +-- go.mod -- +module rsc.io/needgo123 +go 1.23 + +-- .info -- +{"Version":"v0.0.1"} +-- p.go -- +package p + +func F() {} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_needgo124_v0.0.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_needgo124_v0.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..634f50477fa544f5b956ff54d0379e8d72553028 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_needgo124_v0.0.1.txt @@ -0,0 +1,17 @@ +rsc.io/needgo124 0.0.1 +written by hand + +-- .mod -- +module rsc.io/needgo124 +go 1.24 + +-- go.mod -- +module rsc.io/needgo124 +go 1.24 + +-- .info -- +{"Version":"v0.0.1"} +-- p.go -- +package p + +func F() {} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_panicnil_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_panicnil_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..6ea1b22e0816955af56e5f8383df2466dcef0d23 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_panicnil_v1.0.0.txt @@ -0,0 +1,13 @@ +rsc.io/panicnil v1.0.0 +written by hand + +-- .mod -- +module rsc.io/panicnil +-- .info -- +{"Version":"v1.0.0"} +-- fortune.go -- +package main + +func main() { + panic(nil) +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_panicnil_v1.1.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_panicnil_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..fe67a8838c3bd9ab5d48c7194307f284f14eae13 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_panicnil_v1.1.0.txt @@ -0,0 +1,14 @@ +rsc.io/panicnil v1.1.0 +written by hand + +-- .mod -- +module rsc.io/panicnil +go 1.21 +-- .info -- +{"Version":"v1.1.0"} +-- fortune.go -- +package main + +func main() { + panic(nil) +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180214005133-e7a685a342c0.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180214005133-e7a685a342c0.txt new file mode 100644 index 0000000000000000000000000000000000000000..8ae173e7aec71ffd8055273a3617f0741f3091f4 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180214005133-e7a685a342c0.txt @@ -0,0 +1,60 @@ +rsc.io/quote@e7a685a342 + +-- .mod -- +module "rsc.io/quote" +-- .info -- +{"Version":"v0.0.0-20180214005133-e7a685a342c0","Name":"e7a685a342c001acc3eb7f5eafa82980480042c7","Short":"e7a685a342c0","Time":"2018-02-14T00:51:33Z"} +-- go.mod -- +module "rsc.io/quote" +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +// Hello returns a greeting. +func Hello() string { + return "Hello, world." +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import "testing" + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory. Share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180214005840-23179ee8a569.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180214005840-23179ee8a569.txt new file mode 100644 index 0000000000000000000000000000000000000000..bc626bac7a49e22f79368972e840cda549d0e4a6 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180214005840-23179ee8a569.txt @@ -0,0 +1,86 @@ +rsc.io/quote@v0.0.0-20180214005840-23179ee8a569 + +-- .mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- .info -- +{"Version":"v0.0.0-20180214005840-23179ee8a569","Name":"23179ee8a569bb05d896ae05c6503ec69a19f99f","Short":"23179ee8a569","Time":"2018-02-14T00:58:40Z"} +-- go.mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/sampler" + +// Hello returns a greeting. +func Hello() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180628003336-dd9747d19b04.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180628003336-dd9747d19b04.txt new file mode 100644 index 0000000000000000000000000000000000000000..bbc8097dc3a2f9ba7c8b5d60f6c06f75c634ce91 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180628003336-dd9747d19b04.txt @@ -0,0 +1,100 @@ +rsc.io/quote@dd9747d + +-- .mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- .info -- +{"Version":"v0.0.0-20180628003336-dd9747d19b04","Name":"dd9747d19b041365fbddf0399ddba6bff5eb1b3e","Short":"dd9747d19b04","Time":"2018-06-28T00:33:36Z"} +-- buggy/buggy_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package buggy + +import "testing" + +func Test(t *testing.T) { + t.Fatal("buggy!") +} +-- go.mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/sampler" + +AN EVEN WORSE CHANGE! + +// Hello returns a greeting. +func Hello() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709153244-fd906ed3b100.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709153244-fd906ed3b100.txt new file mode 100644 index 0000000000000000000000000000000000000000..e461ed4231e20b0ef009e985e869954e8ec46daf --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709153244-fd906ed3b100.txt @@ -0,0 +1,86 @@ +rsc.io/quote@v2.0.0 + +-- .mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- .info -- +{"Version":"v0.0.0-20180709153244-fd906ed3b100","Name":"fd906ed3b100e47181ffa9ec36d82294525c9109","Short":"fd906ed3b100","Time":"2018-07-09T15:32:44Z"} +-- go.mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/sampler" + +// Hello returns a greeting. +func HelloV2() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func GlassV2() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func GoV2() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func OptV2() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709160352-0d003b9c4bfa.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709160352-0d003b9c4bfa.txt new file mode 100644 index 0000000000000000000000000000000000000000..c1d511fda71b9ea26ec793be0e2388b99534c5e0 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709160352-0d003b9c4bfa.txt @@ -0,0 +1,98 @@ +rsc.io/quote@v0.0.0-20180709160352-0d003b9c4bfa + +-- .mod -- +module rsc.io/quote + +require rsc.io/sampler v1.3.0 +-- .info -- +{"Version":"v0.0.0-20180709160352-0d003b9c4bfa","Name":"0d003b9c4bfac881641be8eb1598b782a467a97f","Short":"0d003b9c4bfa","Time":"2018-07-09T16:03:52Z"} +-- buggy/buggy_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package buggy + +import "testing" + +func Test(t *testing.T) { + t.Fatal("buggy!") +} +-- go.mod -- +module rsc.io/quote + +require rsc.io/sampler v1.3.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/quote/v2" + +// Hello returns a greeting. +func Hello() string { + return quote.HelloV2() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return quote.GlassV2() +} + +// Go returns a Go proverb. +func Go() string { + return quote.GoV2() +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return quote.OptV2() +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709162749-b44a0b17b2d1.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709162749-b44a0b17b2d1.txt new file mode 100644 index 0000000000000000000000000000000000000000..f7f794d76dd79fcb475cf9cec13ec3a3d323b4fb --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709162749-b44a0b17b2d1.txt @@ -0,0 +1,104 @@ +rsc.io/quote@v0.0.0-20180709162749-b44a0b17b2d1 + +-- .mod -- +module rsc.io/quote + +require ( + rsc.io/quote/v2 v2.0.1 + rsc.io/sampler v1.3.0 +) +-- .info -- +{"Version":"v0.0.0-20180709162749-b44a0b17b2d1","Name":"b44a0b17b2d1fe4c98a8d0e7a68c9bf9e762799a","Short":"b44a0b17b2d1","Time":"2018-07-09T16:27:49Z"} +-- buggy/buggy_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package buggy + +import "testing" + +func Test(t *testing.T) { + t.Fatal("buggy!") +} +-- go.mod -- +module rsc.io/quote + +require ( + rsc.io/quote/v2 v2.0.1 + rsc.io/sampler v1.3.0 +) +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/quote/v2" + +// Hello returns a greeting. +func Hello() string { + return quote.HelloV2() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return quote.GlassV2() +} + +// Go returns a Go proverb. +func Go() string { + return quote.GoV2() +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return quote.OptV2() +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709162816-fe488b867524.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709162816-fe488b867524.txt new file mode 100644 index 0000000000000000000000000000000000000000..2d5d8b4e72aa36b2ef25a58ea0f846fd97a2eedb --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709162816-fe488b867524.txt @@ -0,0 +1,104 @@ +rsc.io/quote@v0.0.0-20180709162816-fe488b867524 + +-- .mod -- +module rsc.io/quote + +require ( + rsc.io/quote/v2 v2.0.1 + rsc.io/sampler v1.3.0 +) +-- .info -- +{"Version":"v0.0.0-20180709162816-fe488b867524","Name":"fe488b867524806e861c3f4f43ae6946a42ca3f1","Short":"fe488b867524","Time":"2018-07-09T16:28:16Z"} +-- buggy/buggy_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package buggy + +import "testing" + +func Test(t *testing.T) { + t.Fatal("buggy!") +} +-- go.mod -- +module rsc.io/quote + +require ( + rsc.io/quote/v2 v2.0.1 + rsc.io/sampler v1.3.0 +) +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/quote/v2" + +// Hello returns a greeting. +func Hello() string { + return quote.HelloV2() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return quote.GlassV2() +} + +// Go returns a Go proverb. +func Go() string { + return quote.GoV2() +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return quote.OptV2() +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709162918-a91498bed0a7.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709162918-a91498bed0a7.txt new file mode 100644 index 0000000000000000000000000000000000000000..853a8c2a1ac7fcc502340a22d4da6d8cb0117b6f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180709162918-a91498bed0a7.txt @@ -0,0 +1,98 @@ +rsc.io/quote@v0.0.0-20180709162918-a91498bed0a7 + +-- .mod -- +module rsc.io/quote + +require rsc.io/sampler v1.3.0 +-- .info -- +{"Version":"v0.0.0-20180709162918-a91498bed0a7","Name":"a91498bed0a73d4bb9c1fb2597925f7883bc40a7","Short":"a91498bed0a7","Time":"2018-07-09T16:29:18Z"} +-- buggy/buggy_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package buggy + +import "testing" + +func Test(t *testing.T) { + t.Fatal("buggy!") +} +-- go.mod -- +module rsc.io/quote + +require rsc.io/sampler v1.3.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/quote/v3" + +// Hello returns a greeting. +func Hello() string { + return quote.HelloV3() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return quote.GlassV3() +} + +// Go returns a Go proverb. +func Go() string { + return quote.GoV3() +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return quote.OptV3() +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180710144737-5d9f230bcfba.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180710144737-5d9f230bcfba.txt new file mode 100644 index 0000000000000000000000000000000000000000..2ebeac397146fa95b166a87c9c458c9df313776e --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v0.0.0-20180710144737-5d9f230bcfba.txt @@ -0,0 +1,104 @@ +rsc.io/quote@v0.0.0-20180710144737-5d9f230bcfba + +-- .mod -- +module rsc.io/quote + +require ( + rsc.io/quote/v3 v3.0.0 + rsc.io/sampler v1.3.0 +) +-- .info -- +{"Version":"v0.0.0-20180710144737-5d9f230bcfba","Name":"5d9f230bcfbae514bb6c2215694c2ce7273fc604","Short":"5d9f230bcfba","Time":"2018-07-10T14:47:37Z"} +-- buggy/buggy_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package buggy + +import "testing" + +func Test(t *testing.T) { + t.Fatal("buggy!") +} +-- go.mod -- +module rsc.io/quote + +require ( + rsc.io/quote/v3 v3.0.0 + rsc.io/sampler v1.3.0 +) +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/quote/v3" + +// Hello returns a greeting. +func Hello() string { + return quote.HelloV3() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return quote.GlassV3() +} + +// Go returns a Go proverb. +func Go() string { + return quote.GoV3() +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return quote.OptV3() +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..9a0793744455fa9e4fba7fd68faef2bd90c10395 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.0.0.txt @@ -0,0 +1,35 @@ +rsc.io/quote@v1.0.0 + +-- .mod -- +module "rsc.io/quote" +-- .info -- +{"Version":"v1.0.0","Name":"f488df80bcdbd3e5bafdc24ad7d1e79e83edd7e6","Short":"f488df80bcdb","Time":"2018-02-14T00:45:20Z"} +-- go.mod -- +module "rsc.io/quote" +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +// Hello returns a greeting. +func Hello() string { + return "Hello, world." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import "testing" + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.1.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.1.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..0c416053901ce1a4dcfe4198661d91eeaa6a5a47 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.1.0.txt @@ -0,0 +1,48 @@ +rsc.io/quote@v1.1.0 + +-- .mod -- +module "rsc.io/quote" +-- .info -- +{"Version":"v1.1.0","Name":"cfd7145f43f92a8d56b4a3dd603795a3291381a9","Short":"cfd7145f43f9","Time":"2018-02-14T00:46:44Z"} +-- go.mod -- +module "rsc.io/quote" +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +// Hello returns a greeting. +func Hello() string { + return "Hello, world." +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import "testing" + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.2.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.2.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..e714f0b913719e8cec983d916d69237097961c3d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.2.0.txt @@ -0,0 +1,61 @@ +rsc.io/quote@v1.2.0 + +-- .mod -- +module "rsc.io/quote" +-- .info -- +{"Version":"v1.2.0","Name":"d8a3de91045c932a1c71e545308fe97571d6d65c","Short":"d8a3de91045c","Time":"2018-02-14T00:47:51Z"} +-- go.mod -- +module "rsc.io/quote" +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +// Hello returns a greeting. +func Hello() string { + return "Hello, world." +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import "testing" + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +// Go returns a Go proverb. +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory. Share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.2.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.2.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..89d5191d3a068eb92992252be8efbabd7698512a --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.2.1.txt @@ -0,0 +1,60 @@ +rsc.io/quote@v1.2.1 + +-- .mod -- +module "rsc.io/quote" +-- .info -- +{"Version":"v1.2.1","Name":"5c1f03b64ab7aa958798a569a31924655dc41e76","Short":"5c1f03b64ab7","Time":"2018-02-14T00:54:20Z"} +-- go.mod -- +module "rsc.io/quote" +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +// Hello returns a greeting. +func Hello() string { + return "Hello, world." +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import "testing" + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.3.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.3.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..d62766c7d2b950f5ef290b8483d5c0a7bcdc6396 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.3.0.txt @@ -0,0 +1,73 @@ +rsc.io/quote@v1.3.0 + +-- .mod -- +module "rsc.io/quote" +-- .info -- +{"Version":"v1.3.0","Name":"84de74b35823c1e49634f2262f1a58cfc951ebae","Short":"84de74b35823","Time":"2018-02-14T00:54:53Z"} +-- go.mod -- +module "rsc.io/quote" +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +// Hello returns a greeting. +func Hello() string { + return "Hello, world." +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import "testing" + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.4.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.4.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..698ff8de81222020e39d2df4711cb400d288587c --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.4.0.txt @@ -0,0 +1,79 @@ +rsc.io/quote@v1.4.0 + +-- .mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.0.0 +-- .info -- +{"Version":"v1.4.0","Name":"19e8b977bd2f437798c2cc2dcfe8a1c0f169481b","Short":"19e8b977bd2f","Time":"2018-02-14T00:56:05Z"} +-- go.mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.0.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/sampler" + +// Hello returns a greeting. +func Hello() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import "testing" + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..e7fcdbccff5317095c54d931abbcdf66ef85ca6f --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.0.txt @@ -0,0 +1,79 @@ +rsc.io/quote@v1.5.0 + +-- .mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- .info -- +{"Version":"v1.5.0","Name":"3ba1e30dc83bd52c990132b9dfb1688a9d22de13","Short":"3ba1e30dc83b","Time":"2018-02-14T00:58:15Z"} +-- go.mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/sampler" + +// Hello returns a greeting. +func Hello() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import "testing" + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..eed051bea04f18c2023002dcb5ff3a245c6e8959 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.1.txt @@ -0,0 +1,86 @@ +rsc.io/quote@23179ee8a569 + +-- .mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- .info -- +{"Version":"v1.5.1","Name":"23179ee8a569bb05d896ae05c6503ec69a19f99f","Short":"23179ee8a569","Time":"2018-02-14T00:58:40Z"} +-- go.mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/sampler" + +// Hello returns a greeting. +func Hello() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.2.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.2.txt new file mode 100644 index 0000000000000000000000000000000000000000..8671f6fe772de54147fadc51e1bbee57cbad2962 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.2.txt @@ -0,0 +1,98 @@ +rsc.io/quote@v1.5.2 + +-- .mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- .info -- +{"Version":"v1.5.2","Name":"c4d4236f92427c64bfbcf1cc3f8142ab18f30b22","Short":"c4d4236f9242","Time":"2018-02-14T15:44:20Z"} +-- buggy/buggy_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package buggy + +import "testing" + +func Test(t *testing.T) { + t.Fatal("buggy!") +} +-- go.mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/sampler" + +// Hello returns a greeting. +func Hello() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.3-pre1.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.3-pre1.txt new file mode 100644 index 0000000000000000000000000000000000000000..212ef13aaf82503671712da0cb8b06ed8f1a4922 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v1.5.3-pre1.txt @@ -0,0 +1,100 @@ +rsc.io/quote@v1.5.3-pre1 + +-- .mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- .info -- +{"Version":"v1.5.3-pre1","Name":"2473dfd877c95382420e47686aa9076bf58c79e0","Short":"2473dfd877c9","Time":"2018-06-28T00:32:53Z"} +-- buggy/buggy_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package buggy + +import "testing" + +func Test(t *testing.T) { + t.Fatal("buggy!") +} +-- go.mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/sampler" + +// A CHANGE! + +// Hello returns a greeting. +func Hello() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func Glass() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func Go() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func Opt() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v2.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v2.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..e461ed4231e20b0ef009e985e869954e8ec46daf --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v2.0.0.txt @@ -0,0 +1,86 @@ +rsc.io/quote@v2.0.0 + +-- .mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- .info -- +{"Version":"v0.0.0-20180709153244-fd906ed3b100","Name":"fd906ed3b100e47181ffa9ec36d82294525c9109","Short":"fd906ed3b100","Time":"2018-07-09T15:32:44Z"} +-- go.mod -- +module "rsc.io/quote" + +require "rsc.io/sampler" v1.3.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/sampler" + +// Hello returns a greeting. +func HelloV2() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func GlassV2() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func GoV2() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func OptV2() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v2_v2.0.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v2_v2.0.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..d51128c46b9f602c74bf70a2e46c00b5101056de --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v2_v2.0.1.txt @@ -0,0 +1,86 @@ +rsc.io/quote/v2@v2.0.1 + +-- .mod -- +module rsc.io/quote/v2 + +require rsc.io/sampler v1.3.0 +-- .info -- +{"Version":"v2.0.1","Name":"754f68430672776c84704e2d10209a6ec700cd64","Short":"754f68430672","Time":"2018-07-09T16:25:34Z"} +-- go.mod -- +module rsc.io/quote/v2 + +require rsc.io/sampler v1.3.0 +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/sampler" + +// Hello returns a greeting. +func HelloV2() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func GlassV2() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func GoV2() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func OptV2() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} +-- quote_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quote + +import ( + "os" + "testing" +) + +func init() { + os.Setenv("LC_ALL", "en") +} + +func TestHello(t *testing.T) { + hello := "Hello, world." + if out := Hello(); out != hello { + t.Errorf("Hello() = %q, want %q", out, hello) + } +} + +func TestGlass(t *testing.T) { + glass := "I can eat glass and it doesn't hurt me." + if out := Glass(); out != glass { + t.Errorf("Glass() = %q, want %q", out, glass) + } +} + +func TestGo(t *testing.T) { + go1 := "Don't communicate by sharing memory, share memory by communicating." + if out := Go(); out != go1 { + t.Errorf("Go() = %q, want %q", out, go1) + } +} + +func TestOpt(t *testing.T) { + opt := "If a program is too slow, it must have a loop." + if out := Opt(); out != opt { + t.Errorf("Opt() = %q, want %q", out, opt) + } +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_quote_v3_v3.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_quote_v3_v3.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..0afe1f0519992e9b0e43fbfd15ae710938f4bc83 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_quote_v3_v3.0.0.txt @@ -0,0 +1,45 @@ +rsc.io/quote/v3@v3.0.0 + +-- .mod -- +module rsc.io/quote/v3 + +require rsc.io/sampler v1.3.0 + +-- .info -- +{"Version":"v3.0.0","Name":"d88915d7e77ed0fd35d0a022a2f244e2202fd8c8","Short":"d88915d7e77e","Time":"2018-07-09T15:34:46Z"} +-- go.mod -- +module rsc.io/quote/v3 + +require rsc.io/sampler v1.3.0 + +-- quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote // import "rsc.io/quote" + +import "rsc.io/sampler" + +// Hello returns a greeting. +func HelloV3() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func GlassV3() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a Go proverb. +func GoV3() string { + return "Don't communicate by sharing memory, share memory by communicating." +} + +// Opt returns an optimization truth. +func OptV3() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..c4b6a71c88c405e927490bcfd356304bab1e2c1d --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.0.0.txt @@ -0,0 +1,20 @@ +rsc.io/sampler@v1.0.0 + +-- .mod -- +module "rsc.io/sampler" +-- .info -- +{"Version":"v1.0.0","Name":"60bef405c52117ad21d2adb10872b95cf17f8fca","Short":"60bef405c521","Time":"2018-02-13T18:05:54Z"} +-- go.mod -- +module "rsc.io/sampler" +-- sampler.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package sampler shows simple texts. +package sampler // import "rsc.io/sampler" + +// Hello returns a greeting. +func Hello() string { + return "Hello, world." +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.2.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.2.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..98c35fa238901321e24e54dd9cbdcb0f69702f22 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.2.0.txt @@ -0,0 +1,138 @@ +rsc.io/sampler@v1.2.0 + +-- .mod -- +module "rsc.io/sampler" + +require "golang.org/x/text" v0.0.0-20170915032832-14c0d48ead0c +-- .info -- +{"Version":"v1.2.0","Name":"25f24110b153246056eccc14a3a4cd81afaff586","Short":"25f24110b153","Time":"2018-02-13T18:13:45Z"} +-- go.mod -- +module "rsc.io/sampler" + +require "golang.org/x/text" v0.0.0-20170915032832-14c0d48ead0c +-- hello.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Translations by Google Translate. + +package sampler + +var hello = newText(` + +English: en: Hello, world. +French: fr: Bonjour le monde. +Spanish: es: Hola Mundo. + +`) +-- hello_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package sampler + +import ( + "testing" + + "golang.org/x/text/language" +) + +var helloTests = []struct { + prefs []language.Tag + text string +}{ + { + []language.Tag{language.Make("en-US"), language.Make("fr")}, + "Hello, world.", + }, + { + []language.Tag{language.Make("fr"), language.Make("en-US")}, + "Bonjour la monde.", + }, +} + +func TestHello(t *testing.T) { + for _, tt := range helloTests { + text := Hello(tt.prefs...) + if text != tt.text { + t.Errorf("Hello(%v) = %q, want %q", tt.prefs, text, tt.text) + } + } +} +-- sampler.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package sampler shows simple texts. +package sampler // import "rsc.io/sampler" + +import ( + "os" + "strings" + + "golang.org/x/text/language" +) + +// DefaultUserPrefs returns the default user language preferences. +// It consults the $LC_ALL, $LC_MESSAGES, and $LANG environment +// variables, in that order. +func DefaultUserPrefs() []language.Tag { + var prefs []language.Tag + for _, k := range []string{"LC_ALL", "LC_MESSAGES", "LANG"} { + if env := os.Getenv(k); env != "" { + prefs = append(prefs, language.Make(env)) + } + } + return prefs +} + +// Hello returns a localized greeting. +// If no prefs are given, Hello uses DefaultUserPrefs. +func Hello(prefs ...language.Tag) string { + if len(prefs) == 0 { + prefs = DefaultUserPrefs() + } + return hello.find(prefs) +} + +// A text is a localized text. +type text struct { + byTag map[string]string + matcher language.Matcher +} + +// newText creates a new localized text, given a list of translations. +func newText(s string) *text { + t := &text{ + byTag: make(map[string]string), + } + var tags []language.Tag + for _, line := range strings.Split(s, "\n") { + line = strings.TrimSpace(line) + if line == "" { + continue + } + f := strings.Split(line, ": ") + if len(f) != 3 { + continue + } + tag := language.Make(f[1]) + tags = append(tags, tag) + t.byTag[tag.String()] = f[2] + } + t.matcher = language.NewMatcher(tags) + return t +} + +// find finds the text to use for the given language tag preferences. +func (t *text) find(prefs []language.Tag) string { + tag, _, _ := t.matcher.Match(prefs...) + s := t.byTag[tag.String()] + if strings.HasPrefix(s, "RTL ") { + s = "\u200F" + strings.TrimPrefix(s, "RTL ") + "\u200E" + } + return s +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.2.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.2.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..7982cccea100c0a523aa9e668ed45aa2d6dfada6 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.2.1.txt @@ -0,0 +1,134 @@ +generated by ./addmod.bash rsc.io/sampler@v1.2.1 + +-- .mod -- +module "rsc.io/sampler" + +require "golang.org/x/text" v0.0.0-20170915032832-14c0d48ead0c +-- .info -- +{"Version":"v1.2.1","Name":"cac3af4f8a0ab40054fa6f8d423108a63a1255bb","Short":"cac3af4f8a0a","Time":"2018-02-13T18:16:22Z"} +-- hello.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Translations by Google Translate. + +package sampler + +var hello = newText(` + +English: en: Hello, world. +French: fr: Bonjour le monde. +Spanish: es: Hola Mundo. + +`) +-- hello_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package sampler + +import ( + "testing" + + "golang.org/x/text/language" +) + +var helloTests = []struct { + prefs []language.Tag + text string +}{ + { + []language.Tag{language.Make("en-US"), language.Make("fr")}, + "Hello, world.", + }, + { + []language.Tag{language.Make("fr"), language.Make("en-US")}, + "Bonjour le monde.", + }, +} + +func TestHello(t *testing.T) { + for _, tt := range helloTests { + text := Hello(tt.prefs...) + if text != tt.text { + t.Errorf("Hello(%v) = %q, want %q", tt.prefs, text, tt.text) + } + } +} +-- sampler.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package sampler shows simple texts. +package sampler // import "rsc.io/sampler" + +import ( + "os" + "strings" + + "golang.org/x/text/language" +) + +// DefaultUserPrefs returns the default user language preferences. +// It consults the $LC_ALL, $LC_MESSAGES, and $LANG environment +// variables, in that order. +func DefaultUserPrefs() []language.Tag { + var prefs []language.Tag + for _, k := range []string{"LC_ALL", "LC_MESSAGES", "LANG"} { + if env := os.Getenv(k); env != "" { + prefs = append(prefs, language.Make(env)) + } + } + return prefs +} + +// Hello returns a localized greeting. +// If no prefs are given, Hello uses DefaultUserPrefs. +func Hello(prefs ...language.Tag) string { + if len(prefs) == 0 { + prefs = DefaultUserPrefs() + } + return hello.find(prefs) +} + +// A text is a localized text. +type text struct { + byTag map[string]string + matcher language.Matcher +} + +// newText creates a new localized text, given a list of translations. +func newText(s string) *text { + t := &text{ + byTag: make(map[string]string), + } + var tags []language.Tag + for _, line := range strings.Split(s, "\n") { + line = strings.TrimSpace(line) + if line == "" { + continue + } + f := strings.Split(line, ": ") + if len(f) != 3 { + continue + } + tag := language.Make(f[1]) + tags = append(tags, tag) + t.byTag[tag.String()] = f[2] + } + t.matcher = language.NewMatcher(tags) + return t +} + +// find finds the text to use for the given language tag preferences. +func (t *text) find(prefs []language.Tag) string { + tag, _, _ := t.matcher.Match(prefs...) + s := t.byTag[tag.String()] + if strings.HasPrefix(s, "RTL ") { + s = "\u200F" + strings.TrimPrefix(s, "RTL ") + "\u200E" + } + return s +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.3.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.3.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..febe51fd9a93358f31e53637410521a4bc14e5c7 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.3.0.txt @@ -0,0 +1,202 @@ +rsc.io/sampler@v1.3.0 + +-- .mod -- +module "rsc.io/sampler" + +require "golang.org/x/text" v0.0.0-20170915032832-14c0d48ead0c +-- .info -- +{"Version":"v1.3.0","Name":"0cc034b51e57ed7832d4c67d526f75a900996e5c","Short":"0cc034b51e57","Time":"2018-02-13T19:05:03Z"} +-- glass.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Translations from Frank da Cruz, Ethan Mollick, and many others. +// See http://kermitproject.org/utf8.html. +// http://www.oocities.org/nodotus/hbglass.html +// https://en.wikipedia.org/wiki/I_Can_Eat_Glass + +package sampler + +var glass = newText(` + +English: en: I can eat glass and it doesn't hurt me. +French: fr: Je peux manger du verre, ça ne me fait pas mal. +Spanish: es: Puedo comer vidrio, no me hace daño. + +`) +-- glass_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package sampler + +import ( + "testing" + + "golang.org/x/text/language" + _ "rsc.io/testonly" +) + +var glassTests = []struct { + prefs []language.Tag + text string +}{ + { + []language.Tag{language.Make("en-US"), language.Make("fr")}, + "I can eat glass and it doesn't hurt me.", + }, + { + []language.Tag{language.Make("fr"), language.Make("en-US")}, + "Je peux manger du verre, ça ne me fait pas mal.", + }, +} + +func TestGlass(t *testing.T) { + for _, tt := range glassTests { + text := Glass(tt.prefs...) + if text != tt.text { + t.Errorf("Glass(%v) = %q, want %q", tt.prefs, text, tt.text) + } + } +} +-- go.mod -- +module "rsc.io/sampler" + +require "golang.org/x/text" v0.0.0-20170915032832-14c0d48ead0c +-- hello.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Translations by Google Translate. + +package sampler + +var hello = newText(` + +English: en: Hello, world. +French: fr: Bonjour le monde. +Spanish: es: Hola Mundo. + +`) +-- hello_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package sampler + +import ( + "testing" + + "golang.org/x/text/language" +) + +var helloTests = []struct { + prefs []language.Tag + text string +}{ + { + []language.Tag{language.Make("en-US"), language.Make("fr")}, + "Hello, world.", + }, + { + []language.Tag{language.Make("fr"), language.Make("en-US")}, + "Bonjour le monde.", + }, +} + +func TestHello(t *testing.T) { + for _, tt := range helloTests { + text := Hello(tt.prefs...) + if text != tt.text { + t.Errorf("Hello(%v) = %q, want %q", tt.prefs, text, tt.text) + } + } +} +-- sampler.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package sampler shows simple texts. +package sampler // import "rsc.io/sampler" + +import ( + "os" + "strings" + + "golang.org/x/text/language" +) + +// DefaultUserPrefs returns the default user language preferences. +// It consults the $LC_ALL, $LC_MESSAGES, and $LANG environment +// variables, in that order. +func DefaultUserPrefs() []language.Tag { + var prefs []language.Tag + for _, k := range []string{"LC_ALL", "LC_MESSAGES", "LANG"} { + if env := os.Getenv(k); env != "" { + prefs = append(prefs, language.Make(env)) + } + } + return prefs +} + +// Hello returns a localized greeting. +// If no prefs are given, Hello uses DefaultUserPrefs. +func Hello(prefs ...language.Tag) string { + if len(prefs) == 0 { + prefs = DefaultUserPrefs() + } + return hello.find(prefs) +} + +// Glass returns a localized silly phrase. +// If no prefs are given, Glass uses DefaultUserPrefs. +func Glass(prefs ...language.Tag) string { + if len(prefs) == 0 { + prefs = DefaultUserPrefs() + } + return glass.find(prefs) +} + +// A text is a localized text. +type text struct { + byTag map[string]string + matcher language.Matcher +} + +// newText creates a new localized text, given a list of translations. +func newText(s string) *text { + t := &text{ + byTag: make(map[string]string), + } + var tags []language.Tag + for _, line := range strings.Split(s, "\n") { + line = strings.TrimSpace(line) + if line == "" { + continue + } + f := strings.Split(line, ": ") + if len(f) != 3 { + continue + } + tag := language.Make(f[1]) + tags = append(tags, tag) + t.byTag[tag.String()] = f[2] + } + t.matcher = language.NewMatcher(tags) + return t +} + +// find finds the text to use for the given language tag preferences. +func (t *text) find(prefs []language.Tag) string { + tag, _, _ := t.matcher.Match(prefs...) + s := t.byTag[tag.String()] + if strings.HasPrefix(s, "RTL ") { + s = "\u200F" + strings.TrimPrefix(s, "RTL ") + "\u200E" + } + return s +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.3.1.txt b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.3.1.txt new file mode 100644 index 0000000000000000000000000000000000000000..a293f108696ea3e114e3239567d570bb571b8904 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.3.1.txt @@ -0,0 +1,201 @@ +rsc.io/sampler@v1.3.1 + +-- .mod -- +module "rsc.io/sampler" + +require "golang.org/x/text" v0.0.0-20170915032832-14c0d48ead0c +-- .info -- +{"Version":"v1.3.1","Name":"f545d0289d06e2add4556ea6a15fc4938014bf87","Short":"f545d0289d06","Time":"2018-02-14T16:34:12Z"} +-- glass.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Translations from Frank da Cruz, Ethan Mollick, and many others. +// See http://kermitproject.org/utf8.html. +// http://www.oocities.org/nodotus/hbglass.html +// https://en.wikipedia.org/wiki/I_Can_Eat_Glass + +package sampler + +var glass = newText(` + +English: en: I can eat glass and it doesn't hurt me. +French: fr: Je peux manger du verre, ça ne me fait pas mal. +Spanish: es: Puedo comer vidrio, no me hace daño. + +`) +-- glass_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package sampler + +import ( + "testing" + + "golang.org/x/text/language" +) + +var glassTests = []struct { + prefs []language.Tag + text string +}{ + { + []language.Tag{language.Make("en-US"), language.Make("fr")}, + "I can eat glass and it doesn't hurt me.", + }, + { + []language.Tag{language.Make("fr"), language.Make("en-US")}, + "Je peux manger du verre, ça ne me fait pas mal.", + }, +} + +func TestGlass(t *testing.T) { + for _, tt := range glassTests { + text := Glass(tt.prefs...) + if text != tt.text { + t.Errorf("Glass(%v) = %q, want %q", tt.prefs, text, tt.text) + } + } +} +-- go.mod -- +module "rsc.io/sampler" + +require "golang.org/x/text" v0.0.0-20170915032832-14c0d48ead0c +-- hello.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Translations by Google Translate. + +package sampler + +var hello = newText(` + +English: en: Hello, world. +French: fr: Bonjour le monde. +Spanish: es: Hola Mundo. + +`) +-- hello_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package sampler + +import ( + "testing" + + "golang.org/x/text/language" +) + +var helloTests = []struct { + prefs []language.Tag + text string +}{ + { + []language.Tag{language.Make("en-US"), language.Make("fr")}, + "Hello, world.", + }, + { + []language.Tag{language.Make("fr"), language.Make("en-US")}, + "Bonjour le monde.", + }, +} + +func TestHello(t *testing.T) { + for _, tt := range helloTests { + text := Hello(tt.prefs...) + if text != tt.text { + t.Errorf("Hello(%v) = %q, want %q", tt.prefs, text, tt.text) + } + } +} +-- sampler.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package sampler shows simple texts in a variety of languages. +package sampler // import "rsc.io/sampler" + +import ( + "os" + "strings" + + "golang.org/x/text/language" +) + +// DefaultUserPrefs returns the default user language preferences. +// It consults the $LC_ALL, $LC_MESSAGES, and $LANG environment +// variables, in that order. +func DefaultUserPrefs() []language.Tag { + var prefs []language.Tag + for _, k := range []string{"LC_ALL", "LC_MESSAGES", "LANG"} { + if env := os.Getenv(k); env != "" { + prefs = append(prefs, language.Make(env)) + } + } + return prefs +} + +// Hello returns a localized greeting. +// If no prefs are given, Hello uses DefaultUserPrefs. +func Hello(prefs ...language.Tag) string { + if len(prefs) == 0 { + prefs = DefaultUserPrefs() + } + return hello.find(prefs) +} + +// Glass returns a localized silly phrase. +// If no prefs are given, Glass uses DefaultUserPrefs. +func Glass(prefs ...language.Tag) string { + if len(prefs) == 0 { + prefs = DefaultUserPrefs() + } + return glass.find(prefs) +} + +// A text is a localized text. +type text struct { + byTag map[string]string + matcher language.Matcher +} + +// newText creates a new localized text, given a list of translations. +func newText(s string) *text { + t := &text{ + byTag: make(map[string]string), + } + var tags []language.Tag + for _, line := range strings.Split(s, "\n") { + line = strings.TrimSpace(line) + if line == "" { + continue + } + f := strings.Split(line, ": ") + if len(f) != 3 { + continue + } + tag := language.Make(f[1]) + tags = append(tags, tag) + t.byTag[tag.String()] = f[2] + } + t.matcher = language.NewMatcher(tags) + return t +} + +// find finds the text to use for the given language tag preferences. +func (t *text) find(prefs []language.Tag) string { + tag, _, _ := t.matcher.Match(prefs...) + s := t.byTag[tag.String()] + if strings.HasPrefix(s, "RTL ") { + s = "\u200F" + strings.TrimPrefix(s, "RTL ") + "\u200E" + } + return s +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.99.99.txt b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.99.99.txt new file mode 100644 index 0000000000000000000000000000000000000000..5036d20ab58b79421e0b2c8a3b449766f8f14925 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_sampler_v1.99.99.txt @@ -0,0 +1,140 @@ +rsc.io/sampler@v1.99.99 + +-- .mod -- +module "rsc.io/sampler" + +require "golang.org/x/text" v0.0.0-20170915032832-14c0d48ead0c +-- .info -- +{"Version":"v1.99.99","Name":"732a3c400797d8835f2af34a9561f155bef85435","Short":"732a3c400797","Time":"2018-02-13T22:20:19Z"} +-- go.mod -- +module "rsc.io/sampler" + +require "golang.org/x/text" v0.0.0-20170915032832-14c0d48ead0c +-- hello.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Translations by Google Translate. + +package sampler + +var hello = newText(` + +English: en: 99 bottles of beer on the wall, 99 bottles of beer, ... + +`) +-- hello_test.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package sampler + +import ( + "testing" + + "golang.org/x/text/language" +) + +var helloTests = []struct { + prefs []language.Tag + text string +}{ + { + []language.Tag{language.Make("en-US"), language.Make("fr")}, + "Hello, world.", + }, + { + []language.Tag{language.Make("fr"), language.Make("en-US")}, + "Bonjour le monde.", + }, +} + +func TestHello(t *testing.T) { + for _, tt := range helloTests { + text := Hello(tt.prefs...) + if text != tt.text { + t.Errorf("Hello(%v) = %q, want %q", tt.prefs, text, tt.text) + } + } +} +-- sampler.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package sampler shows simple texts. +package sampler // import "rsc.io/sampler" + +import ( + "os" + "strings" + + "golang.org/x/text/language" +) + +// DefaultUserPrefs returns the default user language preferences. +// It consults the $LC_ALL, $LC_MESSAGES, and $LANG environment +// variables, in that order. +func DefaultUserPrefs() []language.Tag { + var prefs []language.Tag + for _, k := range []string{"LC_ALL", "LC_MESSAGES", "LANG"} { + if env := os.Getenv(k); env != "" { + prefs = append(prefs, language.Make(env)) + } + } + return prefs +} + +// Hello returns a localized greeting. +// If no prefs are given, Hello uses DefaultUserPrefs. +func Hello(prefs ...language.Tag) string { + if len(prefs) == 0 { + prefs = DefaultUserPrefs() + } + return hello.find(prefs) +} + +func Glass() string { + return "I can eat glass and it doesn't hurt me." +} + +// A text is a localized text. +type text struct { + byTag map[string]string + matcher language.Matcher +} + +// newText creates a new localized text, given a list of translations. +func newText(s string) *text { + t := &text{ + byTag: make(map[string]string), + } + var tags []language.Tag + for _, line := range strings.Split(s, "\n") { + line = strings.TrimSpace(line) + if line == "" { + continue + } + f := strings.Split(line, ": ") + if len(f) != 3 { + continue + } + tag := language.Make(f[1]) + tags = append(tags, tag) + t.byTag[tag.String()] = f[2] + } + t.matcher = language.NewMatcher(tags) + return t +} + +// find finds the text to use for the given language tag preferences. +func (t *text) find(prefs []language.Tag) string { + tag, _, _ := t.matcher.Match(prefs...) + s := t.byTag[tag.String()] + if strings.HasPrefix(s, "RTL ") { + s = "\u200F" + strings.TrimPrefix(s, "RTL ") + "\u200E" + } + return s +} diff --git a/go/src/cmd/go/testdata/mod/rsc.io_testonly_v1.0.0.txt b/go/src/cmd/go/testdata/mod/rsc.io_testonly_v1.0.0.txt new file mode 100644 index 0000000000000000000000000000000000000000..dfb8ca24ec9ce4a07feb55db2e14b0889bf11363 --- /dev/null +++ b/go/src/cmd/go/testdata/mod/rsc.io_testonly_v1.0.0.txt @@ -0,0 +1,9 @@ +rsc.io/testonly v1.0.0 +written by hand + +-- .mod -- +module rsc.io/testonly +-- .info -- +{"Version":"v1.0.0"} +-- testonly.go -- +package testonly diff --git a/go/src/cmd/go/testdata/savedir.go b/go/src/cmd/go/testdata/savedir.go new file mode 100644 index 0000000000000000000000000000000000000000..bd42c3e485c43f3f007b65b984a5bbfd8768a772 --- /dev/null +++ b/go/src/cmd/go/testdata/savedir.go @@ -0,0 +1,79 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore +// +build ignore + +// Savedir archives a directory tree as a txtar archive printed to standard output. +// +// Usage: +// +// go run savedir.go /path/to/dir >saved.txt +// +// Typically the tree is later extracted during a test with tg.extract("testdata/saved.txt"). +package main + +import ( + "cmd/go/internal/str" + "flag" + "fmt" + "internal/txtar" + "io/fs" + "log" + "os" + "path/filepath" + "strings" + "unicode/utf8" +) + +func usage() { + fmt.Fprintf(os.Stderr, "usage: go run savedir.go dir >saved.txt\n") + os.Exit(2) +} + +const goCmd = "vgo" + +func main() { + flag.Usage = usage + flag.Parse() + if flag.NArg() != 1 { + usage() + } + + log.SetPrefix("savedir: ") + log.SetFlags(0) + + dir := flag.Arg(0) + + a := new(txtar.Archive) + dir = filepath.Clean(dir) + filepath.WalkDir(dir, func(path string, info fs.DirEntry, err error) error { + if path == dir { + return nil + } + name := info.Name() + if strings.HasPrefix(name, ".") { + if info.IsDir() { + return filepath.SkipDir + } + return nil + } + if !info.Type().IsRegular() { + return nil + } + data, err := os.ReadFile(path) + if err != nil { + log.Fatal(err) + } + if !utf8.Valid(data) { + log.Printf("%s: ignoring invalid UTF-8 data", path) + return nil + } + a.Files = append(a.Files, txtar.File{Name: str.TrimFilePathPrefix(path, dir), Data: data}) + return nil + }) + + data := txtar.Format(a) + os.Stdout.Write(data) +} diff --git a/go/src/cmd/go/testdata/script/README b/go/src/cmd/go/testdata/script/README new file mode 100644 index 0000000000000000000000000000000000000000..2b5ab6948bdff1cb584da6528c97e8b3634a90d5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/README @@ -0,0 +1,428 @@ +This file is generated by 'go generate cmd/go'. DO NOT EDIT. + +This directory holds test scripts *.txt run during 'go test cmd/go'. +To run a specific script foo.txt + + go test cmd/go -run=Script/^foo$ + +In general script files should have short names: a few words, not whole sentences. +The first word should be the general category of behavior being tested, +often the name of a go subcommand (list, build, test, ...) or concept (vendor, pattern). + +Each script is a text archive (go doc internal/txtar). +The script begins with an actual command script to run +followed by the content of zero or more supporting files to +create in the script's temporary file system before it starts executing. + +As an example, run_hello.txt says: + + # hello world + go run hello.go + stderr 'hello world' + ! stdout . + + -- hello.go -- + package main + func main() { println("hello world") } + +Each script runs in a fresh temporary work directory tree, available to scripts as $WORK. +Scripts also have access to other environment variables, including: + + GOARCH= + GOCACHE= + GOEXE= + GOOS= + GOPATH=$WORK/gopath + GOPROXY= + GOROOT= + TESTGO_GOROOT= + HOME=/no-home + PATH= + TMPDIR=$WORK/tmp + GODEBUG= + devnull= + goversion= + +On Plan 9, the variables $path and $home are set instead of $PATH and $HOME. +On Windows, the variables $USERPROFILE and $TMP are set instead of +$HOME and $TMPDIR. + +The lines at the top of the script are a sequence of commands to be executed by +a small script engine configured in ../../script_test.go (not the system shell). + +The scripts' supporting files are unpacked relative to $GOPATH/src +(aka $WORK/gopath/src) and then the script begins execution in that directory as +well. Thus the example above runs in $WORK/gopath/src with GOPATH=$WORK/gopath +and $WORK/gopath/src/hello.go containing the listed contents. + +Each line of a script is parsed into a sequence of space-separated command +words, with environment variable expansion within each word and # marking +an end-of-line comment. Additional variables named ':' and '/' are expanded +within script arguments (expanding to the value of os.PathListSeparator and +os.PathSeparator respectively) but are not inherited in subprocess environments. + +Adding single quotes around text keeps spaces in that text from being treated +as word separators and also disables environment variable expansion. Inside a +single-quoted block of text, a repeated single quote indicates a literal single +quote, as in: + + 'Don''t communicate by sharing memory.' + +A line beginning with # is a comment and conventionally explains what is being +done or tested at the start of a new section of the script. + +Commands are executed one at a time, and errors are checked for each command; +if any command fails unexpectedly, no subsequent commands in the script are +executed. The command prefix ! indicates that the command on the rest of the +line (typically go or a matching predicate) must fail instead of succeeding. +The command prefix ? indicates that the command may or may not succeed, but the +script should continue regardless. + +The command prefix [cond] indicates that the command on the rest of the line +should only run when the condition is satisfied. + +A condition can be negated: [!root] means to run the rest of the line only if +the user is not root. Multiple conditions may be given for a single command, +for example, '[linux] [amd64] skip'. The command will run if all conditions are +satisfied. + +When TestScript runs a script and the script fails, by default TestScript shows +the execution of the most recent phase of the script (since the last # comment) +and only shows the # comments for earlier phases. For example, here is a +multi-phase script with a bug in it: + + # GOPATH with p1 in d2, p2 in d2 + env GOPATH=$WORK${/}d1${:}$WORK${/}d2 + + # build & install p1 + env + go install -i p1 + ! stale p1 + ! stale p2 + + # modify p2 - p1 should appear stale + cp $WORK/p2x.go $WORK/d2/src/p2/p2.go + stale p1 p2 + + # build & install p1 again + go install -i p11 + ! stale p1 + ! stale p2 + + -- $WORK/d1/src/p1/p1.go -- + package p1 + import "p2" + func F() { p2.F() } + -- $WORK/d2/src/p2/p2.go -- + package p2 + func F() {} + -- $WORK/p2x.go -- + package p2 + func F() {} + func G() {} + +The bug is that the final phase installs p11 instead of p1. The test failure looks like: + + $ go test -run=Script + --- FAIL: TestScript (3.75s) + --- FAIL: TestScript/install_rebuild_gopath (0.16s) + script_test.go:223: + # GOPATH with p1 in d2, p2 in d2 (0.000s) + # build & install p1 (0.087s) + # modify p2 - p1 should appear stale (0.029s) + # build & install p1 again (0.022s) + > go install -i p11 + [stderr] + can't load package: package p11: cannot find package "p11" in any of: + /Users/rsc/go/src/p11 (from $GOROOT) + $WORK/d1/src/p11 (from $GOPATH) + $WORK/d2/src/p11 + [exit status 1] + FAIL: unexpected go command failure + + script_test.go:73: failed at testdata/script/install_rebuild_gopath.txt:15 in $WORK/gopath/src + + FAIL + exit status 1 + FAIL cmd/go 4.875s + $ + +Note that the commands in earlier phases have been hidden, so that the relevant +commands are more easily found, and the elapsed time for a completed phase +is shown next to the phase heading. To see the entire execution, use "go test -v", +which also adds an initial environment dump to the beginning of the log. + +Note also that in reported output, the actual name of the per-script temporary directory +has been consistently replaced with the literal string $WORK. + +The cmd/go test flag -testwork (which must appear on the "go test" command line after +standard test flags) causes each test to log the name of its $WORK directory and other +environment variable settings and also to leave that directory behind when it exits, +for manual debugging of failing tests: + + $ go test -run=Script -work + --- FAIL: TestScript (3.75s) + --- FAIL: TestScript/install_rebuild_gopath (0.16s) + script_test.go:223: + WORK=/tmp/cmd-go-test-745953508/script-install_rebuild_gopath + GOARCH= + GOCACHE=/Users/rsc/Library/Caches/go-build + GOOS= + GOPATH=$WORK/gopath + GOROOT=/Users/rsc/go + HOME=/no-home + TMPDIR=$WORK/tmp + exe= + + # GOPATH with p1 in d2, p2 in d2 (0.000s) + # build & install p1 (0.085s) + # modify p2 - p1 should appear stale (0.030s) + # build & install p1 again (0.019s) + > go install -i p11 + [stderr] + can't load package: package p11: cannot find package "p11" in any of: + /Users/rsc/go/src/p11 (from $GOROOT) + $WORK/d1/src/p11 (from $GOPATH) + $WORK/d2/src/p11 + [exit status 1] + FAIL: unexpected go command failure + + script_test.go:73: failed at testdata/script/install_rebuild_gopath.txt:15 in $WORK/gopath/src + + FAIL + exit status 1 + FAIL cmd/go 4.875s + $ + + $ WORK=/tmp/cmd-go-test-745953508/script-install_rebuild_gopath + $ cd $WORK/d1/src/p1 + $ cat p1.go + package p1 + import "p2" + func F() { p2.F() } + $ + +The available commands are: +cat files... + concatenate files and print to the script's stdout buffer + + +cc args... + run the platform C compiler + + +cd dir + change the working directory + + +chmod perm paths... + change file mode bits + + Changes the permissions of the named files or directories to + be equal to perm. + Only numerical permissions are supported. + +cmp [-q] file1 file2 + compare files for differences + + By convention, file1 is the actual data and file2 is the + expected data. + The command succeeds if the file contents are identical. + File1 can be 'stdout' or 'stderr' to compare the stdout or + stderr buffer from the most recent command. + +cmpenv [-q] file1 file2 + compare files for differences, with environment expansion + + By convention, file1 is the actual data and file2 is the + expected data. + The command succeeds if the file contents are identical + after substituting variables from the script environment. + File1 can be 'stdout' or 'stderr' to compare the script's + stdout or stderr buffer. + +cp src... dst + copy files to a target file or directory + + src can include 'stdout' or 'stderr' to copy from the + script's stdout or stderr buffer. + +echo string... + display a line of text + + +env [key[=value]...] + set or log the values of environment variables + + With no arguments, print the script environment to the log. + Otherwise, add the listed key=value pairs to the environment + or print the listed keys. + +exec program [args...] [&] + run an executable program with arguments + + Note that 'exec' does not terminate the script (unlike Unix + shells). + +exists [-readonly] [-exec] file... + check that files exist + + +go [args...] [&] + run the 'go' program provided by the script host + + +grep [-count=N] [-q] 'pattern' file + find lines in a file that match a pattern + + The command succeeds if at least one match (or the exact + count, if given) is found. + The -q flag suppresses printing of matches. + +help [-v] name... + log help text for commands and conditions + + To display help for a specific condition, enclose it in + brackets: 'help [amd64]'. + To display complete documentation when listing all commands, + pass the -v flag. + +mkdir path... + create directories, if they do not already exist + + Unlike Unix mkdir, parent directories are always created if + needed. + +mv old new + rename a file or directory to a new path + + OS-specific restrictions may apply when old and new are in + different directories. + +replace [old new]... file + replace strings in a file + + The 'old' and 'new' arguments are unquoted as if in quoted + Go strings. + +rm path... + remove a file or directory + + If the path is a directory, its contents are removed + recursively. + +skip [msg] + skip the current test + + +sleep duration [&] + sleep for a specified duration + + The duration must be given as a Go time.Duration string. + +stale target... + check that build targets are stale + + +stderr [-count=N] [-q] 'pattern' file + find lines in the stderr buffer that match a pattern + + The command succeeds if at least one match (or the exact + count, if given) is found. + The -q flag suppresses printing of matches. + +stdout [-count=N] [-q] 'pattern' file + find lines in the stdout buffer that match a pattern + + The command succeeds if at least one match (or the exact + count, if given) is found. + The -q flag suppresses printing of matches. + +stop [msg] + stop execution of the script + + The message is written to the script log, but no error is + reported from the script engine. + +symlink path -> target + create a symlink + + Creates path as a symlink to target. + The '->' token (like in 'ls -l' output on Unix) is required. + +wait + wait for completion of background commands + + Waits for all background commands to complete. + The output (and any error) from each command is printed to + the log in the order in which the commands were started. + After the call to 'wait', the script's stdout and stderr + buffers contain the concatenation of the background + commands' outputs. + + + +The available conditions are: +[GOARCH:*] + runtime.GOARCH == +[GODEBUG:*] + GODEBUG contains +[GOEXPERIMENT:*] + GOEXPERIMENT is enabled +[GOOS:*] + runtime.GOOS == +[abscc] + default $CC path is absolute and exists +[asan] + GOOS/GOARCH supports -asan +[buildmode:*] + go supports -buildmode= +[bzr] + the 'bzr' executable exists and provides the standard CLI +[case-sensitive] + $WORK filesystem is case-sensitive +[cc:*] + go env CC = (ignoring the go/env file) +[cgo] + host CGO_ENABLED +[cgolinkext] + platform requires external linking for cgo +[compiler:*] + runtime.Compiler == +[cross] + cmd/go GOOS/GOARCH != GOHOSTOS/GOHOSTARCH +[exec:*] + names an executable in the test binary's PATH +[fuzz] + GOOS/GOARCH supports -fuzz +[fuzz-instrumented] + GOOS/GOARCH supports -fuzz with instrumentation +[git] + the 'git' executable exists and provides the standard CLI +[git-sha256] + the local 'git' version is recent enough to support sha256 object/commit hashes +[go-builder] + GO_BUILDER_NAME is non-empty +[link] + testenv.HasLink() +[msan] + GOOS/GOARCH supports -msan +[mustlinkext] + platform always requires external linking +[net:*] + can connect to external network host +[pielinkext] + platform requires external linking for PIE +[race] + GOOS/GOARCH supports -race +[root] + os.Geteuid() == 0 +[short] + testing.Short() +[symlink] + testenv.HasSymlink() +[trimpath] + test binary was built with -trimpath +[verbose] + testing.Verbose() + diff --git a/go/src/cmd/go/testdata/script/autocgo.txt b/go/src/cmd/go/testdata/script/autocgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..586c80251da3196433bcb4adce706b59cbd54ec6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/autocgo.txt @@ -0,0 +1,29 @@ +# Test automatic setting of CGO_ENABLED based on $CC and what's in $PATH. + +[!cgo] skip +[cross] skip + +# Assume we're on a system that can enable cgo normally. +env CGO_ENABLED= +go env CGO_ENABLED +stdout 1 + +# Clearing CC and removing everything but Go from the PATH should usually +# disable cgo: no C compiler anymore (unless the baked-in defaultCC is an +# absolute path and exists. +env CC= +env PATH=$GOROOT/bin +go env CGO_ENABLED +[!abscc] stdout 0 +[abscc] stdout 1 + +# Setting CC should re-enable cgo. +env CC=cc +go env CGO_ENABLED +stdout 1 + +# So should setting CGO_ENABLED. +env CC= +env CGO_ENABLED=1 +go env CGO_ENABLED +stdout 1 diff --git a/go/src/cmd/go/testdata/script/badgo.txt b/go/src/cmd/go/testdata/script/badgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..cf4e2584d656508ef0505e568b1d6b0866371160 --- /dev/null +++ b/go/src/cmd/go/testdata/script/badgo.txt @@ -0,0 +1,50 @@ +go get example.net/badgo@v1.0.0 +go get example.net/badgo@v1.1.0 +go get example.net/badgo@v1.2.0 +go get example.net/badgo@v1.3.0 +go get example.net/badgo@v1.4.0 +go get example.net/badgo@v1.5.0 +! go get example.net/badgo@v1.6.0 +stderr 'invalid go version .X.Y.: must match format 1.23' + +-- go.mod -- +module m + +replace ( + example.net/badgo v1.0.0 => ./v1.0.0 + example.net/badgo v1.1.0 => ./v1.1.0 + example.net/badgo v1.2.0 => ./v1.2.0 + example.net/badgo v1.3.0 => ./v1.3.0 + example.net/badgo v1.4.0 => ./v1.4.0 + example.net/badgo v1.5.0 => ./v1.5.0 + example.net/badgo v1.6.0 => ./v1.6.0 +) + +-- v1.0.0/go.mod -- +module example.net/badgo +go 1.17.0 + +-- v1.1.0/go.mod -- +module example.net/badgo +go 1.17rc2 + +-- v1.2.0/go.mod -- +module example.net/badgo +go 1.17.1 + +-- v1.3.0/go.mod -- +module example.net/badgo +go v1.17.0 + +-- v1.4.0/go.mod -- +module example.net/badgo +go v1.17.0-rc.2 + +-- v1.5.0/go.mod -- +module example.net/badgo +go v1.17.1 + +-- v1.6.0/go.mod -- +module example.net/badgo +go X.Y + diff --git a/go/src/cmd/go/testdata/script/bug.txt b/go/src/cmd/go/testdata/script/bug.txt new file mode 100644 index 0000000000000000000000000000000000000000..f64fb85bdc42e037f6c8ec7b894b3baa728a78f6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/bug.txt @@ -0,0 +1,58 @@ +# Verify that go bug creates the appropriate URL issue body + +[!GOOS:linux] skip +[short] skip + +go install +go build -o $TMPDIR/go ./go +env BROWSER=$GOPATH/bin/browser PATH=$TMPDIR:$PATH +go bug +exists $TMPDIR/browser +grep '^go version' $TMPDIR/browser +grep '^GOROOT/bin/go version: go version' $TMPDIR/browser +grep '^GOROOT/bin/go tool compile -V: compile version' $TMPDIR/browser +grep '^uname -sr: Linux' $TMPDIR/browser + +-- go.mod -- +module browser + +-- main.go -- +package main + +import ( + "fmt" + "net/url" + "os" + "path/filepath" +) + +func main() { + u, err := url.Parse(os.Args[1]) + if err != nil { + panic(err) + } + body, err := url.PathUnescape(u.Query().Get("body")) + if err != nil { + panic(err) + } + out := filepath.Join(os.TempDir(), "browser") + f, err := os.Create(out) + if err != nil { + panic(err) + } + fmt.Fprintln(f, body) + if err := f.Close(); err != nil { + panic(err) + } +} + +-- go/main.go -- +package main + +import ( + "os" +) + +func main() { + os.Exit(1) +} diff --git a/go/src/cmd/go/testdata/script/build_GOTMPDIR.txt b/go/src/cmd/go/testdata/script/build_GOTMPDIR.txt new file mode 100644 index 0000000000000000000000000000000000000000..6ad0157e5f629b79d8add3abc34ab2295c2823e6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_GOTMPDIR.txt @@ -0,0 +1,52 @@ +[short] skip 'runs build' + +# Set GOCACHE to a clean directory to ensure that 'go build' has work to report. +[!GOOS:windows] env GOCACHE=$WORK/gocache +[GOOS:windows] env GOCACHE=$WORK\gocache + +# 'go build' should use GOTMPDIR if set. +[!GOOS:windows] env GOTMPDIR=$WORK/my-favorite-tmpdir +[GOOS:windows] env GOTMPDIR=$WORK\my-favorite-tmpdir +mkdir $GOTMPDIR +go build -x hello.go +stderr ^WORK=.*my-favorite-tmpdir + +# Make GOTMPDIR a regular file. This prevents the creation of work directories, +# so we can check that certain commands don't create them. +# This simulates running on a full disk or a read-only volume. +rm $GOTMPDIR +cp hello.go $GOTMPDIR # any file will do + +# 'go build' should fail if GOTMPDIR is read-only. +! go build -x . +stderr '^go: creating work dir: \w+ '$GOTMPDIR + +# 'go list' should only fail if it needs to build something. +go list -x . +! stderr 'creating work dir' +stdout m +go list -m all +stdout m +! go list -x -export . +stderr '^go: creating work dir: \w+ '$GOTMPDIR + +# 'go clean -cache' and 'go clean -modcache' should not fail. +go clean -x -cache +! stderr 'creating work dir' +go clean -x -modcache +! stderr 'creating work dir' + +# 'go env' should not fail for specific variables. +# Without arguments, it needs to initialize a builder to load cgo flags, and +# that uses a temporary directory. +! go env +stderr '^go: creating work dir: \w+ '$GOTMPDIR +go env GOROOT + +-- go.mod -- +module m + +go 1.15 +-- hello.go -- +package main +func main() { println("hello") } diff --git a/go/src/cmd/go/testdata/script/build_acl_windows.txt b/go/src/cmd/go/testdata/script/build_acl_windows.txt new file mode 100644 index 0000000000000000000000000000000000000000..2cb60e0ffdcfdba14cfe820db7d29d271751796b --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_acl_windows.txt @@ -0,0 +1,44 @@ +[!GOOS:windows] stop +[!exec:icacls] skip +[!exec:powershell] skip + +# Create $WORK\guest and give the Guests group full access. +# Files created within that directory will have different security attributes by default. +mkdir $WORK\guest +exec icacls $WORK\guest /grant '*S-1-5-32-546:(oi)(ci)f' + +env TMP=$WORK\guest +env TEMP=$WORK\guest + +# Build a binary using the guest directory as an intermediate +cd TestACL +go build -o main.exe main.go +# Build the same binary, but write it to the guest directory. +go build -o $TMP\main.exe main.go + +# Read ACLs for the files. +exec powershell -Command 'Get-Acl main.exe | Select -expand AccessToString' +cp stdout $WORK\exe-acl.txt +exec powershell -Command 'Get-Acl main.go | Select -expand AccessToString' +cp stdout $WORK\src-acl.txt +cd $TMP +exec powershell -Command 'Get-Acl main.exe | Select -expand AccessToString' +cp stdout $WORK\guest-acl.txt + +cd $WORK + +# The executable written to the source directory should have the same ACL as the source file. +cmp $WORK\exe-acl.txt $WORK\src-acl.txt + +# The file written to the guest-allowed directory should give Guests control. +grep 'BUILTIN\\Guests\s+Allow' $WORK\guest-acl.txt + +# The file written to the ordinary directory should not. +! grep 'BUILTIN\\Guests\s+Allow' $WORK\exe-acl.txt + + +-- TestACL/go.mod -- +module TestACL +-- TestACL/main.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_arm.txt b/go/src/cmd/go/testdata/script/build_arm.txt new file mode 100644 index 0000000000000000000000000000000000000000..ff2a36456e406d4444ee82bd14bc14ce20806bfd --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_arm.txt @@ -0,0 +1,13 @@ +[short] skip 'skipping cross-compile in short mode' + +env GOARCH=arm +env GOOS=linux +env GOARM=5 + +go build hello.go +! stderr 'unable to find math.a' + +-- hello.go -- +package main + +func main() {} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/build_buildvcs_auto.txt b/go/src/cmd/go/testdata/script/build_buildvcs_auto.txt new file mode 100644 index 0000000000000000000000000000000000000000..cfd5d8243b8e2007f4d32858477e5220d2215819 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_buildvcs_auto.txt @@ -0,0 +1,91 @@ +# Regression test for https://go.dev/issue/51748: by default, 'go build' should +# not attempt to stamp VCS information when the VCS tool is not present. + +[short] skip +[!git] skip + +cd sub +exec git init . +exec git config user.name 'Nameless Gopher' +exec git config user.email 'nobody@golang.org' +exec git add sub.go +exec git commit -m 'initial state' +cd .. + +exec git init +exec git config user.name 'Nameless Gopher' +exec git config user.email 'nobody@golang.org' +exec git submodule add ./sub +exec git add go.mod example.go +exec git commit -m 'initial state' + + +# Control case: with a git binary in $PATH, +# 'go build' on a package in the same git repo +# succeeds and stamps VCS metadata by default. + +go build -o example.exe . +go version -m example.exe +stdout '^\tbuild\tvcs=git$' +stdout '^\tbuild\tvcs.modified=false$' + + +# Building a binary from a different (nested) VCS repo should not stamp VCS +# info. It should be an error if VCS stamps are requested explicitly with +# '-buildvcs' (since we know the VCS metadata exists), but not an error +# with '-buildvcs=auto'. + +go build -o sub.exe ./sub +go version -m sub.exe +! stdout '^\tbuild\tvcs' + +! go build -buildvcs -o sub.exe ./sub +stderr '\Aerror obtaining VCS status: main package is in repository ".*" but current directory is in repository ".*"\n\tUse -buildvcs=false to disable VCS stamping.\n\z' + +cd ./sub +go build -o sub.exe . +go version -m sub.exe +! stdout '^\tbuild\tvcs' + +! go build -buildvcs -o sub.exe . +stderr '\Aerror obtaining VCS status: main module is in repository ".*" but current directory is in repository ".*"\n\tUse -buildvcs=false to disable VCS stamping.\n\z' +cd .. + + +# After removing 'git' from $PATH, 'go build -buildvcs' should fail... + +env PATH= +env path= +! go build -buildvcs -o example.exe . +stderr 'go: missing Git command\. See https://golang\.org/s/gogetcmd$' + +# ...but by default we should omit VCS metadata when the tool is missing. + +go build -o example.exe . +go version -m example.exe +! stdout '^\tbuild\tvcs' + +# The default behavior can be explicitly set with '-buildvcs=auto'. + +go build -buildvcs=auto -o example.exe . +go version -m example.exe +! stdout '^\tbuild\tvcs' + +# Other flag values should be rejected with a useful error message. + +! go build -buildvcs=hg -o example.exe . +stderr '\Ainvalid boolean value "hg" for -buildvcs: value is neither ''auto'' nor a valid bool\nusage: go build .*\nRun ''go help build'' for details.\n\z' + + +-- go.mod -- +module example + +go 1.18 +-- example.go -- +package main + +func main() {} +-- sub/sub.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_cache_arch_mode.txt b/go/src/cmd/go/testdata/script/build_cache_arch_mode.txt new file mode 100644 index 0000000000000000000000000000000000000000..931827fbde62334cb8da3aa5c4bf95204eb80e1e --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cache_arch_mode.txt @@ -0,0 +1,21 @@ +# Issue 9737: verify that GOARM affects the computed build ID + +[short] skip + +# arm +env GOOS=linux +env GOARCH=arm +env GOARM=5 +go install mycmd +env GOARM=7 +stale mycmd + + +-- go.mod -- +module mycmd + +go 1.16 +-- x.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_cache_compile.txt b/go/src/cmd/go/testdata/script/build_cache_compile.txt new file mode 100644 index 0000000000000000000000000000000000000000..64b391f9aa4651dcac1826be4a74f95f7bc9d2f7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cache_compile.txt @@ -0,0 +1,21 @@ +env GO111MODULE=off +[short] skip + +# Set up fresh GOCACHE. +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +# Building trivial non-main package should run compiler the first time. +go build -x lib.go +stderr '(compile|gccgo)( |\.exe).*lib\.go' + +# ... but not again ... +go build -x lib.go +! stderr '(compile|gccgo)( |\.exe).*lib\.go' + +# ... unless we use -a. +go build -a -x lib.go +stderr '(compile|gccgo)( |\.exe)' + +-- lib.go -- +package lib diff --git a/go/src/cmd/go/testdata/script/build_cache_disabled.txt b/go/src/cmd/go/testdata/script/build_cache_disabled.txt new file mode 100644 index 0000000000000000000000000000000000000000..cb1a7558fca71f3edab009c32329376f45b7a45e --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cache_disabled.txt @@ -0,0 +1,50 @@ +# The build cache is required to build anything. It also may be needed to +# initialize the build system, which is needed for commands like 'go env'. +# However, there are lots of commands the cache is not needed for, and we +# shouldn't require it when it won't be used. +# +# TODO(golang.org/issue/39882): commands below should work, too. +# * go clean -modcache +# * go env +# * go fix +# * go fmt +# * go generate +# * go get +# * go list (without -export or -compiled) + +env GOCACHE=off + +# Commands that don't completely load packages should work. +go doc fmt +stdout Printf + +! go tool compile -h +stderr usage: + +go version +stdout '^go version' + + +# Module commands that don't load packages should work. +go mod init m +exists go.mod + +go mod edit -require rsc.io/quote@v1.5.2 + +go mod download rsc.io/quote + +go mod graph +stdout rsc.io/quote + +go mod verify + + +# Commands that load but don't build packages should work. +go fmt . + +go doc . + +-- main.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_cache_gomips.txt b/go/src/cmd/go/testdata/script/build_cache_gomips.txt new file mode 100644 index 0000000000000000000000000000000000000000..0cbf16a923b8b2c129a9a7149afc761755e1f207 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cache_gomips.txt @@ -0,0 +1,40 @@ +env GO111MODULE=off +[short] skip # rebuilds std for mips + +# Set up fresh GOCACHE. +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +# Building for mipsle without setting GOMIPS will use floating point registers. +env GOARCH=mipsle +env GOOS=linux +go build -gcflags=-S f.go +stderr ADDD.F[0-9]+,.F[0-9]+,.F[0-9]+ + +# Clean cache +go clean -cache + +# Building with GOMIPS=softfloat will not use floating point registers +env GOMIPS=softfloat +go build -gcflags=-S f.go +! stderr ADDD.F[0-9]+,.F[0-9]+,.F[0-9]+ + +# Clean cache +go clean -cache + +# Build without setting GOMIPS +env GOMIPS= +go build -gcflags=-S f.go +stderr ADDD.F[0-9]+,.F[0-9]+,.F[0-9]+ + +# Building with GOMIPS should still not use floating point registers. +env GOMIPS=softfloat +go build -gcflags=-S f.go +! stderr ADDD.F[0-9]+,.F[0-9]+,.F[0-9]+ + +-- f.go -- +package f + +func F(x float64) float64 { + return x + x +} diff --git a/go/src/cmd/go/testdata/script/build_cache_link.txt b/go/src/cmd/go/testdata/script/build_cache_link.txt new file mode 100644 index 0000000000000000000000000000000000000000..b9c740ac10ea23acdb23901b3d9a113081e5d169 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cache_link.txt @@ -0,0 +1,26 @@ +env GO111MODULE=off +[short] skip + +# Set up fresh GOCACHE. +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +# Building a main package should run the compiler and linker ... +go build -o $devnull -x main.go +stderr '(compile|gccgo)( |\.exe).*main\.go' +stderr '(link|gccgo)( |\.exe)' + +# ... and then the linker again ... +go build -o $devnull -x main.go +! stderr '(compile|gccgo)( |\.exe).*main\.go' +stderr '(link|gccgo)( |\.exe)' + +# ... but the output binary can serve as a cache. +go build -o main$GOEXE -x main.go +stderr '(link|gccgo)( |\.exe)' +go build -o main$GOEXE -x main.go +! stderr '(link|gccgo)( |\.exe)' + +-- main.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_cache_output.txt b/go/src/cmd/go/testdata/script/build_cache_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..fc040b48cfe5f0a6a7748d15a3de1fc1a8e1c009 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cache_output.txt @@ -0,0 +1,67 @@ +env GO111MODULE=off +env GODEBUG=gocachetest=1 + +[!compiler:gc] skip +[short] skip # clears cache, rebuilds too much + +# Set up fresh GOCACHE. +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +# Building a trivial non-main package should run compiler the first time. +go build -x -gcflags=-m lib.go +stderr 'compile( |\.exe"?)' +stderr 'lib.go:2.* can inline f' + +# ... but not the second, even though it still prints the compiler output. +go build -x -gcflags=-m lib.go +! stderr 'compile( |\.exe"?)' +stderr 'lib.go:2.* can inline f' + +# Building a trivial main package should run the compiler and linker the first time. +go build -x -gcflags=-m -ldflags='-v -w' main.go +stderr 'compile( |\.exe"?)' +stderr 'main.go:2.* can inline main' # from compiler +stderr 'link(\.exe"?)? -' +stderr '\d+ symbols' # from linker + +# ... but not the second, even though it still prints the compiler and linker output. +go build -x -gcflags=-m -ldflags='-v -w' main.go +! stderr 'compile( |\.exe"?)' +stderr 'main.go:2.* can inline main' # from compiler +! stderr 'link(\.exe"?)? -' +stderr '\d+ symbols' # from linker + +# Running a test should run the compiler, linker, and the test the first time. +go test -v -x -gcflags=-m -ldflags=-v p +stderr 'compile( |\.exe"?)' +stderr 'p_test.go:.*can inline Test' # from compile of p_test +stderr 'testmain\.go:.*inlin' # from compile of testmain +stderr 'link(\.exe"?)? -' +stderr '\d+ symbols' # from linker +stderr 'p\.test( |\.exe"?)' +stdout 'TEST' # from test + +# ... but not the second, even though it still prints the compiler, linker, and test output. +go test -v -x -gcflags=-m -ldflags=-v p +! stderr 'compile( |\.exe"?)' +stderr 'p_test.go:.*can inline Test' # from compile of p_test +stderr 'testmain\.go:.*inlin' # from compile of testmain +! stderr 'link(\.exe"?)? -' +stderr '\d+ symbols' # from linker +! stderr 'p\.test( |\.exe"?)' +stdout 'TEST' # from test + + +-- lib.go -- +package p +func f(x *int) *int { return x } + +-- main.go -- +package main +func main() {} + +-- p/p_test.go -- +package p +import "testing" +func Test(t *testing.T) {println("TEST")} diff --git a/go/src/cmd/go/testdata/script/build_cache_pgo.txt b/go/src/cmd/go/testdata/script/build_cache_pgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..cedae03cf8247a1310e1dc5c66b315ac8723bf81 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cache_pgo.txt @@ -0,0 +1,33 @@ +[short] skip + +# Set up fresh GOCACHE. +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +# Building trivial non-main package should run preprofile the first time. +go build -x -pgo=default.pgo lib.go +stderr 'preprofile.*default\.pgo' + +# ... but not again ... +go build -x -pgo=default.pgo lib.go +! stderr 'preprofile.*default\.pgo' + +# ... unless we use -a. +go build -a -x -pgo=default.pgo lib.go +stderr 'preprofile.*default\.pgo' + +# ... building a different package should not run preprofile again, instead +# using a profile from cache. +# +# Note we can't directly look for $GOCACHE in the regex below because the +# Windows slashes would need to be escaped. Instead just look for the "gocache" +# component (specified above) as an approximation. +go build -x -pgo=default.pgo lib2.go +! stderr 'preprofile.*default\.pgo' +stderr 'compile.*-pgoprofile=\S+gocache.*lib2.go' + +-- lib.go -- +package lib +-- lib2.go -- +package lib2 +-- default.pgo -- diff --git a/go/src/cmd/go/testdata/script/build_cache_trimpath.txt b/go/src/cmd/go/testdata/script/build_cache_trimpath.txt new file mode 100644 index 0000000000000000000000000000000000000000..7ee3c3b41d489a7cd3059efe567737f25b040559 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cache_trimpath.txt @@ -0,0 +1,47 @@ +[short] skip +env GO111MODULE=on + +# Set up fresh GOCACHE. +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +cd $WORK +go build -o a.out + +# Varying -trimpath should cause a rebuild. +go build -x -o a.out -trimpath +stderr '(compile|gccgo)( |\.exe)' +stderr 'link( |\.exe)' + +# Two distinct versions of the same module with identical content should +# still be cached separately. +# Verifies golang.org/issue/35412. +go get example.com/stack@v1.0.0 +go run -trimpath printstack.go +stdout '^example.com/stack@v1.0.0/stack.go$' +go get example.com/stack@v1.0.1 +go run -trimpath printstack.go +stdout '^example.com/stack@v1.0.1/stack.go$' + +-- $WORK/hello.go -- +package main +func main() { println("hello") } + +-- $WORK/printstack.go -- +// +build ignore + +package main + +import ( + "fmt" + + "example.com/stack" +) + +func main() { + fmt.Println(stack.TopFile()) +} +-- $WORK/go.mod -- +module m + +go 1.14 diff --git a/go/src/cmd/go/testdata/script/build_cacheprog_issue70848.txt b/go/src/cmd/go/testdata/script/build_cacheprog_issue70848.txt new file mode 100644 index 0000000000000000000000000000000000000000..194fd47d93443d8379ece62ee55c8e4dafbff5d1 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cacheprog_issue70848.txt @@ -0,0 +1,27 @@ +[short] skip 'builds go programs' + +go build -o cacheprog$GOEXE cacheprog.go +env GOCACHEPROG=$GOPATH/src/cacheprog$GOEXE + +# This should not deadlock +go build simple.go +! stderr 'cacheprog closed' + +-- simple.go -- +package main + +func main() {} +-- cacheprog.go -- +// This is a minimal GOCACHEPROG program that doesn't respond to close. +package main + +import ( + "encoding/json" + "os" +) + +func main() { + json.NewEncoder(os.Stdout).Encode(map[string][]string{"KnownCommands": {"close"}}) + var res struct{} + json.NewDecoder(os.Stdin).Decode(&res) +} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/build_cc_cache_issue64423.txt b/go/src/cmd/go/testdata/script/build_cc_cache_issue64423.txt new file mode 100644 index 0000000000000000000000000000000000000000..f1bc2c3108596fab59b70326ea3587c4b28a2e05 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cc_cache_issue64423.txt @@ -0,0 +1,121 @@ +# Regression test for https://go.dev/issue/64423: +# +# When we parse the version for a Clang binary, we should accept +# an arbitrary vendor prefix, which (as of 2023) may be injected +# by defining CLANG_VENDOR when building clang itself. +# +# Since we don't want to actually rebuild the Clang toolchain in +# this test, we instead simulate it by injecting a fake "clang" +# binary that runs the real one as a subprocess. + +[!cgo] skip +[short] skip 'builds and links a fake clang binary' +[!cc:clang] skip 'test is specific to clang version parsing' + +# Save the location of the real clang command for our fake one to use. +go run ./which clang +cp stdout $WORK/.realclang + +# Build a fake clang and ensure that it is the one in $PATH. +mkdir $WORK/bin +go build -o $WORK/bin/clang$GOEXE ./fakeclang +[!GOOS:plan9] env PATH=$WORK${/}bin +[GOOS:plan9] env path=$WORK${/}bin + +# Force CGO_ENABLED=1 so that the following commands should error +# out if the fake clang doesn't work. +env CGO_ENABLED=1 + +# The bug in https://go.dev/issue/64423 resulted in cache keys that +# didn't contain any information about the C compiler. +# Since the bug was in cache key computation, isolate the cache: +# if we change the way caching works, we want the test to fail +# instead of accidentally reusing the cached information from a +# previous test run. +env GOCACHE=$WORK${/}.cache +mkdir $GOCACHE + +go build -x runtime/cgo + + # Tell our fake clang to stop working. + # Previously, 'go build -x runtime/cgo' would continue to + # succeed because both the broken clang and the non-broken one + # resulted in a cache key with no clang version information. +env GO_BREAK_CLANG=1 +! go build -x runtime/cgo +stderr '# runtime/cgo\nGO_BREAK_CLANG is set' + +-- go.mod -- +module example/issue64423 +go 1.20 +-- which/main.go -- +package main + +import ( + "os" + "os/exec" +) + +func main() { + path, err := exec.LookPath(os.Args[1]) + if err != nil { + panic(err) + } + os.Stdout.WriteString(path) +} +-- fakeclang/main.go -- +package main + +import ( + "bufio" + "bytes" + "log" + "os" + "os/exec" + "path/filepath" + "strings" +) + +func main() { + if os.Getenv("GO_BREAK_CLANG") != "" { + os.Stderr.WriteString("GO_BREAK_CLANG is set\n") + os.Exit(1) + } + + b, err := os.ReadFile(filepath.Join(os.Getenv("WORK"), ".realclang")) + if err != nil { + log.Fatal(err) + } + clang := string(bytes.TrimSpace(b)) + cmd := exec.Command(clang, os.Args[1:]...) + cmd.Stdout = os.Stdout + stderr, err := cmd.StderrPipe() + if err != nil { + log.Fatal(err) + } + + if err := cmd.Start(); err != nil { + log.Fatal(err) + } + + r := bufio.NewReader(stderr) + for { + line, err := r.ReadString('\n') + if line != "" { + if strings.Contains(line, "clang version") { + // Simulate a clang version string with an arbitrary vendor prefix. + const vendorString = "Gopher Solutions Unlimited " + os.Stderr.WriteString(vendorString) + } + os.Stderr.WriteString(line) + } + if err != nil { + break + } + } + os.Stderr.Close() + + if err := cmd.Wait(); err != nil { + os.Exit(1) + } +} diff --git a/go/src/cmd/go/testdata/script/build_cc_cache_issue64589.txt b/go/src/cmd/go/testdata/script/build_cc_cache_issue64589.txt new file mode 100644 index 0000000000000000000000000000000000000000..42ae91b196c2b63d23554e468f17bb7fe10fa51b --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cc_cache_issue64589.txt @@ -0,0 +1,100 @@ +# Regression test for https://go.dev/issue/64589: +# This test is very similar to build_cc_cache_issue64423. Issue #64423 +# was that we weren't properly parsing the versions output by the compiler. +# That test checked that we could parse the version and incorporate the +# version into the hash for the action id. This issue #64589 is that +# we treat all errors getting the version of the compiler the same, so +# we'd get the same action id for a missing compiler vs one whose +# version is unparseable. So the test now first does a run with a compiler +# that produces unparseable version output, and then runs it again with a missing +# compiler and ensures the command doesn't return the cached output for the +# first run when running the second run. + +[!cgo] skip +[short] skip 'builds and links a fake clang binary' +[!cc:clang] skip 'test is specific to clang version parsing' + +# Save the location of the real clang command for our fake one to use. +go run ./which clang +cp stdout $WORK/.realclang + +# Build a fake clang and ensure that it is the one in $PATH. +mkdir $WORK/bin +go build -o $WORK/bin/clang$GOEXE ./fakeclang +[!GOOS:plan9] env PATH=$WORK${/}bin +[GOOS:plan9] env path=$WORK${/}bin + +# Force CGO_ENABLED=1 so that the following commands should error +# out if the fake clang doesn't work. +env CGO_ENABLED=1 + +# The bug in https://go.dev/issue/64589 resulted in cache keys that +# didn't contain any information about the error getting the compiler version. +# Since the bug was in cache key computation, isolate the cache: +# if we change the way caching works, we want the test to fail +# instead of accidentally reusing the cached information from a +# previous test run. +env GOCACHE=$WORK${/}.cache +mkdir $GOCACHE + +go build -x runtime/cgo + + # Tell our fake clang to stop working. + # Previously, 'go build -x runtime/cgo' would continue to + # succeed because both the broken clang and the non-broken one + # resulted in a cache key with no clang version information. +env GO_BREAK_CLANG=1 +! go build -x runtime/cgo +stderr '# runtime/cgo\nGO_BREAK_CLANG is set' + +-- go.mod -- +module example/issue64589 +go 1.20 +-- which/main.go -- +package main + +import ( + "os" + "os/exec" +) + +func main() { + path, err := exec.LookPath(os.Args[1]) + if err != nil { + panic(err) + } + os.Stdout.WriteString(path) +} +-- fakeclang/main.go -- +package main + +import ( + "bytes" + "log" + "os" + "os/exec" + "path/filepath" + "slices" +) + +func main() { + if os.Getenv("GO_BREAK_CLANG") != "" { + os.Stderr.WriteString("GO_BREAK_CLANG is set\n") + os.Exit(1) + } + + b, err := os.ReadFile(filepath.Join(os.Getenv("WORK"), ".realclang")) + if err != nil { + log.Fatal(err) + } + if slices.Contains(os.Args, "-###") { // We are being run by gccToolID to determine the tool id used in the action id. + return // The important thing is that we don't print the string "version"! + } + clang := string(bytes.TrimSpace(b)) + cmd := exec.Command(clang, os.Args[1:]...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + log.Fatal(err) + } +} diff --git a/go/src/cmd/go/testdata/script/build_cd_gopath_different.txt b/go/src/cmd/go/testdata/script/build_cd_gopath_different.txt new file mode 100644 index 0000000000000000000000000000000000000000..64d7d74ce214fd9b4567d19067885ea3e985924f --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cd_gopath_different.txt @@ -0,0 +1,73 @@ +[compiler:gccgo] skip 'gccgo does not support -ldflags -X' +env GO111MODULE=off +go build run_go.go + +# Apply identity function to GOPATH +exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH IDENTITY build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked +exec $WORK/tmp/a.exe +stderr 'linkXworked' +rm $WORK/tmp/a.exe + +[!GOOS:windows] stop 'rest of the tests only apply to Windows' + +# Replace '\' with '/' in GOPATH +exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH REPLACE_SLASH build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked +exec $WORK/tmp/a.exe +stderr 'linkXworked' +rm $WORK/tmp/a.exe + +# Apply identity function to GOPATH +exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH UPPER build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked +exec $WORK/tmp/a.exe +stderr 'linkXworked' +rm $WORK/tmp/a.exe + +# Apply identity function to GOPATH +exec ./run_go$GOEXE $GOPATH/src/my.pkg/main $GOPATH LOWER build -o $WORK/tmp/a.exe -ldflags -X=my.pkg.Text=linkXworked +exec $WORK/tmp/a.exe +stderr 'linkXworked' +rm $WORK/tmp/a.exe + +-- run_go.go -- +package main + +import ( + "fmt" + "os" + "os/exec" + "strings" +) + +func main() { + dir := os.Args[1] + gopath := os.Args[2] + switch os.Args[3] { + case "IDENTITY": + case "REPLACE_SLASH": gopath = strings.ReplaceAll(gopath, `\`, `/`) + case "UPPER": gopath = strings.ToUpper(gopath) + case "LOWER": gopath = strings.ToLower(gopath) + default: fmt.Fprintln(os.Stderr, "bad op"); os.Exit(1) + } + cmd := exec.Command("go", os.Args[4:]...) + cmd.Dir = dir + cmd.Env = append(os.Environ(), "GOPATH="+gopath) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} + +-- my.pkg/main/main.go -- +package main + +import "my.pkg" + +func main() { + println(pkg.Text) +} +-- my.pkg/pkg.go -- +package pkg + +var Text = "unset" diff --git a/go/src/cmd/go/testdata/script/build_cgo_consistent_results.txt b/go/src/cmd/go/testdata/script/build_cgo_consistent_results.txt new file mode 100644 index 0000000000000000000000000000000000000000..f22994f71fcaf5247c483af3e274d29d640bc4f3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cgo_consistent_results.txt @@ -0,0 +1,23 @@ +[short] skip +[!cgo] skip + +[GOOS:solaris] skip "skipping on Solaris; see golang.org/issue/13247" +[GOOS:illumos] skip "skipping on Solaris; see golang.org/issue/13247" + +go build -o $WORK/exe1$GOEXE cgotest +go build -x -o $WORK/exe2$GOEXE cgotest + +# TODO(matloob): skip if stderr does not contain '-fdebug-prefix-map=\$WORK' + +cmp $WORK/exe1$GOEXE $WORK/exe2$GOEXE + +-- go.mod -- +module cgotest + +go 1.16 +-- m.go -- +package cgotest + +import "C" + +var _ C.int diff --git a/go/src/cmd/go/testdata/script/build_cgo_error.txt b/go/src/cmd/go/testdata/script/build_cgo_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..c11ab46ecc344ce93b7f20ea5c0eabb3d0f771de --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cgo_error.txt @@ -0,0 +1,17 @@ +[short] skip +[!cgo] skip + +! go build . +stderr '# foo\nfoo.c:' +! stderr 'EXTRA string' + +-- go.mod -- +module foo + +go 1.20 +-- foo.go -- +package foo + +import "C" +-- foo.c -- +#include "doesnotexist.h" \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/build_concurrent_backend.txt b/go/src/cmd/go/testdata/script/build_concurrent_backend.txt new file mode 100644 index 0000000000000000000000000000000000000000..9cac635e5a6760ca21b89163cdf6eec6b650382f --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_concurrent_backend.txt @@ -0,0 +1,10 @@ +# Tests golang.org/issue/48490 +# cmd/go should enable concurrent compilation by default + +# Reset all experiments, since one of them can disable +# concurrent compilation, e.g: fieldtrack. +env GOEXPERIMENT=none + +env GOMAXPROCS=4 +go build -n -x -a fmt +stderr ' -c=4 ' diff --git a/go/src/cmd/go/testdata/script/build_cwd_newline.txt b/go/src/cmd/go/testdata/script/build_cwd_newline.txt new file mode 100644 index 0000000000000000000000000000000000000000..91cb57fa49e8219c18fcf16ee290676a2966353e --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_cwd_newline.txt @@ -0,0 +1,138 @@ +[GOOS:windows] skip 'filesystem normalizes / to \' +[GOOS:plan9] skip 'filesystem disallows \n in paths' + +# If the directory path containing a package to be built includes a newline, +# the go command should refuse to even try to build the package. + +env DIR=$WORK${/}${newline}'package main'${newline}'func main() { panic("uh-oh")'${newline}'/*' + +mkdir $DIR +cd $DIR +exec pwd +cp $WORK/go.mod ./go.mod +cp $WORK/main.go ./main.go +cp $WORK/main_nocgo.go ./main_nocgo.go +cp $WORK/main_test.go ./main_test.go + +! go build -o $devnull . +stderr 'package example: invalid package directory .*uh-oh' + +[cgo] ! go build -o $devnull main.go +[!cgo] ! go build -o $devnull main_nocgo.go +stderr 'package command-line-arguments: invalid package directory .*uh-oh' + +! go run . +stderr 'package example: invalid package directory .*uh-oh' + +[cgo] ! go run main.go +[!cgo] ! go run main_nocgo.go +stderr 'package command-line-arguments: invalid package directory .*uh-oh' + +! go test . +stderr 'package example: invalid package directory .*uh-oh' + +[cgo] ! go test -v main.go main_test.go +[!cgo] ! go test -v main_nocgo.go main_test.go +stderr 'package command-line-arguments: invalid package directory .*uh-oh' + +go list -compiled -e -f '{{with .CompiledGoFiles}}{{.}}{{end}}' . +! stdout . +! stderr . +! exists obj_ + + +# The cgo tool should only accept the source file if the working directory +# is not written in line directives in the resulting files. + +[cgo] ! go tool cgo main.go +[cgo] stderr 'cgo: input path contains newline character: .*uh-oh' +[cgo] ! exists _obj + +[cgo] go tool cgo -trimpath=$PWD main.go +[cgo] grep '//line main\.go:1:1' _obj/main.cgo1.go +[cgo] ! grep 'uh-oh' _obj/main.cgo1.go +[cgo] rm _obj + + +# Since we do preserve $PWD (or set it appropriately) for commands, and we do +# not resolve symlinks unnecessarily, referring to the contents of the unsafe +# directory via a safe symlink should be ok, and should not inject the data from +# the symlink target path. + +[!symlink] stop 'remainder of test checks symlink behavior' +[short] stop 'links and runs binaries' + +symlink $WORK${/}link -> $DIR + +[cgo] go run $WORK${/}link${/}main.go +[!cgo] go run $WORK${/}link${/}main_nocgo.go +! stdout panic +! stderr panic +stderr '^ok$' + +[cgo] go test -v $WORK${/}link${/}main.go $WORK${/}link${/}main_test.go +[!cgo] go test -v $WORK${/}link${/}main_nocgo.go $WORK${/}link${/}main_test.go +! stdout panic +! stderr panic +stdout '^ok$' # 'go test' combines the test's stdout into stderr + +cd $WORK/link + +[cgo] ! go run $DIR${/}main.go +[!cgo] ! go run $DIR${/}main_nocgo.go +stderr 'package command-line-arguments: invalid package directory .*uh-oh' + +go run . +! stdout panic +! stderr panic +stderr '^ok$' + +[cgo] go run main.go +[!cgo] go run main_nocgo.go +! stdout panic +! stderr panic +stderr '^ok$' + +go test -v +! stdout panic +! stderr panic +stdout '^ok$' # 'go test' combines the test's stdout into stderr + +go test -v . +! stdout panic +! stderr panic +stdout '^ok$' # 'go test' combines the test's stdout into stderr + +[cgo] go tool cgo main.go +[cgo] grep '//line .*'${/}'link'${/}'main\.go:1:1' _obj/main.cgo1.go +[cgo] ! grep 'uh-oh' _obj/main.cgo1.go + +-- $WORK/go.mod -- +module example +go 1.19 +-- $WORK/main.go -- +package main + +import "C" + +func main() { + /* nothing here */ + println("ok") +} +-- $WORK/main_nocgo.go -- +//go:build !cgo + +package main + +func main() { + /* nothing here */ + println("ok") +} +-- $WORK/main_test.go -- +package main + +import "testing" + +func TestMain(*testing.M) { + main() +} diff --git a/go/src/cmd/go/testdata/script/build_darwin_cc_arch.txt b/go/src/cmd/go/testdata/script/build_darwin_cc_arch.txt new file mode 100644 index 0000000000000000000000000000000000000000..df3fa5bd35fa90863d795f6aac73e52ee08511e2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_darwin_cc_arch.txt @@ -0,0 +1,24 @@ +# Test that we pass -arch flag to C compiler on Darwin (issue 43692). + +[!GOOS:darwin] skip +[!cgo] skip + +# clear CC, in case user sets it +env CC= + +env CGO_ENABLED=1 + +env GOARCH=amd64 +go build -n -x c.go +stderr 'clang.*-arch x86_64' + +env GOARCH=arm64 +go build -n -x c.go +stderr 'clang.*-arch arm64' + +-- c.go -- +package main + +import "C" + +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_dash_n_cgo.txt b/go/src/cmd/go/testdata/script/build_dash_n_cgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f49ef6f9ea80cba4e87b6c90e9e5541b1ddc88c --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_dash_n_cgo.txt @@ -0,0 +1,18 @@ +# Tests golang.org/issue/14944 + +[!cgo] skip + +go build -n foo.go +! stderr 'os.Stat .* no such file or directory' # there shouldn't be a stat of the archive file + +-- foo.go -- +package main + +/* +#include +*/ +import "C" + +func main() { + println(C.INT_MAX) +} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/build_dash_o_dev_null.txt b/go/src/cmd/go/testdata/script/build_dash_o_dev_null.txt new file mode 100644 index 0000000000000000000000000000000000000000..e415fc224dc1261f2ab5aa5450c08e01cb4a1862 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_dash_o_dev_null.txt @@ -0,0 +1,13 @@ +# Issue #25579 + +[short] skip + +go build -o $devnull hello.go +! exists 'hello'$GOEXE + +-- hello.go -- +package main + +func main() { + println("hello, world") +} diff --git a/go/src/cmd/go/testdata/script/build_dash_x.txt b/go/src/cmd/go/testdata/script/build_dash_x.txt new file mode 100644 index 0000000000000000000000000000000000000000..c7a2c6fe671ca72bdeca1c20c877e9857ef3a15a --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_dash_x.txt @@ -0,0 +1,55 @@ +[short] skip +[!cgo] skip + +[!exec:/usr/bin/env] skip +[!exec:bash] skip + +mkdir $WORK/tmp/cache +env GOCACHE=$WORK/tmp/cache + +# Before building our test main.go, ensure that an up-to-date copy of +# runtime/cgo is present in the cache. If it isn't, the 'go build' step below +# will fail with "can't open import". See golang.org/issue/29004. +# +# (The fix in golang.org/issue/29004 didn't completely fix the underlying issue: +# cmd/go/internal/load adds a bunch of implicit dependencies +# based on various heuristics, and, due to a bug described in +# https://golang.org/issue/31544#issuecomment-490607180, +# those implicit dependencies are not added early enough during +# loading to properly affect the import graph.) +go build runtime/cgo + +go build -x -o main ./... +cp stderr commands.txt +cat header.txt commands.txt +cp stdout test.sh + +exec ./main +cmp stderr hello.txt +rm ./main + +exec /usr/bin/env bash -x test.sh +exec ./main +cmp stderr hello.txt + +grep '^WORK=(.*)\n' commands.txt + +-- main.go -- +package main + +import "C" + +func main() { + print("hello\n") +} +-- go.mod -- +module example + +go 1.24 + +ignore foo +-- foo/foo.txt -- +-- header.txt -- +set -e +-- hello.txt -- +hello diff --git a/go/src/cmd/go/testdata/script/build_exe.txt b/go/src/cmd/go/testdata/script/build_exe.txt new file mode 100644 index 0000000000000000000000000000000000000000..a994d170884d64a5d0badecbb9d3e4031236b219 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_exe.txt @@ -0,0 +1,25 @@ +# go build with -o and -buildmode=exe should report an error on a non-main package. + +! go build -buildmode=exe -o out$GOEXE ./not_main +stderr '-buildmode=exe requires exactly one main package' +! exists out$GOEXE +! go build -buildmode=exe -o out$GOEXE ./main_one ./main_two +stderr '-buildmode=exe requires exactly one main package' +! exists out$GOEXE + +-- go.mod -- +module m + +go 1.16 +-- not_main/not_main.go -- +package not_main + +func F() {} +-- main_one/main_one.go -- +package main + +func main() {} +-- main_two/main_two.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_gcflags.txt b/go/src/cmd/go/testdata/script/build_gcflags.txt new file mode 100644 index 0000000000000000000000000000000000000000..9603e0b7b710e94c689637bd0836282b6ba06bef --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_gcflags.txt @@ -0,0 +1,22 @@ +env GO111MODULE=off + +# Test that the user can override default code generation flags. + +[compiler:gccgo] skip # gccgo does not use -gcflags +[!cgo] skip +[!GOOS:linux] skip # test only works if c-archive implies -shared +[short] skip + +env GOCACHE=$WORK/gocache # Looking for compile commands, so need a clean cache. +go build -x -n -buildmode=c-archive -gcflags=all=-shared=false ./override.go +stderr '^.*/compile (.* )?-shared (.* )?-shared=false' + +-- override.go -- +package main + +import "C" + +//export GoFunc +func GoFunc() {} + +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_gcflags_order.txt b/go/src/cmd/go/testdata/script/build_gcflags_order.txt new file mode 100644 index 0000000000000000000000000000000000000000..3725c89eb39231056fb52d1c0d177f529dd36567 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_gcflags_order.txt @@ -0,0 +1,22 @@ +# Tests golang.org/issue/47682 +# Flags specified with -gcflags should appear after other flags generated by cmd/go. + +cd m +go build -n -gcflags=-lang=go1.17 +stderr ' -lang=go1.16.* -lang=go1.17' +! go build -gcflags='-c 0' +stderr 'compile: -c must be at least 1, got 0' + +-- m/go.mod -- +module example.com + +go 1.16 + +-- m/main.go -- +package main + +func main() { + var s = []int{1, 2, 3} + var pa = (*[2]int)(s[1:]) + println(pa[1]) +} diff --git a/go/src/cmd/go/testdata/script/build_git_missing_tree.txt b/go/src/cmd/go/testdata/script/build_git_missing_tree.txt new file mode 100644 index 0000000000000000000000000000000000000000..43a9ae0a6d1a12d082f8df3b22debab07f888e93 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_git_missing_tree.txt @@ -0,0 +1,51 @@ +# Regression test for https://go.dev/issue/65339. +# Unnecessary git tree object required + +[short] skip 'constructs a local git repo' +[!git] skip + +env GIT_AUTHOR_NAME='Go Gopher' +env GIT_AUTHOR_EMAIL='gopher@golang.org' +env GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME +env GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL + +# Create 2 commit +env GIT_COMMITTER_DATE=2024-01-30T10:52:00+08:00 +env GIT_AUTHOR_DATE=2024-01-30T10:52:00+08:00 + +cd $WORK/repo +exec git init +exec git add go.mod main.go +exec git commit -m 'initial commit' + +env GIT_COMMITTER_DATE=2024-01-30T10:53:00+08:00 +env GIT_AUTHOR_DATE=2024-01-30T10:53:00+08:00 +exec git add extra.go +exec git commit -m 'add extra.go' + +# Assume the tree object from initial commit is not available (e.g. partial clone) +exec git log --pretty=%T +cmp stdout $WORK/.git-trees + +rm .git/objects/66/400c89b45cc96da36d232844dbf9ea5daa6bcf + +# Build the module, which should succeed +go build -v -buildvcs=true -o test +go version -m test +stdout '^\tbuild\tvcs.revision=fe3c8204d2332a731166269932dd23760c1b576a$' + +-- $WORK/repo/go.mod -- +module github.com/golang/issue65339 + +go 1.20 +-- $WORK/repo/main.go -- +package main + +func main() { + println("hello, world") +} +-- $WORK/repo/extra.go -- +package main +-- $WORK/.git-trees -- +ac724c6e5e3f86815e057ff58a639cab613abf28 +66400c89b45cc96da36d232844dbf9ea5daa6bcf diff --git a/go/src/cmd/go/testdata/script/build_git_sha256_go_get_branch.txt b/go/src/cmd/go/testdata/script/build_git_sha256_go_get_branch.txt new file mode 100644 index 0000000000000000000000000000000000000000..1e71e25f11fede571bec52068dfdc10fff5ce5c6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_git_sha256_go_get_branch.txt @@ -0,0 +1,29 @@ +[short] skip +[!git] skip +[!git-sha256] skip + +env GOPRIVATE=vcs-test.golang.org + +go get vcs-test.golang.org/go/mod/gitrepo-sha256@basic_module +stderr 'downloading vcs-test\.golang.org/go/mod/gitrepo-sha256 v1.3.0' + +go run . +stdout '1234' + +-- main.go -- +package main + +import ( + "fmt" + + sha256repo "vcs-test.golang.org/go/mod/gitrepo-sha256" +) + +func main() { + fmt.Println(sha256repo.Foobar(1234)) +} + +-- go.mod -- +module test + +go 1.24.3 diff --git a/go/src/cmd/go/testdata/script/build_git_sha256_moddep.txt b/go/src/cmd/go/testdata/script/build_git_sha256_moddep.txt new file mode 100644 index 0000000000000000000000000000000000000000..7048e8f2e4b860df8a649b3a8c9d15c0104ea64f --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_git_sha256_moddep.txt @@ -0,0 +1,31 @@ +[short] skip +[!git] skip +[!git-sha256] skip + +env GOPRIVATE=vcs-test.golang.org + +go mod tidy +stderr 'downloading vcs-test\.golang.org/go/mod/gitrepo-sha256 v1.3.0' + +go run . +stdout '1234' + +-- main.go -- +package main + +import ( + "fmt" + + sha256repo "vcs-test.golang.org/go/mod/gitrepo-sha256" +) + +func main() { + fmt.Println(sha256repo.Foobar(1234)) +} + +-- go.mod -- +module test + +go 1.24.3 + +require vcs-test.golang.org/go/mod/gitrepo-sha256 v1.3.0 diff --git a/go/src/cmd/go/testdata/script/build_gopath_order.txt b/go/src/cmd/go/testdata/script/build_gopath_order.txt new file mode 100644 index 0000000000000000000000000000000000000000..caf25022e4cdd94ab9f9f83a47261d5bd56886c6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_gopath_order.txt @@ -0,0 +1,36 @@ +# golang.org/issue/14176#issuecomment-179895769 +# golang.org/issue/14192 +# -I arguments to compiler could end up not in GOPATH order, +# leading to unexpected import resolution in the compiler. + +env GO111MODULE=off +env GOPATH=$WORK/p1${:}$WORK/p2 +mkdir $WORK/p1/src/foo $WORK/p2/src/baz +mkdir $WORK/p2/pkg/${GOOS}_${GOARCH} $WORK/p1/src/bar +cp foo.go $WORK/p1/src/foo/foo.go +cp baz.go $WORK/p2/src/baz/baz.go +cp foo.a $WORK/p2/pkg/${GOOS}_${GOARCH}/foo.a +cp bar.go $WORK/p1/src/bar/bar.go + +go install -x bar + +# add in baz.a to the mix +mkdir $WORK/p1/pkg/${GOOS}_${GOARCH} +cp baz.a $WORK/p1/pkg/${GOOS}_${GOARCH}/baz.a +env GOPATH=$WORK/p1${:}$WORK/p2 +go install -x bar +env GOPATH=$WORK/p2${:}$WORK/p1 +go install -x bar + +-- foo.go -- +package foo +-- baz.go -- +package baz +-- foo.a -- +bad +-- baz.a -- +bad +-- bar.go -- +package bar +import _ "baz" +import _ "foo" diff --git a/go/src/cmd/go/testdata/script/build_ignore_leading_bom.txt b/go/src/cmd/go/testdata/script/build_ignore_leading_bom.txt new file mode 100644 index 0000000000000000000000000000000000000000..37141f3466b3e7d7ac785d6e5cd909157bb2febe --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_ignore_leading_bom.txt @@ -0,0 +1,27 @@ +# Per https://golang.org/ref/spec#Source_code_representation: +# a compiler may ignore a UTF-8-encoded byte order mark (U+FEFF) +# if it is the first Unicode code point in the source text. + +go list -f 'Imports: {{.Imports}} EmbedFiles: {{.EmbedFiles}}' . +stdout '^Imports: \[embed m/hello\] EmbedFiles: \[.*file\]$' + +-- go.mod -- +module m + +go 1.16 +-- m.go -- +package main + +import ( + _ "embed" + + "m/hello" +) + +//go:embed file +var s string + +-- hello/hello.go -- +package hello + +-- file -- diff --git a/go/src/cmd/go/testdata/script/build_ignoredirective.txt b/go/src/cmd/go/testdata/script/build_ignoredirective.txt new file mode 100644 index 0000000000000000000000000000000000000000..d3da9d6a0837d757c017ccc5db0555c21bc9dd9d --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_ignoredirective.txt @@ -0,0 +1,147 @@ +# go build ./... should skip 'ignore' directives +# See golang.org/issue/42965 + +env ROOT=$WORK${/}gopath${/}src + +# no ignore directive; should not skip any directories. +cp go.mod.orig go.mod +go build -x ./... +stderr 'packagefile example/foo/secret' +stderr 'packagefile example/pkg/foo' +stderr 'packagefile example/pkg/fo' +! stderr 'ignoring directory' + +# ignored ./foo should be skipped. +cp go.mod.relative go.mod +go build -x ./... +stderr 'packagefile example/pkg/foo' +stderr 'packagefile example/pkg/fo' +! stderr 'packagefile example/foo/secret' +stderr 'ignoring directory '$ROOT''${/}'foo' +! stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# ignored foo; any foo should be skipped. +cp go.mod.any go.mod +go build -x ./... +stderr 'packagefile example/pkg/fo' +! stderr 'packagefile example/pkg/foo' +! stderr 'packagefile example/foo/secret' +stderr 'ignoring directory '$ROOT''${/}'foo' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# non-existent ignore; should not skip any directories. +cp go.mod.dne go.mod +go build -x ./... +stderr 'packagefile example/foo/secret' +stderr 'packagefile example/pkg/foo' +stderr 'packagefile example/pkg/fo' +! stderr 'ignoring directory' + +# ignored fo; should not skip foo/ and should skip fo/ +cp go.mod.partial go.mod +go build -x ./... +! stderr 'ignoring directory '$ROOT''${/}'foo' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'fo$' +! stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# ignored pkg/foo; should skip pkg/foo/ +cp go.mod.tree go.mod +go build -x ./... +stderr 'packagefile example/foo/secret' +stderr 'packagefile example/pkg/fo' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# ignored /pkg/foo/; should skip pkg/foo/ +cp go.mod.sep1 go.mod +go build -x ./... +stderr 'packagefile example/foo/secret' +stderr 'packagefile example/pkg/fo' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# ignored pkg/foo/; should skip pkg/foo/ +cp go.mod.sep2 go.mod +go build -x ./... +stderr 'packagefile example/foo/secret' +stderr 'packagefile example/pkg/fo' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# ignored /pkg/foo; should skip pkg/foo/ +cp go.mod.sep3 go.mod +go build -x ./... +stderr 'packagefile example/foo/secret' +stderr 'packagefile example/pkg/fo' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +-- foo/secret/secret.go -- +package main +func main() {} +-- pkg/foo/foo.go -- +package main +func main() {} +-- pkg/fo/fo.go -- +package main +func main() {} +-- go.mod.orig -- +module example + +go 1.24 + +-- go.mod.relative -- +module example + +go 1.24 + +ignore ./foo + +-- go.mod.any -- +module example + +go 1.24 + +ignore foo + +-- go.mod.dne -- +module example + +go 1.24 + +ignore bar + +-- go.mod.partial -- +module example + +go 1.24 + +ignore fo + +-- go.mod.tree -- +module example + +go 1.24 + +ignore pkg/foo + +-- go.mod.sep1 -- +module example + +go 1.24 + +ignore /pkg/foo/ + +-- go.mod.sep2 -- +module example + +go 1.24 + +ignore pkg/foo/ + +-- go.mod.sep3 -- +module example + +go 1.24 + +ignore /pkg/foo + +-- main.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_import_comment.txt b/go/src/cmd/go/testdata/script/build_import_comment.txt new file mode 100644 index 0000000000000000000000000000000000000000..b500340bfb48b6e0405702caa67d7cb267d8bec3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_import_comment.txt @@ -0,0 +1,68 @@ +# Test in GOPATH mode first. +env GO111MODULE=off +cd m + +# Import comment matches +go build -n works.go + +# Import comment mismatch +! go build -n wrongplace.go +stderr 'wrongplace expects import "my/x"' + +# Import comment syntax error +! go build -n bad.go +stderr 'cannot parse import comment' + +# Import comment conflict +! go build -n conflict.go +stderr 'found import comments' + + +# Test in module mode. +# We ignore import comments, so these commands should succeed. +env GO111MODULE=on + +# Import comment matches +go build -n works.go + +# Import comment mismatch +go build -n wrongplace.go + +# Import comment syntax error +go build -n bad.go + +# Import comment conflict +go build -n conflict.go + +-- m/go.mod -- +module m + +go 1.16 +-- m/bad.go -- +package p + +import "m/bad" +-- m/conflict.go -- +package p + +import "m/conflict" +-- m/works.go -- +package p + +import _ "m/works/x" +-- m/wrongplace.go -- +package p + +import "m/wrongplace" +-- m/bad/bad.go -- +package bad // import +-- m/conflict/a.go -- +package conflict // import "a" +-- m/conflict/b.go -- +package conflict /* import "b" */ +-- m/works/x/x.go -- +package x // import "m/works/x" +-- m/works/x/x1.go -- +package x // important! not an import comment +-- m/wrongplace/x.go -- +package x // import "my/x" diff --git a/go/src/cmd/go/testdata/script/build_import_cycle.txt b/go/src/cmd/go/testdata/script/build_import_cycle.txt new file mode 100644 index 0000000000000000000000000000000000000000..16e4e87daeeeae113061b4c62bb28dd389bd273e --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_import_cycle.txt @@ -0,0 +1,13 @@ +# mod_import_cycle covers this error in module mode. +env GO111MODULE=off + +! go build selfimport +stderr -count=1 'import cycle not allowed' + +go list -e -f '{{.Error}}' selfimport # Don't hang forever +stdout -count=1 'import cycle not allowed' + +-- selfimport/selfimport.go -- +package selfimport + +import "selfimport" diff --git a/go/src/cmd/go/testdata/script/build_internal.txt b/go/src/cmd/go/testdata/script/build_internal.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a37d6520c6a7aef39cfcf4f2b7135e2de967bde --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_internal.txt @@ -0,0 +1,65 @@ +# Test internal package errors are handled +cd testinternal3 +go list . +stdout 'testinternal3' + +# Test internal cache +cd ../testinternal4 +! go build testinternal4/p +stderr 'internal' + +# Test internal packages outside GOROOT are respected +cd ../testinternal2 +env GO111MODULE=off +! go build -v . +stderr 'p\.go:3:8: use of internal package .*internal/w not allowed' +env GO111MODULE='' + +[compiler:gccgo] skip # gccgo does not have GOROOT +cd ../testinternal +! go build -v . +stderr 'p\.go:3:8: use of internal package net/http/internal not allowed' + +-- testinternal/go.mod -- +module testinternal + +go 1.16 +-- testinternal/p.go -- +package p + +import _ "net/http/internal" +-- testinternal2/go.mod -- +module testinternal2 + +go 1.16 +-- testinternal2/p.go -- +package p + +import _ "./x/y/z/internal/w" +-- testinternal2/x/y/z/internal/w/w.go -- +package w +-- testinternal3/go.mod -- +module testinternal3 + +go 1.16 +-- testinternal3/t.go -- +package t + +import _ "internal/does-not-exist" +-- testinternal4/go.mod -- +module testinternal4 + +go 1.16 +-- testinternal4/p/p.go -- +package p + +import ( + _ "testinternal4/q/internal/x" + _ "testinternal4/q/j" +) +-- testinternal4/q/internal/x/x.go -- +package x +-- testinternal4/q/j/j.go -- +package j + +import _ "testinternal4/q/internal/x" diff --git a/go/src/cmd/go/testdata/script/build_issue59571.txt b/go/src/cmd/go/testdata/script/build_issue59571.txt new file mode 100644 index 0000000000000000000000000000000000000000..2cf32594bf40334ce21389a1e90688ee231cb597 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_issue59571.txt @@ -0,0 +1,40 @@ +# Regression test for https://go.dev/issue/59571 +# Build should be reproducible, even with aliased generic types. + +go build -a -o 1.a +go build -a -o 2.a +cmp -q 1.a 2.a + +-- go.mod -- +module m + +go 1.20 +-- m.go -- +package m + +type ( + SliceFlag[T any] struct{} + + Alias1 = SliceFlag[[1]int] + Alias2 = SliceFlag[[2]int] + Alias3 = SliceFlag[[3]int] + Alias4 = SliceFlag[[4]int] + Alias5 = SliceFlag[[5]int] + Alias6 = SliceFlag[[6]int] + Alias7 = SliceFlag[[7]int] + Alias8 = SliceFlag[[8]int] + Alias9 = SliceFlag[[9]int] + Alias10 = SliceFlag[[10]int] + Alias11 = SliceFlag[[11]int] + Alias12 = SliceFlag[[12]int] + Alias13 = SliceFlag[[13]int] + Alias14 = SliceFlag[[14]int] + Alias15 = SliceFlag[[15]int] + Alias16 = SliceFlag[[16]int] + Alias17 = SliceFlag[[17]int] + Alias18 = SliceFlag[[18]int] + Alias19 = SliceFlag[[19]int] + Alias20 = SliceFlag[[20]int] +) + +func (x *SliceFlag[T]) String() string { return "zzz" } diff --git a/go/src/cmd/go/testdata/script/build_issue62156.txt b/go/src/cmd/go/testdata/script/build_issue62156.txt new file mode 100644 index 0000000000000000000000000000000000000000..d241570cf61955a445f03bed1bfcc442ce797f7f --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_issue62156.txt @@ -0,0 +1,27 @@ +# Regression test for https://go.dev/issue/62156: +# DWARF generation for inlined functions may require more runtime type +# descriptors to be written. + +go build + +-- go.mod -- +module m + +go 1.20 +-- main.go -- +package main + +import "m/sub" + +func main() { sub.F() } +-- sub/sub.go -- +package sub + +type iface interface{ m() } + +func F() { + f := func(rt []iface) []iface { + return append([]iface{}, rt...) + } + f(nil) +} diff --git a/go/src/cmd/go/testdata/script/build_issue6480.txt b/go/src/cmd/go/testdata/script/build_issue6480.txt new file mode 100644 index 0000000000000000000000000000000000000000..991112fff118d4bf747a466dbce9fe104a5e2c91 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_issue6480.txt @@ -0,0 +1,128 @@ +# "go test -c -test.bench=XXX errors" should not hang. +# "go test -c" should also produce reproducible binaries. +# "go test -c" should also appear to write a new binary every time, +# even if it's really just updating the mtime on an existing up-to-date binary. + +[compiler:gccgo] skip +[short] skip + +# Install some commands to compare mtimes +env GOBIN=$WORK/tmp/bin +go install m/now m/mtime m/before + +# Initial builds +go test -c -test.bench=XXX errors +go test -c -o errors2.test errors +cmp errors.test$GOEXE errors2.test # // errors2.test has no exeSuffix because -o above doesn't have it + +# Check errors.test mtime is updated +exec $GOBIN/now +cp stdout start_time.txt +go test -x -c -test.bench=XXX errors +! stderr '[\\/]link|gccgo' # make sure up-to-date test binary is not relinked +exec $GOBIN/mtime errors.test$GOEXE +cp stdout errors1_mod_time.txt +exec $GOBIN/before start_time.txt errors1_mod_time.txt +rm start_time.txt errors1_mod_time.txt + +# Check errors2.test mtime is updated +exec $GOBIN/now +cp stdout start_time.txt +go test -x -c -o errors2.test errors +! stderr '[\\/]link|gccgo' # make sure up-to-date test binary is not relinked +exec $GOBIN/mtime errors2.test +cp stdout errors2_mod_time.txt +exec $GOBIN/before start_time.txt errors2_mod_time.txt + +-- go.mod -- +module m + +go 1.16 +-- now/now.go -- +// Writes time.Now() to a file +package main + +import ( + "encoding/json" + "fmt" + "os" + "time" +) + +func main() { + if err := json.NewEncoder(os.Stdout).Encode(time.Now()); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} +-- mtime/mtime.go -- +package main + +import ( + "encoding/json" + "fmt" + "os" +) + +func main() { + info, err := os.Stat(os.Args[1]) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + if err := json.NewEncoder(os.Stdout).Encode(info.ModTime()); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} +-- before/before.go -- +package main + +import ( + "encoding/json" + "fmt" + "os" + "time" +) + +func truncateLike(t, p time.Time) time.Time { + nano := p.UnixNano() + d := 1 * time.Nanosecond + for nano%int64(d) == 0 && d < 1*time.Second { + d *= 10 + } + for nano%int64(d) == 0 && d < 2*time.Second { + d *= 2 + } + return t.Truncate(d) +} + +func main() { + var t1 time.Time + b1, err := os.ReadFile(os.Args[1]) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + if err := json.Unmarshal(b1, &t1); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + var t2 time.Time + b2, err := os.ReadFile(os.Args[2]) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + if err := json.Unmarshal(b2, &t2); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + t1 = truncateLike(t1, t2) + if !t1.Before(t2) { + fmt.Fprintf(os.Stderr, "time in %v (%v) is not before time in %v (%v)", os.Args[1], t1, os.Args[2], t2) + os.Exit(1) + } +} diff --git a/go/src/cmd/go/testdata/script/build_issue68658.txt b/go/src/cmd/go/testdata/script/build_issue68658.txt new file mode 100644 index 0000000000000000000000000000000000000000..d0fcb3c44f39175ea8e106271ecd8edebb14ae89 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_issue68658.txt @@ -0,0 +1,31 @@ +# Test for issue #68658: In GOPATH mode, files with a //go:build fileVersion +# earlier than go1.21 should downgrade to go1.21 and no further. + +[short] skip 'requires build' + +env GO111MODULE=off +go build foo bar + +-- foo/main.go -- +//go:build go1.10 + +package p + +import "fmt" + +func main() { + var x any // any was added in Go 1.18 + fmt.Println(x) +} + +-- bar/main.go -- +//go:build go1.20 + +package p + +import "fmt" + +func main() { + y := max(1, 2) // max was added in Go 1.21 + fmt.Println(y) +} diff --git a/go/src/cmd/go/testdata/script/build_issue_65528.txt b/go/src/cmd/go/testdata/script/build_issue_65528.txt new file mode 100644 index 0000000000000000000000000000000000000000..ab4d62bbb2b473a6f692b42e7db308008ec18a89 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_issue_65528.txt @@ -0,0 +1,9 @@ +go build + +-- go.mod -- +module test + +go 1.0 + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/script/build_json.txt b/go/src/cmd/go/testdata/script/build_json.txt new file mode 100644 index 0000000000000000000000000000000000000000..716bdf4fa9dab687fbfc8f9f2a61a874a3762fe0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_json.txt @@ -0,0 +1,48 @@ +[short] skip + +# Basic build error. This test also checks that the output is fully-formed JSON. +! go build -json -o=$devnull ./compileerror +stdout '^\{"ImportPath":"m/compileerror","Action":"build-output","Output":"# m/compileerror\\n"\}$' +stdout '^\{"ImportPath":"m/compileerror","Action":"build-output","Output":"compileerror(/|\\\\)main.go:3:11: undefined: y\\n"}$' +stdout '^\{"ImportPath":"m/compileerror","Action":"build-fail"\}$' +! stderr '.' + +# Check that a build failure in an imported package is attributed correctly. +! go build -json -o=$devnull ./importerror +stdout '"ImportPath":"m/compileerror","Action":"build-fail"' +! stderr '.' + +# TODO(#65335): Attributing this to "x" doesn't make much sense, +# especially since the reported line is the import statement. +! go build -json -o=$devnull ./loaderror +stdout '"ImportPath":"x","Action":"build-output","Output":".*package x is not in std.*\\n"' +stdout '"ImportPath":"x","Action":"build-fail"' +! stderr '.' + +# Check that a load error in an imported package is attributed correctly. +! go build -json -o=$devnull ./loadimporterror +stdout '"ImportPath":"x","Action":"build-output","Output":".*package x is not in std.*\\n"' +stdout '"ImportPath":"x","Action":"build-fail"' +! stderr '.' + +-- go.mod -- +module m +go 1.21 +-- compileerror/main.go -- +package compileerror + +const x = y +-- importerror/main.go -- +package main + +import _ "m/compileerror" +-- loaderror/main.go -- +// A bad import causes a failure directly in cmd/go during import processing. + +package loaderror + +import _ "x" +-- loadimporterror/main.go -- +package loadimporterror + +import _ "m/loaderror" diff --git a/go/src/cmd/go/testdata/script/build_link_x_import_path_escape.txt b/go/src/cmd/go/testdata/script/build_link_x_import_path_escape.txt new file mode 100644 index 0000000000000000000000000000000000000000..d47c482170ae28553de014de0a25af816656ac17 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_link_x_import_path_escape.txt @@ -0,0 +1,22 @@ +[compiler:gccgo] skip 'gccgo does not support -ldflags -X' + +go build -o linkx$GOEXE -ldflags -X=my.pkg.Text=linkXworked my.pkg/main +exec ./linkx$GOEXE +stderr '^linkXworked$' + +-- go.mod -- +module my.pkg + +go 1.16 +-- main/main.go -- +package main + +import "my.pkg" + +func main() { + println(pkg.Text) +} +-- pkg.go -- +package pkg + +var Text = "unset" diff --git a/go/src/cmd/go/testdata/script/build_multi_main.txt b/go/src/cmd/go/testdata/script/build_multi_main.txt new file mode 100644 index 0000000000000000000000000000000000000000..8afd8b8a2e11af607e639cb2a8eb41982265164b --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_multi_main.txt @@ -0,0 +1,43 @@ +# Verify build -o can output multiple executables to a directory. + +mkdir $WORK/bin +go build -o $WORK/bin ./cmd/c1 ./cmd/c2 +! stderr 'multiple packages' + +! go build -o $WORK/bin ./pkg1 ./pkg1 +stderr 'no main packages' + +! go build ./cmd/c1 +stderr 'already exists and is a directory' + +# Verify build -o output correctly local packages +mkdir $WORK/local +go build -o $WORK/local ./exec.go +exists $WORK/local/exec$GOEXE + +-- go.mod -- +module exmod + +-- cmd/c1/main.go -- +package main + +func main() {} + +-- cmd/c2/main.go -- +package main + +func main() {} + +-- pkg1/pkg1.go -- +package pkg1 + +-- pkg2/pkg2.go -- +package pkg2 + +-- exec.go -- +package main + +func main() {} + +-- c1$GOEXE/keep.txt -- +Create c1 directory. diff --git a/go/src/cmd/go/testdata/script/build_n_cgo.txt b/go/src/cmd/go/testdata/script/build_n_cgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..fa01927720b0dc94220c3623bef0ff86ddc299b4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_n_cgo.txt @@ -0,0 +1,18 @@ +[!cgo] skip + +# Test that nothing is prepended to $WORK path prefix. +# See issue golang.org/issue/37012. +go build -n +! stderr '[/\\]\$WORK' +stderr '[ =]\$WORK' + +-- go.mod -- +module m + +go 1.16 +-- main.go -- +package main + +import "C" + +var _ C.int diff --git a/go/src/cmd/go/testdata/script/build_negative_p.txt b/go/src/cmd/go/testdata/script/build_negative_p.txt new file mode 100644 index 0000000000000000000000000000000000000000..9123907dc87a40e41803c145433602aada4db3dd --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_negative_p.txt @@ -0,0 +1,5 @@ +! go build -p=-1 example.go +stderr 'go: -p must be a positive integer: -1' + +-- example.go -- +package example \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/build_no_go.txt b/go/src/cmd/go/testdata/script/build_no_go.txt new file mode 100644 index 0000000000000000000000000000000000000000..b61d7522740d34447f64f75056a8cd15f9bffbbf --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_no_go.txt @@ -0,0 +1,41 @@ +! go build ./empty/test +stderr 'no non-test Go files in ' + +! go build ./empty/xtest +stderr 'no non-test Go files in ' + +! go build ./empty/testxtest +stderr 'no non-test Go files in ' + +! go build ./exclude +stderr 'build constraints exclude all Go files in ' + +! go build ./exclude/ignore +stderr 'no Go files in ' + +! go build ./exclude/empty +stderr 'no Go files in ' + +-- go.mod -- +module m + +go 1.16 +-- empty/test/test_test.go -- +package p +-- empty/testxtest/test_test.go -- +package p +-- empty/testxtest/xtest_test.go -- +package p_test +-- empty/xtest/xtest_test.go -- +package p_test +-- exclude/empty/x.txt -- +-- exclude/ignore/_x.go -- +package x +-- exclude/x.go -- +// +build linux,!linux + +package x +-- exclude/x_linux.go -- +// +build windows + +package x diff --git a/go/src/cmd/go/testdata/script/build_nocache.txt b/go/src/cmd/go/testdata/script/build_nocache.txt new file mode 100644 index 0000000000000000000000000000000000000000..b21e755e8939fb63ab69ecae07280cfc2db655bd --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_nocache.txt @@ -0,0 +1,40 @@ +env GO111MODULE=off + +# As of Go 1.12, the module cache is required. + +# If none of the variables we use to locate GOCACHE are set, the cache is off +# and we cannot build. +env GOCACHE= +env XDG_CACHE_HOME= +env HOME= +[GOOS:plan9] env home= +[GOOS:windows] env LocalAppData= +! go build -o triv triv.go +stderr 'build cache is required, but could not be located: GOCACHE is not defined and .*' + +# If GOCACHE is set but is not an absolute path, and we cannot build. +env GOCACHE=test +! go build -o triv triv.go +stderr 'build cache is required, but could not be located: GOCACHE is not an absolute path' + +# An explicit GOCACHE=off also disables builds. +env GOCACHE=off +! go build -o triv triv.go +stderr 'build cache is disabled by GOCACHE=off' + +# If GOCACHE is set to an unwritable directory, we should diagnose it as such. +[GOOS:windows] stop # Does not support unwritable directories. +[root] skip # Can write to unwritable directories. + +mkdir $WORK/unwritable/home +chmod 0555 $WORK/unwritable/home +[!GOOS:plan9] env HOME=$WORK/unwritable/home +[GOOS:plan9] env home=$WORK/unwritable/home + +env GOCACHE=$WORK/unwritable/home +! go build -o triv triv.go +stderr 'failed to initialize build cache.* permission denied' + +-- triv.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_output.txt b/go/src/cmd/go/testdata/script/build_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..457960f9ac5641edcf3e6bdf89da32596c54da19 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_output.txt @@ -0,0 +1,117 @@ +[compiler:gccgo] skip 'gccgo has no standard packages' +[short] skip + +[!GOOS:windows] env NONEXE='.exe' +[GOOS:windows] env NONEXE='' + +env GOBIN=$WORK/tmp/bin +go install m/isarchive & + +go build x.go +exists -exec x$GOEXE +rm x$GOEXE +! exists x$NONEXE + +go build -o myprog x.go +! exists x +! exists x.exe +exists -exec myprog +! exists myprogr.exe + +! exists bin +go build -o bin/x x.go +exists -exec bin/x +rm bin + +! exists bin +go build -o bin/ x.go +exists -exec bin/x$GOEXE +rm bin + +[GOOS:windows] ! exists bin +[GOOS:windows] go build -o bin\x x.go +[GOOS:windows] exists -exec bin\x +[GOOS:windows] rm bin + +[GOOS:windows] ! exists bin +[GOOS:windows] go build -o bin\ x.go +[GOOS:windows] exists -exec bin\x.exe +[GOOS:windows] rm bin + +! exists bin +mkdir bin +go build -o bin x.go +exists -exec bin/x$GOEXE +rm bin + +go build p.go +! exists p +! exists p.a +! exists p.o +! exists p.exe + +wait # for isarchive + +go build -o p.a p.go +exists p.a +exec $GOBIN/isarchive p.a + +go build cmd/gofmt +exists -exec gofmt$GOEXE +rm gofmt$GOEXE +! exists gofmt$NONEXE + +go build -o mygofmt cmd/gofmt +exists -exec mygofmt +! exists mygofmt.exe +! exists gofmt +! exists gofmt.exe + +go build sync/atomic +! exists atomic +! exists atomic.exe + +go build -o myatomic.a sync/atomic +exists myatomic.a +exec $GOBIN/isarchive myatomic.a +! exists atomic +! exists atomic.a +! exists atomic.exe + +! go build -o whatever cmd/gofmt sync/atomic +stderr 'multiple packages' + +-- go.mod -- +module m + +go 1.16 +-- x.go -- +package main + +func main() {} +-- p.go -- +package p +-- isarchive/isarchive.go -- +package main + +import ( + "bytes" + "fmt" + "io" + "os" +) + +func main() { + f, err := os.Open(os.Args[1]) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + buf := make([]byte, 100) + io.ReadFull(f, buf) + f.Close() + if !bytes.HasPrefix(buf, []byte("!\n")) { + fmt.Fprintf(os.Stderr, "file %s exists but is not an archive\n", os.Args[1]) + os.Exit(1) + } +} diff --git a/go/src/cmd/go/testdata/script/build_output_overwrite.txt b/go/src/cmd/go/testdata/script/build_output_overwrite.txt new file mode 100644 index 0000000000000000000000000000000000000000..c7b967ccec39d666cf1b64aeaa7b3a7c9fd9f825 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_output_overwrite.txt @@ -0,0 +1,20 @@ +# windows executables have the .exe extension and won't overwrite source files +[GOOS:windows] skip + +mkdir out +env GOTMPDIR=$PWD/out + +grep 'this should still exist' foo.go + +! go build +stderr 'already exists and is not an object file' + +grep 'this should still exist' foo.go + +-- go.mod -- +module foo.go + +-- foo.go -- +package main // this should still exist + +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_overlay.txt b/go/src/cmd/go/testdata/script/build_overlay.txt new file mode 100644 index 0000000000000000000000000000000000000000..1111d119ba28417b84802ec1a4631552e11a294c --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_overlay.txt @@ -0,0 +1,315 @@ +[short] skip + +# Test building in overlays. +# TODO(#39958): add a test case where the destination file in the replace map +# isn't a go file. Either completely exclude that case in fs.IsDirWithGoFiles +# if the compiler doesn't allow it, or test that it works all the way. +# TODO(#39958): add a test that both gc and gccgo assembly files can include .h +# files. + +# The main package (m) is contained in an overlay. It imports m/dir2 which has one +# file in an overlay and one file outside the overlay, which in turn imports m/dir, +# which only has source files in the overlay. + +cd m + +! go build . +go build -overlay overlay.json -o main$GOEXE . +exec ./main$goexe +stdout '^hello$' + +go build -overlay overlay.json -o print_abspath$GOEXE ./printpath +exec ./print_abspath$GOEXE +stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go + +go vet -overlay overlay.json ./printpath + +go build -overlay overlay.json -o print_trimpath$GOEXE -trimpath ./printpath +exec ./print_trimpath$GOEXE +stdout ^m[/\\]printpath[/\\]main.go + +go build -overlay overlay.json -o print_trimpath_two_files$GOEXE printpath/main.go printpath/other.go +exec ./print_trimpath_two_files$GOEXE +stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go +stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]other.go + +[cgo] go build -overlay overlay.json -o main_cgo_replace$GOEXE ./cgo_hello_replace +[cgo] exec ./main_cgo_replace$GOEXE +[cgo] stdout '^hello cgo\r?\n' + +[cgo] go build -overlay overlay.json -o main_cgo_quote$GOEXE ./cgo_hello_quote +[cgo] exec ./main_cgo_quote$GOEXE +[cgo] stdout '^hello cgo\r?\n' + +[cgo] go build -overlay overlay.json -o main_cgo_angle$GOEXE ./cgo_hello_angle +[cgo] exec ./main_cgo_angle$GOEXE +[cgo] stdout '^hello cgo\r?\n' + +go build -overlay overlay.json -o main_call_asm$GOEXE ./call_asm +exec ./main_call_asm$GOEXE +! stdout . + +[cgo] go list -compiled -overlay overlay.json -f '{{range .CompiledGoFiles}}{{. | printf "%s\n"}}{{end}}' ./cgo_hello_replace +[cgo] cp stdout compiled_cgo_sources.txt +[cgo] go run ../print_line_comments.go compiled_cgo_sources.txt +[cgo] stdout $GOPATH[/\\]src[/\\]m[/\\]cgo_hello_replace[/\\]cgo_hello_replace.go +[cgo] ! stdout $GOPATH[/\\]src[/\\]m[/\\]overlay[/\\]hello.c + +# Change the contents of a file in the overlay and ensure that makes the target stale +env OLD_GOCACHE=$GOCACHE +env GOCACHE=$WORK/cache # use a fresh cache so that multiple runs of the test don't interfere +go build -x -overlay overlay.json ./test_cache +stderr '(compile|gccgo)( |\.exe).*test_cache.go' +go build -x -overlay overlay.json ./test_cache +! stderr '(compile|gccgo)( |\.exe).*test_cache.go' # cached +cp overlay/test_cache_different.go overlay/test_cache.go +go build -x -overlay overlay.json ./test_cache +stderr '(compile|gccgo)( |\.exe).*test_cache.go' # not cached +env CACHE=$OLD_GOCACHE + +# Run same tests but with gccgo. +env GO111MODULE=off +[!exec:gccgo] stop +[cross] stop # gccgo can't necessarily cross-compile + +! go build -compiler=gccgo . +go build -compiler=gccgo -overlay overlay.json -o main_gccgo$GOEXE . +exec ./main_gccgo$goexe +stdout '^hello$' + +go build -compiler=gccgo -overlay overlay.json -o print_abspath_gccgo$GOEXE ./printpath +exec ./print_abspath_gccgo$GOEXE +stdout $WORK[/\\]gopath[/\\]src[/\\]m[/\\]printpath[/\\]main.go + +go build -compiler=gccgo -overlay overlay.json -o print_trimpath_gccgo$GOEXE -trimpath ./printpath +exec ./print_trimpath_gccgo$GOEXE +stdout ^\.[/\\]printpath[/\\]main.go + + +go build -compiler=gccgo -overlay overlay.json -o main_cgo_replace_gccgo$GOEXE ./cgo_hello_replace +exec ./main_cgo_replace_gccgo$GOEXE +stdout '^hello cgo\r?\n' + +go build -compiler=gccgo -overlay overlay.json -o main_cgo_quote_gccgo$GOEXE ./cgo_hello_quote +exec ./main_cgo_quote_gccgo$GOEXE +stdout '^hello cgo\r?\n' + +go build -compiler=gccgo -overlay overlay.json -o main_cgo_angle_gccgo$GOEXE ./cgo_hello_angle +exec ./main_cgo_angle_gccgo$GOEXE +stdout '^hello cgo\r?\n' + +go build -compiler=gccgo -overlay overlay.json -o main_call_asm_gccgo$GOEXE ./call_asm +exec ./main_call_asm_gccgo$GOEXE +! stdout . + + +-- m/go.mod -- +// TODO(matloob): how do overlays work with go.mod (especially if mod=readonly) +module m + +go 1.16 + +-- m/dir2/h.go -- +package dir2 + +func PrintMessage() { + printMessage() +} +-- m/dir/foo.txt -- +The build action code currently expects the package directory +to exist, so it can run the compiler in that directory. +TODO(matloob): Remove this requirement. +-- m/printpath/about.txt -- +the actual code is in the overlay +-- m/overlay.json -- +{ + "Replace": { + "f.go": "overlay/f.go", + "dir/g.go": "overlay/dir_g.go", + "dir2/i.go": "overlay/dir2_i.go", + "printpath/main.go": "overlay/printpath.go", + "printpath/other.go": "overlay2/printpath2.go", + "call_asm/asm_gc.s": "overlay/asm_gc.s", + "call_asm/asm_gccgo.s": "overlay/asm_gccgo.s", + "test_cache/main.go": "overlay/test_cache.go", + "cgo_hello_replace/cgo_header.h": "overlay/cgo_head.h", + "cgo_hello_replace/hello.c": "overlay/hello.c", + "cgo_hello_quote/cgo_hello.go": "overlay/cgo_hello_quote.go", + "cgo_hello_quote/cgo_header.h": "overlay/cgo_head.h", + "cgo_hello_angle/cgo_hello.go": "overlay/cgo_hello_angle.go", + "cgo_hello_angle/cgo_header.h": "overlay/cgo_head.h" + } +} +-- m/cgo_hello_replace/cgo_hello_replace.go -- +package main + +// #include "cgo_header.h" +import "C" + +func main() { + C.say_hello() +} +-- m/cgo_hello_replace/cgo_header.h -- + // Test that this header is replaced with one that has the proper declaration. +void say_goodbye(); + +-- m/cgo_hello_replace/hello.c -- +#include + +void say_goodbye() { puts("goodbye cgo\n"); fflush(stdout); } + +-- m/overlay/f.go -- +package main + +import "m/dir2" + +func main() { + dir2.PrintMessage() +} +-- m/call_asm/main.go -- +package main + +func foo() // There will be a "missing function body" error if the assembly file isn't found. + +func main() { + foo() +} +-- m/overlay/dir_g.go -- +package dir + +import "fmt" + +func PrintMessage() { + fmt.Println("hello") +} +-- m/overlay/printpath.go -- +package main + +import ( + "fmt" + "path/filepath" + "runtime" +) + +func main() { + _, file, _, _ := runtime.Caller(0) + + // Since https://golang.org/cl/214286, the runtime's debug paths are + // slash-separated regardless of platform, so normalize them to system file + // paths. + fmt.Println(filepath.FromSlash(file)) +} +-- m/overlay2/printpath2.go -- +package main + +import ( + "fmt" + "path/filepath" + "runtime" +) + +func init() { + _, file, _, _ := runtime.Caller(0) + fmt.Println(filepath.FromSlash(file)) +} +-- m/overlay/dir2_i.go -- +package dir2 + +import "m/dir" + +func printMessage() { + dir.PrintMessage() +} +-- m/overlay/cgo_hello_quote.go -- +package main + +// #include "cgo_header.h" +import "C" + +func main() { + C.say_hello() +} +-- m/overlay/cgo_hello_angle.go -- +package main + +// #include +import "C" + +func main() { + C.say_hello() +} +-- m/overlay/cgo_head.h -- +void say_hello(); +-- m/overlay/hello.c -- +#include + +void say_hello() { puts("hello cgo\n"); fflush(stdout); } +-- m/overlay/asm_gc.s -- +// +build gc + +TEXT ·foo(SB),0,$0 + RET + +-- m/overlay/asm_gccgo.s -- +// +build gccgo + +.globl main.foo +.text +main.foo: + ret + +-- m/overlay/test_cache.go -- +package foo + +import "fmt" + +func bar() { + fmt.Println("something") +} +-- m/overlay/test_cache_different.go -- +package foo + +import "fmt" + +func bar() { + fmt.Println("different") +} +-- m/cgo_hello_quote/hello.c -- +#include + +void say_hello() { puts("hello cgo\n"); fflush(stdout); } +-- m/cgo_hello_angle/hello.c -- +#include + +void say_hello() { puts("hello cgo\n"); fflush(stdout); } + +-- print_line_comments.go -- +package main + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "strings" +) + +func main() { + compiledGoFilesArg := os.Args[1] + b, err := ioutil.ReadFile(compiledGoFilesArg) + if err != nil { + log.Fatal(err) + } + compiledGoFiles := strings.Split(strings.TrimSpace(string(b)), "\n") + for _, f := range compiledGoFiles { + b, err := ioutil.ReadFile(f) + if err != nil { + log.Fatal(err) + } + for _, line := range strings.Split(string(b), "\n") { + if strings.HasPrefix(line, "#line") || strings.HasPrefix(line, "//line") { + fmt.Println(line) + } + } + } +} diff --git a/go/src/cmd/go/testdata/script/build_patterns_outside_gopath.txt b/go/src/cmd/go/testdata/script/build_patterns_outside_gopath.txt new file mode 100644 index 0000000000000000000000000000000000000000..6a600cfb0a8c5761f59d73141b79b731bffdeef3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_patterns_outside_gopath.txt @@ -0,0 +1,36 @@ +# Tests issue #18778 +[short] skip + +cd pkgs + +env GO111MODULE=off +go build ./... +! stdout . +go test ./... +stdout '^ok' +go list ./... +stdout 'pkgs$' +stdout 'pkgs/a' + +-- pkgs/go.mod -- +module pkgs + +go 1.16 +-- pkgs/a.go -- +package x +-- pkgs/a_test.go -- +package x_test + +import "testing" + +func TestX(t *testing.T) { +} +-- pkgs/a/a.go -- +package a +-- pkgs/a/a_test.go -- +package a_test + +import "testing" + +func TestA(t *testing.T) { +} diff --git a/go/src/cmd/go/testdata/script/build_perpkgflag.txt b/go/src/cmd/go/testdata/script/build_perpkgflag.txt new file mode 100644 index 0000000000000000000000000000000000000000..9a607567a3f79a7af28e789fc5c07aa3fe9e1e62 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_perpkgflag.txt @@ -0,0 +1,35 @@ +# Test the work and tool patterns in a per-package flag + +go build -n '-gcflags=work=-fakeflag' example.com/foo/a +stderr 'compile.*-p example.com/foo/a.*-fakeflag' +! stderr 'compile.*-p example.com/dep.*-fakeflag' + +go build -n '-gcflags=tool=-fakeflag' example.com/foo/a example.com/dep/tooldep +! stderr 'compile.*-p example.com/foo/a.*-fakeflag' +! stderr 'compile.*-p example.com/dep.*-fakeflag' +stderr 'compile.*-p main.*-fakeflag.*main.go' + +-- go.mod -- +module example.com/foo + +go 1.24 + +tool example.com/dep/tooldep + +require example.com/dep v1.0.0 + +replace example.com/dep => ./dep +-- a/a.go -- +package a + +import _ "example.com/dep" +-- dep/go.mod -- +module example.com/dep + +go 1.24 +-- dep/dep.go -- +package dep +-- dep/tooldep/main.go -- +package main + +import _ "example.com/dep" diff --git a/go/src/cmd/go/testdata/script/build_pgo.txt b/go/src/cmd/go/testdata/script/build_pgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..792d299ab18edb3e95a7134c99b21498d8b0b2ab --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_pgo.txt @@ -0,0 +1,86 @@ +# Test go build -pgo flag. +# Specifically, the build cache handles profile content correctly. + +[short] skip 'compiles and links executables' + +# Set up fresh GOCACHE. +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +# build without PGO +go build triv.go + +# build with PGO, should trigger rebuild +# starting with an empty profile (the compiler accepts it) +go build -x -pgo=prof -o triv.exe triv.go +stderr 'preprofile.*-i.*prof' +stderr 'compile.*-pgoprofile=.*triv.go' + +# check that PGO appears in build info +# N.B. we can't start the stdout check with -pgo because the script assumes that +# if the first arg starts with - it is a grep flag. +go version -m triv.exe +stdout 'build\s+-pgo=.*'${/}'prof' + +# store the build ID +go list -export -json=BuildID -pgo=prof triv.go +stdout '"BuildID":' # check that output actually contains a build ID +cp stdout list.out + +# build again with the same profile, should be cached +go build -x -pgo=prof -o triv.exe triv.go +! stderr 'compile.*triv.go' + +# check that the build ID is the same +go list -export -json=BuildID -pgo=prof triv.go +cmp stdout list.out + +# overwrite the prof +go run overwrite.go + +# build again, profile content changed, should trigger rebuild, including std +go build -n -pgo=prof triv.go +stderr 'preprofile.*-i.*prof' +stderr 'compile.*-pgoprofile=.*triv.go' +stderr 'compile.*-p runtime.*-pgoprofile=.*' + +# check that the build ID is different +go list -export -json=BuildID -pgo=prof triv.go +! cmp stdout list.out + +# build with trimpath, buildinfo path should be trimmed +go build -x -pgo=prof -trimpath -o triv.exe triv.go + +# check that path is trimmed +go version -m triv.exe +stdout 'build\s+-pgo=prof' + +-- prof -- +-- triv.go -- +package main +func main() {} +-- overwrite.go -- +package main + +import ( + "os" + "runtime/pprof" + "time" +) + +func main() { + f, err := os.Create("prof") + if err != nil { + panic(err) + } + err = pprof.StartCPUProfile(f) + if err != nil { + panic(err) + } + // Spin to ensure we get some samples. If we get no samples, the result + // is equivalent to an empty profile. + start := time.Now() + for time.Since(start) < 100*time.Millisecond {} + pprof.StopCPUProfile() + f.Close() +} diff --git a/go/src/cmd/go/testdata/script/build_pgo_auto.txt b/go/src/cmd/go/testdata/script/build_pgo_auto.txt new file mode 100644 index 0000000000000000000000000000000000000000..dc2570272fe5332643841efd8aee5cc7af61d547 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_pgo_auto.txt @@ -0,0 +1,102 @@ +# Test go build -pgo=auto flag. + +[short] skip 'compiles and links executables' + +# Set up fresh GOCACHE. +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +# use default.pgo for a single main package +go build -n -pgo=auto -o a1.exe ./a/a1 +stderr 'preprofile.*-i.*default\.pgo' +stderr 'compile.*-pgoprofile=.*a1.go' + +# check that pgo applied to dependencies +stderr 'compile.*-p test/dep.*-pgoprofile=.*' + +# check that pgo appears in build info +# N.B. we can't start the stdout check with -pgo because the script assumes that +# if the first arg starts with - it is a grep flag. +stderr 'build\\t-pgo=.*default\.pgo' + +# check also that -pgo appears with the other flags, before non-flag settings +! stderr 'build\\t[A-Za-z].*build\\t-pgo' + +# use default.pgo for ... with a single main package +go build -n -pgo=auto ./a/... +stderr 'compile.*-pgoprofile=.*a1.go' + +# check that pgo appears in build info +stderr 'build\\t-pgo=.*default\.pgo' + +# build succeeds without PGO when default.pgo file is absent +go build -n -pgo=auto -o nopgo.exe ./nopgo +stderr 'compile.*nopgo.go' +! stderr 'compile.*-pgoprofile' + +# check that pgo doesn't appear in build info +! stderr 'build\\t-pgo=' + +# other build-related commands +go install -a -n -pgo=auto ./a/a1 +stderr 'compile.*-pgoprofile=.*a1.go' + +go run -a -n -pgo=auto ./a/a1 +stderr 'compile.*-pgoprofile=.*a1.go' + +go test -a -n -pgo=auto ./a/a1 +stderr 'compile.*-pgoprofile=.*a1.go.*a1_test.go' +stderr 'compile.*-pgoprofile=.*external_test.go' + +# go list commands should succeed as usual +go list -pgo=auto ./a/a1 + +go list -test -pgo=auto ./a/a1 + +go list -deps -pgo=auto ./a/a1 + +# -pgo=auto is the default. Commands without explicit -pgo=auto +# should work as -pgo=auto. +go build -a -n -o a1.exe ./a/a1 +stderr 'compile.*-pgoprofile=.*a1.go' +stderr 'compile.*-p test/dep.*-pgoprofile=.*' + +# check that pgo appears in build info +stderr 'build\\t-pgo=.*default\.pgo' + +go build -a -n -o nopgo.exe ./nopgo +stderr 'compile.*nopgo.go' +! stderr 'compile.*-pgoprofile' + +# check that pgo doesn't appear in build info +! stderr 'build\\t-pgo=' + +# -pgo=off should turn off PGO. +go build -a -n -pgo=off -o a1.exe ./a/a1 +stderr 'compile.*a1.go' +! stderr 'compile.*-pgoprofile' + +# check that pgo doesn't appear in build info +! stderr 'build\\t-pgo=' + +-- go.mod -- +module test +go 1.20 +-- a/a1/a1.go -- +package main +import _ "test/dep" +func main() {} +-- a/a1/a1_test.go -- +package main +import "testing" +func TestA(*testing.T) {} +-- a/a1/external_test.go -- +package main_test +import "testing" +func TestExternal(*testing.T) {} +-- a/a1/default.pgo -- +-- nopgo/nopgo.go -- +package main +func main() {} +-- dep/dep.go -- +package dep diff --git a/go/src/cmd/go/testdata/script/build_pgo_auto_multi.txt b/go/src/cmd/go/testdata/script/build_pgo_auto_multi.txt new file mode 100644 index 0000000000000000000000000000000000000000..509edb0230dc1aca4ef978efc994b59b5b8bb6ce --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_pgo_auto_multi.txt @@ -0,0 +1,103 @@ +# Test go build -pgo=auto flag with multiple main packages. + +go install -a -n -pgo=auto ./a ./b ./nopgo + +# a/default.pgo and b/default.pgo are both preprocessed +stderr 'preprofile.*-i.*a(/|\\\\)default\.pgo' +stderr 'preprofile.*-i.*b(/|\\\\)default\.pgo' + +# a and b built once each with PGO. +# Ideally we would check that the passed profile is the expected profile (here +# and for dependencies). Unfortunately there is no nice way to map the expected +# paths after preprocessing. +stderr -count=1 'compile.*-pgoprofile=.*a(/|\\\\)a\.go' +stderr -count=1 'compile.*-pgoprofile=.*b(/|\\\\)b\.go' + +# nopgo should be built without PGO. +! stderr 'compile.*-pgoprofile=.*nopgo(/|\\\\)nopgo\.go' + +# Dependencies should also be built with and without PGO. +# Here we want to match a compile action without -pgoprofile, +# by matching 3 occurrences of "compile dep.go", among which +# 2 of them have -pgoprofile (therefore one without). +stderr -count=3 'compile.*dep(/|\\\\)dep.go' +stderr -count=2 'compile.*-pgoprofile=.*dep(/|\\\\)dep\.go' + +stderr -count=3 'compile.*dep2(/|\\\\)dep2.go' +stderr -count=2 'compile.*-pgoprofile=.*dep2(/|\\\\)dep2\.go' + +stderr -count=3 'compile.*dep3(/|\\\\)dep3.go' +stderr -count=2 'compile.*-pgoprofile=.*dep3(/|\\\\)dep3\.go' + +# check that pgo appears or not in build info as expected +stderr 'path\\ttest/a\\n.*build\\t-pgo=.*a(/|\\\\)default\.pgo' +stderr 'path\\ttest/b\\n.*build\\t-pgo=.*b(/|\\\\)default\.pgo' +! stderr 'path\\ttest/nopgo\\n.*build\\t-pgo=' + +# go test works the same way +go test -a -n -pgo=auto ./a ./b ./nopgo +stderr -count=1 'compile.*-pgoprofile=.*a(/|\\\\)a_test\.go' +stderr -count=1 'compile.*-pgoprofile=.*b(/|\\\\)b_test\.go' +stderr -count=2 'compile.*-pgoprofile=.*dep(/|\\\\)dep\.go' +! stderr 'compile.*-pgoprofile=.*nopgo(/|\\\\)nopgo_test\.go' + +# test-only dependencies also have profiles attached +stderr -count=2 'compile.*-pgoprofile=.*testdep(/|\\\\)testdep\.go' +stderr -count=2 'compile.*-pgoprofile=.*testdep2(/|\\\\)testdep2\.go' + +# go list -deps prints packages built multiple times. +go list -pgo=auto -deps ./a ./b ./nopgo +stdout 'test/dep \[test/a\]' +stdout 'test/dep \[test/b\]' +stdout 'test/dep$' + +# Here we have 3 main packages, a, b, and nopgo, where a and b each has +# its own default.pgo profile, and nopgo has none. +# All 3 main packages import dep and dep2, both of which then import dep3 +# (a diamond-shape import graph). +-- go.mod -- +module test +go 1.20 +-- a/a.go -- +package main +import _ "test/dep" +import _ "test/dep2" +func main() {} +-- a/a_test.go -- +package main +import "testing" +import _ "test/testdep" +func TestA(*testing.T) {} +-- a/default.pgo -- +-- b/b.go -- +package main +import _ "test/dep" +import _ "test/dep2" +func main() {} +-- b/b_test.go -- +package main +import "testing" +import _ "test/testdep" +func TestB(*testing.T) {} +-- b/default.pgo -- +-- nopgo/nopgo.go -- +package main +import _ "test/dep" +import _ "test/dep2" +func main() {} +-- nopgo/nopgo_test.go -- +package main +import "testing" +func TestNopgo(*testing.T) {} +-- dep/dep.go -- +package dep +import _ "test/dep3" +-- dep2/dep2.go -- +package dep2 +-- dep3/dep3.go -- +package dep3 +-- testdep/testdep.go -- +package testdep +import _ "test/testdep2" +-- testdep2/testdep2.go -- +package testdep2 diff --git a/go/src/cmd/go/testdata/script/build_pie_race.txt b/go/src/cmd/go/testdata/script/build_pie_race.txt new file mode 100644 index 0000000000000000000000000000000000000000..39bea0521fcd96e7fd5917a8510f447cc575c73c --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_pie_race.txt @@ -0,0 +1,30 @@ +# go build -buildmode=pie -race main.go on Darwin should work without errors + +[!race] skip 'test requires race detector support' + +[!GOOS:darwin] ! go build -buildmode=pie -race +[!GOOS:darwin] stderr '^-buildmode=pie not supported when -race is enabled on '$GOOS'/'$GOARCH'$' +[!GOOS:darwin] stop 'not testing -buildmode=pie -race on platform that does not support it' + +go build -buildmode=pie -race bytes +! stderr . + +[short] stop 'not linking a binary in -short mode' + +go build -buildmode=pie -race main.go +! stderr . +exec ./main +stdout 'Hello, 世界' + +-- go.mod -- +module m + +go 1.21 +-- main.go -- +package main + +import "fmt" + +func main() { + fmt.Println("Hello, 世界") +} diff --git a/go/src/cmd/go/testdata/script/build_plugin_non_main.txt b/go/src/cmd/go/testdata/script/build_plugin_non_main.txt new file mode 100644 index 0000000000000000000000000000000000000000..e0bbbefb19418ba922be4c877b2d398d3da89dd4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_plugin_non_main.txt @@ -0,0 +1,13 @@ +# Plugins are not supported on all platforms. +[!buildmode:plugin] skip + +go build -n testdep +! go build -buildmode=plugin testdep +stderr '-buildmode=plugin requires exactly one main package' + +-- go.mod -- +module testdep + +go 1.16 +-- testdep.go -- +package p diff --git a/go/src/cmd/go/testdata/script/build_plugin_reproducible.txt b/go/src/cmd/go/testdata/script/build_plugin_reproducible.txt new file mode 100644 index 0000000000000000000000000000000000000000..3379a6be5f99ceff5589b43f765c14a69b5351d9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_plugin_reproducible.txt @@ -0,0 +1,12 @@ +[!buildmode:plugin] skip +[short] skip +[!cgo] skip '-buildmode=plugin requires external linking' + +go build -trimpath -buildvcs=false -buildmode=plugin -o a.so main.go +go build -trimpath -buildvcs=false -buildmode=plugin -o b.so main.go +cmp -q a.so b.so + +-- main.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/build_relative_pkgdir.txt b/go/src/cmd/go/testdata/script/build_relative_pkgdir.txt new file mode 100644 index 0000000000000000000000000000000000000000..57f18eefcec45a11a9e6aea3a5b0128f4d7e7c76 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_relative_pkgdir.txt @@ -0,0 +1,9 @@ +env GO111MODULE=off + +# Regression test for golang.org/issue/21309: accept relative -pkgdir argument. + +[short] skip + +mkdir $WORK/gocache +env GOCACHE=$WORK/gocache +go build -pkgdir=. runtime diff --git a/go/src/cmd/go/testdata/script/build_relative_tmpdir.txt b/go/src/cmd/go/testdata/script/build_relative_tmpdir.txt new file mode 100644 index 0000000000000000000000000000000000000000..ea7412e1168e5154ca5ea71062464eabd0c25e63 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_relative_tmpdir.txt @@ -0,0 +1,18 @@ +env GO111MODULE=off + +# If GOTMPDIR is relative, 'go build' should derive an absolute $WORK directory. +cd $WORK +mkdir tmp +env GOTMPDIR=tmp +go build -work a +stderr 'WORK='$WORK + +# Similarly if TMP/TMPDIR is relative. +env GOTMPDIR= +env TMP=tmp # Windows +env TMPDIR=tmp # Unix +go build -work a +stderr 'WORK='$WORK + +-- a/a.go -- +package a diff --git a/go/src/cmd/go/testdata/script/build_repeated_godebug_issue62346.txt b/go/src/cmd/go/testdata/script/build_repeated_godebug_issue62346.txt new file mode 100644 index 0000000000000000000000000000000000000000..23534dde584534a67ded0c588e5595b09aa795cf --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_repeated_godebug_issue62346.txt @@ -0,0 +1,14 @@ +[short] skip # runs go build +! go build file.go +! stderr 'panic:' +! stderr 'runtime error' +stderr 'file.go:2:1: repeated //go:debug for panicnil' + +-- file.go -- +//go:debug panicnil=1 +//go:debug panicnil=1 + +package main + +func main() { +} diff --git a/go/src/cmd/go/testdata/script/build_runtime_gcflags.txt b/go/src/cmd/go/testdata/script/build_runtime_gcflags.txt new file mode 100644 index 0000000000000000000000000000000000000000..31695b1772fa23ca01486e7b0ddbfd91f461c802 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_runtime_gcflags.txt @@ -0,0 +1,11 @@ +env GO111MODULE=off +[short] skip # rebuilds all of std + +# Set up fresh GOCACHE. +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +# Verify the standard library (specifically internal/runtime/atomic) can be +# built with -gcflags when -n is given. See golang.org/issue/29346. +go build -n -gcflags=all='-l' std +stderr 'compile.* internal/runtime/atomic .* -l' diff --git a/go/src/cmd/go/testdata/script/build_shared_reproducible.txt b/go/src/cmd/go/testdata/script/build_shared_reproducible.txt new file mode 100644 index 0000000000000000000000000000000000000000..7e3bb348f37b68bf885c0b7997eac82c54bb107a --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_shared_reproducible.txt @@ -0,0 +1,10 @@ +[!buildmode:shared] skip +[short] skip +[!cgo] skip '-buildmode=shared requires external linking' +[!GOOS:linux] skip + +env GO111MODULE=off +env CGO_ENABLED=1 +go install -a -trimpath -buildvcs=false -buildmode=shared -pkgdir=pkgdir1 runtime +go install -a -trimpath -buildvcs=false -buildmode=shared -pkgdir=pkgdir2 runtime +[GOOS:linux] cmp -q pkgdir1/libruntime.so pkgdir2/libruntime.so diff --git a/go/src/cmd/go/testdata/script/build_shorten_pkg.txt b/go/src/cmd/go/testdata/script/build_shorten_pkg.txt new file mode 100644 index 0000000000000000000000000000000000000000..38672b65df758fd38e88fe71b2ec3200a2e83bb1 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_shorten_pkg.txt @@ -0,0 +1,81 @@ +[short] skip + +# This test may go away when the loopvar experiment goes away. +# Accurate reporting of notable loops in the presence of inlining +# can create warnings in sibling directories, and it's nice if those +# can be trimmed like subdirectory paths are. + +env GOEXPERIMENT=loopvar +go build -gcflags=inlines/a=-d=loopvar=2 . +stderr ^\.[\\/]b[\\/]b\.go:12:6:.*loop.inlined.into.a[\\/]a\.go +stderr ^\.[\\/]b[\\/]b\.go:12:9:.*loop.inlined.into.a[\\/]a\.go + +-- go.mod -- +module inlines + +go 1.21 +-- a/a.go -- +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +import "inlines/b" + +func F() []*int { + var s []*int + for i := 0; i < 10; i++ { + s = append(s, &i) + } + return s +} + +func Fb() []*int { + bf, _ := b.F() + return bf +} +-- b/b.go -- +package b + +var slice = []int{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024} + +func F() ([]*int, []*int) { + return g() +} + +func g() ([]*int, []*int) { + var s []*int + var t []*int + for i, j := range slice { + s = append(s, &i) + t = append(t, &j) + } + return s[:len(s)-1], t +} +-- main.go -- +package main + +import ( + "fmt" + "inlines/a" + "inlines/b" +) + +func sum(s []*int) int { + sum := 0 + for _, pi := range s { + sum += *pi + } + return sum +} + +func main() { + af := a.F() + bf, _ := b.F() + abf := a.Fb() + + saf, sbf, sabf := sum(af), sum(bf), sum(abf) + + fmt.Printf("af, bf, abf sums = %d, %d, %d\n", saf, sbf, sabf) +} diff --git a/go/src/cmd/go/testdata/script/build_single_error.txt b/go/src/cmd/go/testdata/script/build_single_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..241cdb954ba7664ce796ea16c761d23a59dfe45c --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_single_error.txt @@ -0,0 +1,18 @@ +# go test ./... with a bad package should report the error once (#44624). +! go test ./... +stderr -count=1 undefined + +-- go.mod -- +module example.com + +go 1.18 +-- a/a.go -- +package a + +import "example.com/b" +-- b/b.go -- +package b + +var X = Y +-- b/b_test.go -- +package b diff --git a/go/src/cmd/go/testdata/script/build_static.txt b/go/src/cmd/go/testdata/script/build_static.txt new file mode 100644 index 0000000000000000000000000000000000000000..7db90a1600f398ce05912e9217e93050fb92e60c --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_static.txt @@ -0,0 +1,44 @@ +[short] skip 'links and runs binaries' + +# This test requires external linking. Assume that if cgo is supported +# then external linking works. +[!cgo] skip 'requires a C linker' + +# Only run on Unix systems. +[GOOS:windows] skip +[GOOS:plan9] skip + +# Ordinary build should work. +go build +exec ./hello +stdout Hello + +# Building with -linkmode=external should not say anything about +# runtime/cgo (issue #31544). +go build -ldflags=-linkmode=external +! stderr runtime/cgo +exec ./hello +stdout Hello + +# Some targets don't support -static +[GOOS:darwin] skip 'no static linking on Darwin' +[GOOS:solaris] skip 'no static linking on Solaris' + +# Building with -linkmode=external -extldflags=-static should work. +go build -ldflags='-linkmode=external -extldflags=-static' +! stderr runtime/cgo +exec ./hello +stdout Hello + +-- go.mod -- +module hello + +go 1.20 +-- hello.go -- +package main + +import "fmt" + +func main() { + fmt.Println("Hello, world") +} diff --git a/go/src/cmd/go/testdata/script/build_tag_goexperiment.txt b/go/src/cmd/go/testdata/script/build_tag_goexperiment.txt new file mode 100644 index 0000000000000000000000000000000000000000..bee218f4c1fff290b993cf68930a4753ecbce708 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_tag_goexperiment.txt @@ -0,0 +1,31 @@ +[short] skip +# Reset all experiments so fieldtrack is definitely off. +env GOEXPERIMENT=none +go run m +stderr 'fieldtrack off' +# Turn fieldtrack on. +env GOEXPERIMENT=none,fieldtrack +go run m +stderr 'fieldtrack on' + +-- ft_off.go -- +// +build !goexperiment.fieldtrack + +package main + +func main() { + println("fieldtrack off") +} + +-- ft_on.go -- +// +build goexperiment.fieldtrack + +package main + +func main() { + println("fieldtrack on") +} + +-- go.mod -- +module m +go 1.14 diff --git a/go/src/cmd/go/testdata/script/build_tags_no_comma.txt b/go/src/cmd/go/testdata/script/build_tags_no_comma.txt new file mode 100644 index 0000000000000000000000000000000000000000..a14a200b676fc85ddd0a2793c6dbba7dbfb71dbc --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_tags_no_comma.txt @@ -0,0 +1,4 @@ +[compiler:gccgo] skip 'gccgo has no standard packages' +go build -tags 'tag1 tag2' math +! go build -tags 'tag1,tag2 tag3' math +stderr 'space-separated list contains comma' \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/build_test_only.txt b/go/src/cmd/go/testdata/script/build_test_only.txt new file mode 100644 index 0000000000000000000000000000000000000000..8693a80a08e67539a7e331870cd846cb045d57a8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_test_only.txt @@ -0,0 +1,19 @@ +# Named explicitly, test-only packages should be reported as +# unbuildable/uninstallable, even if there is a wildcard also matching. +! go build m/testonly m/testonly... +stderr 'no non-test Go files in' +! go install ./testonly +stderr 'no non-test Go files in' + +# Named through a wildcard, the test-only packages should be silently ignored. +go build m/testonly... +go install ./testonly... + +-- go.mod -- +module m + +go 1.16 +-- testonly/t_test.go -- +package testonly +-- testonly2/t.go -- +package testonly2 diff --git a/go/src/cmd/go/testdata/script/build_trimpath.txt b/go/src/cmd/go/testdata/script/build_trimpath.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f4dde98cb816295049104a7f2bd79a26a312d26 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_trimpath.txt @@ -0,0 +1,167 @@ +[short] skip + +# If GOROOT is set, 'go build -trimpath' bakes that into the resulting +# binary. Explicitly unset it here. +env GOROOT= + +# Set up two identical directories that can be used as GOPATH. +env GO111MODULE=on +mkdir $WORK/a/src/paths $WORK/b/src/paths +cp paths.go $WORK/a/src/paths +cp paths.go $WORK/b/src/paths +cp overlay.json $WORK/a/src/paths +cp overlay.json $WORK/b/src/paths +cp go.mod $WORK/a/src/paths/ +cp go.mod $WORK/b/src/paths/ + + +# A binary built without -trimpath should contain the module root dir +# and GOROOT for debugging and stack traces. +cd $WORK/a/src/paths +go build -o $WORK/paths-dbg.exe . +exec $WORK/paths-dbg.exe $WORK/paths-dbg.exe +stdout 'binary contains module root: true' +stdout 'binary contains an empty GOROOT' + +# A binary built with -trimpath should not contain the current workspace. +go build -trimpath -o $WORK/paths-a.exe . +exec $WORK/paths-a.exe $WORK/paths-a.exe +stdout 'binary contains module root: false' +stdout 'binary contains an empty GOROOT' + +# A binary from an external module built with -trimpath should not contain +# the current workspace or GOROOT. +go get rsc.io/fortune +go install -trimpath rsc.io/fortune +exec $WORK/paths-a.exe $GOPATH/bin/fortune$GOEXE +stdout 'binary contains module root: false' +stdout 'binary contains an empty GOROOT' +go mod edit -droprequire rsc.io/fortune + +# Two binaries built from identical packages in different directories +# should be identical. +cd $WORK/b/src/paths +go build -trimpath -o $WORK/paths-b.exe +cmp -q $WORK/paths-a.exe $WORK/paths-b.exe + + +# Same sequence of tests but with overlays. +# A binary built without -trimpath should contain the module root dir +# and GOROOT for debugging and stack traces. +cd $WORK/a/src/paths +go build -overlay overlay.json -o $WORK/paths-dbg.exe ./overlaydir +exec $WORK/paths-dbg.exe $WORK/paths-dbg.exe +stdout 'binary contains module root: true' +stdout 'binary contains an empty GOROOT' + +# A binary built with -trimpath should not contain the current workspace. +go build -overlay overlay.json -trimpath -o $WORK/paths-a.exe ./overlaydir +exec $WORK/paths-a.exe $WORK/paths-a.exe +stdout 'binary contains module root: false' +stdout 'binary contains an empty GOROOT' + +# Two binaries built from identical packages in different directories +# should be identical. +cd $WORK/b/src/paths +go build -overlay overlay.json -trimpath -o $WORK/paths-b.exe ./overlaydir +cmp -q $WORK/paths-a.exe $WORK/paths-b.exe + + +# Same sequence of tests but in GOPATH mode. +# A binary built without -trimpath should contain GOPATH and GOROOT. +env GO111MODULE=off +cd $WORK +env GOPATH=$WORK/a +go build -o paths-dbg.exe paths +exec ./paths-dbg.exe paths-dbg.exe +stdout 'binary contains GOPATH: true' +stdout 'binary contains an empty GOROOT' + +# A binary built with -trimpath should not contain GOPATH. +go build -trimpath -o paths-a.exe paths +exec ./paths-a.exe paths-a.exe +stdout 'binary contains GOPATH: false' +stdout 'binary contains an empty GOROOT' + +# Two binaries built from identical packages in different GOPATH roots +# should be identical. +env GOPATH=$WORK/b +go build -trimpath -o paths-b.exe paths +cmp -q paths-a.exe paths-b.exe + + +# Same sequence of tests but with gccgo. +# gccgo does not support builds in module mode. +[!exec:gccgo] stop +[cross] stop # gccgo can't necessarily cross-compile +env GOPATH=$WORK/a + +# A binary built with gccgo without -trimpath should contain the current +# GOPATH and GOROOT. +go build -compiler=gccgo -o paths-dbg.exe paths +exec ./paths-dbg.exe paths-dbg.exe +stdout 'binary contains GOPATH: true' +stdout 'binary contains an empty GOROOT' + +# gccgo doesn't load std from GOROOT. +# A binary built with gccgo with -trimpath should not contain GOPATH or GOROOT. +go build -compiler=gccgo -trimpath -o paths-a.exe paths +exec ./paths-a.exe paths-a.exe +stdout 'binary contains GOPATH: false' +stdout 'binary contains an empty GOROOT' + +# Two binaries built from identical packages in different directories +# should be identical. +env GOPATH=$WORK/b +go build -compiler=gccgo -trimpath -o paths-b.exe paths +cmp -q paths-a.exe paths-b.exe + +-- paths.go -- +package main + +import ( + "bytes" + "fmt" + "io/ioutil" + "log" + "os" + "os/exec" + "path/filepath" + "strings" +) + +func main() { + exe := os.Args[1] + data, err := ioutil.ReadFile(exe) + if err != nil { + log.Fatal(err) + } + + if os.Getenv("GO111MODULE") == "on" { + out, err := exec.Command("go", "env", "GOMOD").Output() + if err != nil { + log.Fatal(err) + } + modRoot := filepath.Dir(strings.TrimSpace(string(out))) + check(data, "module root", modRoot) + } else { + check(data, "GOPATH", os.Getenv("GOPATH")) + } + check(data, "GOROOT", os.Getenv("GOROOT")) +} + +func check(data []byte, desc, dir string) { + if dir == "" { + fmt.Printf("binary contains an empty %s\n", desc) + return + } + containsDir := bytes.Contains(data, []byte(dir)) + containsSlashDir := bytes.Contains(data, []byte(filepath.ToSlash(dir))) + fmt.Printf("binary contains %s: %v\n", desc, containsDir || containsSlashDir) +} +-- overlay.json -- +{ "Replace": { "overlaydir/paths.go": "paths.go" } } +-- go.mod -- +module paths + +go 1.14 diff --git a/go/src/cmd/go/testdata/script/build_trimpath_cgo.txt b/go/src/cmd/go/testdata/script/build_trimpath_cgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..b0cc401ad679158a64a7283b291ce0d47c2777c7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_trimpath_cgo.txt @@ -0,0 +1,187 @@ +# This test builds a cgo binary and verifies the source directory path +# does not appear in the binary, either literally or in compressed DWARF. +# TODO(golang.org/issue/36072): ideally we should build a binary from identical +# sources in different directories and verify the binary and all intermediate +# files are identical. + +[short] skip +[!cgo] skip + +# Check that the source path appears when -trimpath is not used. +go build -o hello.exe . +grep -q gopath[/\\]src hello.exe +go run ./list-dwarf hello.exe +stdout gopath[/\\]src + +# Check that the source path does not appear when -trimpath is used. +[GOOS:aix] stop # can't inspect XCOFF binaries +go build -trimpath -o hello.exe . +! grep -q gopath[/\\]src hello.exe +go run ./list-dwarf hello.exe +! stdout gopath/src + + +# Do the above, with the cgo (but not .c) sources in an overlay +# Check that the source path appears when -trimpath is not used. +mkdir $WORK/overlay +cp hello.go $WORK/overlay/hello.go +mkdir hello_overlay +cp hello.c hello_overlay/hello.c +go build -overlay overlay.json -o hello_overlay.exe ./hello_overlay +grep -q gopath[/\\]src hello_overlay.exe +! grep -q $WORK[/\\]overlay hello_overlay.exe +go run ./list-dwarf hello_overlay.exe +stdout gopath[/\\]src +! stdout $WORK[/\\]overlay + +# Check that the source path does not appear when -trimpath is used. +go build -overlay overlay.json -trimpath -o hello_overlay.exe ./hello_overlay +! grep -q gopath[/\\]src hello_overlay.exe +! grep -q $WORK[/\\]overlay hello_overlay.exe +go run ./list-dwarf hello_overlay.exe +! stdout gopath/src +! stdout $WORK[/\\]overlay + +-- go.mod -- +module m + +go 1.14 +-- overlay.json -- +{ + "Replace": { + "hello_overlay/hello.go": "../../overlay/hello.go" + } +} +-- hello.c -- +#include + +void say_hello() { puts("Hello, world!\n"); } + +-- hello.go -- +package main + +// void say_hello(); +import "C" + +func main() { + C.say_hello() +} + +-- list-dwarf/list-dwarf.go -- +package main + +import ( + "debug/dwarf" + "fmt" + "io" + "log" + "os" + "sort" +) + +func main() { + files, err := run(os.Args[1]) + if err != nil { + log.Fatal(err) + } + for _, file := range files { + fmt.Println(file) + } +} + +func run(exePath string) ([]string, error) { + dwarfData, err := readDWARF(exePath) + if err != nil { + return nil, err + } + + dwarfReader := dwarfData.Reader() + files := make(map[string]bool) + for { + e, err := dwarfReader.Next() + if err != nil { + return nil, err + } + if e == nil { + break + } + lr, err := dwarfData.LineReader(e) + if err != nil { + return nil, err + } + if lr == nil { + continue + } + + var le dwarf.LineEntry + for { + if err := lr.Next(&le); err != nil { + if err == io.EOF { + break + } + return nil, err + } + if le.EndSequence { + continue + } + files[le.File.Name] = true + } + } + + sortedFiles := make([]string, 0, len(files)) + for file := range files { + sortedFiles = append(sortedFiles, file) + } + sort.Strings(sortedFiles) + return sortedFiles, nil +} +-- list-dwarf/read_darwin.go -- +package main + +import ( + "debug/dwarf" + "debug/macho" +) + +func readDWARF(exePath string) (*dwarf.Data, error) { + machoFile, err := macho.Open(exePath) + if err != nil { + return nil, err + } + defer machoFile.Close() + return machoFile.DWARF() +} +-- list-dwarf/read_elf.go -- +// +build android dragonfly freebsd illumos linux netbsd openbsd solaris + +package main + +import ( + "debug/dwarf" + "debug/elf" +) + +func readDWARF(exePath string) (*dwarf.Data, error) { + elfFile, err := elf.Open(exePath) + if err != nil { + return nil, err + } + defer elfFile.Close() + return elfFile.DWARF() +} +-- list-dwarf/read_windows.go -- +package main + +import ( + "debug/dwarf" + "debug/pe" +) + +func readDWARF(exePath string) (*dwarf.Data, error) { + peFile, err := pe.Open(exePath) + if err != nil { + return nil, err + } + defer peFile.Close() + return peFile.DWARF() +} diff --git a/go/src/cmd/go/testdata/script/build_trimpath_goroot.txt b/go/src/cmd/go/testdata/script/build_trimpath_goroot.txt new file mode 100644 index 0000000000000000000000000000000000000000..e31eccec06eec0377209257bd9db4409d8174692 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_trimpath_goroot.txt @@ -0,0 +1,97 @@ +# Regression test for https://go.dev/issue/51461 and https://go.dev/issue/51483. +# +# When built with -trimpath, runtime.GOROOT() returned the bogus string "go" +# if GOROOT was not set explicitly in the environment. +# It should instead return the empty string, since we know that we don't +# have a valid path to return. + +[trimpath] env GOROOT= +[trimpath] ! go env GOROOT +[trimpath] stderr '^go: cannot find GOROOT directory: ''go'' binary is trimmed and GOROOT is not set$' +[trimpath] env GOROOT=$TESTGO_GOROOT + +[short] stop + +# With GOROOT still set, 'go build' and 'go test -c' +# should cause runtime.GOROOT() to report either the correct GOROOT +# (without -trimpath) or no GOROOT at all (with -trimpath). + +go build -o example.exe . +go build -trimpath -o example-trimpath.exe . +go test -c -o example.test.exe . +go test -trimpath -c -o example.test-trimpath.exe . + +env GOROOT= + +exec ./example.exe +stdout '^GOROOT '$TESTGO_GOROOT'$' +stdout '^runtime '$TESTGO_GOROOT${/}src${/}runtime'$' + +! exec ./example-trimpath.exe +stdout '^GOROOT $' +stderr 'cannot find package "runtime" in any of:\n\t\(\$GOROOT not set\)\n\t'$WORK${/}gopath${/}src${/}runtime' \(from \$GOPATH\)\n\z' + +exec ./example.test.exe -test.v +stdout '^GOROOT '$TESTGO_GOROOT'$' +stdout '^runtime '$TESTGO_GOROOT${/}src${/}runtime'$' + +! exec ./example.test-trimpath.exe -test.v +stdout '^GOROOT $' +stderr 'cannot find package "runtime" in any of:\n\t\(\$GOROOT not set\)\n\t'$WORK${/}gopath${/}src${/}runtime' \(from \$GOPATH\)$' + +# If a correct GOROOT is baked in to the 'go' command itself, 'go run' and +# 'go test' should not implicitly set GOROOT in the process environment +# (because that could mask an unexpected production dependency on the GOROOT +# environment variable), but 'go generate' should (because the generator may +# reasonably expect to be able to locate the GOROOT for which it is generating +# code). + +[trimpath] stop + +! go run -trimpath . +stdout '^GOROOT $' +stderr 'cannot find package "runtime" in any of:\n\t\(\$GOROOT not set\)\n\t'$WORK${/}gopath${/}src${/}runtime' \(from \$GOPATH\)\nexit status 1\n\z' + +! go test -trimpath -v . +stdout '^GOROOT $' +stdout 'cannot find package "runtime" in any of:\n\t\(\$GOROOT not set\)\n\t'$WORK${/}gopath${/}src${/}runtime' \(from \$GOPATH\)$' + +env GOFLAGS=-trimpath +go generate . +stdout '^GOROOT '$TESTGO_GOROOT'$' +stdout '^runtime '$TESTGO_GOROOT${/}src${/}runtime'$' + +-- go.mod -- +module example + +go 1.19 +-- main.go -- +package main + +//go:generate go run . + +import ( + "fmt" + "go/build" + "os" + "runtime" +) + +func main() { + fmt.Println("GOROOT", runtime.GOROOT()) + + p, err := build.Default.Import("runtime", "", build.FindOnly) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + fmt.Println("runtime", p.Dir) +} +-- main_test.go -- +package main + +import "testing" + +func TestMain(*testing.M) { + main() +} diff --git a/go/src/cmd/go/testdata/script/build_unsupported_goos.txt b/go/src/cmd/go/testdata/script/build_unsupported_goos.txt new file mode 100644 index 0000000000000000000000000000000000000000..c94d6d252e845734f3965aefad3734a06bd9ffc7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_unsupported_goos.txt @@ -0,0 +1,6 @@ +[compiler:gccgo] skip # gccgo assumes cross-compilation is always possible + +env GOOS=windwos # intentional misspelling of windows + +! go build -n exclude +stderr 'unsupported GOOS/GOARCH pair' diff --git a/go/src/cmd/go/testdata/script/build_vendor.txt b/go/src/cmd/go/testdata/script/build_vendor.txt new file mode 100644 index 0000000000000000000000000000000000000000..f430ff2c3eb888d596b848f5f95ee06d50fe446d --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_vendor.txt @@ -0,0 +1,42 @@ +# Build +env GO111MODULE=off +go build vend/x +! stdout . +! stderr . + +-- vend/dir1/dir1.go -- +package dir1 +-- vend/subdir/bad.go -- +package subdir + +import _ "r" +-- vend/subdir/good.go -- +package subdir + +import _ "p" +-- vend/vendor/p/p.go -- +package p +-- vend/vendor/q/q.go -- +package q +-- vend/vendor/vend/dir1/dir2/dir2.go -- +package dir2 +-- vend/x/invalid/invalid.go -- +package invalid + +import "vend/x/invalid/vendor/foo" +-- vend/x/vendor/p/p/p.go -- +package p + +import _ "notfound" +-- vend/x/vendor/p/p.go -- +package p +-- vend/x/vendor/r/r.go -- +package r +-- vend/x/x.go -- +package x + +import _ "p" +import _ "q" +import _ "r" +import _ "vend/dir1" // not vendored +import _ "vend/dir1/dir2" // vendored diff --git a/go/src/cmd/go/testdata/script/build_version_stamping_git.txt b/go/src/cmd/go/testdata/script/build_version_stamping_git.txt new file mode 100644 index 0000000000000000000000000000000000000000..f9dbb370b65a9a7fd42ef4d2db1476f340e9472e --- /dev/null +++ b/go/src/cmd/go/testdata/script/build_version_stamping_git.txt @@ -0,0 +1,211 @@ +# Test that the version of a binary is stamped using git tag information. +# See https://go.dev/issue/50603 + +[short] skip 'constructs a local git repo' +[!git] skip + +# Redirect git to a test-specific .gitconfig. +# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer. +# For older git versions we also set $HOME. +env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig +env HOME=$WORK${/}home${/}gopher +exec git config --global --show-origin user.name +stdout 'Go Gopher' + +cd $WORK/repo +# Use devel when git information is missing. +go build +go version -m example$GOEXE +stdout '\s+mod\s+example\s+\(devel\)' +rm example$GOEXE + +env GIT_AUTHOR_NAME='Go Gopher' +env GIT_AUTHOR_EMAIL='gopher@golang.org' +env GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME +env GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL + +exec git init +env GIT_COMMITTER_DATE=2022-07-19T11:07:00-04:00 +env GIT_AUTHOR_DATE=2022-07-19T11:07:00-04:00 +exec git add . +exec git commit -m 'initial commit' +exec git branch -m main + +# Use a 0.0.0 pseudo-version when no tags are present. +go build +go version -m example$GOEXE +stdout '\s+mod\s+example\s+v0.0.0-20220719150700-e7537ba8fd6d\s+' +rm example$GOEXE + +# Use a 0.0.0 pseudo-version if the current tag is not a valid semantic version. +exec git tag 1.0.1 +go build +go version -m example$GOEXE +stdout '\s+mod\s+example\s+v0.0.0-20220719150700-e7537ba8fd6d\s+' +rm example$GOEXE + +# Use the current tag which has a valid semantic version to stamp the version. +exec git tag v1.0.1 +go build +go version -m example$GOEXE +stdout '\s+mod\s+example\s+v1.0.1\s+' +rm example$GOEXE + +# Use tag+dirty when there are uncommitted changes present. +cp $WORK/copy/README $WORK/repo/README +go build +go version -m example$GOEXE +stdout '\s+mod\s+example\s+v1.0.1\+dirty\s+' +rm example$GOEXE + +env GIT_COMMITTER_DATE=2022-07-19T11:07:01-04:00 +env GIT_AUTHOR_DATE=2022-07-19T11:07:01-04:00 +exec git add . +exec git commit -m 'commit 2' + +# Use the updated tag to stamp the version. +exec git tag v1.0.2 +go build +go version -m example$GOEXE +stdout '\s+mod\s+example\s+v1.0.2\s+' +rm example$GOEXE + +env GIT_COMMITTER_DATE=2022-07-19T11:07:02-04:00 +env GIT_AUTHOR_DATE=2022-07-19T11:07:02-04:00 +mv README README2 +exec git add . +exec git commit -m 'commit 3' + +# Use a pseudo-version when current commit doesn't match a tagged version. +go build +go version -m example$GOEXE +stdout '\s+mod\s+example\s+v1.0.3-0.20220719150702-b0226f18a7ae\s+' +rm example$GOEXE + +# Use pseudo+dirty when uncommitted changes are present. +mv README2 README3 +go build +go version -m example$GOEXE +stdout '\s+mod\s+example\s+v1.0.3-0.20220719150702-b0226f18a7ae\+dirty\s+' +rm example$GOEXE + +# Make sure we always use the previously tagged version to generate the pseudo-version at a untagged revision. +env GIT_COMMITTER_DATE=2022-07-19T11:07:03-04:00 +env GIT_AUTHOR_DATE=2022-07-19T11:07:03-04:00 +exec git add . +exec git commit -m 'commit 4' + +mv README3 README4 +env GIT_COMMITTER_DATE=2022-07-19T11:07:04-04:00 +env GIT_AUTHOR_DATE=2022-07-19T11:07:04-04:00 +exec git add . +exec git commit -m 'commit 5' +exec git tag v1.0.4 +# Jump back to commit 4 which is untagged. +exec git checkout ':/commit 4' +go build +go version -m example$GOEXE +stdout '\s+mod\s+example\s+v1.0.3-0.20220719150703-2ebc76937b49\s+' +rm example$GOEXE + +# Create +incompatible module +exec git checkout v1.0.4 +exec git rm go.mod +exec git commit -m 'commit 6' +exec git tag v2.0.0 +exec git checkout HEAD^ go.mod +# And make the tree +dirty +mv README4 README5 +go build +go version -m example$GOEXE +stdout '\s+mod\s+example\s+v2.0.0\+incompatible.dirty\s+' +rm example$GOEXE + +# Make sure v2 works as expected. +exec git checkout v1.0.4 +go mod edit -module example/v2 +exec git add . +exec git commit -m 'commit 7' +exec git tag v2.1.1 +go build +go version -m example$GOEXE +stdout '\s+mod\s+example/v2\s+v2.1.1\s+' +rm example$GOEXE + +# v2+dirty +mv README5 README6 +go build +go version -m example$GOEXE +stdout '\s+mod\s+example/v2\s+v2.1.1\+dirty\s+' +rm example$GOEXE + +# v2+pseudo +exec git add . +exec git commit -m 'commit 8' +go build +go version -m example$GOEXE +stdout '\s+mod\s+example/v2\s+v2.1.2-0.20220719150704-0ebeb94ecde2\s+' +rm example$GOEXE + +# v2+pseudo+dirty +mv README6 README7 +go build +go version -m example$GOEXE +stdout '\s+mod\s+example/v2\s+v2.1.2-0.20220719150704-0ebeb94ecde2\+dirty\s+' +rm example$GOEXE + +# modules in subdirectories should be stamped with the correct tag +exec git add . +cd subdir +exec git commit -m 'commit 9' +go build +go version -m subdir$GOEXE +# missing tag creates a pseudo version with v2.0.0 +stdout '\s+mod\s+example/subdir/v2\s+v2.0.0-20220719150704-fbef6799938f\s+' +rm subdir$GOEXE +# tag with subdir +exec git tag subdir/v2.1.0 +go build +go version -m subdir$GOEXE +stdout '\s+mod\s+example/subdir/v2\s+v2.1.0\s+' +# v2+dirty +mv ../README7 README8 +go build +go version -m subdir$GOEXE +stdout '\s+mod\s+example/subdir/v2\s+v2.1.0\+dirty\s+' +rm subdir$GOEXE + +# modules in a subdirectory without a go.mod in the root should result in (devel) +rm ../go.mod +go build +go version -m subdir$GOEXE +stdout '\s+mod\s+example/subdir/v2\s+\(devel\)\s+' +rm subdir$GOEXE + +-- $WORK/repo/go.mod -- +module example + +go 1.18 +-- $WORK/repo/main.go -- +package main + +func main() { +} +-- $WORK/copy/README -- +hello + +-- $WORK/repo/subdir/go.mod -- +module example/subdir/v2 + +go 1.18 + +-- $WORK/repo/subdir/main.go -- +package main + +func main() { +} + +-- $WORK/home/gopher/.gitconfig -- +[user] + name = Go Gopher + email = gopher@golang.org diff --git a/go/src/cmd/go/testdata/script/cache_unix.txt b/go/src/cmd/go/testdata/script/cache_unix.txt new file mode 100644 index 0000000000000000000000000000000000000000..e11804d39abebdad9bb07f724f5d948346ff3682 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cache_unix.txt @@ -0,0 +1,37 @@ +env GO111MODULE=off + +# Integration test for cache directory calculation (cmd/go/internal/cache). + +[GOOS:windows] skip 'windows does not use XDG_CACHE_HOME' +[GOOS:darwin] skip 'darwin does not use XDG_CACHE_HOME' +[GOOS:ios] skip 'ios does not use XDG_CACHE_HOME' +[GOOS:plan9] skip 'plan9 does not use XDG_CACHE_HOME' + +mkdir $WORK/gocache +mkdir $WORK/xdg +mkdir $WORK/home + +# Set GOCACHE, XDG_CACHE_HOME, and HOME. +env GOCACHE=$WORK/gocache +env XDG_CACHE_HOME=$WORK/xdg +env HOME=$WORK/home + +# With all three set, we should prefer GOCACHE. +go env GOCACHE +stdout $WORK'/gocache$' + +# Without GOCACHE, we should prefer XDG_CACHE_HOME over HOME. +env GOCACHE= +go env GOCACHE +stdout $WORK'/xdg/go-build$$' + +# With only HOME set, we should use $HOME/.cache. +env XDG_CACHE_HOME= +go env GOCACHE +stdout $WORK'/home/.cache/go-build$' + +# With no guidance from the environment, we must disable the cache, but that +# should not cause commands that do not write to the cache to fail. +env HOME= +go env GOCACHE +stdout 'off' diff --git a/go/src/cmd/go/testdata/script/cache_vet.txt b/go/src/cmd/go/testdata/script/cache_vet.txt new file mode 100644 index 0000000000000000000000000000000000000000..6689048f5409ae7585305dc25fde853c5fccfb72 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cache_vet.txt @@ -0,0 +1,22 @@ +env GO111MODULE=off + +[short] skip +[GODEBUG:gocacheverify=1] skip +[compiler:gccgo] skip # gccgo has no standard packages + +# Start with a clean build cache: +# test failures may be masked if the cache has just the right entries already. +env GOCACHE=$WORK/cache + +# Run 'go vet os/user' once to warm up the cache. +go vet os/user + +# Check that second vet reuses cgo-derived inputs. +# The first command could be build instead of vet, +# except that if the cache is empty and there's a net.a +# in GOROOT/pkg, the build will not bother to regenerate +# and cache the cgo outputs, whereas vet always will. + +go vet -x os/user +! stderr '^(clang|gcc)' # should not have run compiler +! stderr '[\\/]cgo ' # should not have run cgo diff --git a/go/src/cmd/go/testdata/script/cgo_asm_error.txt b/go/src/cmd/go/testdata/script/cgo_asm_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..7aaa713e24412c1966b003e3f774888cd9df7dcb --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_asm_error.txt @@ -0,0 +1,25 @@ +[!cgo] skip + +# Test that cgo package can't contain a go assembly file. + +# Ensure the build fails and reports that the package has a Go assembly file. +! go build cgoasm +stderr 'package using cgo has Go assembly file' + +-- go.mod -- +module cgoasm + +go 1.16 +-- p.go -- +package p + +/* +// hi +*/ +import "C" + +func F() {} +-- p.s -- +TEXT asm(SB),$0 + RET + diff --git a/go/src/cmd/go/testdata/script/cgo_bad_directives.txt b/go/src/cmd/go/testdata/script/cgo_bad_directives.txt new file mode 100644 index 0000000000000000000000000000000000000000..0c64b6d9a40f1693c9ec424130d270d2b8fca226 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_bad_directives.txt @@ -0,0 +1,138 @@ +[!cgo] skip +[short] skip + +cp x.go.txt x.go + +# Only allow //go:cgo_ldflag .* in cgo-generated code +[compiler:gc] cp x_gc.go.txt x.go +[compiler:gc] ! go build x +[compiler:gc] stderr '//go:cgo_ldflag .* only allowed in cgo-generated code' + +# Ignore _* files +rm x.go +! go build . +stderr 'no Go files' +cp cgo_yy.go.txt _cgo_yy.go +! go build . +stderr 'no Go files' #_* files are ignored... + +[compiler:gc] ! go build _cgo_yy.go # ... but if forced, the comment is rejected +# Actually, today there is a separate issue that _ files named +# on the command line are ignored. Once that is fixed, +# we want to see the cgo_ldflag error. +[compiler:gc] stderr '//go:cgo_ldflag only allowed in cgo-generated code|no Go files' + +rm _cgo_yy.go + +# Reject #cgo CFLAGS: -fplugin=foo.so +cp x.go.txt x.go +cp y_fplugin.go.txt y.go +! go build x +stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so' + +# Reject #cgo CFLAGS: -lbar -fplugin=foo.so +cp y_lbar_fplugin.go.txt y.go +! go build x +stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so' + +# Reject #cgo pkg-config: -foo +cp y_pkgconfig_dash_foo.txt y.go +! go build x +stderr 'invalid pkg-config package name: -foo' + +# Reject #cgo pkg-config: @foo +cp y_pkgconfig_at_foo.txt y.go +! go build x +stderr 'invalid pkg-config package name: @foo' + +# Reject #cgo pkg-config: --log-file=/tmp/log +cp y_pkgconfig_log_file.txt y.go +! go build x +stderr 'invalid flag in pkg-config: --log-file=/tmp/log' + +# Reject #cgo CFLAGS: @foo +cp y_cflags_at_foo.txt y.go +! go build x +stderr 'invalid flag in #cgo CFLAGS: @foo' + +# Reject #cgo CFLAGS: -D +cp y_cflags_dash_d.txt y.go +! go build x +stderr 'invalid flag in #cgo CFLAGS: -D without argument' + +# Note that -I @foo is allowed because we rewrite it into -I /path/to/src/@foo +# before the check is applied. There's no such rewrite for -D. + +# Reject #cgo CFLAGS: -D @foo +cp y_cflags_dash_d_space_at_foo.txt y.go +! go build x +stderr 'invalid flag in #cgo CFLAGS: -D @foo' + +# Reject #cgo CFLAGS -D@foo +cp y_cflags_dash_d_at_foo.txt y.go +! go build x +stderr 'invalid flag in #cgo CFLAGS: -D@foo' + +# Check for CFLAGS in commands +env CGO_CFLAGS=-D@foo +cp y_no_cflags.txt y.go +go build -n x +stderr '-D@foo' + +-- go.mod -- +module x + +go 1.16 +-- x_gc.go.txt -- +package x + +//go:cgo_ldflag "-fplugin=foo.so" + +import "C" +-- cgo_yy.go.txt -- +package x + +//go:cgo_ldflag "-fplugin=foo.so" + +import "C" +-- x.go.txt -- +package x +-- y_fplugin.go.txt -- +package x +// #cgo CFLAGS: -fplugin=foo.so +import "C" +-- y_lbar_fplugin.go.txt -- +package x +// #cgo CFLAGS: -Ibar -fplugin=foo.so +import "C" +-- y_pkgconfig_dash_foo.txt -- +package x +// #cgo pkg-config: -foo +import "C" +-- y_pkgconfig_at_foo.txt -- +package x +// #cgo pkg-config: @foo +import "C" +-- y_pkgconfig_log_file.txt -- +package x +// #cgo pkg-config: --log-file=/tmp/log +import "C" +-- y_cflags_at_foo.txt -- +package x +// #cgo CFLAGS: @foo +import "C" +-- y_cflags_dash_d.txt -- +package x +// #cgo CFLAGS: -D +import "C" +-- y_cflags_dash_d_space_at_foo.txt -- +package x +// #cgo CFLAGS: -D @foo +import "C" +-- y_cflags_dash_d_at_foo.txt -- +package x +// #cgo CFLAGS: -D@foo +import "C" +-- y_no_cflags.txt -- +package x +import "C" diff --git a/go/src/cmd/go/testdata/script/cgo_badmethod_issue57926.txt b/go/src/cmd/go/testdata/script/cgo_badmethod_issue57926.txt new file mode 100644 index 0000000000000000000000000000000000000000..81ef850cb960ca45733ef2f2016f4f75fa24982c --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_badmethod_issue57926.txt @@ -0,0 +1,31 @@ +[short] skip +[!cgo] skip + +# Test that cgo rejects attempts to declare methods +# on the types C.T or *C.T; see issue #57926. + +! go build +stderr 'cannot define new methods on non-local type C.T' +stderr 'cannot define new methods on non-local type \*C.T' +! stderr 'Alias' + +-- go.mod -- +module example.com +go 1.12 + +-- a.go -- +package a + +/* +typedef int T; +*/ +import "C" + +func (C.T) f() {} +func (recv *C.T) g() {} + +// The check is more education than enforcement, +// and is easily defeated using a type alias. +type Alias = C.T +func (Alias) h() {} +func (*Alias) i() {} diff --git a/go/src/cmd/go/testdata/script/cgo_badmethod_issue60725.txt b/go/src/cmd/go/testdata/script/cgo_badmethod_issue60725.txt new file mode 100644 index 0000000000000000000000000000000000000000..1ed087aa7417ae3b78f14ca892801f6b4fda3958 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_badmethod_issue60725.txt @@ -0,0 +1,26 @@ +[short] skip +[!cgo] skip + +# Test that cgo rejects attempts to declare methods +# on the types A or *A; see issue #60725. + +! go build ./a +stderr 'cannot define new methods on non-local type A' +stderr 'cannot define new methods on non-local type A' + +-- go.mod -- +module example.com +go 1.24 + +-- a/a.go -- +package a + +/* +typedef int T; +*/ +import "C" + +type A = C.T + +func (A) m1() {} +func (*A) m2() {} diff --git a/go/src/cmd/go/testdata/script/cgo_depends_on_syscall.txt b/go/src/cmd/go/testdata/script/cgo_depends_on_syscall.txt new file mode 100644 index 0000000000000000000000000000000000000000..bd4777c821cd4a3bdc25177b7e5d3fab0348b2b7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_depends_on_syscall.txt @@ -0,0 +1,15 @@ +[!cgo] skip +[!race] skip + +go list -race -deps foo +stdout syscall + +-- go.mod -- +module foo + +go 1.16 +-- foo.go -- +package foo + +// #include +import "C" diff --git a/go/src/cmd/go/testdata/script/cgo_flag_contains_space.txt b/go/src/cmd/go/testdata/script/cgo_flag_contains_space.txt new file mode 100644 index 0000000000000000000000000000000000000000..a3372bbbc7672622704d58252d0751c0b30cf554 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_flag_contains_space.txt @@ -0,0 +1,16 @@ +[short] skip +[!cgo] skip + +env GOCACHE=$WORK/gocache # Looking for compile flags, so need a clean cache. +go build -x -n main.go +stderr '"-I[^"]+c flags"' # find quoted c flags +! stderr '"-I[^"]+c flags".*"-I[^"]+c flags"' # don't find too many quoted c flags per line +stderr '"-L[^"]+ld flags"' # find quoted ld flags +! stderr '"-L[^"]+c flags".*"-L[^"]+c flags"' # don't find too many quoted ld flags per line + +-- main.go -- +package main +// #cgo CFLAGS: -I"c flags" +// #cgo LDFLAGS: -L"ld flags" +import "C" +func main() {} diff --git a/go/src/cmd/go/testdata/script/cgo_long_cmd.txt b/go/src/cmd/go/testdata/script/cgo_long_cmd.txt new file mode 100644 index 0000000000000000000000000000000000000000..36b913371566a4c22e8ed41750b67a0780545a60 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_long_cmd.txt @@ -0,0 +1,46 @@ +# Issue #66456 + +[!cgo] skip +[GOOS:windows] skip +[GOOS:plan9] skip + +# Generate a file with a very long #cgo LDFLAGS line. +# This used to cause "go build" to fail with "argument list too long". +go generate + +# Build with the generated file. +go build + +-- go.mod -- +module cgolongcmd + +go 1.22 +-- generate.go -- +//go:build ignore + +package main + +import ( + "fmt" + "log" + "os" + "bytes" +) + +func main() { + var buf bytes.Buffer + buf.WriteString("package p\n") + buf.WriteString("// #cgo LDFLAGS:") + for i := range 10000 { + fmt.Fprintf(&buf, " -Wl,-rpath,/nonexistentpath/%d", i) + } + buf.WriteString("\n") + buf.WriteString(`import "C"`+"\n") + if err := os.WriteFile("generated.go", buf.Bytes(), 0o644); err != nil { + log.Fatal(err) + } +} +-- gen.go -- +package p + +//go:generate go run generate.go diff --git a/go/src/cmd/go/testdata/script/cgo_path.txt b/go/src/cmd/go/testdata/script/cgo_path.txt new file mode 100644 index 0000000000000000000000000000000000000000..0c8838e35459f4b3baa9bcaaf6cb7f7bd6694b19 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_path.txt @@ -0,0 +1,43 @@ +[short] skip 'runs build' + +[!cgo] skip + +# Require that CC is something that requires a PATH lookup. +# Normally, the default is gcc or clang, but if CC was set during make.bash, +# that becomes the default. +[!cc:clang] [!cc:gcc] skip 'C compiler is not gcc or clang' + +env GOCACHE=$WORK/gocache # Looking for compile flags, so need a clean cache. +[!GOOS:windows] env PATH=.:$PATH +[!GOOS:windows] chmod 0755 p/gcc p/clang +[!GOOS:windows] exists -exec p/gcc p/clang +[GOOS:windows] exists -exec p/gcc.bat p/clang.bat +! exists p/bug.txt +! go build -x +stderr '^cgo: C compiler "(clang|gcc)" not found: exec: "(clang|gcc)": cannot run executable found relative to current directory' +! exists p/bug.txt + +-- go.mod -- +module m + +-- m.go -- +package m + +import _ "m/p" + +-- p/p.go -- +package p + +// #define X 1 +import "C" + +-- p/gcc -- +#!/bin/sh +echo ran gcc >bug.txt +-- p/clang -- +#!/bin/sh +echo ran clang >bug.txt +-- p/gcc.bat -- +echo ran gcc >bug.txt +-- p/clang.bat -- +echo ran clang >bug.txt diff --git a/go/src/cmd/go/testdata/script/cgo_path_space.txt b/go/src/cmd/go/testdata/script/cgo_path_space.txt new file mode 100644 index 0000000000000000000000000000000000000000..1a789022a5bcd82d367ee4b5d7a770166023b06d --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_path_space.txt @@ -0,0 +1,56 @@ +# Check that if the PATH directory containing the C compiler has a space, +# we can still use that compiler with cgo. +# Verifies #43808. +[!cgo] skip + +# Set CC explicitly to something that requires a PATH lookup. +# Normally, the default is gcc or clang, but if CC was set during make.bash, +# that becomes the default. +[exec:clang] env CC=clang +[exec:gcc] env CC=gcc +[!exec:clang] [!exec:gcc] skip 'Unknown C compiler' + +[!GOOS:windows] chmod 0755 $WORK/'program files'/clang +[!GOOS:windows] chmod 0755 $WORK/'program files'/gcc +[!GOOS:windows] exists -exec $WORK/'program files'/clang +[!GOOS:windows] exists -exec $WORK/'program files'/gcc +[!GOOS:windows] env PATH=$WORK/'program files':$PATH +[GOOS:windows] exists -exec $WORK/'program files'/gcc.bat +[GOOS:windows] exists -exec $WORK/'program files'/clang.bat +[GOOS:windows] env PATH=$WORK\'program files';%PATH% + +! exists $WORK/log.txt +? go build -x +exists $WORK/log.txt +rm $WORK/log.txt + +# TODO(#41400, #43078): when CC is set explicitly, it should be allowed to +# contain spaces separating arguments, and it should be possible to quote +# arguments with spaces (including the path), as in CGO_CFLAGS and other +# variables. For now, this doesn't work. +[!GOOS:windows] env CC=$WORK/'program files'/gcc +[GOOS:windows] env CC=$WORK\'program files'\gcc.bat +! go build -x +! exists $WORK/log.txt + +-- go.mod -- +module m + +-- m.go -- +package m + +// #define X 1 +import "C" + +-- $WORK/program files/gcc -- +#!/bin/sh + +echo ok >$WORK/log.txt +-- $WORK/program files/clang -- +#!/bin/sh + +echo ok >$WORK/log.txt +-- $WORK/program files/gcc.bat -- +echo ok >%WORK%\log.txt +-- $WORK/program files/clang.bat -- +echo ok >%WORK%\log.txt diff --git a/go/src/cmd/go/testdata/script/cgo_path_space_quote.txt b/go/src/cmd/go/testdata/script/cgo_path_space_quote.txt new file mode 100644 index 0000000000000000000000000000000000000000..955610130088d512759b29d86d0dba92a0875ef2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_path_space_quote.txt @@ -0,0 +1,58 @@ +# This test checks that the CC environment variable may contain quotes and +# spaces. Arguments are normally split on spaces, tabs, newlines. If an +# argument contains these characters, the entire argument may be quoted +# with single or double quotes. This is the same as -gcflags and similar +# options. + +[short] skip +[!exec:clang] [!exec:gcc] skip +[!cgo] skip + +env GOENV=$WORK/go.env +mkdir 'program files' +go build -o 'program files' './which cc/which cc.go' +[exec:clang] env CC='"'$PWD${/}program' 'files${/}which' 'cc"' 'clang +[!exec:clang] env CC='"'$PWD${/}program' 'files${/}which' 'cc"' 'gcc +go env CC +stdout 'program files[/\\]which cc" (clang|gcc)$' +go env -w CC=$CC +env CC= +go env CC +stdout 'program files[/\\]which cc" (clang|gcc)$' + +go run . +stdout 1 + +-- go.mod -- +module test + +go 1.17 +-- which cc/which cc.go -- +package main + +import ( + "fmt" + "os" + "os/exec" +) + +func main() { + args := append([]string{"-DWRAPPER_WAS_USED=1"}, os.Args[2:]...) + cmd := exec.Command(os.Args[1], args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} +-- hello.go -- +package main + +// int x = WRAPPER_WAS_USED; +import "C" +import "fmt" + +func main() { + fmt.Println(C.x) +} diff --git a/go/src/cmd/go/testdata/script/cgo_stale.txt b/go/src/cmd/go/testdata/script/cgo_stale.txt new file mode 100644 index 0000000000000000000000000000000000000000..0d30aeaa9d41df08764303e99cc56b9c1e4df231 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_stale.txt @@ -0,0 +1,39 @@ +# golang.org/issue/46347: a stale runtime/cgo should only force a single rebuild + +[!cgo] skip +[short] skip + + +# If we set a unique CGO_CFLAGS, the installed copy of runtime/cgo +# should be reported as stale. + +env CGO_CFLAGS=-DTestScript_cgo_stale=true +stale runtime/cgo + + +# If we then build a package that uses cgo, runtime/cgo should be rebuilt and +# cached with the new flag, but not installed to GOROOT. +# It has no install target, and thus is never stale. + +env GOCACHE=$WORK/cache # Use a fresh cache to avoid interference between runs. + +go build -x . +stderr '[/\\]cgo'$GOEXE'["]? .* -importpath runtime/cgo' +! stale runtime/cgo + + +# After runtime/cgo has been rebuilt and cached, it should not be rebuilt again. + +go build -x . +! stderr '[/\\]cgo'$GOEXE'["]? .* -importpath runtime/cgo' +! stale runtime/cgo + + +-- go.mod -- +module example.com/m + +go 1.17 +-- m.go -- +package m + +import "C" diff --git a/go/src/cmd/go/testdata/script/cgo_stale_precompiled.txt b/go/src/cmd/go/testdata/script/cgo_stale_precompiled.txt new file mode 100644 index 0000000000000000000000000000000000000000..7f0b515f2e55142988ccb707ab89222e9a88afd3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_stale_precompiled.txt @@ -0,0 +1,32 @@ +# Regression test for https://go.dev/issue/47215 and https://go.dev/issue/50183: +# A missing $CC caused the C dependencies of the net +# package to appear stale, and it could not be rebuilt due to a missing $CC. + +[!cgo] skip + +# This test may start with the runtime/cgo package already stale. +# Explicitly rebuild it to ensure that it is cached. +# (See https://go.dev/issue/50892.) +# +# If running in non-short mode, explicitly vary CGO_CFLAGS +# as a control case (to ensure that our regexps do catch rebuilds). + +[!short] env GOCACHE=$WORK/cache +[!short] env CGO_CFLAGS=-DTestScript_cgo_stale_precompiled=true +go build -x runtime/cgo +[!short] stderr '[/\\]cgo'$GOEXE'["]? .* -importpath runtime/cgo' + +# https://go.dev/issue/47215: a missing $(go env CC) caused the precompiled net +# to be stale. But as of https://go.dev/cl/452457 the precompiled libraries are +# no longer installed anyway! Since we're requiring a C compiler in order to +# build and use cgo libraries in the standard library, we should make sure it +# matches what's in the cache. + +[abscc] stop + +env CGO_ENABLED=1 +env CC='' +[!GOOS:plan9] env PATH='' # Guaranteed not to include $(go env CC)! +[GOOS:plan9] env path='' +! go build -x runtime/cgo +stderr 'C compiler .* not found' diff --git a/go/src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt b/go/src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt new file mode 100644 index 0000000000000000000000000000000000000000..b4b2d14b11df337f18623cb977562e6dccef9ae0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt @@ -0,0 +1,209 @@ +# Test case to verify that when we have a package that uses CGO in +# combination with selected "unusual" flags (involving plugins, LTO) +# that we force external linking. See related +# issues 58619, 58620, and 58848. + +[compiler:gccgo] skip # only external linking for gccgo + +[!cgo] skip 'test verifies behavior that depends on CGO_CFLAGS' +[mustlinkext] skip 'test expects internal linking for non-cgo programs' + +# Here we build three program: one with explicit CGO use, one with no +# CGO use, and one that uses a stdlib package ("runtime/cgo") that has +# CGO in it. It used to be that only the explicit use of CGO would +# trigger external linking, and that the program that only used +# "runtime/cgo" would always be handled with internal linking. This caused +# issues when users included odd/unusual flags (ex: -fplugin, -flto) +# in CGO_CFLAGS, causing the Go linker to have to read and interpret +# non-standard host objects. +# +# As of 1.21 we continue to use internal linking for programs whose +# CGO use comes only from stdlib packages in the absence of any flag +# funny business, however if the Go command sees flags that may be suspicious, +# it signals the Go linker to invoke the external linker. + +# The next few tests run builds passing "-n" to the Go command, then +# checking the output to see if the Go command is trying to pass a +# "preferlinkext" token to the linker to request external linking. + +#----------------------- + +# Use a fresh GOCACHE for these next steps, so as to have the real +# actions for the runtime/cgo package appear in the "-n -x" output. +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +# First build: there is no CGO in use, so no token should be present regardless +# of weird CGO flags. +go build -x -n -o dummy.exe ./noUseOfCgo +! stderr preferlinkext +env CGO_CFLAGS=-flto +go build -x -n -o dummy.exe ./noUseOfCgo +! stderr preferlinkext +env CGO_CFLAGS= + +# Second build uses CGO, so we expect to see the token present in the +# -n output only when strange flags are used. +go build -x -n -o dummy.exe ./usesInternalCgo +! stderr preferlinkext +env CGO_CFLAGS=-flto +go build -x -n -o dummy.exe ./usesInternalCgo +stderr preferlinkext +env CGO_CFLAGS=-fplugin +go build -x -n -o dummy.exe ./usesInternalCgo +stderr preferlinkext +env CGO_CFLAGS=-fprofile-instr-generate +go build -x -n -o dummy.exe ./usesInternalCgo +stderr preferlinkext + +# Trimming file information for the UndefinedBehaviorSanitizer is permitted for internal linking. +env CGO_CFLAGS=-fsanitize-undefined-strip-path-components=-1 +go build -x -n -o dummy.exe ./usesInternalCgo +! stderr preferlinkext +env CGO_CFLAGS=-fsanitize-undefined-strip-path-components=2 +go build -x -n -o dummy.exe ./usesInternalCgo +! stderr preferlinkext + +# The -fdebug-prefix-map=path is permitted for internal linking. +env CGO_CFLAGS=-fdebug-prefix-map=/some/sandbox/execroot/workspace=/tmp/new +go build -x -n -o dummy.exe ./usesInternalCgo +! stderr preferlinkext +env CGO_CFLAGS=-fdebug-prefix-map=/Users/someone/.cache/bazel/_bazel_someone/3fa7e4650c43657ead684537951f49e2/sandbox/linux-sandbox/10/execroot/rules_go_static=. +go build -x -n -o dummy.exe ./usesInternalCgo +! stderr preferlinkext +# The -ffile-prefix-map=path is permitted for internal linking too. +env CGO_CFLAGS=-ffile-prefix-map=/Users/someone/.cache/bazel/_bazel_someone/3fa7e4650c43657ead684537951f49e2/sandbox/linux-sandbox/10/execroot/rules_go_static/bazel-out/aarch64-fastbuild-ST-b33d65c724e6/bin/external/io_bazel_rules_go/stdlib_=. +go build -x -n -o dummy.exe ./usesInternalCgo +! stderr preferlinkext +# Verifying that -fdebug-prefix-map=path, -ffile-prefix-map, -no-canonical-prefixes +# and -fno-canonical-systemd-headers are permitted for internal linking. +env CGO_CFLAGS=-fdebug-prefix-map=old=/tmp/new +go build -x -n -o dummy.exe ./usesInternalCgo +! stderr preferlinkext +env CGO_CFLAGS=-ffile-prefix-map=/Users/someone/_11233/things=new +go build -x -n -o dummy.exe ./usesInternalCgo +! stderr preferlinkext +env CGO_CFLAGS=-no-canonical-prefixes +go build -x -n -o dummy.exe ./usesInternalCgo +! stderr preferlinkext +env CGO_CFLAGS=-fno-canonical-system-headers +go build -x -n -o dummy.exe ./usesInternalCgo +! stderr preferlinkext +env CGO_CFLAGS= + +[short] skip + +# In the remaining tests below we do actual builds (without -n) to +# verify that the Go linker is going the right thing in addition to the +# Go command. Here the idea is to pass "-tmpdir" to the linker, then +# check after the link is done for the presence of the file +# /go.o, which the Go linker creates prior to kicking off the +# external linker. + +mkdir tmp1 +mkdir tmp2 +mkdir tmp3 +mkdir tmp4 +mkdir tmp5 + +# First build: no external linking expected +go build -ldflags=-tmpdir=tmp1 -o $devnull ./noUseOfCgo & + +# Second build: using only "runtime/cgo", expect internal linking. +go build -ldflags=-tmpdir=tmp2 -o $devnull ./usesInternalCgo & + +# Third build: program uses only "runtime/cgo", so we would normally +# expect internal linking, except that cflags contain suspicious entries +# (in this case, a flag that does not appear on the allow list). +env CGO_CFLAGS=-fmerge-all-constants +env CGO_LDFLAGS=-fmerge-all-constants +go build -ldflags=-tmpdir=tmp3 -o $devnull ./usesInternalCgo & +env CGO_CFLAGS= +env CGO_LDFLAGS= + +# Fourth build: explicit CGO, expect external linking. +go build -ldflags=-tmpdir=tmp4 -o $devnull ./usesExplicitCgo & + +# Fifth build: explicit CGO, but we specifically asked for internal linking +# via a flag, so using internal linking it is. +[cgolinkext] go list ./usesInternalCgo +[!cgolinkext] go build '-ldflags=-tmpdir=tmp5 -linkmode=internal' -o $devnull ./usesInternalCgo & + +# Sixth build: explicit CGO use in a non-main package. +go build -o p.a ./nonMainPackageUsesExplicitCgo & + +wait + +# Check first build: no external linking expected +! exists tmp1/go.o + +# Check second build: using only "runtime/cgo", expect internal linking. +[!cgolinkext] ! exists tmp2/go.o +[cgolinkext] exists tmp2/go.o + +# Check third build: has suspicious flag. +exists tmp3/go.o + +# Fourth build: explicit CGO, expect external linking. +exists tmp4/go.o + +# Fifth build: explicit CGO, -linkmode=internal. +! exists tmp5/go.o + +# Sixth build: make sure that "go tool nm" doesn't get confused +# by the presence of the "preferlinkext" sentinel. +go tool nm p.a + +-- go.mod -- + +module cgo.example + +go 1.20 + +-- noUseOfCgo/main.go -- + +package main + +func main() { + println("clean as a whistle") +} + +-- usesInternalCgo/main.go -- + +package main + +import ( + "runtime/cgo" +) + +func main() { + q := "hello" + h := cgo.NewHandle(q) + h.Delete() +} + +-- usesExplicitCgo/main.go -- + +package main + +/* +int meaningOfLife() { return 42; } +*/ +import "C" + +func main() { + println(C.meaningOfLife()) +} + +-- nonMainPackageUsesExplicitCgo/main.go -- + +package p + +/* +int meaningOfLife() { return 42; } +*/ +import "C" + +func PrintIt() { + println(C.meaningOfLife()) +} diff --git a/go/src/cmd/go/testdata/script/cgo_syso_issue29253.txt b/go/src/cmd/go/testdata/script/cgo_syso_issue29253.txt new file mode 100644 index 0000000000000000000000000000000000000000..18526c6d311e374f6fd5344b9aa01ce07eed02b3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_syso_issue29253.txt @@ -0,0 +1,31 @@ +env GO111MODULE=off +[short] skip + +# This test tests that we can link in-package syso files that provides symbols +# for cgo. See issue 29253. +[!cgo] stop +[!compiler:gc] stop +cc -c -o pkg/o.syso ext.c +go build main.go + +-- ext.c -- +// +build ignore + +int f() { return 42; } +-- pkg/pkg.go -- +package pkg + +// extern int f(void); +import "C" + +func init() { + if v := C.f(); v != 42 { + panic(v) + } +} +-- main.go -- +package main + +import _ "pkg" + +func main() {} diff --git a/go/src/cmd/go/testdata/script/cgo_trimpath_macro.txt b/go/src/cmd/go/testdata/script/cgo_trimpath_macro.txt new file mode 100644 index 0000000000000000000000000000000000000000..b5cc1167cbe5ba1d76b262e09185d7ef10996eb0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_trimpath_macro.txt @@ -0,0 +1,71 @@ +# This is a test that -trimpath trims the paths of every directory +# of Cgo dependencies in the module, and trims file paths included +# through the __FILE__ macro using --file-prefix-map. + +[!cgo] skip +[short] skip 'links and runs binaries' + +# Test in main module. +go run -trimpath -mod=vendor ./main +stdout '(\\_\\_|/_)[\\/]m[\\/]c[\\/]bar.h' + +# Test in vendored module. +go run -trimpath -mod=vendor v.com/main +stdout '(\\_\\_|/_)[\\/]vendor[\\/]v.com[\\/]c[\\/]bar.h' + +# Test in GOPATH mode. +env GO111MODULE=off +go run -trimpath ./main +stdout '(\\_\\_|/_)[\\/]GOPATH[\\/]src[\\/]c[\\/]bar.h' + +-- go.mod -- +module m + +require v.com v1.0.0 +-- go.sum -- +v.com v1.0.0 h1:xxx +v.com v1.0.0/go.mod h1:xxx +-- vendor/modules.txt -- +# v.com v1.0.0 +## explicit; go 1.20 +v.com/main +-- vendor/v.com/main/main.go -- +package main + +// #cgo CFLAGS: -I../c +// #include "stdio.h" +// void printfile(); +import "C" + +func main() { + C.printfile() + C.fflush(C.stdout) +} +-- vendor/v.com/main/foo.c -- +#include "bar.h" +-- vendor/v.com/c/bar.h -- +#include "stdio.h" + +void printfile() { + printf("%s\n", __FILE__); +} +-- main/main.go -- +package main + +// #cgo CFLAGS: -I../c +// #include "stdio.h" +// void printfile(); +import "C" + +func main() { + C.printfile() + C.fflush(C.stdout) +} +-- main/foo.c -- +#include "bar.h" +-- c/bar.h -- +#include "stdio.h" + +void printfile() { + printf("%s\n", __FILE__); +} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/cgo_undef.txt b/go/src/cmd/go/testdata/script/cgo_undef.txt new file mode 100644 index 0000000000000000000000000000000000000000..8e84f1d6b5bf80915d766acae114d6e7727e8f09 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cgo_undef.txt @@ -0,0 +1,89 @@ +# Issue 52863. + +# We manually create a .syso and a .a file in package a, +# such that the .syso file only works when linked against the .a file. +# Package a has #cgo LDFLAGS to make this happen. +# +# Package c imports package a, and uses cgo itself. +# The generation of the _cgo_import.go for package c will fail, +# because it won't know that it has to link against a/libb.a +# (because we don't gather the #cgo LDFLAGS from all transitively +# imported packages). +# +# The _cgo_import.go file is only needed for internal linking. +# When generating _cgo_import.go for package c fails, an ordinary +# external link should still work. But an internal link is expected +# to fail, because the failure to create _cgo_import.go should cause +# the linker to report an inability to internally link. + +[short] skip +[!cgo] skip +[!exec:ar] skip + +cc -c -o a/b.syso b/b.c +cc -c -o b/lib.o b/lib.c +exec ar rc a/libb.a b/lib.o + +go build +! stderr 'undefined reference' + +! go build -ldflags=-linkmode=internal +stderr 'some packages could not be built to support internal linking.*m/c|requires external linking|does not support internal cgo' + +# Test for issue #68743. +go build -x m/d +! stderr 'undefined reference' +stderr 'test for internal linking' + +-- go.mod -- +module m + +-- a/a.go -- +package a + +// #cgo LDFLAGS: -L. -lb +// extern int CFn(int); +import "C" + +func GoFn(v int) int { return int(C.CFn(C.int(v))) } + +-- b/b.c -- +extern int LibFn(int); +int CFn(int i) { return LibFn(i); } + +-- b/lib.c -- +int LibFn(int i) { return i; } + +-- c/c.go -- +package c + +// static int D(int i) { return i; } +import "C" + +import "m/a" + +func Fn(i int) (int, int) { + return a.GoFn(i), int(C.D(C.int(i))) +} + +-- d/d.go -- +// Package d is a copy of package c, to build with -x. +package d + +// static int D(int i) { return i; } +import "C" + +import "m/a" + +func Fn(i int) (int, int) { + return a.GoFn(i), int(C.D(C.int(i))) +} + +-- main.go -- +package main + +import "m/c" + +func main() { + println(c.Fn(0)) +} diff --git a/go/src/cmd/go/testdata/script/chdir.txt b/go/src/cmd/go/testdata/script/chdir.txt new file mode 100644 index 0000000000000000000000000000000000000000..41def410d5fa37dfee368356f716e4d480878566 --- /dev/null +++ b/go/src/cmd/go/testdata/script/chdir.txt @@ -0,0 +1,39 @@ +env OLD=$PWD + +# basic -C functionality +cd $GOROOT/src/math +go list -C ../strings +stdout strings +! go list -C ../nonexist +stderr 'chdir.*nonexist' + +# check for -C in subcommands with custom flag parsing +# cmd/go/chdir_test.go handles the normal ones more directly. + +# go doc +go doc -C ../strings HasPrefix + +# go env +go env -C $OLD/custom GOMOD +stdout 'custom[\\/]go.mod' +! go env -C ../nonexist +stderr '^go: chdir ../nonexist: ' + +# go test +go test -C ../strings -n +stderr 'strings\.test' + +# go vet +go vet -C ../strings -n +stderr strings_test + +# go fix +go fix -C ../strings -n +stderr strings_test + +# -C must be first on command line (as of Go 1.21) +! go test -n -C ../strings +stderr '^invalid value "../strings" for flag -C: -C flag must be first flag on command line$' + +-- custom/go.mod -- +module m diff --git a/go/src/cmd/go/testdata/script/check_goexperiment.txt b/go/src/cmd/go/testdata/script/check_goexperiment.txt new file mode 100644 index 0000000000000000000000000000000000000000..3434cb9d6dbe4f7c1d9ddaeaf37ebf7d9dbe1450 --- /dev/null +++ b/go/src/cmd/go/testdata/script/check_goexperiment.txt @@ -0,0 +1,10 @@ +# Test that [GOEXPERIMENT:x] is accepted. +# Here fieldtrack is picked arbitrarily. + +[GOEXPERIMENT:nofieldtrack] env + +[GOEXPERIMENT:fieldtrack] env + +#[GOEXPERIMENT:crashme] env + + diff --git a/go/src/cmd/go/testdata/script/clean_binary.txt b/go/src/cmd/go/testdata/script/clean_binary.txt new file mode 100644 index 0000000000000000000000000000000000000000..7335f8a4c78aa9fe6960a1fe99615cceb875f109 --- /dev/null +++ b/go/src/cmd/go/testdata/script/clean_binary.txt @@ -0,0 +1,78 @@ +# Build something to create the executable, including several cases +[short] skip + +# --------------------- clean executables ------------------------- + +# case1: test file-named executable 'main' +env GO111MODULE=on + +! exists main$GOEXE +go build main.go +exists -exec main$GOEXE +go clean +! exists main$GOEXE + +# case2: test module-named executable 'a.b.c' +! exists a.b.c$GOEXE +go build +exists -exec a.b.c$GOEXE +go clean +! exists a.b.c$GOEXE + +# case3: directory-named executable 'src' +env GO111MODULE=off + +! exists src$GOEXE +go build +exists -exec src$GOEXE +go clean +! exists src$GOEXE + +# --------------------- clean test files ------------------------- + +# case1: test file-named test file +env GO111MODULE=on + +! exists main.test$GOEXE +go test -c main_test.go +exists -exec main.test$GOEXE +go clean +! exists main.test$GOEXE + +# case2: test module-named test file +! exists a.b.c.test$GOEXE +go test -c +exists -exec a.b.c.test$GOEXE +go clean +! exists a.b.c.test$GOEXE + +# case3: test directory-based test file +env GO111MODULE=off + +! exists src.test$GOEXE +go test -c +exists -exec src.test$GOEXE +go clean +! exists src.test$GOEXE + +-- main.go -- +package main + +import "fmt" + +func main() { + fmt.Println("hello!") +} + +-- main_test.go -- +package main + +import "testing" + +func TestSomething(t *testing.T) { +} + +-- go.mod -- +module example.com/a.b.c/v2 + +go 1.12 \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/clean_cache_n.txt b/go/src/cmd/go/testdata/script/clean_cache_n.txt new file mode 100644 index 0000000000000000000000000000000000000000..8ac9befa5b8036cd46bc9aecfa9b618c61322b8f --- /dev/null +++ b/go/src/cmd/go/testdata/script/clean_cache_n.txt @@ -0,0 +1,35 @@ +[short] skip 'runs go build' + +# We're testing cache behavior, so start with a clean GOCACHE. +env GOCACHE=$WORK/cache + +# Build something so that the cache gets populates +go build main.go + +# Check that cache contains directories before running +exists $GOCACHE/00 + +# Run go clean -cache -n and ensure that directories weren't deleted +go clean -cache -n +exists $GOCACHE/00 + +# Re-run go clean cache without the -n flag go ensure that directories were properly removed +go clean -cache +! exists $GOCACHE/00 + +! go clean -cache . +stderr 'go: clean -cache cannot be used with package arguments' + +# GOCACHE must be an absolute path. +env GOCACHE=. +! go clean -cache +stderr 'go: GOCACHE is not an absolute path' + +-- main.go -- +package main + +import "fmt" + +func main() { + fmt.Println("hello!") +} diff --git a/go/src/cmd/go/testdata/script/clean_testcache.txt b/go/src/cmd/go/testdata/script/clean_testcache.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f98602c4ea6a6abf67dfdeeb39cc7e9a56fe349 --- /dev/null +++ b/go/src/cmd/go/testdata/script/clean_testcache.txt @@ -0,0 +1,28 @@ +env GO111MODULE=off +[short] skip + +# go clean -testcache +# should work (see golang.org/issue/29757). +cd x +go test x_test.go +go clean -testcache +go test x_test.go +! stdout 'cached' +! go clean -testcache ../x +stderr 'go: clean -testcache cannot be used with package arguments' + +# golang.org/issue/29100: 'go clean -testcache' should succeed +# if the cache directory doesn't exist at all. +# It should not write a testexpire.txt file, since there are no +# test results that need to be invalidated in the first place. +env GOCACHE=$WORK/nonexistent +go clean -testcache +! exists $WORK/nonexistent + +-- x/x_test.go -- +package x_test +import ( + "testing" +) +func TestMain(t *testing.T) { +} diff --git a/go/src/cmd/go/testdata/script/cmd_import_error.txt b/go/src/cmd/go/testdata/script/cmd_import_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..89e1dbbffdeeb7b36756cafa560369c05b6ea6c5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cmd_import_error.txt @@ -0,0 +1,16 @@ +env GO111MODULE=on + +# Regression test for golang.org/issue/31031: +# Importing or loading a non-existent package in cmd/ should print +# a clear error in module mode. + +! go list cmd/unknown +stderr '^package cmd/unknown is not in std \('$GOROOT'[/\\]src[/\\]cmd[/\\]unknown\)$' + +go list -f '{{range .DepsErrors}}{{.Err}}{{end}}' x.go +stdout '^package cmd/unknown is not in std \('$GOROOT'[/\\]src[/\\]cmd[/\\]unknown\)$' + +-- x.go -- +package x + +import _ "cmd/unknown" diff --git a/go/src/cmd/go/testdata/script/cover_asm.txt b/go/src/cmd/go/testdata/script/cover_asm.txt new file mode 100644 index 0000000000000000000000000000000000000000..c7b7114b3071240ddfad3edb13b39559116e2410 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_asm.txt @@ -0,0 +1,33 @@ +[short] skip +[compiler:gccgo] skip # gccgo has no cover tool + +# Test cover for a package that has an assembly function. + +go test -outputdir=$WORK -coverprofile=cover.out coverasm +go tool cover -func=$WORK/cover.out +stdout '\tg\t*100.0%' # Check g is 100% covered. +! stdout '\tf\t*[0-9]' # Check for no coverage on the assembly function + +-- go.mod -- +module coverasm + +go 1.16 +-- p.go -- +package p + +func f() + +func g() { + println("g") +} +-- p.s -- +// empty asm file, +// so go test doesn't complain about declaration of f in p.go. +-- p_test.go -- +package p + +import "testing" + +func Test(t *testing.T) { + g() +} diff --git a/go/src/cmd/go/testdata/script/cover_atomic_pkgall.txt b/go/src/cmd/go/testdata/script/cover_atomic_pkgall.txt new file mode 100644 index 0000000000000000000000000000000000000000..c3bc67df534687b7823a4244e8b9a612e976d70e --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_atomic_pkgall.txt @@ -0,0 +1,25 @@ +env GO111MODULE=off + +[short] skip + +go test -coverpkg=all -covermode=atomic x +stdout ok[\s\S]+?coverage + +[!race] stop + +go test -coverpkg=all -race x +stdout ok[\s\S]+?coverage + +-- x/x.go -- +package x + +import _ "sync/atomic" + +func F() {} + +-- x/x_test.go -- +package x + +import "testing" + +func TestF(t *testing.T) { F() } diff --git a/go/src/cmd/go/testdata/script/cover_blank_func_decl.txt b/go/src/cmd/go/testdata/script/cover_blank_func_decl.txt new file mode 100644 index 0000000000000000000000000000000000000000..e7d5250468cd01e8444338f7add92ea39825f100 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_blank_func_decl.txt @@ -0,0 +1,35 @@ +[short] skip +go test -cover coverblank +stdout 'coverage: 100.0% of statements' + + +-- go.mod -- +module coverblank + +go 1.16 +-- a.go -- +package coverblank + +func _() { + println("unreachable") +} + +type X int + +func (x X) Print() { + println(x) +} + +func (x X) _() { + println("unreachable") +} + +-- a_test.go -- +package coverblank + +import "testing" + +func TestX(t *testing.T) { + var x X + x.Print() +} diff --git a/go/src/cmd/go/testdata/script/cover_build_cmdline_pkgs.txt b/go/src/cmd/go/testdata/script/cover_build_cmdline_pkgs.txt new file mode 100644 index 0000000000000000000000000000000000000000..ba382639e9cdf2e82d5f500afa541e2b456fc1bf --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_build_cmdline_pkgs.txt @@ -0,0 +1,72 @@ + +# This test is intended to verify that when a user does "go run -cover ..." +# or "go build -cover ...", packages named on the command line are +# always instrumented (but not their dependencies). This rule applies +# inside and outside the standard library. + +[short] skip + +# Compile an object. +go tool compile -p tiny tiny/tiny.go tiny/tiny2.go + +# Build a stdlib command with coverage. +go build -o $WORK/nm.exe -cover cmd/nm + +# Save off old GOCOVERDIR setting +env SAVEGOCOVERDIR=$GOCOVERDIR + +# Collect a coverage profile from running 'cmd/nm' on the object. +mkdir $WORK/covdata +env GOCOVERDIR=$WORK/covdata +exec $WORK/nm.exe tiny.o + +# Restore previous GOCOVERDIR setting +env GOCOVERDIR=$SAVEGOCOVERDIR + +# Check to make sure we instrumented just the main package, not +# any dependencies. +go tool covdata pkglist -i=$WORK/covdata +stdout cmd/nm +! stdout cmd/internal/goobj pkglist.txt + +# ... now collect a coverage profile from a Go file +# listed on the command line. +go build -cover -o $WORK/another.exe testdata/another.go +mkdir $WORK/covdata2 +env GOCOVERDIR=$WORK/covdata2 +exec $WORK/another.exe + +# Restore previous GOCOVERDIR setting +env GOCOVERDIR=$SAVEGOCOVERDIR + +# Check to make sure we instrumented just the main package. +go tool covdata pkglist -i=$WORK/covdata2 +stdout command-line-arguments +! stdout fmt + +-- go.mod -- + +module example.prog + +-- testdata/another.go -- + +package main + +import "fmt" + +func main() { + fmt.Println("Hi dad") +} + +-- tiny/tiny.go -- + +package tiny + +var Tvar int + +-- tiny/tiny2.go -- + +package tiny + +var Tvar2 bool + diff --git a/go/src/cmd/go/testdata/script/cover_build_pkg_select.txt b/go/src/cmd/go/testdata/script/cover_build_pkg_select.txt new file mode 100644 index 0000000000000000000000000000000000000000..3a59e72e88317afd8fcdecd0736a7dbaf0f0ca56 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_build_pkg_select.txt @@ -0,0 +1,111 @@ +# This test checks more of the "go build -cover" functionality, +# specifically which packages get selected when building. + +[short] skip + +#------------------------------------------- + +# Build for coverage. +go build -mod=mod -o $WORK/modex.exe -cover mod.example/main + +# Save off old GOCOVERDIR setting +env SAVEGOCOVERDIR=$GOCOVERDIR + +# Execute. +mkdir $WORK/covdata +env GOCOVERDIR=$WORK/covdata +exec $WORK/modex.exe + +# Restore previous GOCOVERDIR setting +env GOCOVERDIR=$SAVEGOCOVERDIR + +# Examine the result. +go tool covdata percent -i=$WORK/covdata +stdout 'coverage: 100.0% of statements' + +# By default we want to see packages resident in the module covered, +# but not dependencies. +go tool covdata textfmt -i=$WORK/covdata -o=$WORK/covdata/out.txt +grep 'mode: set' $WORK/covdata/out.txt +grep 'mod.example/main/main.go:' $WORK/covdata/out.txt +grep 'mod.example/sub/sub.go:' $WORK/covdata/out.txt +! grep 'rsc.io' $WORK/covdata/out.txt + +rm $WORK/covdata +rm $WORK/modex.exe + +#------------------------------------------- + +# Repeat the build but with -coverpkg=all + +go build -mod=mod -coverpkg=all -o $WORK/modex.exe -cover mod.example/main + +# Execute. +mkdir $WORK/covdata +env GOCOVERDIR=$WORK/covdata +exec $WORK/modex.exe + +# Restore previous GOCOVERDIR setting +env GOCOVERDIR=$SAVEGOCOVERDIR + +# Examine the result. +go tool covdata percent -i=$WORK/covdata +stdout 'coverage:.*[1-9][0-9.]+%' + +# The whole enchilada. +go tool covdata textfmt -i=$WORK/covdata -o=$WORK/covdata/out.txt +grep 'mode: set' $WORK/covdata/out.txt +grep 'mod.example/main/main.go:' $WORK/covdata/out.txt +grep 'mod.example/sub/sub.go:' $WORK/covdata/out.txt +grep 'rsc.io' $WORK/covdata/out.txt +grep 'bufio/bufio.go:' $WORK/covdata/out.txt + +# Use the covdata tool to select a specific set of module paths +mkdir $WORK/covdata2 +go tool covdata merge -pkg=rsc.io/quote -i=$WORK/covdata -o=$WORK/covdata2 + +# Examine the result. +go tool covdata percent -i=$WORK/covdata2 +stdout 'coverage:.*[1-9][0-9.]+%' + +# Check for expected packages + check that we don't see things from stdlib. +go tool covdata textfmt -i=$WORK/covdata2 -o=$WORK/covdata2/out.txt +grep 'mode: set' $WORK/covdata2/out.txt +! grep 'mod.example/main/main.go:' $WORK/covdata2/out.txt +! grep 'mod.example/sub/sub.go:' $WORK/covdata2/out.txt +grep 'rsc.io' $WORK/covdata2/out.txt +! grep 'bufio/bufio.go:' $WORK/covdata2/out.txt + +#------------------------------------------- +# end of test cmds, start of harness and related files. + +-- go.mod -- +module mod.example + +go 1.20 + +require rsc.io/quote/v3 v3.0.0 + +-- main/main.go -- +package main + +import ( + "fmt" + "mod.example/sub" + + "rsc.io/quote" +) + +func main() { + fmt.Println(quote.Go(), sub.F()) +} + +-- sub/sub.go -- + +package sub + +func F() int { + return 42 +} + + diff --git a/go/src/cmd/go/testdata/script/cover_build_simple.txt b/go/src/cmd/go/testdata/script/cover_build_simple.txt new file mode 100644 index 0000000000000000000000000000000000000000..ee451a68ab18bf2bcfbaef5123b55bd200a5c429 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_build_simple.txt @@ -0,0 +1,146 @@ +# This test checks basic "go build -cover" functionality. + +[short] skip + +# Build for coverage. +go build -gcflags=-m -o example.exe -cover example/main & +[race] go build -o examplewithrace.exe -race -cover example/main & +wait + +# First execute without GOCOVERDIR set... +env GOCOVERDIR= +exec ./example.exe normal +stderr '^warning: GOCOVERDIR not set, no coverage data emitted' + +# ... then with GOCOVERDIR set. +env GOCOVERDIR=data/normal +exec ./example.exe normal +! stderr '^warning: GOCOVERDIR not set, no coverage data emitted' +go tool covdata percent -i=data/normal +stdout 'coverage:.*[1-9][0-9.]+%' + +# Program makes a direct call to os.Exit(0). +env GOCOVERDIR=data/goodexit +exec ./example.exe goodexit +! stderr '^warning: GOCOVERDIR not set, no coverage data emitted' +go tool covdata percent -i=data/goodexit +stdout 'coverage:.*[1-9][0-9.]+%' + +# Program makes a direct call to os.Exit(1). +env GOCOVERDIR=data/badexit +! exec ./example.exe badexit +! stderr '^warning: GOCOVERDIR not set, no coverage data emitted' +go tool covdata percent -i=data/badexit +stdout 'coverage:.*[1-9][0-9.]+%' + +# Program invokes panic. +env GOCOVERDIR=data/panic +! exec ./example.exe panic +! stderr '^warning: GOCOVERDIR not set, no coverage data emitted' +go tool covdata percent -i=data/panic +stdout 'coverage:.*[0-9.]+%' + +# Skip remainder if no race detector support. +[!race] skip + +env GOCOVERDIR=data2/normal +exec ./examplewithrace.exe normal +! stderr '^warning: GOCOVERDIR not set, no coverage data emitted' +go tool covdata percent -i=data2/normal +stdout 'coverage:.*[1-9][0-9.]+%' + +# Program makes a direct call to os.Exit(0). +env GOCOVERDIR=data2/goodexit +exec ./examplewithrace.exe goodexit +! stderr '^warning: GOCOVERDIR not set, no coverage data emitted' +go tool covdata percent -i=data2/goodexit +stdout 'coverage:.*[1-9][0-9.]+%' + +# Program makes a direct call to os.Exit(1). +env GOCOVERDIR=data2/badexit +! exec ./examplewithrace.exe badexit +! stderr '^warning: GOCOVERDIR not set, no coverage data emitted' +go tool covdata percent -i=data2/badexit +stdout 'coverage:.*[1-9][0-9.]+%' + +# Program invokes panic. +env GOCOVERDIR=data2/panic +! exec ./examplewithrace.exe panic +! stderr '^warning: GOCOVERDIR not set, no coverage data emitted' +go tool covdata percent -i=data2/panic +stdout 'coverage:.*[0-9.]+%' + +# end of test cmds, start of harness and related files. + +-- go.mod -- +module example + +go 1.18 + +-- main/example.go -- +package main + +import "example/sub" + +func main() { + sub.S() +} + +-- sub/sub.go -- + +package sub + +import "os" + +func S() { + switch os.Args[1] { + case "normal": + println("hi") + case "goodexit": + os.Exit(0) + case "badexit": + os.Exit(1) + case "panic": + panic("something bad happened") + } +} + +-- data/README.txt -- + +Just a location where we can write coverage profiles. + +-- data/normal/f.txt -- + +X + +-- data/goodexit/f.txt -- + +X + +-- data/badexit/f.txt -- + +X + +-- data/panic/f.txt -- + +X + +-- data2/README.txt -- + +Just a location where we can write coverage profiles. + +-- data2/normal/f.txt -- + +X + +-- data2/goodexit/f.txt -- + +X + +-- data2/badexit/f.txt -- + +X + +-- data2/panic/f.txt -- + +X diff --git a/go/src/cmd/go/testdata/script/cover_cgo.txt b/go/src/cmd/go/testdata/script/cover_cgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..85754b51825cd0dd79766e1b7e82e9dde7dd2266 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_cgo.txt @@ -0,0 +1,42 @@ +[short] skip +[!cgo] skip +[compiler:gccgo] skip # gccgo has no cover tool + +# Test coverage on cgo code. + +go test -short -cover cgocover +stdout 'coverage:.*[1-9][0-9.]+%' +! stderr '[^0-9]0\.0%' + +-- go.mod -- +module cgocover + +go 1.16 +-- p.go -- +package p + +/* +void +f(void) +{ +} +*/ +import "C" + +var b bool + +func F() { + if b { + for { + } + } + C.f() +} +-- p_test.go -- +package p + +import "testing" + +func TestF(t *testing.T) { + F() +} diff --git a/go/src/cmd/go/testdata/script/cover_cgo_extra_file.txt b/go/src/cmd/go/testdata/script/cover_cgo_extra_file.txt new file mode 100644 index 0000000000000000000000000000000000000000..afc2178c87be27d46f4c5f6d25f31fe5406456d7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_cgo_extra_file.txt @@ -0,0 +1,48 @@ +[short] skip +[!cgo] skip +[compiler:gccgo] skip # gccgo has no cover tool + +# Test coverage on cgo code. This test case includes an +# extra empty non-cgo file in the package being checked. + +go test -short -cover cgocover4 +stdout 'coverage:.*[1-9][0-9.]+%' +! stderr '[^0-9]0\.0%' + +-- go.mod -- +module cgocover4 + +go 1.16 +-- notcgo.go -- +package p +-- p.go -- +package p + +/* +void +f(void) +{ +} +*/ +import "C" + +var b bool + +func F() { + if b { + for { + } + } + C.f() +} +-- x_test.go -- +package p_test + +import ( + . "cgocover4" + "testing" +) + +func TestF(t *testing.T) { + F() +} diff --git a/go/src/cmd/go/testdata/script/cover_cgo_extra_test.txt b/go/src/cmd/go/testdata/script/cover_cgo_extra_test.txt new file mode 100644 index 0000000000000000000000000000000000000000..ad09baba78717134c1bc349158a0f1449660725b --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_cgo_extra_test.txt @@ -0,0 +1,49 @@ +[short] skip +[!cgo] skip +[compiler:gccgo] skip # gccgo has no cover tool + +# Test coverage on cgo code. This test case has an external +# test that tests the code and an in-package test file with +# no test cases. + +go test -short -cover cgocover3 +stdout 'coverage:.*[1-9][0-9.]+%' +! stderr '[^0-9]0\.0%' + +-- go.mod -- +module cgocover3 + +go 1.16 +-- p.go -- +package p + +/* +void +f(void) +{ +} +*/ +import "C" + +var b bool + +func F() { + if b { + for { + } + } + C.f() +} +-- p_test.go -- +package p +-- x_test.go -- +package p_test + +import ( + . "cgocover3" + "testing" +) + +func TestF(t *testing.T) { + F() +} diff --git a/go/src/cmd/go/testdata/script/cover_cgo_xtest.txt b/go/src/cmd/go/testdata/script/cover_cgo_xtest.txt new file mode 100644 index 0000000000000000000000000000000000000000..0900a48976c381a20c14df48f612b8a90c275dd8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_cgo_xtest.txt @@ -0,0 +1,45 @@ +[short] skip +[!cgo] skip +[compiler:gccgo] skip # gccgo has no cover tool + +# Test cgo coverage with an external test. + +go test -short -cover cgocover2 +stdout 'coverage:.*[1-9][0-9.]+%' +! stderr '[^0-9]0\.0%' + +-- go.mod -- +module cgocover2 + +go 1.16 +-- p.go -- +package p + +/* +void +f(void) +{ +} +*/ +import "C" + +var b bool + +func F() { + if b { + for { + } + } + C.f() +} +-- x_test.go -- +package p_test + +import ( + . "cgocover2" + "testing" +) + +func TestF(t *testing.T) { + F() +} diff --git a/go/src/cmd/go/testdata/script/cover_coverpkg_partial.txt b/go/src/cmd/go/testdata/script/cover_coverpkg_partial.txt new file mode 100644 index 0000000000000000000000000000000000000000..efdfe2f27d85bc448d5ae8428736aca49e06302b --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_coverpkg_partial.txt @@ -0,0 +1,148 @@ + +# Testcase related to #58770 and #24570. This is intended to ensure +# that coverage collection works in situations where we're testing a +# collection of packages and supplying a -coverpkg pattern that +# matches some but not all of the collection. In addition, some of the +# packages have Go code but no tests, and other packages have tests +# but no Go code. Package breakdown: +# +# Package Code? Tests? Stmts Imports +# a yes yes 2 f +# b yes yes 1 a, d +# c yes yes 3 --- +# d yes no 1 --- +# e no yes 0 a, b +# f yes no 3 --- +# + +[short] skip + +# Test all packages with -coverpkg=./... +go test -coverprofile=cov.p -coverpkg=./... ./... +stdout '^ok\s+M/a\s+\S+\s+coverage: 50.0% of statements in ./...' +stdout '^ok\s+M/b\s+\S+\s+coverage: 60.0% of statements in ./...' +stdout '^ok\s+M/c\s+\S+\s+coverage: 30.0% of statements in ./...' +stdout '^\s*M/d\s+coverage: 0.0% of statements' +stdout '^\s*M/f\s+coverage: 0.0% of statements' + +# Test just the test-only package ./e but with -coverpkg=./... +# Total number of statements should be 7 (e.g. a/b/d/f but not c) +# and covered percent should be 6/7 (we hit everything in the +# coverpkg pattern except the func in "d"). +go test -coverprofile=bar.p -coverpkg=./... ./e +stdout '^ok\s+M/e\s+\S+\s+coverage: 85.7% of statements in ./...' + +# Test b and f with -coverpkg set to a/d/f. Total of 6 statements +# in a/d/f, again we hit everything except DFunc. +go test -coverprofile=baz.p -coverpkg=./a,./d,./f ./b ./f +stdout '^ok\s+M/b\s+\S+\s+coverage: 83.3% of statements in ./a, ./d, ./f' +stdout '^\s*M/f\s+coverage: 0.0% of statements' + +# This sub-test inspired by issue 65653: if package P is is matched +# via the package pattern supplied as the argument to "go test -cover" +# but P is not part of "-coverpkg", then we don't want coverage for P +# (including the specific case where P has no test files). +go test -coverpkg=./a ./... +stdout '^ok\s+M/a\s+\S+\s+coverage: 100.0% of statements in ./a' +stdout '^\s*\?\s+M/f\s+\[no test files\]' + +-- a/a.go -- +package a + +import "M/f" + +var G int + +func AFunc() int { + G = 1 + return f.Id() +} +-- a/a_test.go -- +package a + +import "testing" + +func TestA(t *testing.T) { + if AFunc() != 42 { + t.Fatalf("bad!") + } +} +-- b/b.go -- +package b + +import ( + "M/a" + "M/d" +) + +func BFunc() int { + return -d.FortyTwo + a.AFunc() +} +-- b/b_test.go -- +package b + +import "testing" + +func TestB(t *testing.T) { + if BFunc() == 1010101 { + t.Fatalf("bad!") + } +} +-- c/c.go -- +package c + +var G int + +func CFunc(x, y int) int { + G += x + G -= y + return x + y +} +-- c/c_test.go -- +package c + +import "testing" + +func TestC(t *testing.T) { + if CFunc(10, 10) == 1010101 { + t.Fatalf("bad!") + } +} +-- d/d.go -- +package d + +const FortyTwo = 42 + +func DFunc() int { + return FortyTwo +} + +-- e/e_test.go -- +package e + +import ( + "M/a" + "M/b" + "testing" +) + +func TestBlah(t *testing.T) { + if b.BFunc() == 1010101 { + t.Fatalf("bad") + } + a.AFunc() +} +-- f/f.go -- +package f + +var F int + +func Id() int { + F += 9 + F *= 2 + return 42 +} +-- go.mod -- +module M + +go 1.21 diff --git a/go/src/cmd/go/testdata/script/cover_coverpkg_with_init.txt b/go/src/cmd/go/testdata/script/cover_coverpkg_with_init.txt new file mode 100644 index 0000000000000000000000000000000000000000..bb5bcfa823979fc0c4ca44e8a4f6bd2935d81285 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_coverpkg_with_init.txt @@ -0,0 +1,129 @@ + +# Testcase inspired by issue #58770, intended to verify that we're +# doing the right thing when running "go test -coverpkg=./... ./..." +# on a collection of packages where some have init functions and some +# do not, some have tests and some do not. + +[short] skip + +# Verify correct statements percentages. We have a total of 10 +# statements in the packages matched by "./..."; package "a" (for +# example) has two statements so we expect 20.0% stmts covered. Go +# 1.19 would print 50% here (due to force importing of all ./... +# packages); prior to the fix for #58770 Go 1.20 would show 100% +# coverage. For packages "x" and "f" (which have no tests), check for +# 0% stmts covered (as opposed to "no test files"). + +go test -count=1 -coverprofile=cov.dat -coverpkg=./... ./... +stdout '^\s*\?\s+M/n\s+\[no test files\]' +stdout '^\s*M/x\s+coverage: 0.0% of statements' +stdout '^\s*M/f\s+coverage: 0.0% of statements' +stdout '^ok\s+M/a\s+\S+\s+coverage: 30.0% of statements in ./...' +stdout '^ok\s+M/b\s+\S+\s+coverage: 20.0% of statements in ./...' +stdout '^ok\s+M/main\s+\S+\s+coverage: 80.0% of statements in ./...' + +# Check for selected elements in the collected coverprofile as well. + +go tool cover -func=cov.dat +stdout '^M/x/x.go:3:\s+XFunc\s+0.0%' +stdout '^M/b/b.go:7:\s+BFunc\s+100.0%' +stdout '^total:\s+\(statements\)\s+80.0%' + +-- go.mod -- +module M + +go 1.21 +-- a/a.go -- +package a + +import "M/f" + +func init() { + println("package 'a' init: launch the missiles!") +} + +func AFunc() int { + return f.Id() +} +-- a/a_test.go -- +package a + +import "testing" + +func TestA(t *testing.T) { + if AFunc() != 42 { + t.Fatalf("bad!") + } +} +-- b/b.go -- +package b + +func init() { + println("package 'b' init: release the kraken") +} + +func BFunc() int { + return -42 +} +-- b/b_test.go -- +package b + +import "testing" + +func TestB(t *testing.T) { + if BFunc() != -42 { + t.Fatalf("bad!") + } +} +-- f/f.go -- +package f + +func Id() int { + return 42 +} +-- main/main.go -- +package main + +import ( + "M/a" + "M/b" +) + +func MFunc() string { + return "42" +} + +func M2Func() int { + return a.AFunc() + b.BFunc() +} + +func init() { + println("package 'main' init") +} + +func main() { + println(a.AFunc() + b.BFunc()) +} +-- main/main_test.go -- +package main + +import "testing" + +func TestMain(t *testing.T) { + if MFunc() != "42" { + t.Fatalf("bad!") + } + if M2Func() != 0 { + t.Fatalf("also bad!") + } +} +-- n/n.go -- +package n + +type N int +-- x/x.go -- +package x + +func XFunc() int { + return 2 * 2 +} diff --git a/go/src/cmd/go/testdata/script/cover_coverprofile_multipkg.txt b/go/src/cmd/go/testdata/script/cover_coverprofile_multipkg.txt new file mode 100644 index 0000000000000000000000000000000000000000..543626f7838a5906a55ed1f2d027dc3f27317956 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_coverprofile_multipkg.txt @@ -0,0 +1,193 @@ + +# Testcase for #63356. In this bug we're doing a "go test -coverprofile" +# run for a collection of packages, mostly independent (hence tests can +# be done in parallel) and in the original bug, temp coverage profile +# files were not being properly qualified and were colliding, resulting +# in a corrupted final profile. Actual content of the packages doesn't +# especially matter as long as we have a mix of packages with tests and +# multiple packages without tests. + +[short] skip + +# Kick off test. +go test -p=10 -vet=off -count=1 -coverprofile=cov.p ./... + +# Make sure resulting profile is digestible. +go tool cover -func=cov.p + +# No extraneous extra files please. +! exists _cover_.out + +-- a/a.go -- +package a + +func init() { + println("package 'a' init: launch the missiles!") +} + +func AFunc() int { + return 42 +} +-- a/a_test.go -- +package a + +import "testing" + +func TestA(t *testing.T) { + if AFunc() != 42 { + t.Fatalf("bad!") + } +} +-- aa/aa.go -- +package aa + +import "M/it" + +func AA(y int) int { + c := it.Conc{} + x := it.Callee(&c) + println(x, y) + return 0 +} +-- aa/aa_test.go -- +package aa + +import "testing" + +func TestMumble(t *testing.T) { + AA(3) +} +-- b/b.go -- +package b + +func init() { + println("package 'b' init: release the kraken") +} + +func BFunc() int { + return -42 +} +-- b/b_test.go -- +package b + +import "testing" + +func TestB(t *testing.T) { + if BFunc() != -42 { + t.Fatalf("bad!") + } +} +-- deadstuff/deadstuff.go -- +package deadstuff + +func downStreamOfPanic(x int) { + panic("bad") + if x < 10 { + println("foo") + } +} +-- deadstuff/deadstuff_test.go -- +package deadstuff + +import "testing" + +func TestMumble(t *testing.T) { + defer func() { + if x := recover(); x != nil { + println("recovered") + } + }() + downStreamOfPanic(10) +} +-- go.mod -- +module M + +go 1.21 +-- it/it.go -- +package it + +type Ctr interface { + Count() int +} + +type Conc struct { + X int +} + +func (c *Conc) Count() int { + return c.X +} + +func DoCall(c *Conc) { + c2 := Callee(c) + println(c2.Count()) +} + +func Callee(ii Ctr) Ctr { + q := ii.Count() + return &Conc{X: q} +} +-- main/main.go -- +package main + +import ( + "M/a" + "M/b" +) + +func MFunc() string { + return "42" +} + +func M2Func() int { + return a.AFunc() + b.BFunc() +} + +func init() { + println("package 'main' init") +} + +func main() { + println(a.AFunc() + b.BFunc()) +} +-- main/main_test.go -- +package main + +import "testing" + +func TestMain(t *testing.T) { + if MFunc() != "42" { + t.Fatalf("bad!") + } + if M2Func() != 0 { + t.Fatalf("also bad!") + } +} +-- n/n.go -- +package n + +type N int +-- onlytest/mumble_test.go -- +package onlytest + +import "testing" + +func TestFoo(t *testing.T) { + t.Logf("Whee\n") +} +-- x/x.go -- +package x + +func XFunc() int { + return 2 * 2 +} +-- xinternal/i.go -- +package i + +func I() int { return 32 } +-- xinternal/q/q.go -- +package q + +func Q() int { + return 42 +} diff --git a/go/src/cmd/go/testdata/script/cover_coverprofile_nocoverpkg.txt b/go/src/cmd/go/testdata/script/cover_coverprofile_nocoverpkg.txt new file mode 100644 index 0000000000000000000000000000000000000000..f077734045c9c7f71b4740cf463e69775ad6d292 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_coverprofile_nocoverpkg.txt @@ -0,0 +1,44 @@ +# Testcase for #70244. In this bug we're doing a "go test -coverprofile" +# run for a pair of packages, the first one without tests and the second +# one with tests. When writing the profile for the second test, profile +# data from the first package was leaking into the output (we should +# only see lines in the output profile for the package whose test is +# being run). + +[short] skip + +# Kick off test. +go test -vet=off -count=1 -coverprofile=cov.p ./... + +# Generate a function profile. +go tool cover -func=cov.p + +stdout 'cov/pkg1/file.go:3:\s+DoSomething\s+0.0%' + +-- go.mod -- +module cov + +-- pkg1/file.go -- +package pkg1 + +func DoSomething() bool { + return true +} +-- pkg2/file.go -- +package pkg2 + +func DoSomething() bool { + return true +} +-- pkg2/file_test.go -- +package pkg2 + +import ( + "cov/pkg1" + "testing" +) + +func TestSmth(t *testing.T) { + pkg1.DoSomething() + DoSomething() +} diff --git a/go/src/cmd/go/testdata/script/cover_dash_c.txt b/go/src/cmd/go/testdata/script/cover_dash_c.txt new file mode 100644 index 0000000000000000000000000000000000000000..f28c69e500542db71977ece7233ff85fa3e4fe18 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_dash_c.txt @@ -0,0 +1,31 @@ +[short] skip +[compiler:gccgo] skip + +# Test for issue 24588 + +go test -c -o $WORK/coverdep -coverprofile=$WORK/no/such/dir/cover.out coverdep +exists -exec $WORK/coverdep + +-- go.mod -- +module coverdep + +go 1.16 +-- p.go -- +package p + +import _ "coverdep/p1" + +func F() { +} +-- p1/p1.go -- +package p1 + +import _ "errors" +-- p_test.go -- +package p + +import "testing" + +func Test(t *testing.T) { + F() +} diff --git a/go/src/cmd/go/testdata/script/cover_dep_loop.txt b/go/src/cmd/go/testdata/script/cover_dep_loop.txt new file mode 100644 index 0000000000000000000000000000000000000000..46748e17cc077dcade8e49dcb27f8efe0bb2f64d --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_dep_loop.txt @@ -0,0 +1,36 @@ +[short] skip +[compiler:gccgo] skip + +# coverdep2/p1's xtest imports coverdep2/p2 which imports coverdep2/p1. +# Make sure that coverage on coverdep2/p2 recompiles coverdep2/p2. + +go test -short -cover coverdep2/p1 +stdout 'coverage: 100.0% of statements' # expect 100.0% coverage + +-- go.mod -- +module coverdep2 + +go 1.16 +-- p1/p.go -- +package p1 + +func F() int { return 1 } +-- p1/p_test.go -- +package p1_test + +import ( + "coverdep2/p2" + "testing" +) + +func Test(t *testing.T) { + p2.F() +} +-- p2/p2.go -- +package p2 + +import "coverdep2/p1" + +func F() { + p1.F() +} diff --git a/go/src/cmd/go/testdata/script/cover_dot_import.txt b/go/src/cmd/go/testdata/script/cover_dot_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..a336b1c9baca218217b65c98c32158f8f733805b --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_dot_import.txt @@ -0,0 +1,29 @@ +[short] skip +[compiler:gccgo] skip # gccgo has no cover tool + +go test -coverpkg=coverdot/a,coverdot/b coverdot/b +! stderr '[^0-9]0\.0%' +! stdout '[^0-9]0\.0%' + +-- go.mod -- +module coverdot + +go 1.16 +-- a/a.go -- +package a + +func F() {} +-- b/b.go -- +package b + +import . "coverdot/a" + +func G() { F() } +-- b/b_test.go -- +package b + +import "testing" + +func TestG(t *testing.T) { + G() +} diff --git a/go/src/cmd/go/testdata/script/cover_error.txt b/go/src/cmd/go/testdata/script/cover_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..fa4b58bff7f6f151e01fa64b6b55bde279b97c52 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_error.txt @@ -0,0 +1,45 @@ +[short] skip +[compiler:gccgo] skip + +# Test line numbers in cover errors. + +# Get errors from a go test into stderr.txt +! go test coverbad +stderr 'p\.go:4:2' # look for error at coverbad/p.go:4 +[cgo] stderr 'p1\.go:6:2' # look for error at coverbad/p.go:6 +! stderr $WORK # make sure temporary directory isn't in error + +cp stderr $WORK/stderr.txt + +# Get errors from coverage into stderr2.txt +! go test -cover coverbad +cp stderr $WORK/stderr2.txt + +wait # for go run above + +cmp $WORK/stderr.txt $WORK/stderr2.txt + +-- go.mod -- +module coverbad + +go 1.16 +-- p.go -- +package p + +func f() { + g() +} +-- p1.go -- +package p + +import "C" + +func h() { + j() +} +-- p_test.go -- +package p + +import "testing" + +func Test(t *testing.T) {} diff --git a/go/src/cmd/go/testdata/script/cover_import_main_loop.txt b/go/src/cmd/go/testdata/script/cover_import_main_loop.txt new file mode 100644 index 0000000000000000000000000000000000000000..36a09c2162fee27c3be9a66239847b8ce164cf85 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_import_main_loop.txt @@ -0,0 +1,26 @@ +[compiler:gccgo] skip # gccgo has no cover tool + +! go test -n importmain/test +stderr 'not an importable package' # check that import main was detected +! go test -n -cover importmain/test +stderr 'not an importable package' # check that import main was detected + +-- go.mod -- +module importmain + +go 1.16 +-- ismain/main.go -- +package main + +import _ "importmain/test" + +func main() {} +-- test/test.go -- +package test +-- test/test_test.go -- +package test_test + +import "testing" +import _ "importmain/ismain" + +func TestCase(t *testing.T) {} diff --git a/go/src/cmd/go/testdata/script/cover_list.txt b/go/src/cmd/go/testdata/script/cover_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..7ecc5c05ebfb859748267b7a13223a7a6b8092c2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_list.txt @@ -0,0 +1,68 @@ + +# This test is intended to verify that "go list" accepts coverage related +# build arguments (such as -cover, -covermode). See issue #57785. + +[short] skip + +env GOBIN=$WORK/bin + +# Install a target and then do an ordinary staleness check on it. +go install m/example +! stale m/example + +# Run a second staleness check with "-cover" as a build flag. The +# installed target should indeed be stale, since we didn't build it +# with -cover. +stale -cover m/example + +# Collect build ID from for m/example built with -cover. +go list -cover -export -f '{{.BuildID}}' m/example +cp stdout $WORK/listbuildid.txt + +# Now build the m/example binary with coverage. +go build -cover -o $WORK/m.exe m/example + +# Ask for the binary build ID by running "go tool buildid". +go tool buildid $WORK/m.exe +cp stdout $WORK/rawtoolbuildid.txt + +# Make sure that the two build IDs agree with respect to the +# m/example package. Build IDs from binaries are of the form X/Y/Z/W +# where Y/Z is the package build ID; running the program below will +# pick out the parts of the ID that we want. +env GOCOVERDIR=$WORK +exec $WORK/m.exe $WORK/rawtoolbuildid.txt +cp stdout $WORK/toolbuildid.txt + +# Build IDs should match here. +cmp $WORK/toolbuildid.txt $WORK/listbuildid.txt + +# Make sure that the build succeeds regardless of covermode. +go list -export -covermode=atomic m/example +go list -export -covermode=count m/example + +-- go.mod -- +module m + +go 1.20 +-- example/main.go -- +package main + +import ( + "fmt" + "os" + "strings" +) + +func main() { + println(os.Args[1]) + content, err := os.ReadFile(os.Args[1]) + if err != nil { + os.Exit(1) + } + fields := strings.Split(strings.TrimSpace(string(content)), "/") + if len(fields) != 4 { + os.Exit(2) + } + fmt.Println(fields[1] + "/" + fields[2]) +} diff --git a/go/src/cmd/go/testdata/script/cover_main_import_path.txt b/go/src/cmd/go/testdata/script/cover_main_import_path.txt new file mode 100644 index 0000000000000000000000000000000000000000..3a2f3c3ee28feeaf37bac3821e934fc865c7c975 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_main_import_path.txt @@ -0,0 +1,54 @@ + +# This test is intended to verify that coverage reporting is consistent +# between "go test -cover" and "go build -cover" with respect to how +# the "main" package is handled. See issue 57169 for details. + +[short] skip + +# Build this program with -cover and run to collect a profile. + +go build -cover -o $WORK/prog.exe . + +# Save off old GOCOVERDIR setting +env SAVEGOCOVERDIR=$GOCOVERDIR + +mkdir $WORK/covdata +env GOCOVERDIR=$WORK/covdata +exec $WORK/prog.exe + +# Restore previous GOCOVERDIR setting +env GOCOVERDIR=$SAVEGOCOVERDIR + +# Report percent lines covered. +go tool covdata percent -i=$WORK/covdata +stdout '\s*mainwithtest\s+coverage:' +! stdout 'main\s+coverage:' + +# Go test -cover should behave the same way. +go test -cover . +stdout 'ok\s+mainwithtest\s+\S+\s+coverage:' +! stdout 'ok\s+main\s+.*' + + +-- go.mod -- +module mainwithtest + +go 1.20 +-- mymain.go -- +package main + +func main() { + println("hi mom") +} + +func Mainer() int { + return 42 +} +-- main_test.go -- +package main + +import "testing" + +func TestCoverage(t *testing.T) { + println(Mainer()) +} diff --git a/go/src/cmd/go/testdata/script/cover_mod_empty.txt b/go/src/cmd/go/testdata/script/cover_mod_empty.txt new file mode 100644 index 0000000000000000000000000000000000000000..3c45243edb68ed74b873b087967a09ef3211db1a --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_mod_empty.txt @@ -0,0 +1,9 @@ +go tool cover -func=cover.out +stdout total.*statements.*0.0% + +go mod init golang.org/issue/33855 + +go tool cover -func=cover.out +stdout total.*statements.*0.0% + +-- cover.out -- diff --git a/go/src/cmd/go/testdata/script/cover_modes.txt b/go/src/cmd/go/testdata/script/cover_modes.txt new file mode 100644 index 0000000000000000000000000000000000000000..a27296eafa7907083df7bfaecc6d71bd0e9254aa --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_modes.txt @@ -0,0 +1,25 @@ +env GO111MODULE=off + +# Coverage analysis should use 'set' mode by default, +# and should merge coverage profiles correctly. + +[short] skip +[compiler:gccgo] skip # gccgo has no cover tool + +go test -short -cover encoding/binary errors -coverprofile=$WORK/cover.out +! stderr '[^0-9]0\.0%' +! stdout '[^0-9]0\.0%' + +grep -count=1 '^mode: set$' $WORK/cover.out +grep 'errors\.go' $WORK/cover.out +grep 'binary\.go' $WORK/cover.out + +[!race] stop + +go test -short -race -cover encoding/binary errors -coverprofile=$WORK/cover.out +! stderr '[^0-9]0\.0%' +! stdout '[^0-9]0\.0%' + +grep -count=1 '^mode: atomic$' $WORK/cover.out +grep 'errors\.go' $WORK/cover.out +grep 'binary\.go' $WORK/cover.out diff --git a/go/src/cmd/go/testdata/script/cover_pattern.txt b/go/src/cmd/go/testdata/script/cover_pattern.txt new file mode 100644 index 0000000000000000000000000000000000000000..6c79c10094c395bec6735fe94941e2f342538b9a --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_pattern.txt @@ -0,0 +1,41 @@ +[compiler:gccgo] skip + +# If coverpkg=m/sleepy... expands by package loading +# (as opposed to pattern matching on deps) +# then it will try to load sleepybad, which does not compile, +# and the test command will fail. +! go list m/sleepy... +go test -c -n -coverprofile=$TMPDIR/cover.out -coverpkg=m/sleepy... -run=^$ m/sleepy1 + +-- go.mod -- +module m + +go 1.16 +-- sleepy1/p_test.go -- +package p + +import ( + "testing" + "time" +) + +func Test1(t *testing.T) { + time.Sleep(200 * time.Millisecond) +} +-- sleepy2/p_test.go -- +package p + +import ( + "testing" + "time" +) + +func Test1(t *testing.T) { + time.Sleep(200 * time.Millisecond) +} +-- sleepybad/p.go -- +package p + +import ^ + +var _ = io.DoesNotExist diff --git a/go/src/cmd/go/testdata/script/cover_pkgall_imports.txt b/go/src/cmd/go/testdata/script/cover_pkgall_imports.txt new file mode 100644 index 0000000000000000000000000000000000000000..4e51726b29c4db2ea7c740ba2a5176e94eedaeb5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_pkgall_imports.txt @@ -0,0 +1,48 @@ +# This test checks that -coverpkg=all can be used +# when the package pattern includes packages +# which only have tests. +# Verifies golang.org/issue/27333, golang.org/issue/43242. + +[short] skip +cd $GOPATH/src/example.com/cov + +env GO111MODULE=on +go test -coverpkg=all ./... + +env GO111MODULE=off +go test -coverpkg=all ./... + +-- $GOPATH/src/example.com/cov/go.mod -- +module example.com/cov + +-- $GOPATH/src/example.com/cov/notest/notest.go -- +package notest + +func Foo() {} + +-- $GOPATH/src/example.com/cov/onlytest/onlytest_test.go -- +package onlytest_test + +import ( + "testing" + + "example.com/cov/notest" +) + +func TestFoo(t *testing.T) { + notest.Foo() +} + +-- $GOPATH/src/example.com/cov/withtest/withtest.go -- +package withtest + +func Bar() {} + +-- $GOPATH/src/example.com/cov/withtest/withtest_test.go -- +package withtest + +import "testing" + +func TestBar(t *testing.T) { + Bar() +} diff --git a/go/src/cmd/go/testdata/script/cover_pkgall_multiple_mains.txt b/go/src/cmd/go/testdata/script/cover_pkgall_multiple_mains.txt new file mode 100644 index 0000000000000000000000000000000000000000..f21cd8b3a8e6e696db21146112aeec8d119fc732 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_pkgall_multiple_mains.txt @@ -0,0 +1,46 @@ +# This test checks that multiple main packages can be tested +# with -coverpkg=all without duplicate symbol errors. +# Verifies golang.org/issue/30374, golang.org/issue/34114. + +[short] skip +cd $GOPATH/src/example.com/cov + +env GO111MODULE=on +go test -coverpkg=all ./... + +env GO111MODULE=off +go test -coverpkg=all ./... + +-- $GOPATH/src/example.com/cov/go.mod -- +module example.com/cov + +-- $GOPATH/src/example.com/cov/mainonly/mainonly.go -- +package main + +func main() {} + +-- $GOPATH/src/example.com/cov/mainwithtest/mainwithtest.go -- +package main + +func main() {} + +func Foo() {} + +-- $GOPATH/src/example.com/cov/mainwithtest/mainwithtest_test.go -- +package main + +import "testing" + +func TestFoo(t *testing.T) { + Foo() +} + +-- $GOPATH/src/example.com/cov/xtest/x.go -- +package x + +-- $GOPATH/src/example.com/cov/xtest/x_test.go -- +package x_test + +import "testing" + +func TestX(t *testing.T) {} diff --git a/go/src/cmd/go/testdata/script/cover_pkgall_runtime.txt b/go/src/cmd/go/testdata/script/cover_pkgall_runtime.txt new file mode 100644 index 0000000000000000000000000000000000000000..9927c3069070fdeed6712717bc0c222039b07e06 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_pkgall_runtime.txt @@ -0,0 +1,23 @@ +env GO111MODULE=off + +# Issue 23882 + +[short] skip + +go test -coverpkg=all x +stdout ok[\s\S]+?coverage + +[!race] stop + +go test -coverpkg=all -race x +stdout ok[\s\S]+?coverage + +-- x/x.go -- +package x +import _ "runtime" +func F() {} + +-- x/x_test.go -- +package x +import "testing" +func TestF(t *testing.T) { F() } diff --git a/go/src/cmd/go/testdata/script/cover_runs.txt b/go/src/cmd/go/testdata/script/cover_runs.txt new file mode 100644 index 0000000000000000000000000000000000000000..6df6096563869e19d8db5534195c1334d40ba8de --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_runs.txt @@ -0,0 +1,13 @@ +[compiler:gccgo] skip 'gccgo has no cover tool' +[short] skip + +go test -short -coverpkg=strings strings regexp +! stdout '[^0-9]0\.0%' +stdout 'strings.*coverage:.*[1-9][0-9.]+%' +stdout 'regexp.*coverage:.*[1-9][0-9.]+%' + +go test -short -cover strings math regexp +! stdout '[^0-9]0\.0%' +stdout 'strings.*coverage:.*[1-9][0-9.]+%' +stdout 'math.*coverage:.*[1-9][0-9.]+%' +stdout 'regexp.*coverage:.*[1-9][0-9.]+%' \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/cover_single_vs_multiple.txt b/go/src/cmd/go/testdata/script/cover_single_vs_multiple.txt new file mode 100644 index 0000000000000000000000000000000000000000..47fbae8f2eb7ca41a7e804eccdc58c47991c3960 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_single_vs_multiple.txt @@ -0,0 +1,63 @@ +# Without -coverpkg, we should get the same value for a given +# package regardless of how many other packages are selected +# (see issue 65570). + +[short] skip + +go test -count=1 -cover ./a ./b ./main +stdout '^ok\s+M/main\s+\S+\s+coverage: 75.0% of statements' +go test -count=1 -cover ./main +stdout '^ok\s+M/main\s+\S+\s+coverage: 75.0% of statements' + +-- go.mod -- +module M + +go 1.21 +-- a/a.go -- +package a + +func AFunc() int { + return 42 +} +-- b/b.go -- +package b + +func BFunc() int { + return -42 +} +-- main/main.go -- +package main + +import ( + "M/a" +) + +func MFunc() string { + return "42" +} + +func M2Func() int { + return a.AFunc() +} + +func init() { + println("package 'main' init") +} + +func main() { + println(a.AFunc()) +} +-- main/main_test.go -- +package main + +import "testing" + +func TestMain(t *testing.T) { + if MFunc() != "42" { + t.Fatalf("bad!") + } + if M2Func() != 42 { + t.Fatalf("also bad!") + } +} + diff --git a/go/src/cmd/go/testdata/script/cover_statements.txt b/go/src/cmd/go/testdata/script/cover_statements.txt new file mode 100644 index 0000000000000000000000000000000000000000..f0391ede22d06430f21fbdf2e7f8081bfdfb57dc --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_statements.txt @@ -0,0 +1,93 @@ +[short] skip + +# Workaround for issue 64014 -- for the portion of this test that +# verifies that caching works correctly, the cache should theoretically +# always behave reliably/deterministically, however if other tests are +# concurrently accessing the cache while this test is running, it can +# lead to cache lookup failures, which manifest as test failures here. +# To avoid such flakes, use a separate isolated GOCACHE for this test. +env GOCACHE=$WORK/cache + +# Initial run with simple coverage. +go test -cover ./pkg1 ./pkg2 ./pkg3 ./pkg4 +stdout 'pkg1 coverage: 0.0% of statements' +stdout 'pkg2 \S+ coverage: 0.0% of statements \[no tests to run\]' +stdout 'pkg3 \S+ coverage: 100.0% of statements' +stdout 'pkg4 \S+ coverage: \[no statements\]' + +# Second run to make sure that caching works properly. +go test -x -cover ./pkg1 ./pkg2 ./pkg3 ./pkg4 +stdout 'pkg1 coverage: 0.0% of statements' +stdout 'pkg2 \S+ coverage: 0.0% of statements \[no tests to run\]' +stdout 'pkg3 \S+ coverage: 100.0% of statements' +stdout 'pkg4 \S+ coverage: \[no statements\]' +! stderr 'link(\.exe"?)? -' +! stderr 'compile(\.exe"?)? -' +! stderr 'cover(\.exe"?)? -' +stderr 'covdata(\.exe"?)? percent' + +# Now add in -coverprofile. +go test -cover -coverprofile=cov.dat ./pkg1 ./pkg2 ./pkg3 ./pkg4 +stdout 'pkg1 coverage: 0.0% of statements' +stdout 'pkg2 \S+ coverage: 0.0% of statements \[no tests to run\]' +stdout 'pkg3 \S+ coverage: 100.0% of statements' +stdout 'pkg4 \S+ coverage: \[no statements\]' + +# Validate +go tool cover -func=cov.dat +stdout 'pkg1/a.go:5:\s+F\s+0.0%' + +-- go.mod -- +module m + +go 1.16 +-- pkg1/a.go -- +package pkg1 + +import "fmt" + +func F() { + fmt.Println("pkg1") +} +-- pkg2/a.go -- +package pkg2 + +import "fmt" + +func F() { + fmt.Println("pkg2") +} +-- pkg2/a_test.go -- +package pkg2 +-- pkg3/a.go -- +package pkg3 + +import "fmt" + +func F() { + fmt.Println("pkg3") +} +-- pkg3/a_test.go -- +package pkg3 + +import "testing" + +func TestF(t *testing.T) { + F() +} +-- pkg4/a.go -- +package pkg4 + +type T struct { + X bool +} +-- pkg4/a_test.go -- +package pkg4 + +import ( + "testing" +) + +func TestT(t *testing.T) { + _ = T{} +} diff --git a/go/src/cmd/go/testdata/script/cover_swig.txt b/go/src/cmd/go/testdata/script/cover_swig.txt new file mode 100644 index 0000000000000000000000000000000000000000..decb29aaec2a71d8a302d3fc0c2b398369f1d359 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_swig.txt @@ -0,0 +1,72 @@ + +# Testcase for issue 64661. This testcase is intended to verify that +# we don't try to send swig-generated Go files through the cover tool +# for "go test -cover" runs on packages that have *.swig source files. + +[!exec:swig] skip +[!cgo] skip + +go test -v -count=1 -coverprofile=foo.p +stdout 'coverage: 100.0% of statements' + +-- go.mod -- +module simple + +go 1.21 +-- main.c -- +/* A global variable */ +double Foo = 3.0; + +/* Compute the greatest common divisor of positive integers */ +int gcd(int x, int y) { + int g; + g = y; + while (x > 0) { + g = x; + x = y % x; + y = g; + } + return g; +} + + +-- main.go -- +package main + +import ( + "fmt" +) + +func main() { + // Call our gcd() function + x := 42 + y := 105 + g := Gcd(x, y) + fmt.Println("The gcd of", x, "and", y, "is", g) + + // Manipulate the Foo global variable + + // Output its current value + fmt.Println("Foo =", GetFoo()) + + // Change its value + SetFoo(3.1415926) + + // See if the change took effect + fmt.Println("Foo =", GetFoo()) +} +-- main.swig -- +%module main + +%inline %{ +extern int gcd(int x, int y); +extern double Foo; +%} +-- main_test.go -- +package main + +import "testing" + +func TestSwigFuncs(t *testing.T) { + main() +} diff --git a/go/src/cmd/go/testdata/script/cover_switch_toolchain.txt b/go/src/cmd/go/testdata/script/cover_switch_toolchain.txt new file mode 100644 index 0000000000000000000000000000000000000000..dace804fb6cb27bcba2123ba2ce0f85567abb4e0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_switch_toolchain.txt @@ -0,0 +1,12 @@ +go test -cover -n ./... +[!GOOS:windows] stderr $GOROOT'/bin/go tool covdata' +[GOOS:windows] stderr '\\\\bin\\\\go" tool covdata' + +-- go.mod -- +module example.com/m + +go 1.25.0 +-- m.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/cover_sync_atomic_import.txt b/go/src/cmd/go/testdata/script/cover_sync_atomic_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..7beea137e2d63790b9ff010bed543f76d3f951cd --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_sync_atomic_import.txt @@ -0,0 +1,43 @@ +[short] skip +[compiler:gccgo] skip # gccgo has no cover tool + +go test -short -cover -covermode=atomic -coverpkg=coverdep/p1 coverdep + +# In addition to the above, test to make sure there is no funny +# business if we try "go test -cover" in atomic mode targeting +# sync/atomic itself (see #57445). Just a short test run is needed +# since we're mainly interested in making sure the test builds and can +# execute at least one test. + +go test -short -covermode=atomic -run=TestStoreInt64 sync/atomic +go test -short -covermode=atomic -run=TestAnd8 internal/runtime/atomic + +# Skip remainder if no race detector support. +[!race] skip + +go test -short -cover -race -run=TestStoreInt64 sync/atomic +go test -short -cover -race -run=TestAnd8 internal/runtime/atomic + +-- go.mod -- +module coverdep + +go 1.16 +-- p.go -- +package p + +import _ "coverdep/p1" + +func F() { +} +-- p1/p1.go -- +package p1 + +import _ "errors" +-- p_test.go -- +package p + +import "testing" + +func Test(t *testing.T) { + F() +} diff --git a/go/src/cmd/go/testdata/script/cover_test_localpkg_filepath.txt b/go/src/cmd/go/testdata/script/cover_test_localpkg_filepath.txt new file mode 100644 index 0000000000000000000000000000000000000000..17c58081b2e0bfedf1bd5ee56a650543bc2e6ca8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_test_localpkg_filepath.txt @@ -0,0 +1,40 @@ + +[short] skip + +# collect coverage profile in text format +go test -coverprofile=blah.prof prog.go prog_test.go + +# should not contain cmd-line pseudo-import-path +grep prog.go blah.prof +grep $PWD blah.prof +! grep command-line-arguments blah.prof + +-- prog.go -- +package main + +func Mumble(x int) int { + if x < 0 { + return -x + } + return 42 +} + +func Grumble(y int) int { + return -y +} + +func main() { +} + +-- prog_test.go -- +package main + +import ( + "testing" +) + +func TestMumble(t *testing.T) { + if x := Mumble(10); x != 42 { + t.Errorf("Mumble(%d): got %d want %d", 10, x, 42) + } +} diff --git a/go/src/cmd/go/testdata/script/cover_test_pkgselect.txt b/go/src/cmd/go/testdata/script/cover_test_pkgselect.txt new file mode 100644 index 0000000000000000000000000000000000000000..8e47d142d41ccb654f101a3e7331c991a65d603d --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_test_pkgselect.txt @@ -0,0 +1,77 @@ + +[short] skip + +# Baseline run. +go test -cover example/foo +stdout 'coverage: 50.0% of statements$' + +# Coverage percentage output should mention -coverpkg selection. +go test -coverpkg=example/foo example/foo +stdout 'coverage: 50.0% of statements in example/foo' + +# Try to ask for coverage of a package that doesn't exist. +go test -coverpkg nonexistent example/bar +stderr 'no packages being tested depend on matches for pattern nonexistent' +stdout 'coverage: \[no statements\]' + +# Ask for foo coverage, but test bar. +go test -coverpkg=example/foo example/bar +stdout 'coverage: 50.0% of statements in example/foo' + +# end of test cmds, start of harness and related files. + +-- go.mod -- +module example + +go 1.18 + +-- foo/foo.go -- +package foo + +func FooFunc() int { + return 42 +} +func FooFunc2() int { + return 42 +} + +-- foo/foo_test.go -- +package foo + +import "testing" + +func TestFoo(t *testing.T) { + if FooFunc() != 42 { + t.Fatalf("bad") + } +} + +-- bar/bar.go -- +package bar + +import "example/foo" + +func BarFunc() int { + return foo.FooFunc2() +} + +-- bar/bar_test.go -- +package bar_test + +import ( + "example/bar" + "testing" +) + +func TestBar(t *testing.T) { + if bar.BarFunc() != 42 { + t.Fatalf("bad") + } +} + +-- baz/baz.go -- +package baz + +func BazFunc() int { + return -42 +} diff --git a/go/src/cmd/go/testdata/script/cover_test_race_issue56370.txt b/go/src/cmd/go/testdata/script/cover_test_race_issue56370.txt new file mode 100644 index 0000000000000000000000000000000000000000..2e55f100873dc1d7032b814d8a322b941e06b2be --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_test_race_issue56370.txt @@ -0,0 +1,54 @@ +[short] skip +[!race] skip + +go test -race -cover issue.56370/filter + +-- go.mod -- +module issue.56370 + +go 1.20 + +-- filter/filter.go -- + +package filter + +func New() func(error) bool { + return func(error) bool { + return false + } +} + +-- filter/filter_test.go -- + +package filter_test + +import ( + "testing" + + "issue.56370/filter" +) + +func Test1(t *testing.T) { + t.Parallel() + + _ = filter.New() +} + +func Test2(t *testing.T) { + t.Parallel() + + _ = filter.New() +} + +func Test3(t *testing.T) { + t.Parallel() + + _ = filter.New() +} + +func Test4(t *testing.T) { + t.Parallel() + + _ = filter.New() +} + diff --git a/go/src/cmd/go/testdata/script/cover_var_init_order.txt b/go/src/cmd/go/testdata/script/cover_var_init_order.txt new file mode 100644 index 0000000000000000000000000000000000000000..a9ee63c78c891e0a247eb7c3a7b669c342877cc4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cover_var_init_order.txt @@ -0,0 +1,52 @@ +# This test verifies that issue 56293 has been fixed, and that the +# insertion of coverage instrumentation doesn't perturb package +# initialization order. + +[short] skip + +go test -cover example + +-- go.mod -- +module example + +go 1.20 + +-- m.go -- + +package main + +import ( + "flag" +) + +var ( + fooFlag = flag.String("foo", "", "this should be ok") + foo = flag.Lookup("foo") + + barFlag = flag.String("bar", "", "this should be also ok, but is "+notOK()+".") + bar = flag.Lookup("bar") +) + +func notOK() string { + return "not OK" +} + +-- m_test.go -- + +package main + +import ( + "testing" +) + +func TestFoo(t *testing.T) { + if foo == nil { + t.Fatal() + } +} + +func TestBar(t *testing.T) { + if bar == nil { + t.Fatal() + } +} diff --git a/go/src/cmd/go/testdata/script/cpu_profile_twice.txt b/go/src/cmd/go/testdata/script/cpu_profile_twice.txt new file mode 100644 index 0000000000000000000000000000000000000000..38d6439fb1717eb06abf022ec71ed6a8d9d3a0e6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/cpu_profile_twice.txt @@ -0,0 +1,22 @@ +env GO111MODULE=off + +# Issue 23150 + +[short] skip + +go test -o=$WORK/x.test -cpuprofile=$WORK/cpu_profile_twice.out x +rm $WORK/cpu_profile_twice.out + +go test -o=$WORK/x.test -cpuprofile=$WORK/cpu_profile_twice.out x +exists $WORK/cpu_profile_twice.out + + +-- x/x_test.go -- +package x_test +import ( + "testing" + "time" +) +func TestSleep(t *testing.T) { + time.Sleep(10 * time.Millisecond) +} diff --git a/go/src/cmd/go/testdata/script/darwin_lto_library_ldflag.txt b/go/src/cmd/go/testdata/script/darwin_lto_library_ldflag.txt new file mode 100644 index 0000000000000000000000000000000000000000..d7acefdbad63864c7628a7812dd520b405675dab --- /dev/null +++ b/go/src/cmd/go/testdata/script/darwin_lto_library_ldflag.txt @@ -0,0 +1,17 @@ +[!GOOS:darwin] skip +[!cgo] skip + +! go build +stderr 'invalid flag in #cgo LDFLAGS: -lto_library' + +-- go.mod -- +module ldflag + +-- main.go -- +package main + +// #cgo CFLAGS: -flto +// #cgo LDFLAGS: -lto_library bad.dylib +import "C" + +func main() {} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/darwin_no_cgo.txt b/go/src/cmd/go/testdata/script/darwin_no_cgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..fa445925b7c3740d9d694f55053c68cf679f58dc --- /dev/null +++ b/go/src/cmd/go/testdata/script/darwin_no_cgo.txt @@ -0,0 +1,9 @@ +# For reproducibility and easier cross-compilation, +# nothing in std is supposed to use cgo on macOS. +# Check that cgo does not appear as a dependency +# of cmd/go, which imports approximately everything +# in std (certainly everything relevant). +[!GOOS:darwin] skip +go list -deps cmd/go +! stdout runtime/cgo + diff --git a/go/src/cmd/go/testdata/script/devnull.txt b/go/src/cmd/go/testdata/script/devnull.txt new file mode 100644 index 0000000000000000000000000000000000000000..ccb866aed1a57d90988514000fa5f19105ca5402 --- /dev/null +++ b/go/src/cmd/go/testdata/script/devnull.txt @@ -0,0 +1,26 @@ +env GO111MODULE=off + +# Issue 28035: go test -c -o NUL should work. +# Issue 28549: go test -c -o /dev/null should not overwrite /dev/null when run as root. +cd x +cmp $devnull $WORK/empty.txt +go test -o=$devnull -c +! exists x.test$GOEXE +cmp $devnull $WORK/empty.txt + +# Issue 12407: go build -o /dev/null should succeed. +cd .. +go build -o $devnull y +cmp $devnull $WORK/empty.txt + +-- x/x_test.go -- +package x_test +import ( + "testing" +) +func TestNUL(t *testing.T) { +} +-- y/y.go -- +package y +func main() {} +-- $WORK/empty.txt -- diff --git a/go/src/cmd/go/testdata/script/dist_list_missing.txt b/go/src/cmd/go/testdata/script/dist_list_missing.txt new file mode 100644 index 0000000000000000000000000000000000000000..affaa009d944f1a56c1c26a6e7a91245f52eb4c2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/dist_list_missing.txt @@ -0,0 +1,57 @@ +# Regression test for #60939: when 'go tool dist' is missing, +# 'go tool dist list' should inject its output. + + +# Set GOROOT to a directory that definitely does not include +# a compiled 'dist' tool. 'go tool dist list' should still +# work, because 'cmd/go' itself can impersonate this command. + +mkdir $WORK/goroot/bin +mkdir $WORK/goroot/pkg/tool/${GOOS}_${GOARCH} +env GOROOT=$WORK/goroot + +! go tool -n dist +stderr 'go: no such tool "dist"' + +go tool dist list +stdout linux/amd64 +cp stdout tool.txt + +go tool dist list -v +stdout linux/amd64 +cp stdout tool-v.txt + +go tool dist list -broken +stdout $GOOS/$GOARCH +cp stdout tool-broken.txt + +go tool dist list -json +stdout '"GOOS": "linux",\n\s*"GOARCH": "amd64",\n' +cp stdout tool-json.txt + +go tool dist list -json -broken +stdout '"GOOS": "'$GOOS'",\n\s*"GOARCH": "'$GOARCH'",\n' +cp stdout tool-json-broken.txt + +[short] stop + + +# Check against the real cmd/dist as the source of truth. + +env GOROOT=$TESTGO_GOROOT +go build -o dist.exe cmd/dist + +exec ./dist.exe list +cmp stdout tool.txt + +exec ./dist.exe list -v +cmp stdout tool-v.txt + +exec ./dist.exe list -broken +cmp stdout tool-broken.txt + +exec ./dist.exe list -json +cmp stdout tool-json.txt + +exec ./dist.exe list -json -broken +cmp stdout tool-json-broken.txt diff --git a/go/src/cmd/go/testdata/script/doc.txt b/go/src/cmd/go/testdata/script/doc.txt new file mode 100644 index 0000000000000000000000000000000000000000..3ff1aab093ee3712679b47d8552f09e4aa7a20d4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/doc.txt @@ -0,0 +1,75 @@ +# go doc --help +! go doc --help +stderr 'go doc' +stderr 'go doc ' +stderr 'go doc \[\.\]' +stderr 'go doc \[\.\]\[\.\]' +stderr 'go doc \[\.\]\[\.\]' +stderr 'go doc \[\.\]' + +# go help doc +go help doc +stdout 'go doc' +stdout 'go doc ' +stdout 'go doc \[\.\]' +stdout 'go doc \[\.\]\[\.\]' +stdout 'go doc \[\.\]\[\.\]' +stdout 'go doc \[\.\]' + +# go doc +go doc p/v2 +stdout . + +# go doc +go doc p/v2 Symbol +stdout . + +# go doc +! go doc p/v2 Symbol Method +stderr . + +# go doc . +go doc p/v2.Symbol +stdout . + +# go doc .. +go doc p/v2.Symbol.Method +stdout . + +# go doc +go doc Symbol +stdout . + +# go doc +! go doc Symbol Method +stderr . + +# go doc . +go doc Symbol.Method +stdout . + +# go doc . +go doc p/v2.Method +stdout . + +# go doc +go doc p/v2 Method +stdout . + +# go doc +go doc Method +stdout . + +-- go.mod -- +module p/v2 + +go 1.13 + +-- p.go -- +package p + +type Symbol struct{} + +func (Symbol) Method() error { + return nil +} diff --git a/go/src/cmd/go/testdata/script/embed.txt b/go/src/cmd/go/testdata/script/embed.txt new file mode 100644 index 0000000000000000000000000000000000000000..dcd250549b4e2c25dd99fcee40789c8608e280d0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/embed.txt @@ -0,0 +1,201 @@ +# go list shows patterns and files +go list -f '{{.EmbedPatterns}}' +stdout '\[x\*t\*t\]' +go list -f '{{.EmbedFiles}}' +stdout '\[x.txt\]' +go list -test -f '{{.TestEmbedPatterns}}' +stdout '\[y\*t\*t\]' +go list -test -f '{{.TestEmbedFiles}}' +stdout '\[y.txt\]' +go list -test -f '{{.XTestEmbedPatterns}}' +stdout '\[z\*t\*t\]' +go list -test -f '{{.XTestEmbedFiles}}' +stdout '\[z.txt\]' + +# build embeds x.txt +go build -x +stderr 'x.txt' + +# build uses cache correctly +go build -x +! stderr 'x.txt' +cp x.txt2 x.txt +go build -x +stderr 'x.txt' + +# build rejects invalid names +cp x.go2 x.go +go build -x +cp x.txt .git +! go build -x +stderr '^x.go:5:12: pattern [*]t: cannot embed file [.]git: invalid name [.]git$' +rm .git + +# build rejects symlinks by default +[symlink] symlink x.tzt -> x.txt +[symlink] ! go build -x +[symlink] stderr 'pattern [*]t: cannot embed irregular file x.tzt' +# with GODEBUG embedfollowsymlinks=1, build allows symlinks of leaf files +[symlink] env 'GODEBUG=embedfollowsymlinks=1' +[symlink] go build -x +[symlink] stderr 'x.tzt' +[symlink] rm x.tzt +[symlink] env 'GODEBUG=' + +# build rejects empty directories +mkdir t +! go build -x +stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$' + +# build ignores symlinks and invalid names in directories +cp x.txt t/.git +! go build -x +stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$' +go list -e -f '{{.Incomplete}}' +stdout 'true' +[symlink] symlink t/x.link -> ../x.txt +[symlink] ! go build -x +[symlink] stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$' + +cp x.txt t/x.txt +go build -x + +# build reports errors with positions in imported packages +rm t/x.txt +! go build m/use +stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$' + +# all still ignores .git and symlinks +cp x.go3 x.go +! go build -x +stderr '^x.go:5:12: pattern all:t: cannot embed directory t: contains no embeddable files$' + +# all finds dot files and underscore files +cp x.txt t/.x.txt +go build -x +rm t/.x.txt +cp x.txt t/_x.txt +go build -x + +# build disallows symlinks of directories +[symlink] symlink symdir -> symdirdst +[symlink] cp x.go4 x.go +[symlink] ! go build -x +[symlink] stderr 'x.go:5:12: pattern symdir/[*]: cannot embed file symdir[\\/]x.txt: in non-directory symdir' +[symlink] cp x.go5 x.go +[symlink] ! go build -x +[symlink] stderr 'x.go:5:12: pattern symdir/x.txt: cannot embed file symdir[\\/]x.txt: in non-directory symdir' +# even with GODEBUG=embedfollowsymlinks=1 +[symlink] env 'GODEBUG=embedfollowsymlinks=1' +[symlink] cp x.go4 x.go +[symlink] ! go build -x +[symlink] stderr 'x.go:5:12: pattern symdir/[*]: cannot embed file symdir[\\/]x.txt: in non-directory symdir' +[symlink] cp x.go5 x.go +[symlink] ! go build -x +[symlink] stderr 'x.go:5:12: pattern symdir/x.txt: cannot embed file symdir[\\/]x.txt: in non-directory symdir' +[symlink] env 'GODEBUG=' + +# build rejects names in subdirectories with invalid punctuation +cp x.go6 x.go +mkdir photos/subdir +cp x.txt photos/subdir/foo.jpg +cp x.txt 'photos/subdir/2022-07-22T15''02''45Z.jpg' +! go build -x +stderr '^x.go:5:12: pattern photos/\*: cannot embed file photos/subdir/2022-07-22T15''02''45Z.jpg: invalid name 2022-07-22T15''02''45Z.jpg$' +[!GOOS:windows] mv 'photos/subdir/2022-07-22T15''02''45Z.jpg' photos/subdir/2022-07-22T15:02:45Z.jpg +[!GOOS:windows] ! go build -x +[!GOOS:windows] stderr '^x.go:5:12: pattern photos/\*: cannot embed file photos/subdir/2022-07-22T15:02:45Z.jpg: invalid name 2022-07-22T15:02:45Z.jpg$' +rm photos + +# build ignores hidden names in subdirectories with invalid punctuation +cp x.go6 x.go +mkdir photos/subdir +[!GOOS:windows] cp x.txt photos/subdir/.2022-07-22T15:02:45Z.jpg +[!GOOS:windows] cp x.txt photos/subdir/_2022-07-22T15:02:45Z.jpg +cp x.txt 'photos/subdir/.2022-07-22T15''02''45Z.jpg' +cp x.txt 'photos/subdir/_2022-07-22T15''02''45Z.jpg' +cp x.txt photos/subdir/foo.jpg +go build -x +rm photos + +-- x.go -- +package p + +import "embed" + +//go:embed x*t*t +var X embed.FS + +-- x_test.go -- +package p + +import "embed" + +//go:embed y*t*t +var Y string + +-- x_x_test.go -- +package p_test + +import "embed" + +//go:embed z*t*t +var Z string + +-- x.go2 -- +package p + +import "embed" + +//go:embed *t +var X embed.FS + +-- x.go3 -- +package p + +import "embed" + +//go:embed all:t +var X embed.FS + +-- x.go4 -- +package p + +import "embed" + +//go:embed symdir/* +var X embed.FS + +-- x.go5 -- +package p + +import "embed" + +//go:embed symdir/x.txt +var Z string + +-- x.go6 -- +package p + +import "embed" + +//go:embed photos/* +var X embed.FS + +-- x.txt -- +hello + +-- y.txt -- +-- z.txt -- +-- x.txt2 -- +not hello + +-- use/use.go -- +package use + +import _ "m" +-- symdirdst/x.txt -- +-- go.mod -- +module m + +go 1.16 diff --git a/go/src/cmd/go/testdata/script/embed_brackets.txt b/go/src/cmd/go/testdata/script/embed_brackets.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec17ff3827afd662fd45c100a94d091a13bfb2d7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/embed_brackets.txt @@ -0,0 +1,18 @@ +# issue 53314 +[GOOS:windows] skip +cd [pkg] +go build + +-- [pkg]/go.mod -- +module m + +go 1.19 +-- [pkg]/x.go -- +package p + +import _ "embed" + +//go:embed t.txt +var S string + +-- [pkg]//t.txt -- diff --git a/go/src/cmd/go/testdata/script/embed_fmt.txt b/go/src/cmd/go/testdata/script/embed_fmt.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a16afea8a0946cadc92290a66c4a354fdbb38c8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/embed_fmt.txt @@ -0,0 +1,22 @@ +# go fmt ignores file not found +go fmt xnofmt.go +cmp xnofmt.go xfmt.ref +! go build xnofmt.go +stderr 'xnofmt.go:5:12: pattern missing.txt: no matching files found' + +-- xnofmt.go -- +package p + +import "embed" + +//go:embed missing.txt +var X embed.FS +-- xfmt.ref -- +package p + +import "embed" + +//go:embed missing.txt +var X embed.FS +-- go.mod -- +module m diff --git a/go/src/cmd/go/testdata/script/env_cache.txt b/go/src/cmd/go/testdata/script/env_cache.txt new file mode 100644 index 0000000000000000000000000000000000000000..f2af7ee623ea78e5fb340c246138a88504799b7a --- /dev/null +++ b/go/src/cmd/go/testdata/script/env_cache.txt @@ -0,0 +1,5 @@ +# go env should caches compiler results +go env +go env -x +! stdout '\|\| true' + diff --git a/go/src/cmd/go/testdata/script/env_changed.txt b/go/src/cmd/go/testdata/script/env_changed.txt new file mode 100644 index 0000000000000000000000000000000000000000..da9560062704e60923d1d72898d1e3a52099343f --- /dev/null +++ b/go/src/cmd/go/testdata/script/env_changed.txt @@ -0,0 +1,87 @@ +# Test query for non-defaults in the env + +# Go+BoringCrypto conflicts with GOFIPS140. +[GOEXPERIMENT:boringcrypto] skip + +env GOROOT=./a +env GOTOOLCHAIN=local +env GOSUMDB=nodefault +env GOPROXY=nodefault +env GO111MODULE=auto +env CGO_CFLAGS=nodefault +env CGO_CPPFLAGS=nodefault +env GOFIPS140=latest +[cgo] env CGO_ENABLED=0 +env GCCGO=nodefault + +go env -changed +# linux output like GOTOOLCHAIN='local' +# windows output like GOTOOLCHAIN=local +stdout 'GOTOOLCHAIN=''?local''?' +stdout 'GOSUMDB=''?nodefault''?' +stdout 'GOPROXY=''?nodefault''?' +stdout 'GO111MODULE=''?auto''?' +stdout 'CGO_CFLAGS=''?nodefault''?' +stdout 'CGO_CPPFLAGS=''?nodefault''?' +stdout 'GOFIPS140=''?latest''?' +[cgo] stdout 'CGO_ENABLED=''?0''?' +stdout 'GCCGO=''?nodefault''?' + +go env -changed -json +stdout '"GOTOOLCHAIN": "local"' +stdout '"GOSUMDB": "nodefault"' +stdout '"GOPROXY": "nodefault"' +stdout '"GO111MODULE": "auto"' +stdout '"CGO_CFLAGS": "nodefault"' +stdout '"CGO_CPPFLAGS": "nodefault"' +stdout '"GOFIPS140": "latest"' +[cgo] stdout '"CGO_ENABLED": "0"' +stdout '"GCCGO": "nodefault"' + +[GOOS:windows] env GOOS=linux +[!GOOS:windows] env GOOS=windows +[GOARCH:amd64] env GOARCH=arm64 +[!GOARCH:amd64] env GOARCH=amd64 + +go env -changed GOOS +[GOOS:windows] stdout 'set GOOS=linux' +[!GOOS:windows] stdout 'GOOS=''windows''' +go env -changed GOARCH +[GOARCH:amd64] stdout 'set GOARCH=arm64|GOARCH=''arm64''' +[!GOARCH:amd64] stdout 'set GOARCH=amd64|GOARCH=''amd64''' + +go env -changed -json GOOS +[GOOS:windows] stdout '"GOOS": "linux"' +[!GOOS:windows] stdout '"GOOS": "windows"' +go env -changed -json GOARCH +[GOARCH:amd64] stdout '"GOARCH": "arm64"' +[!GOARCH:amd64] stdout '"GOARCH": "amd64"' + +env GOARCH=amd64 +env GOAMD64=v3 +go env -changed +stdout 'GOAMD64=''?v3''?' + +env GOPROXY=s +go env -changed GOPROXY +! stdout 'GOPROXY' +env GOPROXY=s2 +go env -changed GOPROXY +stdout 'GOPROXY=''?s2''?' + +env GOROOT=./b +go env -changed +! stdout 'GOTOOLCHAIN=''?local''?' + +[GOOS:windows] env LocalAppData=C:\ +[GOOS:windows] env GOCACHE=C:\go-build +[GOOS:windows] go env -changed +[GOOS:windows] ! stdout 'GOCACHE' + +-- a/go.env -- +GOPROXY=s +GOAMD64=v1 +GOFIPS140=off + +-- b/go.env -- +GOTOOLCHAIN=local diff --git a/go/src/cmd/go/testdata/script/env_cross_build.txt b/go/src/cmd/go/testdata/script/env_cross_build.txt new file mode 100644 index 0000000000000000000000000000000000000000..91d1cb936d36527926105cbba2ce4193a83841e7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/env_cross_build.txt @@ -0,0 +1,29 @@ +# Test that the correct default GOEXPERIMENT is used when cross +# building with GOENV (#46815). + +# Unset variables set by the TestScript harness. Users typically won't +# explicitly configure these, and #46815 doesn't repro if they are. +env GOOS= +env GOARCH= +env GOEXPERIMENT= + +env GOENV=windows-amd64 +go build internal/abi + +env GOENV=ios-arm64 +go build internal/abi + +env GOENV=linux-mips +go build internal/abi + +-- windows-amd64 -- +GOOS=windows +GOARCH=amd64 + +-- ios-arm64 -- +GOOS=ios +GOARCH=arm64 + +-- linux-mips -- +GOOS=linux +GOARCH=mips diff --git a/go/src/cmd/go/testdata/script/env_exp.txt b/go/src/cmd/go/testdata/script/env_exp.txt new file mode 100644 index 0000000000000000000000000000000000000000..681512d87c612181a81d2f7f152e98b39115112c --- /dev/null +++ b/go/src/cmd/go/testdata/script/env_exp.txt @@ -0,0 +1,17 @@ +# Test GOEXPERIMENT variable + +# go env shows default empty GOEXPERIMENT +go env +stdout GOEXPERIMENT= + +# go env shows valid experiments +env GOEXPERIMENT=fieldtrack,staticlockranking +go env GOEXPERIMENT +stdout '.*fieldtrack.*staticlockranking.*' +go env +stdout 'GOEXPERIMENT=.*fieldtrack.*staticlockranking.*' + +# go env rejects unknown experiments +env GOEXPERIMENT=bad +! go env GOEXPERIMENT +stderr 'unknown GOEXPERIMENT bad' diff --git a/go/src/cmd/go/testdata/script/env_gocacheprog.txt b/go/src/cmd/go/testdata/script/env_gocacheprog.txt new file mode 100644 index 0000000000000000000000000000000000000000..1547bf058c16ca3b203bed44f1e6f6c8cf8badd9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/env_gocacheprog.txt @@ -0,0 +1,42 @@ +# GOCACHEPROG unset +env GOCACHEPROG= + +go env +stdout 'GOCACHEPROG=''?''?' + +go env -changed +! stdout 'GOCACHEPROG' + +go env -changed -json +! stdout 'GOCACHEPROG' + +# GOCACHEPROG set +[short] skip 'compiles and runs a go program' + +go build -o cacheprog$GOEXE cacheprog.go + +env GOCACHEPROG=$GOPATH/src/cacheprog$GOEXE + +go env +stdout 'GOCACHEPROG=''?'$GOCACHEPROG'''?' + +go env -changed +stdout 'GOCACHEPROG=''?'$GOCACHEPROG'''?' + +go env -changed -json +stdout '"GOCACHEPROG": ".*cacheprog'$GOEXE'"' + +-- cacheprog.go -- +// This is a minimal GOCACHEPROG program that can't actually do anything but exit. +package main + +import ( + "encoding/json" + "os" +) + +func main() { + json.NewEncoder(os.Stdout).Encode(map[string][]string{"KnownCommands": {"close"}}) + var res struct{} + json.NewDecoder(os.Stdin).Decode(&res) +} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/env_gomod_issue61455.txt b/go/src/cmd/go/testdata/script/env_gomod_issue61455.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a94549a9730c5dfde73a7372e5d2c3228aff3af --- /dev/null +++ b/go/src/cmd/go/testdata/script/env_gomod_issue61455.txt @@ -0,0 +1,24 @@ +env TESTGO_VERSION=go1.500 +env TESTGO_VERSION_SWITCH=mismatch + +# go env GOMOD should not trigger a toolchain download +cd $GOPATH/mod +go env GOMOD +stdout mod[/\\]go.mod +! stderr 'go: toolchain go1.500 invoked to provide go1.700' + +# go env GOWORK should not trigger a toolchain download +cd $GOPATH/work +go env GOWORK +stdout work[/\\]go.work +! stderr 'go: toolchain go1.500 invoked to provide go1.700' + +-- $GOPATH/mod/go.mod -- +module example.com + +go 1.700 + +-- $GOPATH/work/go.work -- +module example.com + +go 1.700 \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/env_issue46807.txt b/go/src/cmd/go/testdata/script/env_issue46807.txt new file mode 100644 index 0000000000000000000000000000000000000000..e37bc63e6c9679a8c864537088c42a6478d7feaf --- /dev/null +++ b/go/src/cmd/go/testdata/script/env_issue46807.txt @@ -0,0 +1,12 @@ +! go mod tidy +stderr '^go: warning: ignoring go.mod in \$GOPATH' +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''' + +go env +stdout 'GOPATH=' +stderr '^go: warning: ignoring go.mod in \$GOPATH' + +-- $GOPATH/go.mod -- +module bug + +go 1.21 \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/env_sanitize.txt b/go/src/cmd/go/testdata/script/env_sanitize.txt new file mode 100644 index 0000000000000000000000000000000000000000..cc4d23a8f27c1fd10b30bddfcd155ee6dd6a9c4f --- /dev/null +++ b/go/src/cmd/go/testdata/script/env_sanitize.txt @@ -0,0 +1,5 @@ +env GOFLAGS='$(echo ''cc"''; echo ''OOPS="oops'')' +go env +[GOOS:darwin] stdout 'GOFLAGS=''\$\(echo ''\\''''cc"''\\''''; echo ''\\''''OOPS="oops''\\''''\)''' +[GOOS:linux] stdout 'GOFLAGS=''\$\(echo ''\\''''cc"''\\''''; echo ''\\''''OOPS="oops''\\''''\)''' +[GOOS:windows] stdout 'set GOFLAGS=\$\(echo ''cc"''; echo ''OOPS="oops''\)' diff --git a/go/src/cmd/go/testdata/script/env_unset.txt b/go/src/cmd/go/testdata/script/env_unset.txt new file mode 100644 index 0000000000000000000000000000000000000000..22bc845c37bf4ecc7cde8b989b1d899e7a01e522 --- /dev/null +++ b/go/src/cmd/go/testdata/script/env_unset.txt @@ -0,0 +1,30 @@ +# Test that we can unset variables, even if initially invalid, +# as long as resulting config is valid. + +env GOENV=badenv +env GOOS= +env GOARCH= +env GOEXPERIMENT= + +! go env +stderr '^go(\.exe)?: unknown GOEXPERIMENT badexp$' + +go env -u GOEXPERIMENT + +! go env +stderr '^go: unsupported GOOS/GOARCH pair bados/badarch$' + +! go env -u GOOS +stderr '^go: unsupported GOOS/GOARCH pair \w+/badarch$' + +! go env -u GOARCH +stderr '^go: unsupported GOOS/GOARCH pair bados/\w+$' + +go env -u GOOS GOARCH + +go env + +-- badenv -- +GOOS=bados +GOARCH=badarch +GOEXPERIMENT=badexp diff --git a/go/src/cmd/go/testdata/script/env_write.txt b/go/src/cmd/go/testdata/script/env_write.txt new file mode 100644 index 0000000000000000000000000000000000000000..bf14a2f0bd842308bb05ebb1faa8d31048841f22 --- /dev/null +++ b/go/src/cmd/go/testdata/script/env_write.txt @@ -0,0 +1,208 @@ +env GO111MODULE=off + +# go env should default to the right places +env AppData=$HOME/windowsappdata +env home=$HOME/plan9home +go env GOENV +[GOOS:aix] stdout $HOME/.config/go/env +[GOOS:darwin] stdout $HOME'/Library/Application Support/go/env' +[GOOS:freebsd] stdout $HOME/.config/go/env +[GOOS:linux] stdout $HOME/.config/go/env +[GOOS:netbsd] stdout $HOME/.config/go/env +[GOOS:openbsd] stdout $HOME/.config/go/env +[GOOS:plan9] stdout $HOME/plan9home/lib/go/env +[GOOS:windows] stdout $HOME\\windowsappdata\\go\\env + +# Now override it to something writable. +env GOENV=$WORK/envdir/go/env +go env GOENV +stdout envdir[\\/]go[\\/]env + +# go env shows all variables +go env +stdout GOARCH= +stdout GOOS= +stdout GOROOT= + +# go env ignores invalid flag in GOFLAGS environment variable +env GOFLAGS='=true' +go env + +# checking errors +! go env -w +stderr 'go: no KEY=VALUE arguments given' +! go env -u +stderr 'go: ''go env -u'' requires an argument' + +# go env -w changes default setting +env root= +[GOOS:windows] env root=c: +env GOPATH= +go env -w GOPATH=$root/non-exist/gopath +! stderr .+ +grep GOPATH=$root/non-exist/gopath $WORK/envdir/go/env +go env GOPATH +stdout /non-exist/gopath + +# go env -w does not override OS environment, and warns about that +env GOPATH=$root/other +go env -w GOPATH=$root/non-exist/gopath2 +stderr 'warning: go env -w GOPATH=... does not override conflicting OS environment variable' +go env GOPATH +stdout $root/other + +# but go env -w does do the update, and unsetting the env var exposes the change +env GOPATH= +go env GOPATH +stdout $root/non-exist/gopath2 + +# unsetting with go env -u does not warn about OS environment overrides, +# nor does it warn about variables that haven't been set by go env -w. +env GOPATH=$root/other +go env -u GOPATH +! stderr .+ +go env -u GOPATH +! stderr .+ + +# go env -w rejects unknown or bad variables +! go env -w GOGC=off +stderr 'unknown go command variable GOGC' +! go env -w GOEXE=.bat +stderr 'GOEXE cannot be modified' +! go env -w GOVERSION=customversion +stderr 'GOVERSION cannot be modified' +! go env -w GOENV=/env +stderr 'GOENV can only be set using the OS environment' +! go env -w GODEBUG=gctrace=1 +stderr 'GODEBUG can only be set using the OS environment' + +# go env -w can set multiple variables +env CC= +go env CC +! stdout ^xyc$ +go env -w GOOS=$GOOS CC=xyc +grep CC=xyc $GOENV +# file is maintained in sorted order +grep 'CC=xyc\nGOOS=' $GOENV +go env CC +stdout ^xyc$ + +# go env -u unsets effect of go env -w. +go env -u CC +go env CC +! stdout ^xyc$ + +# go env -w rejects double-set variables +! go env -w GOOS=$GOOS GOOS=$GOOS +stderr 'multiple values for key: GOOS' + +# go env -w rejects missing variables +! go env -w GOOS +stderr 'arguments must be KEY=VALUE: invalid argument: GOOS' + +# go env -w rejects invalid GO111MODULE values, as otherwise cmd/go would break +! go env -w GO111MODULE=badvalue +stderr 'invalid GO111MODULE value "badvalue"' + +# go env -w rejects invalid GOPATH values +! go env -w GOPATH=~/go +stderr 'GOPATH entry cannot start with shell metacharacter' + +! go env -w GOPATH=./go +stderr 'GOPATH entry is relative; must be absolute path' + +# go env -w rejects invalid GOTMPDIR values +! go env -w GOTMPDIR=x +stderr 'go: GOTMPDIR must be an absolute path' + +# go env -w should accept absolute GOTMPDIR value +# and should not create it +[GOOS:windows] go env -w GOTMPDIR=$WORK\x\y\z +[!GOOS:windows] go env -w GOTMPDIR=$WORK/x/y/z +! exists $WORK/x/y/z +# we should be able to clear an env +go env -u GOTMPDIR +go env GOTMPDIR +stdout ^$ + +[GOOS:windows] go env -w GOTMPDIR=$WORK\x\y\z +[!GOOS:windows] go env -w GOTMPDIR=$WORK/x/y/z +go env -w GOTMPDIR= +go env GOTMPDIR +stdout ^$ + +# go env -w rejects relative CC values +[!GOOS:windows] go env -w CC=/usr/bin/clang +go env -w CC=clang +[!GOOS:windows] ! go env -w CC=./clang +[!GOOS:windows] ! go env -w CC=bin/clang +[!GOOS:windows] stderr 'go: CC entry is relative; must be absolute path' + +[GOOS:windows] go env -w CC=$WORK\bin\clang +[GOOS:windows] ! go env -w CC=.\clang +[GOOS:windows] ! go env -w CC=bin\clang +[GOOS:windows] stderr 'go: CC entry is relative; must be absolute path' + +# go env -w rejects relative CXX values +[!GOOS:windows] go env -w CC=/usr/bin/cpp +go env -w CXX=cpp +[!GOOS:windows] ! go env -w CXX=./cpp +[!GOOS:windows] ! go env -w CXX=bin/cpp +[!GOOS:windows] stderr 'go: CXX entry is relative; must be absolute path' + +[GOOS:windows] go env -w CXX=$WORK\bin\cpp +[GOOS:windows] ! go env -w CXX=.\cpp +[GOOS:windows] ! go env -w CXX=bin\cpp +[GOOS:windows] stderr 'go: CXX entry is relative; must be absolute path' + +# go env -w/-u checks validity of GOOS/ARCH combinations +env GOOS= +env GOARCH= +# check -w doesn't allow invalid GOOS +! go env -w GOOS=linuxx +stderr 'unsupported GOOS/GOARCH pair linuxx' +# check -w doesn't allow invalid GOARCH +! go env -w GOARCH=amd644 +stderr 'unsupported GOOS/GOARCH.*/amd644$' +# check -w doesn't allow invalid GOOS with valid GOARCH +! go env -w GOOS=linuxx GOARCH=amd64 +stderr 'unsupported GOOS/GOARCH pair linuxx' +# check a valid GOOS and GOARCH values but an incompatible combinations +! go env -w GOOS=android GOARCH=s390x +stderr 'unsupported GOOS/GOARCH pair android/s390x' +# check that -u considers explicit envs +go env -w GOOS=linux GOARCH=mips +env GOOS=windows +! go env -u GOOS +stderr 'unsupported GOOS/GOARCH.*windows/mips$' +env GOOS= + +# go env -w should reject relative paths in GOMODCACHE environment. +! go env -w GOMODCACHE=~/test +stderr 'go: GOMODCACHE entry is relative; must be absolute path: "~/test"' +! go env -w GOMODCACHE=./test +stderr 'go: GOMODCACHE entry is relative; must be absolute path: "./test"' + +# go env -w checks validity of GOEXPERIMENT +env GOEXPERIMENT= +! go env -w GOEXPERIMENT=badexp +stderr 'unknown GOEXPERIMENT badexp' +go env -w GOEXPERIMENT=fieldtrack + +# go env -w and go env -u work on unknown fields already in the go/env file +cp bad.env $GOENV +go env GOENV +cat $GOENV +go env +! stdout UNKNOWN +go env UNKNOWN +stdout yes +go env -w UNKNOWN=maybe +go env UNKNOWN +stdout maybe +go env -u UNKNOWN +go env UNKNOWN +! stdout . # gone + +-- bad.env -- +UNKNOWN=yes diff --git a/go/src/cmd/go/testdata/script/fileline.txt b/go/src/cmd/go/testdata/script/fileline.txt new file mode 100644 index 0000000000000000000000000000000000000000..5cb35f0dac35f92851ecc768d39e7e5aea55fb36 --- /dev/null +++ b/go/src/cmd/go/testdata/script/fileline.txt @@ -0,0 +1,8 @@ +env GO111MODULE=off + +# look for short, relative file:line in error message +! go run ../../gopath/x/y/z/err.go +stderr ^..[\\/]x[\\/]y[\\/]z[\\/]err.go: + +-- ../x/y/z/err.go -- +package main; import "bar" diff --git a/go/src/cmd/go/testdata/script/fips.txt b/go/src/cmd/go/testdata/script/fips.txt new file mode 100644 index 0000000000000000000000000000000000000000..374902eb702a2ebd3b092bc212c0ff29fbd7179d --- /dev/null +++ b/go/src/cmd/go/testdata/script/fips.txt @@ -0,0 +1,54 @@ +# Go+BoringCrypto conflicts with GOFIPS140. +[GOEXPERIMENT:boringcrypto] skip + +# list with GOFIPS140=off +env GOFIPS140=off +go list -f '{{.DefaultGODEBUG}}' +! stdout fips140 + +# list with GOFIPS140=latest +env GOFIPS140=latest +go list -f '{{.DefaultGODEBUG}}' +stdout fips140=on + +[short] skip + +# build with GOFIPS140=off is cached +env GOFIPS140=off +go build -x -o x.exe +! stderr .-fipso +go build -x -o x.exe +! stderr link + +# build with GOFIPS140=latest is cached too +env GOFIPS140=latest +go build -x -o x.exe +stderr link.*-fipso +go build -x -o x.exe +! stderr link.*-fipso + +# build test with GOFIPS140=off is cached +env GOFIPS140=off +go test -x -c +! stderr .-fipso +go test -x -c +! stderr link + +# build test with GOFIPS140=latest is cached +env GOFIPS140=latest +go test -x -c +stderr link.*-fipso +go test -x -c +! stderr link + +-- go.mod -- +module m +-- x.go -- +package main +import _ "crypto/sha256" +func main() { +} +-- x_test.go -- +package main +import "testing" +func Test(t *testing.T) {} diff --git a/go/src/cmd/go/testdata/script/fipssnap.txt b/go/src/cmd/go/testdata/script/fipssnap.txt new file mode 100644 index 0000000000000000000000000000000000000000..4f2d486c61990f6ab4f8bd8c0704b4ac10f2b827 --- /dev/null +++ b/go/src/cmd/go/testdata/script/fipssnap.txt @@ -0,0 +1,68 @@ +env snap=v1.26.0 +env alias=inprocess + +env GOFIPS140=$snap + +# Go+BoringCrypto conflicts with GOFIPS140. +[GOEXPERIMENT:boringcrypto] skip + +# default GODEBUG includes fips140=on +go list -f '{{.DefaultGODEBUG}}' +stdout fips140=on + +# std lists fips snapshot and not regular fips +go list std +stdout crypto/internal/fips140/$snap/sha256 +! stdout crypto/internal/fips140/sha256 +! stdout crypto/internal/fips140/check + +# build does not use regular fips +go list -json -test +stdout crypto/internal/fips140/$snap/sha256 +! stdout crypto/internal/fips140/sha256 +! stdout crypto/internal/fips140/check + +# again with GOFIPS140=$alias +env GOFIPS140=$alias + +# default GODEBUG includes fips140=on +go list -f '{{.DefaultGODEBUG}}' +stdout fips140=on + +# std lists fips snapshot and not regular fips +go list std +stdout crypto/internal/fips140/$snap/sha256 +! stdout crypto/internal/fips140/sha256 +! stdout crypto/internal/fips140/check + +# build does not use regular fips +go list -json -test +stdout crypto/internal/fips140/$snap/sha256 +! stdout crypto/internal/fips140/sha256 +! stdout crypto/internal/fips140/check + +[short] skip + +# build with GOFIPS140=snap is cached +go build -x -o x.exe +stderr link.*-fipso +go build -x -o x.exe +! stderr link.*-fipso + +# build test with GOFIPS140=snap is cached +go test -x -c +stderr link.*-fipso +go test -x -c +! stderr link + +-- go.mod -- +module m +-- x.go -- +package main +import _ "crypto/sha256" +func main() { +} +-- x_test.go -- +package main +import "testing" +func Test(t *testing.T) {} diff --git a/go/src/cmd/go/testdata/script/fix_diff_exitcode.txt b/go/src/cmd/go/testdata/script/fix_diff_exitcode.txt new file mode 100644 index 0000000000000000000000000000000000000000..2622c0265b6ca4645869a839d3840954a16e9e4d --- /dev/null +++ b/go/src/cmd/go/testdata/script/fix_diff_exitcode.txt @@ -0,0 +1,36 @@ +# Test that go fix -diff exits with non-zero status when diffs exist, +# and exits with zero status when no diffs are needed. +# This is consistent with gofmt -d (#46289) and go mod tidy -diff (#27005). + +# When the source needs fixes, go fix -diff should print the diff +# and exit with a non-zero code. +! go fix -diff example.com/needsfix +stdout 'net.JoinHostPort' + +# When the source is already clean, go fix -diff should print nothing +# and exit with a zero code. +go fix -diff example.com/clean +! stdout . + +-- go.mod -- +module example.com +go 1.26 + +-- needsfix/x.go -- +package needsfix + +import ( + "fmt" + "net" +) + +var s string +var _, _ = net.Dial("tcp", fmt.Sprintf("%s:%d", s, 80)) + +-- clean/x.go -- +package clean + +import "net" + +var s string +var _, _ = net.Dial("tcp", net.JoinHostPort(s, "80")) diff --git a/go/src/cmd/go/testdata/script/fix_suite.txt b/go/src/cmd/go/testdata/script/fix_suite.txt new file mode 100644 index 0000000000000000000000000000000000000000..28ef96e4d1cacdb100eaef1b8131d82734df1f2f --- /dev/null +++ b/go/src/cmd/go/testdata/script/fix_suite.txt @@ -0,0 +1,53 @@ +# Elementary test of each analyzer in the "go fix" suite. +# This is simply to prove that they are running at all; +# detailed behavior is tested in x/tools. +# +# Each assertion matches the expected diff. +# +# Tip: to see the actual stdout, +# temporarily remove the "! " prefix from the go command. + +! go fix -diff example.com/x + +# buildtag +stdout '-// \+build go1.26' + +# hostport +stdout 'net.Dial.*net.JoinHostPort' + +# inline +stdout 'var three = 1 \+ 2' + +# newexpr (proxy for whole modernize suite) +stdout 'var _ = new\(123\)' + +-- go.mod -- +module example.com/x +go 1.26 + +-- x.go -- +//go:build go1.26 +// +build go1.26 + +// ↑ buildtag + +package x + +import ( + "fmt" + "net" +) + +// hostport +var s string +var _, _ = net.Dial("tcp", fmt.Sprintf("%s:%d", s, 80)) + +//go:fix inline +func add(x, y int) int { return x + y } + +// inline +var three = add(1, 2) + +// newexpr +func varOf(x int) *int { return &x } +var _ = varOf(123) diff --git a/go/src/cmd/go/testdata/script/fix_vendor.txt b/go/src/cmd/go/testdata/script/fix_vendor.txt new file mode 100644 index 0000000000000000000000000000000000000000..b1ee1975dbb9b3fce0bcb4db6ffa213658ddee89 --- /dev/null +++ b/go/src/cmd/go/testdata/script/fix_vendor.txt @@ -0,0 +1,44 @@ +# Test that go fix skips fixes to non-main and/or vendored packages. +# (It uses the interface{} -> any modernizer.) + +# Create vendor tree programmatically to avoid +# having to hardcode sums in this txtar archive. +go mod vendor + +# Show fixes on two packages, one in the main module +# and one in a vendored dependency. +# Only the main one (a) is shown. Diff => nonzero exit. +! go fix -diff example.com/a example.com/b +stdout 'a[/\\]a.go' +stdout '\-var _ interface\{\}' +stdout '\+var _ any' +! stdout 'b[/\\]b.go' + +# Apply fixes to the same two packages. +# Only the main module was modified. +go fix example.com/a example.com/b +grep 'var _ any' a/a.go +grep 'var _ interface{}' b/b.go +grep 'var _ interface{}' vendor/example.com/b/b.go + +-- go.mod -- +module example.com +go 1.26 + +require "example.com/b" v0.0.0 +replace "example.com/b" => ./b + +-- a/a.go -- +package a + +import _ "example.com/b" + +var _ interface{} + +-- b/go.mod -- +module example.com/b + +-- b/b.go -- +package b + +var _ interface{} diff --git a/go/src/cmd/go/testdata/script/fmt_load_errors.txt b/go/src/cmd/go/testdata/script/fmt_load_errors.txt new file mode 100644 index 0000000000000000000000000000000000000000..e3a9034ede74268463aa8e8cb5c85bf00f64144e --- /dev/null +++ b/go/src/cmd/go/testdata/script/fmt_load_errors.txt @@ -0,0 +1,38 @@ +env GO111MODULE=off + +! go fmt does-not-exist + +go fmt -n exclude +stdout 'exclude[/\\]x\.go' +stdout 'exclude[/\\]x_linux\.go' + +# Test edge cases with gofmt. + +! exec $GOROOT/bin/gofmt does-not-exist + +exec $GOROOT/bin/gofmt gofmt-dir/no-extension +stdout 'package x' + +exec $GOROOT/bin/gofmt gofmt-dir +! stdout 'package x' + +! exec $GOROOT/bin/gofmt empty.go nopackage.go +stderr -count=1 'empty\.go:1:1: expected .package., found .EOF.' +stderr -count=1 'nopackage\.go:1:1: expected .package., found not' + +-- exclude/empty/x.txt -- +-- exclude/ignore/_x.go -- +package x +-- exclude/x.go -- +// +build linux,!linux + +package x +-- exclude/x_linux.go -- +// +build windows + +package x +-- gofmt-dir/no-extension -- +package x +-- empty.go -- +-- nopackage.go -- +not the proper start to a Go file diff --git a/go/src/cmd/go/testdata/script/fsys_walk.txt b/go/src/cmd/go/testdata/script/fsys_walk.txt new file mode 100644 index 0000000000000000000000000000000000000000..9d1a9451ff7a63d49b08934ec93ba62d669f168a --- /dev/null +++ b/go/src/cmd/go/testdata/script/fsys_walk.txt @@ -0,0 +1,6 @@ +# Test that go list prefix... does not read directories not beginning with prefix. +env GODEBUG=gofsystrace=1 +go list m... +stderr mime +stderr mime[\\/]multipart +! stderr archive diff --git a/go/src/cmd/go/testdata/script/gccgo_link_c.txt b/go/src/cmd/go/testdata/script/gccgo_link_c.txt new file mode 100644 index 0000000000000000000000000000000000000000..d37cb66247e5fe098da0c46b365fcd27dafa148c --- /dev/null +++ b/go/src/cmd/go/testdata/script/gccgo_link_c.txt @@ -0,0 +1,20 @@ +# Issue #7573 +# cmd/cgo: undefined reference when linking a C-library using gccgo + +[!cgo] skip +[!exec:gccgo] skip +[cross] skip # gccgo can't necessarily cross-compile, so don't assume it will reach the step where we expect it to fail + +! go build -x -compiler gccgo +stderr 'gccgo.*\-L [^ ]*alibpath \-lalib' # make sure that Go-inline "#cgo LDFLAGS:" ("-L alibpath -lalib") passed to gccgo linking stage +! stderr 'gccgo.*-lalib.*-lalib' # make sure -lalib is only passed once + +-- go.mod -- +module m +-- cgoref.go -- +package main +// #cgo LDFLAGS: -L alibpath -lalib +// void f(void) {} +import "C" + +func main() { C.f() } diff --git a/go/src/cmd/go/testdata/script/gccgo_link_ldflags.txt b/go/src/cmd/go/testdata/script/gccgo_link_ldflags.txt new file mode 100644 index 0000000000000000000000000000000000000000..80526c66faa79e4a1e568a98d97ab830c2c69d4b --- /dev/null +++ b/go/src/cmd/go/testdata/script/gccgo_link_ldflags.txt @@ -0,0 +1,23 @@ +# Test that #cgo LDFLAGS are properly quoted. +# The #cgo LDFLAGS below should pass a string with spaces to -L, +# as though searching a directory with a space in its name. +# It should not pass --nosuchoption to the external linker. + +[!cgo] skip + +go build + +[!exec:gccgo] skip + +# TODO: remove once gccgo on builder is updated +[GOOS:aix] [GOARCH:ppc64] skip + +go build -compiler gccgo + +-- go.mod -- +module m +-- cgo.go -- +package main +// #cgo LDFLAGS: -L "./ -Wl,--nosuchoption" +import "C" +func main() {} diff --git a/go/src/cmd/go/testdata/script/gccgo_m.txt b/go/src/cmd/go/testdata/script/gccgo_m.txt new file mode 100644 index 0000000000000000000000000000000000000000..beb9c50368e306292731a50a3011af17fbfbc5eb --- /dev/null +++ b/go/src/cmd/go/testdata/script/gccgo_m.txt @@ -0,0 +1,20 @@ +# It's absurd, but builds with -compiler=gccgo used to fail to build module m. +# golang.org/issue/34358 + +env GO111MODULE=off + +[short] skip +[cross] skip # gccgo can't necessarily cross-compile + +cd m +go build +exists m$GOEXE +rm m$GOEXE +[exec:gccgo] go build -compiler=gccgo +[exec:gccgo] exists m$GOEXE + +-- m/go.mod -- +module m +-- m/main.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/gccgo_mangle.txt b/go/src/cmd/go/testdata/script/gccgo_mangle.txt new file mode 100644 index 0000000000000000000000000000000000000000..7a09a8002ec85634cc043d4aaa0a3f7eccb117bd --- /dev/null +++ b/go/src/cmd/go/testdata/script/gccgo_mangle.txt @@ -0,0 +1,15 @@ +# Issue 33871. + +cd m/a.0 +go build + +-- m/go.mod -- +module m +-- m/a.0/a.go -- +package a + +type T int + +func (t T) M() int { + return int(t) +} diff --git a/go/src/cmd/go/testdata/script/gcflags_patterns.txt b/go/src/cmd/go/testdata/script/gcflags_patterns.txt new file mode 100644 index 0000000000000000000000000000000000000000..cc7b2fc0adc56d3c3c1ca9abe903e47df588a3c3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/gcflags_patterns.txt @@ -0,0 +1,93 @@ +env GO111MODULE=off + +[!compiler:gc] skip 'using -gcflags and -ldflags' +[short] skip + +# -gcflags=-e applies to named packages, not dependencies +go build -a -n -v -gcflags=-e z1 z2 +stderr 'compile.* -p z1.* -e ' +stderr 'compile.* -p z2.* -e ' +stderr 'compile.* -p y' +! stderr 'compile.* -p [^z].* -e ' + +# -gcflags can specify package=flags, and can be repeated; last match wins +go build -a -n -v -gcflags=-e -gcflags=z1=-N z1 z2 +stderr 'compile.* -p z1.* -N ' +! stderr 'compile.* -p z1.* -e ' +! stderr 'compile.* -p z2.* -N ' +stderr 'compile.* -p z2.* -e ' +stderr 'compile.* -p y' +! stderr 'compile.* -p [^z].* -e ' +! stderr 'compile.* -p [^z].* -N ' + +# -gcflags can have arbitrary spaces around the flags +go build -a -n -v -gcflags=' z1 = -e ' z1 +stderr 'compile.* -p z1.* -e ' + +# -gcflags='all=-e' should apply to all packages, even with go test +go test -a -c -n -gcflags='all=-e' z1 +stderr 'compile.* -p z3.* -e ' + +# this particular -gcflags argument made the compiler crash +! go build -gcflags=-d=ssa/ z1 +stderr 'PhaseOptions usage' + +# check for valid -ldflags parameter +! go build '-ldflags="-X main.X=Hello"' +stderr 'invalid value' + +# -ldflags for implicit test package applies to test binary +go test -a -c -n -gcflags=-N -ldflags=-X=x.y=z z1 +stderr 'compile.* -N .*z_test.go' +stderr 'link.* -X=x.y=z' + +# -ldflags for explicit test package applies to test binary +go test -a -c -n -gcflags=z1=-N -ldflags=z1=-X=x.y=z z1 +stderr 'compile.* -N .*z_test.go' +stderr 'link.* -X=x.y=z' + +# -ldflags applies to link of command +go build -a -n -ldflags=-X=math.pi=3 my/cmd/prog +stderr 'link.* -X=math.pi=3' + +# -ldflags applies to link of command even with strange directory name +go build -a -n -ldflags=-X=math.pi=3 my/cmd/prog/ +stderr 'link.* -X=math.pi=3' + +# -ldflags applies to current directory +cd my/cmd/prog +go build -a -n -ldflags=-X=math.pi=3 +stderr 'link.* -X=math.pi=3' + +# -ldflags applies to current directory even if GOPATH is funny +[!case-sensitive] cd $WORK/GoPath/src/my/cmd/prog +go build -a -n -ldflags=-X=math.pi=3 +stderr 'link.* -X=math.pi=3' + +# cgo.a should not be a dependency of internally-linked go package +go build -ldflags='-linkmode=external -linkmode=internal' -n prog.go +! stderr 'packagefile .*runtime/cgo.a' + +-- z1/z.go -- +package z1 +import _ "y" +import _ "z2" + +-- z1/z_test.go -- +package z1_test +import "testing" +import _ "z3" +func Test(t *testing.T) {} + +-- z2/z.go -- +package z2 + +-- z3/z.go -- +package z3 + +-- y/y.go -- +package y + +-- my/cmd/prog/prog.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/generate.txt b/go/src/cmd/go/testdata/script/generate.txt new file mode 100644 index 0000000000000000000000000000000000000000..58777c5865a3f18280a1fe6992c5ac1bd127a24e --- /dev/null +++ b/go/src/cmd/go/testdata/script/generate.txt @@ -0,0 +1,107 @@ +[short] skip + +# Install an echo command because Windows doesn't have it. +env GOBIN=$WORK/tmp/bin +go install echo.go +env PATH=$GOBIN${:}$PATH + +# Test go generate handles a simple command +go generate ./generate/simple.go +stdout 'Success' + +# Test go generate handles a command alias +go generate './generate/alias.go' +stdout 'Now is the time for all good men' + +# Test go generate's variable substitution +go generate './generate/substitution.go' +stdout $GOARCH' substitution.go:7 pabc xyzp/substitution.go/123' + +# Test go generate's run and skip flags +go generate -run y.s './generate/flag.go' +stdout 'yes' # flag.go should select yes +! stdout 'no' # flag.go should not select no + +go generate -skip th..sand './generate/flag.go' +stdout 'yes' # flag.go should select yes +! stdout 'no' # flag.go should not select no + +go generate -run . -skip th..sand './generate/flag.go' +stdout 'yes' # flag.go should select yes +! stdout 'no' # flag.go should not select no + +# Test go generate provides the right "$GOPACKAGE" name in an x_test +go generate './generate/env_test.go' +stdout 'main_test' + +# Test go generate provides the right "$PWD" +go generate './generate/env_pwd.go' +stdout $WORK'[/\\]gopath[/\\]src[/\\]generate' + +-- echo.go -- +package main + +import ( + "fmt" + "os" + "strings" +) + +func main() { + fmt.Println(strings.Join(os.Args[1:], " ")) + fmt.Println() +} +-- generate/simple.go -- +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Simple test for go generate. + +// We include a build tag that go generate should ignore. + +// +build ignore + +//go:generate echo Success + +package p +-- generate/alias.go -- +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that go generate handles command aliases. + +//go:generate -command run echo Now is the time +//go:generate run for all good men + +package p +-- generate/substitution.go -- +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test go generate variable substitution. + +//go:generate echo $GOARCH $GOFILE:$GOLINE ${GOPACKAGE}abc xyz$GOPACKAGE/$GOFILE/123 + +package p +-- generate/flag.go -- +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test -run flag + +//go:generate echo oh yes my man +//go:generate echo no, no, a thousand times no + +package p +-- generate/env_test.go -- +package main_test + +//go:generate echo $GOPACKAGE +-- generate/env_pwd.go -- +package p + +//go:generate echo $PWD diff --git a/go/src/cmd/go/testdata/script/generate_bad_imports.txt b/go/src/cmd/go/testdata/script/generate_bad_imports.txt new file mode 100644 index 0000000000000000000000000000000000000000..3da391e2e9d43ebeba8465afd9b18380e9c4b9c4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/generate_bad_imports.txt @@ -0,0 +1,15 @@ +[GOOS:windows] skip # skip because windows has no echo command + +go generate gencycle +stdout 'hello world' # check go generate gencycle ran the generator + +-- go.mod -- +module gencycle + +go 1.16 +-- gencycle.go -- +//go:generate echo hello world + +package gencycle + +import _ "gencycle" diff --git a/go/src/cmd/go/testdata/script/generate_env.txt b/go/src/cmd/go/testdata/script/generate_env.txt new file mode 100644 index 0000000000000000000000000000000000000000..cb76d30e9b1b717305cf7af1a7c7368f2b6706f0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/generate_env.txt @@ -0,0 +1,32 @@ +# Install an env command because Windows and plan9 don't have it. +env GOBIN=$WORK/tmp/bin +go install env.go +[GOOS:plan9] env path=$GOBIN${:}$path +[!GOOS:plan9] env PATH=$GOBIN${:}$PATH + +# Test generators have access to the environment +go generate ./printenv.go +stdout '^GOARCH='$GOARCH +stdout '^GOOS='$GOOS +stdout '^GOFILE=' +stdout '^GOLINE=' +stdout '^GOPACKAGE=' +stdout '^DOLLAR=' + +-- env.go -- +package main + +import ( + "fmt" + "os" +) + +func main() { + for _, v := range os.Environ() { + fmt.Println(v) + } +} +-- printenv.go -- +package main + +//go:generate env \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/generate_goroot_PATH.txt b/go/src/cmd/go/testdata/script/generate_goroot_PATH.txt new file mode 100644 index 0000000000000000000000000000000000000000..24591f0074281916bddb1500471e542e846c8b5c --- /dev/null +++ b/go/src/cmd/go/testdata/script/generate_goroot_PATH.txt @@ -0,0 +1,38 @@ +# https://go.dev/issue/51473: to avoid the need for generators to rely on +# runtime.GOROOT, 'go generate' should run the test with its own GOROOT/bin +# at the beginning of $PATH. + +[short] skip + +[!GOOS:plan9] env PATH= +[GOOS:plan9] env path= +go generate . + +[!GOOS:plan9] env PATH=$WORK${/}bin +[GOOS:plan9] env path=$WORK${/}bin +go generate . + +-- go.mod -- +module example + +go 1.19 +-- main.go -- +//go:generate go run . + +package main + +import ( + "fmt" + "os" + "os/exec" +) + +func main() { + _, err := exec.LookPath("go") + if err != nil { + fmt.Println(err) + os.Exit(1) + } +} +-- $WORK/bin/README.txt -- +This directory contains no executables. diff --git a/go/src/cmd/go/testdata/script/generate_invalid.txt b/go/src/cmd/go/testdata/script/generate_invalid.txt new file mode 100644 index 0000000000000000000000000000000000000000..3bede321a90429b1cab04f2668f505fa9d3b06e5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/generate_invalid.txt @@ -0,0 +1,208 @@ +[short] skip + +# Install an echo command because Windows doesn't have it. +env GOBIN=$WORK/tmp/bin +go install echo.go +env PATH=$GOBIN${:}$PATH + +# Test go generate for directory with no go files +! go generate ./nogo +! stdout 'Fail' +stderr 'no Go files' + +# Test go generate for module which doesn't exist should fail +! go generate foo.bar/nothing +stderr 'no required module provides package foo.bar/nothing' + +# Test go generate for package where all .go files are excluded by build +# constraints +go generate -v ./excluded +! stdout 'Fail' +! stderr 'go' # -v shouldn't list any files + +# Test go generate for "package" with no package clause in any file +go generate ./nopkg +stdout 'Success a' +! stdout 'Fail' + +# Test go generate for package with inconsistent package clauses +# $GOPACKAGE should depend on each file's package clause +go generate ./inconsistent +stdout 'Success a' +stdout 'Success b' +stdout -count=2 'Success c' +! stdout 'Fail' + +# Test go generate for syntax errors before and after package clauses +go generate ./syntax +stdout 'Success a' +stdout 'Success b' +! stdout 'Fail' + +# Test go generate for files importing non-existent packages +go generate ./importerr +stdout 'Success a' +stdout 'Success b' +stdout 'Success c' + +-- echo.go -- +package main + +import ( + "fmt" + "os" + "strings" +) + +func main() { + fmt.Println(strings.Join(os.Args[1:], " ")) + fmt.Println() +} + +-- go.mod -- +module m + +go 1.16 +-- nogo/foo.txt -- +Text file in a directory without go files. +Go generate should ignore this directory. +//go:generate echo Fail nogo + +-- excluded/a.go -- +// Include a build tag that go generate should exclude. +// Go generate should ignore this file. + +// +build a + +//go:generate echo Fail a + +package excluded + +-- excluded/b.go -- +// Include a build tag that go generate should exclude. +// Go generate should ignore this file. + +//go:generate echo Fail b + +// +build b + +package excluded + + +-- nopkg/a.go -- +// Go file with package clause after comment. +// Go generate should process this file. + +/* Pre-comment */ package nopkg +//go:generate echo Success a + +-- nopkg/b.go -- +// Go file with commented package clause. +// Go generate should ignore this file. + +//package nopkg + +//go:generate echo Fail b + +-- nopkg/c.go -- +// Go file with package clause inside multiline comment. +// Go generate should ignore this file. + +/* +package nopkg +*/ + +//go:generate echo Fail c + +-- nopkg/d.go -- +// Go file with package clause inside raw string literal. +// Go generate should ignore this file. + +const foo = ` +package nopkg +` +//go:generate echo Fail d + +-- nopkg/e.go -- +// Go file without package clause. +// Go generate should ignore this file. + +//go:generate echo Fail e + +-- inconsistent/a.go -- +// Valid go file with inconsistent package name. +// Go generate should process this file with GOPACKAGE=a + +package a +//go:generate echo Success $GOPACKAGE + +-- inconsistent/b.go -- +// Valid go file with inconsistent package name. +// Go generate should process this file with GOPACKAGE=b + +//go:generate echo Success $GOPACKAGE +package b + +-- inconsistent/c.go -- +// Go file with two package clauses. +// Go generate should process this file with GOPACKAGE=c + +//go:generate echo Success $GOPACKAGE +package c +// Invalid package clause, should be ignored: +package cinvalid +//go:generate echo Success $GOPACKAGE + +-- inconsistent/d.go -- +// Go file with invalid package name. +// Go generate should ignore this file. + +package +d+ +//go:generate echo Fail $GOPACKAGE + +-- syntax/a.go -- +// Go file with syntax error after package clause. +// Go generate should process this file. + +package syntax +123 +//go:generate echo Success a + +-- syntax/b.go -- +// Go file with syntax error after package clause. +// Go generate should process this file. + +package syntax; 123 +//go:generate echo Success b + +-- syntax/c.go -- +// Go file with syntax error before package clause. +// Go generate should ignore this file. + +foo +package syntax +//go:generate echo Fail c + +-- importerr/a.go -- +// Go file which imports non-existing package. +// Go generate should process this file. + +package importerr +//go:generate echo Success a +import "foo" + +-- importerr/b.go -- +// Go file which imports non-existing package. +// Go generate should process this file. + +//go:generate echo Success b +package importerr +import "bar" + +-- importerr/c.go -- +// Go file which imports non-existing package. +// Go generate should process this file. + +package importerr +import "moo" +//go:generate echo Success c diff --git a/go/src/cmd/go/testdata/script/generate_workspace.txt b/go/src/cmd/go/testdata/script/generate_workspace.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ba23932f1df013b27dc3940fe2fe45f68f75d29 --- /dev/null +++ b/go/src/cmd/go/testdata/script/generate_workspace.txt @@ -0,0 +1,27 @@ +# This is a regression test for Issue #56098: Go generate +# wasn't initializing workspace mode + +[short] skip + +go generate ./mod +cmp ./mod/got.txt want.txt + +-- go.work -- +go 1.22 + +use ./mod +-- mod/go.mod -- +module example.com/mod +-- mod/gen.go -- +//go:generate go run gen.go got.txt + +package main + +import "os" + +func main() { + outfile := os.Args[1] + os.WriteFile(outfile, []byte("Hello World!\n"), 0644) +} +-- want.txt -- +Hello World! \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/get_404_meta.txt b/go/src/cmd/go/testdata/script/get_404_meta.txt new file mode 100644 index 0000000000000000000000000000000000000000..7665155a4440bbffb4f9760422f3d6dcc5b9f853 --- /dev/null +++ b/go/src/cmd/go/testdata/script/get_404_meta.txt @@ -0,0 +1,15 @@ +# golang.org/issue/13037: 'go get' was not parsing tags in 404 served over HTTPS. + +[!net:bazil.org] skip +[!git] skip + +env GONOSUMDB=bazil.org,github.com,golang.org +env GO111MODULE=on +env GOPROXY=direct +go get bazil.org/fuse/fs/fstestutil + + +-- go.mod -- +module m + +go 1.18 diff --git a/go/src/cmd/go/testdata/script/get_insecure.txt b/go/src/cmd/go/testdata/script/get_insecure.txt new file mode 100644 index 0000000000000000000000000000000000000000..f29ec2daed3587868ad844fb7954f7d82ff7d65d --- /dev/null +++ b/go/src/cmd/go/testdata/script/get_insecure.txt @@ -0,0 +1,41 @@ +[!net:insecure.go-get-issue-15410.appspot.com] skip +[!git] skip + +env PATH=$WORK/tmp/bin${:}$PATH +go build -o $WORK/tmp/bin/ssh ssh.go + +# Modules: Set up +env GOPATH=$WORK/m/gp +mkdir $WORK/m +cp module_file $WORK/m/go.mod +cd $WORK/m +env GO111MODULE=on +env GOPROXY='' + +# Modules: Try go get -d of HTTP-only repo (should fail). +! go get -d insecure.go-get-issue-15410.appspot.com/pkg/p + +# Modules: Try again with GOINSECURE (should succeed). +env GOINSECURE=insecure.go-get-issue-15410.appspot.com +env GONOSUMDB=insecure.go-get-issue-15410.appspot.com +go get -d insecure.go-get-issue-15410.appspot.com/pkg/p + +# Modules: Try updating without GOINSECURE (should fail). +env GOINSECURE='' +env GONOSUMDB='' +! go get -d -u -f insecure.go-get-issue-15410.appspot.com/pkg/p + +go list -m ... +stdout 'insecure.go-get-issue' + +-- ssh.go -- +// stub out uses of ssh by go get +package main + +import "os" + +func main() { + os.Exit(1) +} +-- module_file -- +module m diff --git a/go/src/cmd/go/testdata/script/get_insecure_no_longer_supported.txt b/go/src/cmd/go/testdata/script/get_insecure_no_longer_supported.txt new file mode 100644 index 0000000000000000000000000000000000000000..00bf32fc78effbb635570ffa919e96af69e561ee --- /dev/null +++ b/go/src/cmd/go/testdata/script/get_insecure_no_longer_supported.txt @@ -0,0 +1,13 @@ +# GOPATH: Set up +env GO111MODULE=off + +# GOPATH: Fetch with insecure, should error +! go get -insecure test +stderr 'go: -insecure flag is no longer supported; use GOINSECURE instead' + +# Modules: Set up +env GO111MODULE=on + +# Modules: Fetch with insecure, should error +! go get -insecure test +stderr 'go: -insecure flag is no longer supported; use GOINSECURE instead' diff --git a/go/src/cmd/go/testdata/script/get_issue53955.txt b/go/src/cmd/go/testdata/script/get_issue53955.txt new file mode 100644 index 0000000000000000000000000000000000000000..685c6facaa93b7222964acf6c9b5a3eba06d3b7d --- /dev/null +++ b/go/src/cmd/go/testdata/script/get_issue53955.txt @@ -0,0 +1,79 @@ +# Regression test for https://go.dev/issue/53955. +# New remote tags were erroneously added to the local clone of a repo +# only *after* extracting version information for a locally-cached commit, +# causing the version information to have incomplete Tags and Version fields. + +[short] skip 'constructs a local git repo' +[!git] skip +[!net:github.com] skip 'does not actually use github.com because of insteadOf, but silence network check just in case' + +# Redirect git to a test-specific .gitconfig. +# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer. +# For older git versions we also set $HOME. +env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig +env HOME=$WORK${/}home${/}gopher +exec git config --global --show-origin user.name +stdout 'Go Gopher' + +# Inject a local repo in place of a remote one, so that we can +# add commits to the repo partway through the test. +env GIT_ALLOW_PROTOCOL=file +env GOPRIVATE=github.com/golang/issue53955 + +[!GOOS:windows] exec git config --global 'url.file://'$WORK'/repo.insteadOf' 'https://github.com/golang/issue53955' +[GOOS:windows] exec git config --global 'url.file:///'$WORK'/repo.insteadOf' 'https://github.com/golang/issue53955' + +cd $WORK/repo + +env GIT_AUTHOR_NAME='Go Gopher' +env GIT_AUTHOR_EMAIL='gopher@golang.org' +env GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME +env GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL + +exec git init + +env GIT_COMMITTER_DATE=2022-07-19T11:07:00-04:00 +env GIT_AUTHOR_DATE=2022-07-19T11:07:00-04:00 +exec git add go.mod issue53955.go +exec git commit -m 'initial commit' +exec git branch -m main +exec git tag v1.0.9 + +env GIT_COMMITTER_DATE=2022-07-19T11:07:01-04:00 +env GIT_AUTHOR_DATE=2022-07-19T11:07:01-04:00 +exec git add extra.go +exec git commit -m 'next commit' +exec git show-ref --tags --heads +cmp stdout $WORK/.git-refs-1 + +cd $WORK/m +go get -x github.com/golang/issue53955@2cb3d49f +stderr '^go: added github.com/golang/issue53955 v1.0.10-0.20220719150701-2cb3d49f8874$' + +cd $WORK/repo +exec git tag v1.0.10 + +cd $WORK/m +go get -x github.com/golang/issue53955@v1.0.10 +! stderr 'v1\.0\.10 is not a tag' +stderr '^go: upgraded github.com/golang/issue53955 v.* => v1\.0\.10$' + +-- $WORK/repo/go.mod -- +module github.com/golang/issue53955 + +go 1.18 +-- $WORK/repo/issue53955.go -- +package issue53955 +-- $WORK/repo/extra.go -- +package issue53955 +-- $WORK/.git-refs-1 -- +2cb3d49f8874b9362ed0ddd2a6512e4108bbf6b1 refs/heads/main +050526ebf5883191e990529eb3cc9345abaf838c refs/tags/v1.0.9 +-- $WORK/m/go.mod -- +module m + +go 1.18 +-- $WORK/home/gopher/.gitconfig -- +[user] + name = Go Gopher + email = gopher@golang.org diff --git a/go/src/cmd/go/testdata/script/get_panic_issue75251.txt b/go/src/cmd/go/testdata/script/get_panic_issue75251.txt new file mode 100644 index 0000000000000000000000000000000000000000..2cc3f3a9c45caa44e5353659004e36c931d59403 --- /dev/null +++ b/go/src/cmd/go/testdata/script/get_panic_issue75251.txt @@ -0,0 +1,16 @@ +# Issue #75251: Don't panic if the package path or the package version +# contains invalid UTF-8 characters. + +go mod init m + +! go get golang.org/x/net/http/httpgutsÿv0.43.0 # contains 0xff byte +! stderr panic +stderr 'malformed module path' + +! go get golang.org/x/net/http/httpgutsÿ@v0.43.0 # contains 0xff byte +! stderr panic +stderr 'malformed module path' + +! go get golang.org/x/net/http/httpguts@ÿv0.43.0 # contains 0xff byte +! stderr panic +stderr 'disallowed version string' diff --git a/go/src/cmd/go/testdata/script/go_badcmd.txt b/go/src/cmd/go/testdata/script/go_badcmd.txt new file mode 100644 index 0000000000000000000000000000000000000000..661375adc66a2784003c530db224af466ad25df5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/go_badcmd.txt @@ -0,0 +1,2 @@ +! go asdf +stderr '^go asdf: unknown command' diff --git a/go/src/cmd/go/testdata/script/go_version.txt b/go/src/cmd/go/testdata/script/go_version.txt new file mode 100644 index 0000000000000000000000000000000000000000..1a787e1b18c1dd9265e6f2ed29f0871ce98f26d8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/go_version.txt @@ -0,0 +1,9 @@ +# test that go version doesn't panic on non-go binaries +# See Issue #49181 + +[exec:/bin/true] cp /bin/true true +[exec:C:\windows\system32\help.exe] cp C:\windows\system32\help.exe help.exe + +go version -m . +! stdout . +! stderr . diff --git a/go/src/cmd/go/testdata/script/goauth_git.txt b/go/src/cmd/go/testdata/script/goauth_git.txt new file mode 100644 index 0000000000000000000000000000000000000000..37c9b19a0458060e14ba90633b622ef157893b1c --- /dev/null +++ b/go/src/cmd/go/testdata/script/goauth_git.txt @@ -0,0 +1,74 @@ +# This test covers the HTTP authentication mechanism over GOAUTH +# See golang.org/issue/26232 + +[short] skip 'constructs a local git repo' +[!git] skip + +env GOPROXY=direct +env GOSUMDB=off +# Disable 'git credential fill' interactive prompts. +env GIT_TERMINAL_PROMPT=0 +exec git init +exec git config credential.helper 'store --file=.git-credentials' +cp go.mod.orig go.mod + +# Set GOAUTH to git without a working directory. +env GOAUTH='git' +! go get vcs-test.golang.org/auth/or401 +stderr 'GOAUTH=git dir method requires an absolute path to the git working directory' + +# Set GOAUTH to git with a non-existent directory. +env GOAUTH='git gitDir' +! go get vcs-test.golang.org/auth/or401 +stderr 'GOAUTH=git dir method requires an absolute path to the git working directory' + +# Set GOAUTH to git with a relative working directory. +mkdir relative +env GOAUTH='git relative' +! go get vcs-test.golang.org/auth/or401 +stderr 'GOAUTH=git dir method requires an absolute path to the git working directory' + +# Set GOAUTH to git and use a blank .git-credentials. +# Without credentials, downloading a module from a path that requires HTTPS +# basic auth should fail. +env GOAUTH=git' '$PWD'' +! go get -x vcs-test.golang.org/auth/or401 +stderr '^\tserver response: ACCESS DENIED, buddy$' +stderr 'GOAUTH encountered errors for https://vcs-test.golang.org' +stderr GOAUTH=git' '$PWD'' +# go imports should fail as well. +! go mod tidy -x +stderr '^\tserver response: File\? What file\?$' +stderr 'GOAUTH encountered errors for https://vcs-test.golang.org' +stderr GOAUTH=git' '$PWD'' + +# With credentials from git credentials, it should succeed. +cp .git-credentials.cred .git-credentials +go get vcs-test.golang.org/auth/or401 +# go imports should resolve correctly as well. +go mod tidy +go list all +stdout vcs-test.golang.org/auth/or404 +# With cached credentials, re-downloading in debug mode should succeed. +go get -x vcs-test.golang.org/auth/or401 + +# Clearing GOAUTH credentials should result in failures. +env GOAUTH='off' +# Without credentials, downloading a module from a path that requires HTTPS +# basic auth should fail. +! go get vcs-test.golang.org/auth/or401 +stderr '^\tserver response: ACCESS DENIED, buddy$' +# go imports should fail as well. +cp go.mod.orig go.mod +! go mod tidy +stderr '^\tserver response: File\? What file\?$' + +-- main.go -- +package useprivate + +import "vcs-test.golang.org/auth/or404" +-- go.mod.orig -- +module private.example.com +-- .git-credentials -- +-- .git-credentials.cred -- +https://aladdin:opensesame@vcs-test.golang.org diff --git a/go/src/cmd/go/testdata/script/goauth_netrc.txt b/go/src/cmd/go/testdata/script/goauth_netrc.txt new file mode 100644 index 0000000000000000000000000000000000000000..0baa09de1ecaf9cf559531111b9677996b2d8328 --- /dev/null +++ b/go/src/cmd/go/testdata/script/goauth_netrc.txt @@ -0,0 +1,79 @@ +# This test exercises the GOAUTH mechanism for specifying +# credentials passed in HTTPS requests to VCS servers. +# See golang.org/issue/26232 + +env GOPROXY=direct +env GOSUMDB=off + +# GOAUTH should default to netrc behavior. +# Without credentials, downloading a module from a path that requires HTTPS +# basic auth should fail. +# Override default location of $HOME/.netrc +env NETRC=$WORK/empty +! go get vcs-test.golang.org/auth/or401 +stderr '^\tserver response: ACCESS DENIED, buddy$' + +# With credentials from a netrc file, it should succeed. +env NETRC=$WORK/netrc +go get vcs-test.golang.org/auth/or401 + +# GOAUTH=off should result in failures. +env GOAUTH='off' +# Without credentials, downloading a module from a path that requires HTTPS +# basic auth should fail. +env NETRC=$WORK/empty +! go get vcs-test.golang.org/auth/or401 +stderr '^\tserver response: ACCESS DENIED, buddy$' + +# GOAUTH='off' should ignore credentials from a valid netrc file. +env GOAUTH='off' +env NETRC=$WORK/netrc +! go get vcs-test.golang.org/auth/or401 +stderr '^\tserver response: ACCESS DENIED, buddy$' + +# GOAUTH=off cannot be combined with other authentication commands +env GOAUTH='off; netrc' +env NETRC=$WORK/netrc +! go get vcs-test.golang.org/auth/or401 +stderr 'GOAUTH=off cannot be combined with other authentication commands \(GOAUTH=off; netrc\)' + +# An unset GOAUTH should default to netrc. +env GOAUTH= +# Without credentials, downloading a module from a path that requires HTTPS +# basic auth should fail. +env NETRC=$WORK/empty +! go get vcs-test.golang.org/auth/or401 +stderr '^\tserver response: ACCESS DENIED, buddy$' + +# With credentials from a netrc file, it should succeed. +env NETRC=$WORK/netrc +go get vcs-test.golang.org/auth/or401 + +# A missing file should be fail as well. +env NETRC=$WORK/missing +! go get vcs-test.golang.org/auth/or401 +stderr '^\tserver response: ACCESS DENIED, buddy$' + +[short] skip 'requires a remote vcs lookup' +[!git] skip +# An unset home directory should warn the user but not cause a failure. +env NETRC= +env HOME= +env USERPROFILE= +env home= +go get -x vcs-test.golang.org/git/emptytest.git +[!GOOS:windows] [!GOOS:plan9] stderr 'GOAUTH=netrc: \$HOME is not defined' +[GOOS:windows] stderr 'GOAUTH=netrc: \%userprofile\% is not defined' +[GOOS:plan9] stderr 'GOAUTH=netrc: \$home is not defined' + +-- go.mod -- +module private.example.com +-- $WORK/empty -- +-- $WORK/netrc -- +machine vcs-test.golang.org + login aladdin + password opensesame +# first one should override this one +machine vcs-test.golang.org + login aladdin + password ignored diff --git a/go/src/cmd/go/testdata/script/goauth_userauth.txt b/go/src/cmd/go/testdata/script/goauth_userauth.txt new file mode 100644 index 0000000000000000000000000000000000000000..f70933cf585753e41bd602d4da248d2ea3b28b29 --- /dev/null +++ b/go/src/cmd/go/testdata/script/goauth_userauth.txt @@ -0,0 +1,137 @@ +# This test covers the HTTP authentication mechanism over GOAUTH by using a custom authenticator. +# See golang.org/issue/26232 + +[short] skip 'runs build to create authenticators' + +env GOPROXY=direct +env GOSUMDB=off +mkdir $WORK/bin +env PATH=$WORK/bin${:}$PATH + +# Without credentials, downloading a module from a path that requires HTTPS +# basic auth should fail. +env GOAUTH=off +cp go.mod.orig go.mod +! go get vcs-test.golang.org/auth/or401 +stderr '^\tserver response: ACCESS DENIED, buddy$' +# go imports should fail as well. +! go mod tidy +stderr '^\tserver response: ACCESS DENIED, buddy$' + +# Initial invocation of authenticator is successful. +go build -o $WORK/bin/basic$GOEXE scripts/basic.go +# With credentials from the binary, it should succeed. +env GOAUTH='basic'$GOEXE +cp go.mod.orig go.mod +go get vcs-test.golang.org/auth/or401 +# go imports should resolve correctly as well. +go mod tidy +go list all +stdout vcs-test.golang.org/auth/or401 + +# Second invocation of authenticator is successful. +go build -o $WORK/bin/reinvocation$GOEXE scripts/reinvocation.go +# With credentials from the binary, it should succeed. +env GOAUTH='reinvocation'$GOEXE +cp go.mod.orig go.mod +go get vcs-test.golang.org/auth/or401 +# go imports should resolve correctly as well. +go mod tidy +go list all +stdout vcs-test.golang.org/auth/or401 + +# Authenticator can parse arguments correctly. +go build -o $WORK/bin/arguments$GOEXE scripts/arguments.go +# With credentials from the binary, it should succeed. +env GOAUTH='arguments'$GOEXE' --arg1 "value with spaces"' +cp go.mod.orig go.mod +go get vcs-test.golang.org/auth/or401 +# go imports should resolve correctly as well. +go mod tidy +go list all +stdout vcs-test.golang.org/auth/or401 + +# Authenticator provides bad credentials. +go build -o $WORK/bin/invalid$GOEXE scripts/invalid.go +# With credentials from the binary, it should fail. +env GOAUTH='invalid'$GOEXE +cp go.mod.orig go.mod +! go get vcs-test.golang.org/auth/or401 +stderr '^\tserver response: ACCESS DENIED, buddy$' +# go imports should fail as well. +! go mod tidy +stderr '^\tserver response: ACCESS DENIED, buddy$' + +-- go.mod.orig -- +module private.example.com +-- main.go -- +package useprivate + +import "vcs-test.golang.org/auth/or401" +-- scripts/basic.go -- +package main + +import "fmt" + +func main() { + fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l\n\n") +} +-- scripts/reinvocation.go -- +package main + +import( + "bufio" + "flag" + "fmt" + "io" + "log" + "net/http" + "os" + "strings" +) + +func main() { + flag.Parse() + // wait for re-invocation + if !strings.HasPrefix(flag.Arg(0), "https://vcs-test.golang.org") { + return + } + input, err := io.ReadAll(os.Stdin) + if err != nil { + log.Fatal("unexpected error while reading from stdin") + } + reader := bufio.NewReader(strings.NewReader(string(input))) + resp, err := http.ReadResponse(reader, nil) + if err != nil { + log.Fatal("could not parse HTTP response") + } + if resp.StatusCode != 401 { + log.Fatal("expected 401 error code") + } + fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l\n\n") +} +-- scripts/arguments.go -- +package main + +import( + "flag" + "fmt" + "log" +) + +func main() { + arg1 := flag.String("arg1", "", "") + flag.Parse() + if *arg1 != "value with spaces" { + log.Fatal("argument with spaces does not work") + } + fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l\n\n") +} +-- scripts/invalid.go -- +package main + +import "fmt" + +func main() { + fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic invalid\n\n") +} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/godebug_decoratemappings_124.txt b/go/src/cmd/go/testdata/script/godebug_decoratemappings_124.txt new file mode 100644 index 0000000000000000000000000000000000000000..19b466c5d6941af0896f2a335e02d8611dc76077 --- /dev/null +++ b/go/src/cmd/go/testdata/script/godebug_decoratemappings_124.txt @@ -0,0 +1,37 @@ +env GO111MODULE=on + +# Go 1.24 module should disable decoratemappings. +go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' +stdout decoratemappings=0 + +[!GOOS:linux] skip +[short] skip + +# Programs in Go 1.24 module should never see annotations. This ensures that +# the runtime has not overridden the default. +go run . + +-- go.mod -- +go 1.24 +module m + +-- main.go -- +package main + +import ( + "log" + "os" + "strings" +) + +func main() { + b, err := os.ReadFile("/proc/self/maps") + if err != nil { + log.Fatalf("Error reading: %v", err) + } + + if strings.Contains(string(b), "[anon: Go:") { + log.Printf("/proc/self/maps:\n%s", string(b)) + log.Fatalf("/proc/self/maps contains Go annotation") + } +} diff --git a/go/src/cmd/go/testdata/script/godebug_decoratemappings_comment.txt b/go/src/cmd/go/testdata/script/godebug_decoratemappings_comment.txt new file mode 100644 index 0000000000000000000000000000000000000000..7568812e37b3062284e5644926380316dae40193 --- /dev/null +++ b/go/src/cmd/go/testdata/script/godebug_decoratemappings_comment.txt @@ -0,0 +1,34 @@ +env GO111MODULE=on + +[!GOOS:linux] skip +[short] skip + +# Programs with //go:debug decoratemappings=0 should never see annotations. +# This ensures that the runtime has not overridden the default. +go run . + +-- go.mod -- +go 1.25 +module m + +-- main.go -- +//go:debug decoratemappings=1 +package main + +import ( + "log" + "os" + "strings" +) + +func main() { + b, err := os.ReadFile("/proc/self/maps") + if err != nil { + log.Fatalf("Error reading: %v", err) + } + + if strings.Contains(string(b), "[anon: Go:") { + log.Printf("/proc/self/maps:\n%s", string(b)) + log.Fatalf("/proc/self/maps contains Go annotation") + } +} diff --git a/go/src/cmd/go/testdata/script/godebug_default.txt b/go/src/cmd/go/testdata/script/godebug_default.txt new file mode 100644 index 0000000000000000000000000000000000000000..fecdcdb6b55c39fafa7f5bdf63f625251755ab6d --- /dev/null +++ b/go/src/cmd/go/testdata/script/godebug_default.txt @@ -0,0 +1,156 @@ +env GO111MODULE=on +env GOTRACEBACK=single + +# Go 1.21 work module should leave panicnil with an implicit default. +cp go.mod.21 go.mod +go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' +! stdout panicnil +stdout randautoseed=0 + +# Go 1.21 work module should NOT set panicnil=1 in Go 1.20 dependency. +cp go.mod.21 go.mod +go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' q +! stdout panicnil=1 +! stdout randautoseed + +go mod download rsc.io/panicnil # for go.sum +go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' rsc.io/panicnil +! stdout panicnil=1 +! stdout randautoseed + +# Go 1.20 work module should set panicnil=1. +cp go.mod.20 go.mod +go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' +stdout panicnil=1 +stdout randautoseed=0 + +# Go 1.20 work module should set panicnil=1 in Go 1.20 dependency. +cp go.mod.20 go.mod +go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' q +stdout panicnil=1 +! stdout randautoseed + +# Go 1.21 workspace should leave panicnil with an implicit default. +cat q/go.mod +cp go.work.21 go.work +go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' +! stdout panicnil +stdout randautoseed=0 +rm go.work + +# Go 1.20 workspace with Go 1.21 module cannot happen. +cp go.work.20 go.work +cp go.mod.21 go.mod +! go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' +stderr 'go: module . listed in go.work file requires go >= 1.21' +rm go.work + +# Go 1.21 go.mod with godebug default=go1.20 +rm go.work +cp go.mod.21 go.mod +go mod edit -godebug default=go1.20 -godebug asynctimerchan=0 +go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' +stdout panicnil=1 +stdout asynctimerchan=0 + +# Go 1.21 go.work with godebug default=go1.20 +cp go.work.21 go.work +go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' +! stdout panicnil # go.work wins +stdout asynctimerchan=1 # go.work wins +go work edit -godebug default=go1.20 -godebug asynctimerchan=0 +go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' +stdout panicnil=1 +stdout asynctimerchan=0 +rm go.work + +# Go 1.21 go.mod with //go:debug default=go1.20 in program +cp go.mod.21 go.mod +go list -tags godebug -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' +stdout panicnil=1 +stdout asynctimerchan=0 + +# Invalid //go:debug line should be diagnosed at build. +! go build -tags godebugbad +stderr 'invalid //go:debug: value contains space' + +[short] skip + +# Programs in Go 1.21 work module should trigger run-time error. +cp go.mod.21 go.mod +! go run . +stderr 'panic: panic called with nil argument' + +! go run rsc.io/panicnil +stderr 'panic: panic called with nil argument' + +# Programs in Go 1.20 work module use old panic nil behavior. +cp go.mod.20 go.mod +! go run . +stderr 'panic: nil' + +! go run rsc.io/panicnil +stderr 'panic: nil' + +# Programs in no module at all should use their go.mod file. +rm go.mod +! go run rsc.io/panicnil@v1.0.0 +stderr 'panic: nil' + +rm go.mod +! go run rsc.io/panicnil@v1.1.0 +stderr 'panic: panic called with nil argument' + +-- go.work.21 -- +go 1.21 +use . +use ./q + +-- go.work.20 -- +go 1.20 +use . +use ./q + +-- go.mod.21 -- +go 1.21 +module m +require q v1.0.0 +replace q => ./q +require rsc.io/panicnil v1.0.0 + +-- go.mod.20 -- +go 1.20 +module m +require q v1.0.0 +replace q => ./q +require rsc.io/panicnil v1.0.0 + +-- p.go -- +//go:debug randautoseed=0 + +package main + +func main() { + panic(nil) +} + +-- godebug.go -- +//go:build godebug +//go:debug default=go1.20 +//go:debug asynctimerchan=0 + +package main + +-- godebugbad.go -- +//go:build godebugbad +//go:debug default=go1.20 asynctimerchan=0 + +package main + +-- q/go.mod -- +go 1.20 +module q + +-- q/q.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/godebug_unknown.txt b/go/src/cmd/go/testdata/script/godebug_unknown.txt new file mode 100644 index 0000000000000000000000000000000000000000..57dacbcbc5ad8eebc5e84dddacffa6772abb72f5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/godebug_unknown.txt @@ -0,0 +1,9 @@ +! go build +stderr 'p.go:1:1: invalid //go:debug: unknown //go:debug setting "x"' + +-- go.mod -- +module m +-- p.go -- +//go:debug x=y +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/goflags.txt b/go/src/cmd/go/testdata/script/goflags.txt new file mode 100644 index 0000000000000000000000000000000000000000..112086059ce0e57bdea7c08b2c0e132d4c4d7d8d --- /dev/null +++ b/go/src/cmd/go/testdata/script/goflags.txt @@ -0,0 +1,64 @@ +env GO111MODULE=off + +# GOFLAGS sets flags for commands + +env GOFLAGS='-e -f={{.Dir}} --test.benchtime=1s -count=10' +go list asdfasdfasdf # succeeds because of -e +go list runtime +stdout '[\\/]runtime$' + +env GOFLAGS=-race OLDGOARCH=$GOARCH OLDGOOS=$GOOS GOARCH=386 GOOS=linux +! go list runtime +stderr 'race is not supported on linux/386' + +env GOARCH=$OLDGOARCH GOOS=$OLDGOOS + +# go env succeeds even though -f={{.Dir}} is inappropriate +go env + +# bad flags are diagnosed +env GOFLAGS=-typoflag +! go list runtime +stderr 'unknown flag -typoflag' + +env GOFLAGS=- +! go list runtime +stderr '^go: parsing \$GOFLAGS: non-flag "-"' + +env GOFLAGS=-- +! go list runtime +stderr '^go: parsing \$GOFLAGS: non-flag "--"' + +env GOFLAGS=---oops +! go list runtime +stderr '^go: parsing \$GOFLAGS: non-flag "---oops"' + +env GOFLAGS=-=noname +! go list runtime +stderr '^go: parsing \$GOFLAGS: non-flag "-=noname"' + +env GOFLAGS=-f +! go list runtime +stderr '^go: flag needs an argument: -f \(from (\$GOFLAGS|%GOFLAGS%)\)$' + +env GOFLAGS=-e=asdf +! go list runtime +stderr '^go: invalid boolean value \"asdf\" for flag -e \(from (\$GOFLAGS|%GOFLAGS%)\)' + +# except in go bug (untested) and go env +go env +stdout GOFLAGS + +# Flags listed in GOFLAGS should be safe to duplicate on the command line. +env GOFLAGS=-tags=magic +go list -tags=magic +go test -tags=magic -c -o $devnull +go vet -tags=magic + +# GOFLAGS uses the same quoting rules (quoted.Split) as the rest of +# the go command env variables +env GOFLAGS='"-tags=magic wizardry"' +go list + +-- foo_test.go -- +package foo diff --git a/go/src/cmd/go/testdata/script/goline_order.txt b/go/src/cmd/go/testdata/script/goline_order.txt new file mode 100644 index 0000000000000000000000000000000000000000..6212cd64eb18b7320d66b8a59e75a4a1258f944c --- /dev/null +++ b/go/src/cmd/go/testdata/script/goline_order.txt @@ -0,0 +1,74 @@ +# Check that go lines are always >= go lines of dependencies. + +# Using too old a release cannot even complete module load. +env TESTGO_VERSION=go1.21.1 +env TESTGO_VERSION_SWITCH=switch +cp go.mod go.mod.orig + +# If the offending module is not imported, it's not detected. +go list +cmp go.mod go.mod.orig + +# Adding the import produces the error. +# Maybe this should auto-switch, but it requires more plumbing to get this error through, +# and it's a misconfigured system that should not arise in practice, so not switching is fine. +! go list -deps -tags usem1 +cmp go.mod go.mod.orig +stderr '^go: module ./m1 requires go >= 1.21.2 \(running go 1.21.1\)$' + +# go get go@1.21.2 fixes the error. +cp go.mod.orig go.mod +go get go@1.21.2 +go list -deps -tags usem1 + +# go get -tags usem1 fixes the error. +cp go.mod.orig go.mod +go get -tags usem1 +go list -deps -tags usem1 + +# go get fixes the error. +cp go.mod.orig go.mod +go get +go list -deps -tags usem1 + +# Using a new enough release reports the error after module load and suggests 'go mod tidy' +env TESTGO_VERSION=go1.21.2 +cp go.mod.orig go.mod +! go list -deps -tags usem1 +stderr 'updates to go.mod needed' +stderr 'go mod tidy' +go mod tidy +go list -deps -tags usem1 + +# go get also works +cp go.mod.orig go.mod +! go list -deps -tags usem1 +stderr 'updates to go.mod needed' +stderr 'go mod tidy' +go get go@1.21.2 +go list -deps -tags usem1 + + +-- go.mod -- +module m +go 1.21.1 + +require m1 v0.0.1 + +replace m1 => ./m1 + +-- m1/go.mod -- +go 1.21.2 + +-- p.go -- +//go:build usem1 + +package p + +import _ "m1" + +-- p1.go -- +package p + +-- m1/p.go -- +package p diff --git a/go/src/cmd/go/testdata/script/gopath_install.txt b/go/src/cmd/go/testdata/script/gopath_install.txt new file mode 100644 index 0000000000000000000000000000000000000000..6c572eae619f067eac3ec44681314e1706a851f9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/gopath_install.txt @@ -0,0 +1,53 @@ +# Regression test for 'go install' locations in GOPATH mode. +env GO111MODULE=off +[short] skip + +# Without $GOBIN set, binaries should be installed into the GOPATH bin directory. +env GOBIN= +rm $GOPATH/bin/go-cmd-test$GOEXE +go install go-cmd-test +exists $GOPATH/bin/go-cmd-test$GOEXE + +# With $GOBIN set, binaries should be installed to $GOBIN. +env GOBIN=$WORK/bin1 +mkdir -p $GOBIN +go install go-cmd-test +exists $GOBIN/go-cmd-test$GOEXE + +# Issue 11065: installing to the current directory should create an executable. +cd go-cmd-test +env GOBIN=$PWD +go install +exists ./go-cmd-test$GOEXE +cd .. + +# Without $GOBIN set, installing a program outside $GOPATH should fail +# (there is nowhere to install it). +env GOPATH= # reset to default ($HOME/go, which does not exist) +env GOBIN= +! go install go-cmd-test/helloworld.go +stderr '^go: no install location for \.go files listed on command line \(GOBIN not set\)$' + +# With $GOBIN set, should install there. +env GOBIN=$WORK/bin1 +go install go-cmd-test/helloworld.go +exists $GOBIN/helloworld$GOEXE + +# We can't assume that we can write to GOROOT, because it may not be writable. +# However, we can check its install location using 'go list'. +# cmd/fix should be installed to GOROOT/pkg, not GOPATH/bin. +env GOPATH=$PWD +go list -f '{{.Target}}' cmd/fix +stdout $GOROOT'[/\\]pkg[/\\]tool[/\\]'$GOOS'_'$GOARCH'[/\\]fix'$GOEXE'$' + +# GOBIN should not affect toolchain install locations. +env GOBIN=$WORK/bin1 +go list -f '{{.Target}}' cmd/fix +stdout $GOROOT'[/\\]pkg[/\\]tool[/\\]'$GOOS'_'$GOARCH'[/\\]fix'$GOEXE'$' + +-- go-cmd-test/helloworld.go -- +package main + +func main() { + println("hello world") +} diff --git a/go/src/cmd/go/testdata/script/gopath_local.txt b/go/src/cmd/go/testdata/script/gopath_local.txt new file mode 100644 index 0000000000000000000000000000000000000000..efde0e707f4779761f8084d0b9a968de5b80bfee --- /dev/null +++ b/go/src/cmd/go/testdata/script/gopath_local.txt @@ -0,0 +1,117 @@ +env GO111MODULE=off # Relative imports only work in GOPATH mode. + +[short] skip + +# Imports should be resolved relative to the source file. +go build testdata/local/easy.go +exec ./easy$GOEXE +stdout '^easysub\.Hello' + +# Ignored files should be able to import the package built from +# non-ignored files in the same directory. +go build -o easysub$GOEXE testdata/local/easysub/main.go +exec ./easysub$GOEXE +stdout '^easysub\.Hello' + +# Files in relative-imported packages should be able to +# use relative imports themselves. +go build testdata/local/hard.go +exec ./hard$GOEXE +stdout '^sub\.Hello' + +# Explicit source files listed on the command line should not install without +# GOBIN set, since individual source files aren't part of the containing GOPATH. +! go install testdata/local/easy.go +stderr '^go: no install location for \.go files listed on command line \(GOBIN not set\)$' + +[GOOS:windows] stop # Windows does not allow the ridiculous directory name we're about to use. + +env BAD_DIR_NAME='#$%:, &()*;<=>?\^{}' + +mkdir -p testdata/$BAD_DIR_NAME/easysub +mkdir -p testdata/$BAD_DIR_NAME/sub/sub + +cp testdata/local/easy.go testdata/$BAD_DIR_NAME/easy.go +cp testdata/local/easysub/easysub.go testdata/$BAD_DIR_NAME/easysub/easysub.go +cp testdata/local/easysub/main.go testdata/$BAD_DIR_NAME/easysub/main.go +cp testdata/local/hard.go testdata/$BAD_DIR_NAME/hard.go +cp testdata/local/sub/sub.go testdata/$BAD_DIR_NAME/sub/sub.go +cp testdata/local/sub/sub/subsub.go testdata/$BAD_DIR_NAME/sub/sub/subsub.go + +# Imports should be resolved relative to the source file. +go build testdata/$BAD_DIR_NAME/easy.go +exec ./easy$GOEXE +stdout '^easysub\.Hello' + +# Ignored files should be able to import the package built from +# non-ignored files in the same directory. +go build -o easysub$GOEXE testdata/$BAD_DIR_NAME/easysub/main.go +exec ./easysub$GOEXE +stdout '^easysub\.Hello' + +# Files in relative-imported packages should be able to +# use relative imports themselves. +go build testdata/$BAD_DIR_NAME/hard.go +exec ./hard$GOEXE +stdout '^sub\.Hello' + +# Explicit source files listed on the command line should not install without +# GOBIN set, since individual source files aren't part of the containing GOPATH. +! go install testdata/$BAD_DIR_NAME/easy.go +stderr '^go: no install location for \.go files listed on command line \(GOBIN not set\)$' + +-- testdata/local/easy.go -- +package main + +import "./easysub" + +func main() { + easysub.Hello() +} +-- testdata/local/easysub/easysub.go -- +package easysub + +import "fmt" + +func Hello() { + fmt.Println("easysub.Hello") +} +-- testdata/local/easysub/main.go -- +// +build ignore + +package main + +import "." + +func main() { + easysub.Hello() +} +-- testdata/local/hard.go -- +package main + +import "./sub" + +func main() { + sub.Hello() +} +-- testdata/local/sub/sub.go -- +package sub + +import ( + "fmt" + + subsub "./sub" +) + +func Hello() { + fmt.Println("sub.Hello") + subsub.Hello() +} +-- testdata/local/sub/sub/subsub.go -- +package subsub + +import "fmt" + +func Hello() { + fmt.Println("subsub.Hello") +} diff --git a/go/src/cmd/go/testdata/script/gopath_paths.txt b/go/src/cmd/go/testdata/script/gopath_paths.txt new file mode 100644 index 0000000000000000000000000000000000000000..04265b176f57f15dc3d4ff4b527ad41125644e15 --- /dev/null +++ b/go/src/cmd/go/testdata/script/gopath_paths.txt @@ -0,0 +1,43 @@ +# Regression test for GOPATH validation in GOPATH mode. +env GO111MODULE=off + +env ORIG_GOPATH=$GOPATH + +# The literal path '.' in GOPATH should be rejected. +env GOPATH=. +! go build go-cmd-test/helloworld.go +stderr 'GOPATH entry is relative' + +# It should still be rejected if the requested package can be +# found using another entry. +env GOPATH=${:}$ORIG_GOPATH${:}. +! go build go-cmd-test +stderr 'GOPATH entry is relative' + +# GOPATH cannot be a relative subdirectory of the working directory. +env ORIG_GOPATH +stdout 'ORIG_GOPATH='$WORK[/\\]gopath +cd $WORK +env GOPATH=gopath +! go build gopath/src/go-cmd-test/helloworld.go +stderr 'GOPATH entry is relative' + +# Blank paths in GOPATH should be rejected as relative (issue 21928). +env GOPATH=' '${:}$ORIG_GOPATH +! go build go-cmd-test +stderr 'GOPATH entry is relative' + +[short] stop + +# Empty paths in GOPATH should be ignored (issue 21928). +env GOPATH=${:}$ORIG_GOPATH +env GOPATH +go install go-cmd-test +exists $ORIG_GOPATH/bin/go-cmd-test$GOEXE + +-- go-cmd-test/helloworld.go -- +package main + +func main() { + println("hello world") +} diff --git a/go/src/cmd/go/testdata/script/gopath_std_vendor.txt b/go/src/cmd/go/testdata/script/gopath_std_vendor.txt new file mode 100644 index 0000000000000000000000000000000000000000..4aaf46b5d0f0dc55335ea648469dd716488241fa --- /dev/null +++ b/go/src/cmd/go/testdata/script/gopath_std_vendor.txt @@ -0,0 +1,44 @@ +env GO111MODULE=off + +[!compiler:gc] skip + +go list -f '{{.Dir}}' vendor/golang.org/x/net/http2/hpack +stdout $GOPATH[/\\]src[/\\]vendor + +# A package importing 'net/http' should resolve its dependencies +# to the package 'vendor/golang.org/x/net/http2/hpack' within GOROOT. +cd importnethttp +go list -deps -f '{{.ImportPath}} {{.Dir}}' +stdout ^vendor/golang.org/x/net/http2/hpack +stdout $GOROOT[/\\]src[/\\]vendor[/\\]golang.org[/\\]x[/\\]net[/\\]http2[/\\]hpack +! stdout $GOPATH[/\\]src[/\\]vendor + +# In the presence of $GOPATH/src/vendor/golang.org/x/net/http2/hpack, +# a package in GOPATH importing 'golang.org/x/net/http2/hpack' should +# resolve its dependencies in GOPATH/src. +cd ../issue16333 +go build . + +go list -deps -f '{{.ImportPath}} {{.Dir}}' . +stdout $GOPATH[/\\]src[/\\]vendor[/\\]golang.org[/\\]x[/\\]net[/\\]http2[/\\]hpack +! stdout $GOROOT[/\\]src[/\\]vendor + +go list -test -deps -f '{{.ImportPath}} {{.Dir}}' . +stdout $GOPATH[/\\]src[/\\]vendor[/\\]golang.org[/\\]x[/\\]net[/\\]http2[/\\]hpack +! stdout $GOROOT[/\\]src[/\\]vendor + +-- issue16333/issue16333.go -- +package vendoring17 + +import _ "golang.org/x/net/http2/hpack" +-- issue16333/issue16333_test.go -- +package vendoring17 + +import _ "testing" +import _ "golang.org/x/net/http2/hpack" +-- importnethttp/http.go -- +package importnethttp + +import _ "net/http" +-- $GOPATH/src/vendor/golang.org/x/net/http2/hpack/hpack.go -- +package hpack diff --git a/go/src/cmd/go/testdata/script/gopath_vendor_dup_err.txt b/go/src/cmd/go/testdata/script/gopath_vendor_dup_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..5f1e09a88b90eabd799841ec0a64f1cea039cb6d --- /dev/null +++ b/go/src/cmd/go/testdata/script/gopath_vendor_dup_err.txt @@ -0,0 +1,24 @@ +env GO111MODULE=off + +# Issue 17119: Test more duplicate load errors. +! go build dupload +! stderr 'duplicate load|internal error' +stderr 'dupload/vendor/p must be imported as p' + +-- dupload/dupload.go -- +package main + +import ( + _ "dupload/p2" + _ "p" +) + +func main() {} +-- dupload/p/p.go -- +package p +-- dupload/p2/p2.go -- +package p2 + +import _ "dupload/vendor/p" +-- dupload/vendor/p/p.go -- +package p diff --git a/go/src/cmd/go/testdata/script/goroot_executable.txt b/go/src/cmd/go/testdata/script/goroot_executable.txt new file mode 100644 index 0000000000000000000000000000000000000000..ea0f920a3764c9d61bc71124fa1cbb6e58449141 --- /dev/null +++ b/go/src/cmd/go/testdata/script/goroot_executable.txt @@ -0,0 +1,108 @@ +[compiler:gccgo] skip +[short] skip 'builds and links another cmd/go' + +mkdir $WORK/new/bin + +# $GOROOT/bin/go is whatever the user has already installed +# (using make.bash or similar). We can't make assumptions about what +# options it may have been built with, such as -trimpath or not. +# Instead, we build a fresh copy of the binary with known settings. +go build -o $WORK/new/bin/go$GOEXE cmd/go & +go build -trimpath -o $WORK/bin/check$GOEXE check.go & +wait + +env TESTGOROOT=$GOROOT +env GOROOT= + +# Relocated Executable +exec $WORK/bin/check$GOEXE $WORK/new/bin/go$GOEXE $TESTGOROOT + +# Relocated Tree: +# If the binary is sitting in a bin dir next to ../pkg/tool, that counts as a GOROOT, +# so it should find the new tree. +mkdir $WORK/new/pkg/tool +exec $WORK/bin/check$GOEXE $WORK/new/bin/go$GOEXE $WORK/new + +[!symlink] stop 'The rest of the test cases require symlinks' + +# Symlinked Executable: +# With a symlink into go tree, we should still find the go tree. +mkdir $WORK/other/bin +symlink $WORK/other/bin/go$GOEXE -> $WORK/new/bin/go$GOEXE +exec $WORK/bin/check$GOEXE $WORK/new/bin/go$GOEXE $WORK/new + +rm $WORK/new/pkg + +# Runtime GOROOT: +# Binaries built in the new tree should report the +# new tree when they call runtime.GOROOT. +symlink $WORK/new/src -> $TESTGOROOT/src +symlink $WORK/new/pkg -> $TESTGOROOT/pkg +exec $WORK/new/bin/go$GOEXE run check_runtime_goroot.go $WORK/new + +-- check.go -- +package main + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" +) + +func main() { + exe := os.Args[1] + want := os.Args[2] + cmd := exec.Command(exe, "env", "GOROOT") + out, err := cmd.CombinedOutput() + if err != nil { + fmt.Fprintf(os.Stderr, "%s env GOROOT: %v, %s\n", exe, err, out) + os.Exit(1) + } + goroot, err := filepath.EvalSymlinks(strings.TrimSpace(string(out))) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + want, err = filepath.EvalSymlinks(want) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + if !strings.EqualFold(goroot, want) { + fmt.Fprintf(os.Stderr, "go env GOROOT:\nhave %s\nwant %s\n", goroot, want) + os.Exit(1) + } + fmt.Fprintf(os.Stderr, "go env GOROOT: %s\n", goroot) + +} +-- check_runtime_goroot.go -- +package main + +import ( + "fmt" + "os" + "path/filepath" + "runtime" + "strings" +) + +func main() { + goroot, err := filepath.EvalSymlinks(runtime.GOROOT()) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + want, err := filepath.EvalSymlinks(os.Args[1]) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + if !strings.EqualFold(goroot, want) { + fmt.Fprintf(os.Stderr, "go env GOROOT:\nhave %s\nwant %s\n", goroot, want) + os.Exit(1) + } + fmt.Fprintf(os.Stderr, "go env GOROOT: %s\n", goroot) + +} diff --git a/go/src/cmd/go/testdata/script/goroot_executable_trimpath.txt b/go/src/cmd/go/testdata/script/goroot_executable_trimpath.txt new file mode 100644 index 0000000000000000000000000000000000000000..6b859a6207d08941d5034bd843dc48a6fbc9cf9a --- /dev/null +++ b/go/src/cmd/go/testdata/script/goroot_executable_trimpath.txt @@ -0,0 +1,98 @@ +# Regression test for https://go.dev/issue/62119: +# A 'go' command cross-compiled with a different GOHOSTOS +# should be able to locate its GOROOT using os.Executable. +# +# (This also tests a 'go' command built with -trimpath +# that is not cross-compiled, since we need to build that +# configuration for the test anyway.) + +[short] skip 'builds and links another cmd/go' + +mkdir $WORK/new/bin +mkdir $WORK/new/bin/${GOOS}_${GOARCH} + +# In this test, we are specifically checking the logic for deriving +# the value of GOROOT from os.Executable when runtime.GOROOT is +# trimmed away. + +# $GOROOT/bin/go is whatever the user has already installed +# (using make.bash or similar). We can't make assumptions about what +# options it may have been built with, such as -trimpath or not. +# Instead, we build a fresh copy of the binary with known settings. +go build -trimpath -o $WORK/new/bin/go$GOEXE cmd/go & +go build -trimpath -o $WORK/bin/check$GOEXE check.go & +wait + +env TESTGOROOT=$GOROOT +env GOROOT= + +# Unset GOPATH and any variables that its default may be derived from, +# so that we can check for a spurious warning. +env GOPATH= +env HOME='' +env USERPROFILE='' +env home='' + +# Relocated Executable +# Since we built with -trimpath and the binary isn't installed in a +# normal-looking GOROOT, this command should fail. + +! exec $WORK/new/bin/go$GOEXE env GOROOT +stderr '^go: cannot find GOROOT directory: ''go'' binary is trimmed and GOROOT is not set$' +! stderr 'GOPATH set to GOROOT' + +# Cross-compiled binaries in cmd are installed to a ${GOOS}_${GOARCH} subdirectory, +# so we also want to try a copy there. +# (Note that the script engine's 'exec' engine already works around +# https://go.dev/issue/22315, so we don't have to do that explicitly in the +# 'check' program we use later.) +cp $WORK/new/bin/go$GOEXE $WORK/new/bin/${GOOS}_${GOARCH}/go$GOEXE +! exec $WORK/new/bin/${GOOS}_${GOARCH}/go$GOEXE env GOROOT +stderr '^go: cannot find GOROOT directory: ''go'' binary is trimmed and GOROOT is not set$' +! stderr 'GOPATH set to GOROOT' + +# Relocated Tree: +# If the binary is sitting in a bin dir next to ../pkg/tool, that counts as a GOROOT, +# so it should find the new tree. +mkdir $WORK/new/pkg/tool +exec $WORK/bin/check$GOEXE $WORK/new/bin/go$GOEXE $WORK/new +exec $WORK/bin/check$GOEXE $WORK/new/bin/${GOOS}_${GOARCH}/go$GOEXE $WORK/new +! stderr 'GOPATH set to GOROOT' + +-- check.go -- +package main + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" +) + +func main() { + exe := os.Args[1] + want := os.Args[2] + cmd := exec.Command(exe, "env", "GOROOT") + out, err := cmd.CombinedOutput() + if err != nil { + fmt.Fprintf(os.Stderr, "%s env GOROOT: %v, %s\n", exe, err, out) + os.Exit(1) + } + goroot, err := filepath.EvalSymlinks(strings.TrimSpace(string(out))) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + want, err = filepath.EvalSymlinks(want) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + if !strings.EqualFold(goroot, want) { + fmt.Fprintf(os.Stderr, "go env GOROOT:\nhave %s\nwant %s\n", goroot, want) + os.Exit(1) + } + fmt.Fprintf(os.Stderr, "go env GOROOT: %s\n", goroot) + +} diff --git a/go/src/cmd/go/testdata/script/gotoolchain_godebug_trace.txt b/go/src/cmd/go/testdata/script/gotoolchain_godebug_trace.txt new file mode 100644 index 0000000000000000000000000000000000000000..d98f62d165404482e70f09993b3b0053ce9ee2d9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/gotoolchain_godebug_trace.txt @@ -0,0 +1,122 @@ +# Test the GODEBUG=toolchaintrace behavior +# See https://go.dev/issue/63939 +env GODEBUG=toolchaintrace=1 +env TESTGO_VERSION=go1.21.0 +env TESTGO_VERSION_SWITCH=switch +env GOTOOLCHAIN=auto + +# Go line is newer than local go version. +go mod init m +go mod edit -go=1.21.1 +go version +stderr -count=1 'go: upgrading toolchain to go1.21.1 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' +stderr -count=1 'go: using go1.21.1 toolchain from cache located at .*' +stdout 'go version go1.21.1' +rm go.mod + +# Toolchain line is newer than go line. +go mod init m +go mod edit -go=1.21.1 -toolchain=go1.21.2 +go version +stderr -count=1 'go: upgrading toolchain to go1.21.2 \(required by toolchain line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' +stderr -count=1 'go: using go1.21.2 toolchain from cache located at .*' +stdout 'go version go1.21.2' +rm go.mod + +# Go line is newer than local go version and toolchain line. +go mod init m +go mod edit -go=1.22 -toolchain=go1.21.2 +go version +stderr -count=1 'go: upgrading toolchain to go1.21.2 \(required by toolchain line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' +stderr -count=1 'go: upgrading toolchain to go1.22.0 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' +stderr -count=1 'go: using go1.22.0 toolchain from cache located at .*' +stdout 'go version go1.22.0' +rm go.mod + +# No switch. +go mod init m +go mod edit -go=1.21.0 -toolchain=go1.21.0 +go version +stderr -count=1 'go: using local toolchain go1.21.0' +! stderr 'go: upgrading toolchain' +stdout 'go version go1.21.0' +rm go.mod + +# GOTOOLCHAIN+auto is older than go line and toolchain line. +go mod init m +go mod edit -go=1.22 -toolchain=go1.21.2 +env GOTOOLCHAIN=go1.21.0+auto +go version +stderr -count=1 'go: default toolchain set to go1.21.0 from GOTOOLCHAIN=go1.21.0\+auto' +stderr -count=1 'go: upgrading toolchain to go1.21.2 \(required by toolchain line in go.mod; upgrade allowed by GOTOOLCHAIN=\+auto\)' +stderr -count=1 'go: upgrading toolchain to go1.22.0 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=\+auto\)' +stderr -count=1 'go: using go1.22.0 toolchain from cache located at .*' +stdout 'go version go1.22.0' +rm go.mod + +# GOTOOLCHAIN is older than go line and toolchain line. +go mod init m +go mod edit -go=1.22 -toolchain=go1.21.2 +env GOTOOLCHAIN=go1.21.1 +go version +stderr -count=1 'go: default toolchain set to go1.21.1 from GOTOOLCHAIN=go1.21.1' +stderr -count=1 'go: using go1.21.1 toolchain from cache located at .*' +! stderr 'go: upgrading toolchain' +stdout 'go version go1.21.1' +rm go.mod +env GOTOOLCHAIN=auto + +# GOTOOLCHAIN+auto is newer than go line and toolchain line. +go mod init m +go mod edit -go=1.21.1 -toolchain=go1.21.2 +env GOTOOLCHAIN=go1.22.0+auto +go version +stderr -count=1 'go: default toolchain set to go1.22.0 from GOTOOLCHAIN=go1.22.0\+auto' +stderr -count=1 'go: using go1.22.0 toolchain from cache located at .*' +stdout 'go version go1.22.0' +rm go.mod + +# GOTOOLCHAIN=local +env GOTOOLCHAIN=local +go mod init m +go mod edit -go=1.21.1 -toolchain=go1.21.2 +go version +stderr -count=1 'go: default toolchain set to go1.21.0 from GOTOOLCHAIN=local' +stderr -count=1 'go: using local toolchain go1.21.0' +stdout 'go version go1.21.0' +rm go.mod + +[short] stop 'requires build' +# If toolchain found in PATH, ensure we print that. +env GOTOOLCHAIN=auto +env TESTGO_VERSION_SWITCH= +mkdir $WORK/bin +go build -o $WORK/bin/go1.22.0$GOEXE ./fake/fakego.go # adds .exe extension implicitly on Windows +[!GOOS:plan9] env PATH=$WORK/bin +[GOOS:plan9] env path=$WORK/bin +go mod init m +go mod edit -go=1.22.0 +! go version +stderr -count=1 'go: upgrading toolchain to go1.22.0 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' +stderr -count=1 'go: using go1.22.0 toolchain located in system PATH \('$WORK'[/\\]bin[/\\]go1.22.0'$GOEXE'\)' +stderr 'running go1.22.0 from PATH' +rm go.mod + + +-- fake/fakego.go -- +package main + +import ( + "fmt" + "os" + "path/filepath" + "strings" +) + +func main() { + exe, _ := os.Executable() + name := filepath.Base(exe) + name = strings.TrimSuffix(name, ".exe") + fmt.Fprintf(os.Stderr, "running %s from PATH\n", name) + os.Exit(1) // fail in case we are running this accidentally (like in "go mod edit") +} diff --git a/go/src/cmd/go/testdata/script/gotoolchain_issue66175.txt b/go/src/cmd/go/testdata/script/gotoolchain_issue66175.txt new file mode 100644 index 0000000000000000000000000000000000000000..5db4dbf3810ac867e79bef2337c00a61eb0d3352 --- /dev/null +++ b/go/src/cmd/go/testdata/script/gotoolchain_issue66175.txt @@ -0,0 +1,109 @@ +env TESTGO_VERSION=go1.14 + +# Clear the path so this test doesn't fail if the system running it\ +# has a binary named go1.21 or go1.22 on its path. +[GOOS:plan9] env path= +[!GOOS:plan9] env PATH= + +# check for invalid toolchain in go.mod +go mod init m +go mod edit -go=1.14 -toolchain=go1.22 +! go version +stderr 'go: invalid toolchain: go1.22 is a language version but not a toolchain version \(go1.22.x\)' + +rm go.mod +go mod init m +go mod edit -go=1.14 -toolchain=go1.21 +! go version +stderr 'go: invalid toolchain: go1.21 is a language version but not a toolchain version \(go1.21.x\)' + +rm go.mod +go mod init m +go mod edit -go=1.14 -toolchain=go1.20 +! go version +stderr 'go: downloading go1.20 ' + + +# check for invalid GOTOOLCHAIN +env GOTOOLCHAIN=go1.14 +go version +stdout 'go1.14' + +env GOTOOLCHAIN=go1.20 +! go version +stderr 'go: downloading go1.20 ' + +env GOTOOLCHAIN=go1.21 +! go version +stderr 'go: invalid toolchain: go1.21 is a language version but not a toolchain version \(go1.21.x\)' + +env GOTOOLCHAIN=go1.22 +! go version +stderr 'go: invalid toolchain: go1.22 is a language version but not a toolchain version \(go1.22.x\)' + +env GOTOOLCHAIN=go1.20+auto +! go version +stderr 'go: downloading go1.20 ' + +env GOTOOLCHAIN=go1.21+auto +! go version +stderr 'go: invalid toolchain: go1.21 is a language version but not a toolchain version \(go1.21.x\)' + +env GOTOOLCHAIN=go1.22+auto +! go version +stderr 'go: invalid toolchain: go1.22 is a language version but not a toolchain version \(go1.22.x\)' + +env GOTOOLCHAIN=go1.21rc3 +! go version +stderr 'go: downloading go1.21rc3 ' + +env GOTOOLCHAIN=go1.22rc2 +! go version +stderr 'go: downloading go1.22rc2 ' + +env GOTOOLCHAIN=go1.66 +! go version +stderr 'go: invalid toolchain: go1.66 is a language version but not a toolchain version \(go1.66.x\)' + +env GOTOOLCHAIN=go1.18beta2 +! go version +stderr 'go: downloading go1.18beta2 ' + +# go1.X is okay for path lookups +env GOTOOLCHAIN=go1.20+path +! go version +stderr 'go: cannot find "go1.20" in PATH' + +env GOTOOLCHAIN=go1.21+path +! go version +stderr 'go: cannot find "go1.21" in PATH' + +env GOTOOLCHAIN=go1.22+path +! go version +stderr 'go: cannot find "go1.22" in PATH' + +# When a toolchain download takes place, download 1.X.0 +env GOTOOLCHAIN=auto +rm go.mod +go mod init m +go mod edit -go=1.300 -toolchain=none +! go version +stderr 'go: downloading go1.300.0 ' + +rm go.mod +go mod init m +go mod edit -go=1.21 -toolchain=none +! go version +stderr 'go: downloading go1.21.0 ' + +rm go.mod +go mod init m +go mod edit -go=1.22 -toolchain=none +! go version +stderr 'go: downloading go1.22.0 ' + +rm go.mod +go mod init m +go mod edit -go=1.15 -toolchain=none +! go version +stderr 'go: downloading go1.15 ' diff --git a/go/src/cmd/go/testdata/script/gotoolchain_local.txt b/go/src/cmd/go/testdata/script/gotoolchain_local.txt new file mode 100644 index 0000000000000000000000000000000000000000..772281438f0d6095e3be8a86c53e87309582662f --- /dev/null +++ b/go/src/cmd/go/testdata/script/gotoolchain_local.txt @@ -0,0 +1,299 @@ +# This test uses the fake toolchain switch support in cmd/go/internal/toolchain.Switch +# to exercise all the version selection logic without needing actual toolchains. +# See gotoolchain_net.txt and gotoolchain_path.txt for tests of network and PATH toolchains. + +env TESTGO_VERSION=go1.500 +env TESTGO_VERSION_SWITCH=switch + +# GOTOOLCHAIN=auto runs default toolchain without a go.mod or go.work +env GOTOOLCHAIN=auto +go version +stdout go1.500 + +# GOTOOLCHAIN=path runs default toolchain without a go.mod or go.work +env GOTOOLCHAIN=path +go version +stdout go1.500 + +# GOTOOLCHAIN=asdf is a syntax error +env GOTOOLCHAIN=asdf +! go version +stderr '^go: invalid GOTOOLCHAIN "asdf"$' + +# GOTOOLCHAIN=version is used directly. +env GOTOOLCHAIN=go1.600 +go version +stdout go1.600 + +env GOTOOLCHAIN=go1.400 +go version +stdout go1.400 + +# GOTOOLCHAIN=version+auto sets a minimum. +env GOTOOLCHAIN=go1.600+auto +go version +stdout go1.600 + +env GOTOOLCHAIN=go1.400.0+auto +go version +stdout go1.400.0 + +# GOTOOLCHAIN=version+path sets a minimum too. +env GOTOOLCHAIN=go1.600+path +go version +stdout go1.600 + +env GOTOOLCHAIN=go1.400+path +go version +stdout go1.400 + +# Create a go.mod file and test interactions with auto and path. + +# GOTOOLCHAIN=auto uses go line if newer than local toolchain. +env GOTOOLCHAIN=auto +go mod init m +go mod edit -go=1.700 -toolchain=none +go version +stdout 1.700 + +go mod edit -go=1.300 -toolchain=none +go version +stdout 1.500 # local toolchain is newer + +go mod edit -go=1.700 -toolchain=go1.300 +go version +stdout go1.700 # toolchain too old, ignored + +go mod edit -go=1.300 -toolchain=default +go version +stdout go1.500 + +go mod edit -go=1.700 -toolchain=default +go version +stdout go1.500 # toolchain local is like GOTOOLCHAIN=local and wins +! go build +stderr '^go: go.mod requires go >= 1.700 \(running go 1.500; go.mod sets toolchain default\)' + +# GOTOOLCHAIN=path does the same. +env GOTOOLCHAIN=path +go mod edit -go=1.700 -toolchain=none +go version +stdout 1.700 + +go mod edit -go=1.300 -toolchain=none +go version +stdout 1.500 # local toolchain is newer + +go mod edit -go=1.700 -toolchain=go1.300 +go version +stdout go1.700 # toolchain too old, ignored + +go mod edit -go=1.300 -toolchain=default +go version +stdout go1.500 + +go mod edit -go=1.700 -toolchain=default +go version +stdout go1.500 # toolchain default applies even if older than go line +! go build +stderr '^go: go.mod requires go >= 1.700 \(running go 1.500; GOTOOLCHAIN=path; go.mod sets toolchain default\)' + +# GOTOOLCHAIN=min+auto with toolchain default uses min, not local + +env GOTOOLCHAIN=go1.400+auto +go mod edit -go=1.300 -toolchain=default +go version +stdout 1.400 # not 1.500 local toolchain + +env GOTOOLCHAIN=go1.600+auto +go mod edit -go=1.300 -toolchain=default +go version +stdout 1.600 # not 1.500 local toolchain + +# GOTOOLCHAIN names can have -suffix +env GOTOOLCHAIN=go1.800-bigcorp +go version +stdout go1.800-bigcorp + +env GOTOOLCHAIN=auto +go mod edit -go=1.999 -toolchain=go1.800-bigcorp +go version +stdout go1.999 + +go mod edit -go=1.777 -toolchain=go1.800-bigcorp +go version +stdout go1.800-bigcorp + +# go.work takes priority over go.mod +go mod edit -go=1.700 -toolchain=go1.999-wrong +go work init +go work edit -go=1.400 -toolchain=go1.600-right +go version +stdout go1.600-right + +go work edit -go=1.400 -toolchain=default +go version +stdout go1.500 + +# go.work misconfiguration does not break go work edit +# ('go 1.600 / toolchain local' forces use of 1.500 which can't normally load that go.work; allow work edit to fix it.) +go work edit -go=1.600 -toolchain=default +go version +stdout go1.500 + +go work edit -toolchain=none +go version +stdout go1.600 + +rm go.work + +# go.mod misconfiguration does not break go mod edit +go mod edit -go=1.600 -toolchain=default +go version +stdout go1.500 + +go mod edit -toolchain=none +go version +stdout go1.600 + +# toolchain built with a custom version should know how it compares to others + +env TESTGO_VERSION=go1.500-bigcorp +go mod edit -go=1.499 -toolchain=none +go version +stdout go1.500-bigcorp + +go mod edit -go=1.499 -toolchain=go1.499 +go version +stdout go1.500-bigcorp + +go mod edit -go=1.500 -toolchain=none +go version +stdout go1.500-bigcorp + +go mod edit -go=1.500 -toolchain=go1.500 +go version +stdout go1.500-bigcorp + +go mod edit -go=1.501 -toolchain=none +go version +stdout go1.501 + + # If toolchain > go, we must upgrade to the indicated toolchain (not just the go version). +go mod edit -go=1.499 -toolchain=go1.501 +go version +stdout go1.501 + +env TESTGO_VERSION='go1.500 (bigcorp)' +go mod edit -go=1.499 -toolchain=none +go version +stdout 'go1.500 \(bigcorp\)' + +go mod edit -go=1.500 -toolchain=none +go version +stdout 'go1.500 \(bigcorp\)' + +go mod edit -go=1.501 -toolchain=none +go version +stdout go1.501 + +go mod edit -go=1.21 + +# avoid two-step switch, first from install target requirement, then from GOTOOLCHAIN min +# instead, just jump directly to GOTOOLCHAIN min +env TESTGO_VERSION=go1.2.3 +env GODEBUG=toolchaintrace=1 +env GOTOOLCHAIN=go1.23.0+auto +! go install rsc.io/fortune/nonexist@v0.0.1 +! stderr 'switching to go1.22.9' +stderr 'using go1.23.0' +env GOTOOLCHAIN=auto + +# go install m@v and go run m@v should use the go directive from m@v, +# or the go directive in go.mod, whichever is higher. +env TESTGO_VERSION=go1.2.3 +go mod edit -go=1.1.1 -toolchain=go1.1.1 + +! go install rsc.io/fortune/nonexist@v0.0.1 +stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$' +! stderr 'upgrading toolchain' +stderr '^go: rsc.io/fortune/nonexist@v0.0.1: module rsc.io/fortune@v0.0.1 found, but does not contain package rsc.io/fortune/nonexist' + +! go run rsc.io/fortune/nonexist@v0.0.1 +stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$' +! stderr 'upgrading toolchain' +stderr '^go: rsc.io/fortune/nonexist@v0.0.1: module rsc.io/fortune@v0.0.1 found, but does not contain package rsc.io/fortune/nonexist' + +go mod edit -go=1.23rc1 -toolchain=go1.1.1 + +! go install rsc.io/fortune/nonexist@v0.0.1 +stderr '^go: upgrading toolchain to go1.23rc1 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' +! stderr 'switching to' +stderr '^go: rsc.io/fortune/nonexist@v0.0.1: module rsc.io/fortune@v0.0.1 found, but does not contain package rsc.io/fortune/nonexist' + +! go run rsc.io/fortune/nonexist@v0.0.1 +stderr '^go: upgrading toolchain to go1.23rc1 \(required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' +! stderr 'switching to' +stderr '^go: rsc.io/fortune/nonexist@v0.0.1: module rsc.io/fortune@v0.0.1 found, but does not contain package rsc.io/fortune/nonexist' + +go mod edit -go=1.23rc1 -toolchain=go1.998 + +! go install rsc.io/fortune/nonexist@v0.0.1 +stderr '^go: upgrading toolchain to go1.998 \(required by toolchain line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' +! stderr 'switching to' +stderr '^go: rsc.io/fortune/nonexist@v0.0.1: module rsc.io/fortune@v0.0.1 found, but does not contain package rsc.io/fortune/nonexist' + +! go run rsc.io/fortune/nonexist@v0.0.1 +stderr '^go: upgrading toolchain to go1.998 \(required by toolchain line in go.mod; upgrade allowed by GOTOOLCHAIN=auto\)' +! stderr 'switching to' +stderr '^go: rsc.io/fortune/nonexist@v0.0.1: module rsc.io/fortune@v0.0.1 found, but does not contain package rsc.io/fortune/nonexist' + +go mod edit -go=1.1.1 -toolchain=go1.1.1 + +# go install should handle unknown flags to find m@v +! go install -unknownflag rsc.io/fortune/nonexist@v0.0.1 +stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$' +stderr '^flag provided but not defined: -unknownflag' + +! go install -unknownflag arg rsc.io/fortune/nonexist@v0.0.1 +stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$' +stderr '^flag provided but not defined: -unknownflag' + +env GODEBUG= + +# go run cannot handle unknown boolean flags +! go run -unknownflag rsc.io/fortune/nonexist@v0.0.1 +! stderr switching +stderr '^flag provided but not defined: -unknownflag' + +! go run -unknownflag oops rsc.io/fortune/nonexist@v0.0.1 +! stderr switching +stderr '^flag provided but not defined: -unknownflag' + +# go run can handle unknown flag with argument. +! go run -unknown=flag rsc.io/fortune/nonexist@v0.0.1 +stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$' +stderr '^flag provided but not defined: -unknown' + +# go install m@v should handle queries +! go install rsc.io/fortune/nonexist@v0.0 +stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$' +stderr '^go: rsc.io/fortune/nonexist@v0.0: module rsc.io/fortune@v0.0 found \(v0.0.1\), but does not contain package rsc.io/fortune/nonexist' + +# go run m@v should handle queries +! go install rsc.io/fortune/nonexist@v0 +stderr '^go: rsc.io/fortune@v0.0.1 requires go >= 1.21rc999; switching to go1.22.9$' +stderr '^go: rsc.io/fortune/nonexist@v0: module rsc.io/fortune@v0 found \(v0.0.1\), but does not contain package rsc.io/fortune/nonexist' + +# go install m@v should use local toolchain if not upgrading +! go install rsc.io/fortune/nonexist@v1 +! stderr go1.22.9 +! stderr switching +stderr '^go: downloading rsc.io/fortune v1.0.0$' +stderr '^go: rsc.io/fortune/nonexist@v1: module rsc.io/fortune@v1 found \(v1.0.0\), but does not contain package rsc.io/fortune/nonexist' + +# go run m@v should use local toolchain if not upgrading +! go run rsc.io/fortune/nonexist@v1 +! stderr go1.22.9 +! stderr switching +stderr '^go: rsc.io/fortune/nonexist@v1: module rsc.io/fortune@v1 found \(v1.0.0\), but does not contain package rsc.io/fortune/nonexist' diff --git a/go/src/cmd/go/testdata/script/gotoolchain_loop.txt b/go/src/cmd/go/testdata/script/gotoolchain_loop.txt new file mode 100644 index 0000000000000000000000000000000000000000..a803d2eb9a685eec6523ad2b5f7f9bf3e8f3a036 --- /dev/null +++ b/go/src/cmd/go/testdata/script/gotoolchain_loop.txt @@ -0,0 +1,65 @@ +env GOTOOLCHAIN=auto +env TESTGO_VERSION=go1.21.1 + +# Basic switch should work. +env TESTGO_VERSION_SWITCH=switch +go version +stdout go1.21.99 + +# Toolchain target mismatch should be detected. +env TESTGO_VERSION_SWITCH=mismatch +! go version +stderr '^go: toolchain go1.21.1 invoked to provide go1.21.99$' + +# Toolchain loop should be detected. +env TESTGO_VERSION_SWITCH=loop +! go version +stderr -count=10 '^go: switching from go1.21.1 to go1.21.99 \[depth 9[0-9]\]$' +stderr -count=1 '^go: switching from go1.21.1 to go1.21.99 \[depth 100\]$' +stderr '^go: too many toolchain switches$' + +[short] skip + +# Internal env vars should not leak to go test or go run. +env TESTGO_VERSION_SWITCH=switch +go version +stdout go1.21.99 +go test +stdout clean +go run . +stdout clean + +-- go.mod -- +module m +go 1.21.99 + +-- m_test.go -- +package main + +import "testing" + +func TestEnv(t *testing.T) { + // the check is in func init in m.go +} + +-- m.go -- +package main + +import "os" + +func init() { + envs := []string{ + "GOTOOLCHAIN_INTERNAL_SWITCH_COUNT", + "GOTOOLCHAIN_INTERNAL_SWITCH_VERSION", + } + for _, e := range envs { + if v := os.Getenv(e); v != "" { + panic("$"+e+"="+v) + } + } + os.Stdout.WriteString("clean\n") +} + +func main() { +} + diff --git a/go/src/cmd/go/testdata/script/gotoolchain_modcmds.txt b/go/src/cmd/go/testdata/script/gotoolchain_modcmds.txt new file mode 100644 index 0000000000000000000000000000000000000000..e6a45533bcfee28d7057949e7f2c5bdfaf556bf8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/gotoolchain_modcmds.txt @@ -0,0 +1,45 @@ +env TESTGO_VERSION=go1.21.0 +env TESTGO_VERSION_SWITCH=switch + +# If the main module's go.mod file lists a version lower than the version +# required by its dependencies, the commands that fetch and diagnose the module +# graph (such as 'go mod graph' and 'go mod verify') should fail explicitly: +# they can't interpret the graph themselves, and they aren't allowed to update +# the go.mod file to record a specific, stable toolchain version that can. + +! go mod verify +stderr '^go: rsc.io/future@v1.0.0: module rsc.io/future@v1.0.0 requires go >= 1.999 \(running go 1.21.0\)' + +! go mod graph +stderr '^go: rsc.io/future@v1.0.0: module rsc.io/future@v1.0.0 requires go >= 1.999 \(running go 1.21.0\)' + +# TODO(#64008): 'go mod download' without arguments should fail too. + + +# 'go get' should update the main module's go.mod file to a version compatible with the +# go version required for rsc.io/future, not fail. +go get . +stderr '^go: module rsc.io/future@v1.0.0 requires go >= 1.999; switching to go1.999testmod$' +stderr '^go: upgraded go 1.21 => 1.999$' +! stderr '^go: added toolchain' + + +# Now, the various 'go mod' subcommands should succeed. + +go mod download + +go mod verify + +go mod graph + + +-- go.mod -- +module example + +go 1.21 + +require rsc.io/future v1.0.0 +-- example.go -- +package example + +import _ "rsc.io/future" diff --git a/go/src/cmd/go/testdata/script/gotoolchain_net.txt b/go/src/cmd/go/testdata/script/gotoolchain_net.txt new file mode 100644 index 0000000000000000000000000000000000000000..1d6473c6f945c1ff765a4efa45a3d12346c23131 --- /dev/null +++ b/go/src/cmd/go/testdata/script/gotoolchain_net.txt @@ -0,0 +1,70 @@ +# This test only checks that basic network lookups work. +# The full test of toolchain version selection is in gotoolchain.txt. + +# This test is sensitive to "new" Go experiments, so +# update the environment to remove any existing GOEXPERIMENT +# setting, see #62016 for more on this. +env GOEXPERIMENT='' + +env TESTGO_VERSION=go1.21actual + +# GOTOOLCHAIN from network, does not exist +env GOTOOLCHAIN=go1.9999x +! go version +stderr 'go: download go1.9999x for .*: toolchain not available' + +# GOTOOLCHAIN from network +[!exec:/bin/sh] stop 'the fake proxy serves shell scripts instead of binaries' +env GOTOOLCHAIN=go1.999testmod +go version +stderr 'go: downloading go1.999testmod \(.*/.*\)' + +# GOTOOLCHAIN cached from network +go version +! stderr downloading +stdout go1.999testmod + +# GOTOOLCHAIN with GOSUMDB enabled but at a bad URL should operate in cache and not try badurl +env oldsumdb=$GOSUMDB +env GOSUMDB=$oldsumdb' http://badurl' +go version +! stderr downloading +stdout go1.999testmod + +# GOTOOLCHAIN with GOSUMB=off should fail, because it cannot access even the cached sumdb info +# without the sumdb name. +env GOSUMDB=off +! go version +stderr '^go: golang.org/toolchain@v0.0.1-go1.999testmod.[a-z0-9\-]*: verifying module: checksum database disabled by GOSUMDB=off$' + +# GOTOOLCHAIN with GOSUMDB enabled but at a bad URL should fail if cache is incomplete +env GOSUMDB=$oldsumdb' http://badurl' +rm $GOPATH/pkg/mod/cache/download/sumdb +! go version +! stderr downloading +stderr 'panic: use of network' # test catches network access +env GOSUMDB=$oldsumdb + +# Test a real GOTOOLCHAIN +[short] skip +[!net:golang.org] skip +[!net:sum.golang.org] skip +[!GOOS:darwin] [!GOOS:windows] [!GOOS:linux] skip +[!GOARCH:amd64] [!GOARCH:arm64] skip + +env GOPROXY= +[go-builder] env GOSUMDB= +[!go-builder] env GOSUMDB=sum.golang.org # Set explicitly in case GOROOT/go.env is modified. +env GOTOOLCHAIN=go1.20.1 + + # Avoid resolving a "go1.20.1" from the user's real $PATH. + # That would not only cause the "downloading go1.20.1" message + # to be suppressed, but may spuriously fail: + # golang.org/dl/go1.20.1 expects to find its GOROOT in $HOME/sdk, + # but the script environment sets HOME=/no-home. +env PATH= +env path= + +go version +stderr '^go: downloading go1.20.1 ' +stdout go1.20.1 diff --git a/go/src/cmd/go/testdata/script/gotoolchain_path.txt b/go/src/cmd/go/testdata/script/gotoolchain_path.txt new file mode 100644 index 0000000000000000000000000000000000000000..0d4b1631024ca1e7151641d40eb9f8ef3c6a603c --- /dev/null +++ b/go/src/cmd/go/testdata/script/gotoolchain_path.txt @@ -0,0 +1,85 @@ +# This test only checks that basic PATH lookups work. +# The full test of toolchain version selection is in gotoolchain.txt. + +[short] skip + +env TESTGO_VERSION=go1.21pre3 + +# Compile a fake toolchain to put in the path under various names. +env GOTOOLCHAIN= +mkdir $WORK/bin +go build -o $WORK/bin/go1.50.0$GOEXE ./fakego.go # adds .exe extension implicitly on Windows + +[!GOOS:plan9] env PATH=$WORK/bin +[GOOS:plan9] env path=$WORK/bin + +go version +stdout go1.21pre3 + +# GOTOOLCHAIN=go1.50.0 +env GOTOOLCHAIN=go1.50.0 +! go version +stderr 'running go1.50.0 from PATH' + +# GOTOOLCHAIN=path with toolchain line +env GOTOOLCHAIN=local +go mod init m +go mod edit -toolchain=go1.50.0 +grep go1.50.0 go.mod +env GOTOOLCHAIN=path +! go version +stderr 'running go1.50.0 from PATH' + +# GOTOOLCHAIN=path with go line +env GOTOOLCHAIN=local +go mod edit -toolchain=none -go=1.50.0 +grep 'go 1.50.0' go.mod +! grep toolchain go.mod +env GOTOOLCHAIN=path +! go version +stderr 'running go1.50.0 from PATH' + +# GOTOOLCHAIN=auto with toolchain line +env GOTOOLCHAIN=local +go mod edit -toolchain=go1.50.0 -go=1.21 +grep 'go 1.21$' go.mod +grep 'toolchain go1.50.0' go.mod +env GOTOOLCHAIN=auto +! go version +stderr 'running go1.50.0 from PATH' + +# GOTOOLCHAIN=auto with go line +env GOTOOLCHAIN=local +go mod edit -toolchain=none -go=1.50.0 +grep 'go 1.50.0$' go.mod +! grep toolchain go.mod +env GOTOOLCHAIN=auto +! go version +stderr 'running go1.50.0 from PATH' + +# NewerToolchain should find Go 1.50.0. +env GOTOOLCHAIN=local +go mod edit -toolchain=none -go=1.21 +grep 'go 1.21$' go.mod +! grep toolchain go.mod +env GOTOOLCHAIN=path +! go run rsc.io/fortune@v0.0.1 +stderr 'running go1.50.0 from PATH' + +-- fakego.go -- +package main + +import ( + "fmt" + "os" + "path/filepath" + "strings" +) + +func main() { + exe, _ := os.Executable() + name := filepath.Base(exe) + name = strings.TrimSuffix(name, ".exe") + fmt.Fprintf(os.Stderr, "running %s from PATH\n", name) + os.Exit(1) // fail in case we are running this accidentally (like in "go mod edit") +} diff --git a/go/src/cmd/go/testdata/script/gotoolchain_version.txt b/go/src/cmd/go/testdata/script/gotoolchain_version.txt new file mode 100644 index 0000000000000000000000000000000000000000..e0736ff980c5ccbd0f8501d24015d3482e096538 --- /dev/null +++ b/go/src/cmd/go/testdata/script/gotoolchain_version.txt @@ -0,0 +1,22 @@ +[!net:proxy.golang.org] skip + + # In the Go project's official release GOPROXY defaults to proxy.golang.org, + # but it may be changed in GOROOT/go.env (such as in third-party + # distributions). + # + # Make sure it is in use here, because the server for releases not served + # through the proxy (https://golang.org/toolchain?go-get=1) currently only + # serves the latest patch release for each of the supported stable releases. + +[go-builder] env GOPROXY= +[!go-builder] env GOPROXY=https://proxy.golang.org + +go list -m -versions go +stdout 1.20.1 # among others +stdout 1.19rc2 +! stdout go1.20.1 # no go prefixes +! stdout go1.19rc2 + +go list -m -versions toolchain +stdout go1.20.1 # among others +stdout go1.19rc2 diff --git a/go/src/cmd/go/testdata/script/govcs.txt b/go/src/cmd/go/testdata/script/govcs.txt new file mode 100644 index 0000000000000000000000000000000000000000..876f6065bc54b3281847da842eee94fa4f728e81 --- /dev/null +++ b/go/src/cmd/go/testdata/script/govcs.txt @@ -0,0 +1,91 @@ +env GO111MODULE=on +env proxy=$GOPROXY +env GOPROXY=direct + +# GOVCS stops go get +env GOVCS='*:none' +! go get github.com/google/go-cmp +stderr '^go: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$' +env GOPRIVATE='github.com/google' +! go get github.com/google/go-cmp +stderr '^go: GOVCS disallows using git for private github.com/google/go-cmp; see ''go help vcs''$' + +# public pattern works +env GOPRIVATE='github.com/google' +env GOVCS='public:all,private:none' +! go get github.com/google/go-cmp +stderr '^go: GOVCS disallows using git for private github.com/google/go-cmp; see ''go help vcs''$' + +# private pattern works +env GOPRIVATE='hubgit.com/google' +env GOVCS='private:all,public:none' +! go get github.com/google/go-cmp +stderr '^go: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$' + +# other patterns work (for more patterns, see TestGOVCS) +env GOPRIVATE= +env GOVCS='github.com:svn|hg' +! go get github.com/google/go-cmp +stderr '^go: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$' +env GOVCS='github.com/google/go-cmp/inner:git,github.com:svn|hg' +! go get github.com/google/go-cmp +stderr '^go: GOVCS disallows using git for public github.com/google/go-cmp; see ''go help vcs''$' + +# bad patterns are reported (for more bad patterns, see TestGOVCSErrors) +env GOVCS='git' +! go get github.com/google/go-cmp +stderr '^go: github.com/google/go-cmp: malformed entry in GOVCS \(missing colon\): "git"$' + +env GOVCS=github.com:hg,github.com:git +! go get github.com/google/go-cmp +stderr '^go: github.com/google/go-cmp: unreachable pattern in GOVCS: "github.com:git" after "github.com:hg"$' + +# bad GOVCS patterns do not stop commands that do not need to check VCS +go list +env GOPROXY=$proxy +go get rsc.io/quote # ok because used proxy +env GOPROXY=direct + +# svn is disallowed by default +env GOPRIVATE= +env GOVCS= +! go get rsc.io/nonexist.svn/hello +stderr '^go: rsc.io/nonexist.svn/hello: GOVCS disallows using svn for public rsc.io/nonexist.svn; see ''go help vcs''$' + +# fossil is disallowed by default +env GOPRIVATE= +env GOVCS= +! go get rsc.io/nonexist.fossil/hello +stderr '^go: rsc.io/nonexist.fossil/hello: GOVCS disallows using fossil for public rsc.io/nonexist.fossil; see ''go help vcs''$' + +# bzr is disallowed by default +env GOPRIVATE= +env GOVCS= +! go get rsc.io/nonexist.bzr/hello +stderr '^go: rsc.io/nonexist.bzr/hello: GOVCS disallows using bzr for public rsc.io/nonexist.bzr; see ''go help vcs''$' + +# git is OK by default +env GOVCS= +env GONOSUMDB='*' +[net:rsc.io] [git] [!short] go get rsc.io/sampler + +# hg is OK by default +env GOVCS= +env GONOSUMDB='*' +[exec:hg] [!short] go get vcs-test.golang.org/go/custom-hg-hello + +# git can be disallowed +env GOVCS=public:hg +! go get rsc.io/nonexist.git/hello +stderr '^go: rsc.io/nonexist.git/hello: GOVCS disallows using git for public rsc.io/nonexist.git; see ''go help vcs''$' + +# hg can be disallowed +env GOVCS=public:git +! go get rsc.io/nonexist.hg/hello +stderr '^go: rsc.io/nonexist.hg/hello: GOVCS disallows using hg for public rsc.io/nonexist.hg; see ''go help vcs''$' + +-- go.mod -- +module m + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/script/help.txt b/go/src/cmd/go/testdata/script/help.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb15e938f599c19ec8bb41d30a83232d2b7e2f97 --- /dev/null +++ b/go/src/cmd/go/testdata/script/help.txt @@ -0,0 +1,51 @@ +env GO111MODULE=off + +# go help shows overview. +go help +stdout 'Go is a tool' +stdout 'bug.*start a bug report' + +# go help bug shows usage for bug +go help bug +stdout 'usage: go bug' +stdout 'bug report' + +# go bug help is an error (bug takes no arguments) +! go bug help +stderr 'bug takes no arguments' + +# go help mod shows mod subcommands +go help mod +stdout 'go mod ' +stdout tidy + +# go help mod tidy explains tidy +go help mod tidy +stdout 'usage: go mod tidy' + +# go mod help tidy does too +go mod help tidy +stdout 'usage: go mod tidy' + +# go mod --help doesn't print help but at least suggests it. +! go mod --help +stderr 'Run ''go help mod'' for usage.' + +# Earlier versions of Go printed the same as 'go -h' here. +# Also make sure we print the short help line. +! go vet -h +stderr 'usage: go vet .*' +stderr 'Run ''go help vet'' for details.' +stderr 'Run ''go tool vet help'' for a full list of flags and analyzers.' +stderr 'Run ''go tool vet -help'' for an overview.' + +# Earlier versions of Go printed a large document here, instead of these two +# lines. +! go test -h +stderr 'usage: go test' +stderr 'Run ''go help test'' and ''go help testflag'' for details.' + +# go help get shows usage for get +go help get +stdout 'usage: go get' +stdout 'specific module versions' diff --git a/go/src/cmd/go/testdata/script/import_cycle.txt b/go/src/cmd/go/testdata/script/import_cycle.txt new file mode 100644 index 0000000000000000000000000000000000000000..901f43cd276cec54a10b763d625ce13624492c5b --- /dev/null +++ b/go/src/cmd/go/testdata/script/import_cycle.txt @@ -0,0 +1,12 @@ +env GO111MODULE=off + +! go build selfimport +stderr -count=1 'import cycle not allowed' + +# 'go list' shouldn't hang forever. +go list -e -json selfimport + +-- $GOPATH/src/selfimport/selfimport.go -- +package selfimport + +import "selfimport" diff --git a/go/src/cmd/go/testdata/script/import_ignore.txt b/go/src/cmd/go/testdata/script/import_ignore.txt new file mode 100644 index 0000000000000000000000000000000000000000..83a39a0be3d196d92a9fdfbc493768be44cb9433 --- /dev/null +++ b/go/src/cmd/go/testdata/script/import_ignore.txt @@ -0,0 +1,11 @@ +cp go.mod go.mod.orig +go mod tidy +cmp go.mod go.mod.orig + +-- go.mod -- +module m.test + +go 1.16 +-- .ignore.go -- +package p +import _ "golang.org/x/mod/modfile" \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/import_main.txt b/go/src/cmd/go/testdata/script/import_main.txt new file mode 100644 index 0000000000000000000000000000000000000000..bc2cc4d3370aa01bae0b80232954bce04bcaaa20 --- /dev/null +++ b/go/src/cmd/go/testdata/script/import_main.txt @@ -0,0 +1,114 @@ +env GO111MODULE=off + +# Test that you cannot import a main package. +# See golang.org/issue/4210 and golang.org/issue/17475. + +[short] skip +cd $WORK + +# Importing package main from that package main's test should work. +go build x +go test -c x + +# Importing package main from another package should fail. +! go build p1 +stderr 'import "x" is a program, not an importable package' + +# ... even in that package's test. +go build p2 +! go test -c p2 +stderr 'import "x" is a program, not an importable package' + +# ... even if that package's test is an xtest. +go build p3 +! go test p3 +stderr 'import "x" is a program, not an importable package' + +# ... even if that package is a package main +go build p4 +! go test -c p4 +stderr 'import "x" is a program, not an importable package' + +# ... even if that package is a package main using an xtest. +go build p5 +! go test -c p5 +stderr 'import "x" is a program, not an importable package' + +-- x/main.go -- +package main + +var X int + +func main() {} +-- x/main_test.go -- +package main_test + +import ( + "testing" + xmain "x" +) + +var _ = xmain.X + +func TestFoo(t *testing.T) {} +-- p1/p.go -- +package p1 + +import xmain "x" + +var _ = xmain.X +-- p2/p.go -- +package p2 +-- p2/p_test.go -- +package p2 + +import ( + "testing" + xmain "x" +) + +var _ = xmain.X + +func TestFoo(t *testing.T) {} +-- p3/p.go -- +package p +-- p3/p_test.go -- +package p_test + +import ( + "testing" + xmain "x" +) + +var _ = xmain.X + +func TestFoo(t *testing.T) {} +-- p4/p.go -- +package main + +func main() {} +-- p4/p_test.go -- +package main + +import ( + "testing" + xmain "x" +) + +var _ = xmain.X + +func TestFoo(t *testing.T) {} +-- p5/p.go -- +package main +func main() {} +-- p5/p_test.go -- +package main_test + +import ( + "testing" + xmain "x" +) + +var _ = xmain.X + +func TestFoo(t *testing.T) {} diff --git a/go/src/cmd/go/testdata/script/import_unix_tag.txt b/go/src/cmd/go/testdata/script/import_unix_tag.txt new file mode 100644 index 0000000000000000000000000000000000000000..b88ca1e2ee4a74cd2e287e853eb3f7b104518794 --- /dev/null +++ b/go/src/cmd/go/testdata/script/import_unix_tag.txt @@ -0,0 +1,32 @@ +# Regression test for https://go.dev/issue/54712: the "unix" build constraint +# was not applied consistently during package loading. + +go list -x -f '{{if .Module}}{{.ImportPath}}{{end}}' -deps . +stdout 'example.com/version' + +-- go.mod -- +module example + +go 1.19 + +require example.com/version v1.1.0 +-- go.sum -- +example.com/version v1.1.0 h1:VdPnGmIF1NJrntStkxGrF3L/OfhaL567VzCjncGUgtM= +example.com/version v1.1.0/go.mod h1:S7K9BnT4o5wT4PCczXPfWVzpjD4ud4e7AJMQJEgiu2Q= +-- main_notunix.go -- +//go:build !(aix || darwin || dragonfly || freebsd || hurd || linux || netbsd || openbsd || solaris) + +package main + +import _ "example.com/version" + +func main() {} + +-- main_unix.go -- +//go:build unix + +package main + +import _ "example.com/version" + +func main() {} diff --git a/go/src/cmd/go/testdata/script/index.txt b/go/src/cmd/go/testdata/script/index.txt new file mode 100644 index 0000000000000000000000000000000000000000..6a2d13c8b5e68620b897185b8facac4f8f22ef56 --- /dev/null +++ b/go/src/cmd/go/testdata/script/index.txt @@ -0,0 +1,6 @@ +# Check that standard library packages are cached. +go list -json math # refresh cache +env GODEBUG=gofsystrace=1,gofsystracelog=fsys.log +go list -json math +! grep math/abs.go fsys.log +grep 'openIndexPackage .*[\\/]math$' fsys.log diff --git a/go/src/cmd/go/testdata/script/install_backslash.txt b/go/src/cmd/go/testdata/script/install_backslash.txt new file mode 100644 index 0000000000000000000000000000000000000000..adb359c8581a3989d554571aa885ca00f2411374 --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_backslash.txt @@ -0,0 +1,12 @@ +# Issue #24233: allow backslash in path of command +go install -n rsc.io\fortune@v1.0.0 +! stderr 'malformed' + +mkdir m +cd m +go mod init example.com/m +go get rsc.io\fortune +! stderr 'malformed' + +go install -n rsc.io\fortune@v1.0.0 +! stderr 'malformed' diff --git a/go/src/cmd/go/testdata/script/install_cgo_excluded.txt b/go/src/cmd/go/testdata/script/install_cgo_excluded.txt new file mode 100644 index 0000000000000000000000000000000000000000..5a2b46030f12ab80d9023fa2dd956a3db5bd4c19 --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_cgo_excluded.txt @@ -0,0 +1,15 @@ +env CGO_ENABLED=0 + +! go install cgotest +stderr 'build constraints exclude all Go files' + +-- go.mod -- +module cgotest + +go 1.16 +-- m.go -- +package cgotest + +import "C" + +var _ C.int diff --git a/go/src/cmd/go/testdata/script/install_cleans_build.txt b/go/src/cmd/go/testdata/script/install_cleans_build.txt new file mode 100644 index 0000000000000000000000000000000000000000..dc85eb8ceffaf0d343488291c9768c54226c400f --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_cleans_build.txt @@ -0,0 +1,25 @@ +env GO111MODULE=off +[short] skip + +# 'go install' with no arguments should clean up after go build +cd mycmd +go build +exists mycmd$GOEXE +go install +! exists mycmd$GOEXE + +# 'go install mycmd' does not clean up, even in the mycmd directory +go build +exists mycmd$GOEXE +go install mycmd +exists mycmd$GOEXE + +# 'go install mycmd' should not clean up in an unrelated current directory either +cd .. +cp mycmd/mycmd$GOEXE mycmd$GOEXE +go install mycmd +exists mycmd$GOEXE + +-- mycmd/main.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/install_cmd_gobin.txt b/go/src/cmd/go/testdata/script/install_cmd_gobin.txt new file mode 100644 index 0000000000000000000000000000000000000000..049bf415b8d618621db8d4cc916d8526928d4f8c --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_cmd_gobin.txt @@ -0,0 +1,10 @@ +# Check that commands in cmd are install to $GOROOT/bin, not $GOBIN. +# Verifies golang.org/issue/32674. +env GOBIN=gobin +mkdir gobin +go list -f '{{.Target}}' cmd/go +stdout $GOROOT${/}bin${/}go$GOEXE + +# Check that tools are installed to $GOTOOLDIR, not $GOBIN. +go list -f '{{.Target}}' cmd/compile +stdout $GOROOT${/}pkg${/}tool${/}${GOOS}_${GOARCH}${/}compile$GOEXE diff --git a/go/src/cmd/go/testdata/script/install_cross_gobin.txt b/go/src/cmd/go/testdata/script/install_cross_gobin.txt new file mode 100644 index 0000000000000000000000000000000000000000..7679a7e224aac1137f83f5c77899afa3557ed92f --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_cross_gobin.txt @@ -0,0 +1,25 @@ +env GO111MODULE=off +[short] skip # rebuilds std for alternate architecture + +cd mycmd +go build mycmd + +# cross-compile install with implicit GOBIN=$GOPATH/bin can make subdirectory +env GOARCH=386 +[GOARCH:386] env GOARCH=amd64 +env GOOS=linux +go install mycmd +exists $GOPATH/bin/linux_$GOARCH/mycmd + +# cross-compile install with explicit GOBIN cannot make subdirectory +env GOBIN=$WORK/bin +! go install mycmd +! exists $GOBIN/linux_$GOARCH + +# The install directory for a cross-compiled standard command should include GOARCH. +go list -f '{{.Target}}' cmd/pack +stdout ${GOROOT}[/\\]pkg[/\\]tool[/\\]${GOOS}_${GOARCH}[/\\]pack$ + +-- mycmd/x.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/install_dep_version.txt b/go/src/cmd/go/testdata/script/install_dep_version.txt new file mode 100644 index 0000000000000000000000000000000000000000..58330e6b72a1ab5668acc413215809ccf449c874 --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_dep_version.txt @@ -0,0 +1,8 @@ +# Regression test for Issue #54908. When running a go install module@version +# with --mod=readonly moduleInfo was not setting the GoVersion for the module +# because the checksumOk function was failing because modfetch.GoSumFile +# was not set when running outside of a module. + +env GOTOOLCHAIN=local + +go install --mod=readonly example.com/depends/on/generics@v1.0.0 \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/install_goroot_targets.txt b/go/src/cmd/go/testdata/script/install_goroot_targets.txt new file mode 100644 index 0000000000000000000000000000000000000000..f26ee828fa6efac95af610a480d60285e703c4f0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_goroot_targets.txt @@ -0,0 +1,27 @@ +[short] skip + +# Packages in std do not have an install target. +go list -f '{{.Target}}' fmt +! stdout . +go list -export -f '{{.Export}}' fmt +stdout $GOCACHE + +# With GODEBUG=installgoroot=all, fmt has a target. +# (Though we can't try installing it without modifying goroot). +env GODEBUG=installgoroot=all +go list -f '{{.Target}}' fmt +stdout fmt\.a + +# However, the fake packages "builtin" and "unsafe" do not. +go list -f '{{.Target}}' builtin unsafe +! stdout . +go install builtin unsafe # Should succeed as no-ops. + +# With CGO_ENABLED=0, packages that would have +# an install target with cgo on no longer do. +env GODEBUG= +env CGO_ENABLED=0 +go list -f '{{.Target}}' runtime/cgo +! stdout . +go list -export -f '{{.Export}}' runtime/cgo +stdout $GOCACHE diff --git a/go/src/cmd/go/testdata/script/install_modcacherw_issue64282.txt b/go/src/cmd/go/testdata/script/install_modcacherw_issue64282.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e1e6e562a3f7ae51f2c9ac2d923a120c37a9991 --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_modcacherw_issue64282.txt @@ -0,0 +1,45 @@ +# Regression test for https://go.dev/issue/64282. +# +# 'go install' and 'go run' with pkg@version arguments should make +# a best effort to parse flags relevant to downloading modules +# (currently only -modcacherw) before actually downloading the module +# to identify which toolchain version to use. +# +# However, the best-effort flag parsing should not interfere with +# actual flag parsing if we don't switch toolchains. In particular, +# unrecognized flags should still be diagnosed after the module for +# the requested package has been downloaded and checked for toolchain +# upgrades. + + +! go install -cake=delicious -modcacherw example.com/printversion@v0.1.0 +stderr '^flag provided but not defined: -cake$' + # Because the -modcacherw flag was set, we should be able to modify the contents + # of a directory within the module cache. +cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go +go clean -modcache + + +! go install -unknownflag -tags -modcacherw example.com/printversion@v0.1.0 +stderr '^flag provided but not defined: -unknownflag$' +cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go +go clean -modcache + + +# Also try it with a 'go install' that succeeds. +# (But skip in short mode, because linking a binary is expensive.) +[!short] go install -modcacherw example.com/printversion@v0.1.0 +[!short] cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go +[!short] go clean -modcache + + +# The flag should also be applied if given in GOFLAGS +# instead of on the command line. +env GOFLAGS=-modcacherw +! go install -cake=delicious example.com/printversion@v0.1.0 +stderr '^flag provided but not defined: -cake$' +cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/printversion@v0.1.0/extraneous_file.go + + +-- $WORK/extraneous.txt -- +This is not a Go source file. diff --git a/go/src/cmd/go/testdata/script/install_move_not_stale.txt b/go/src/cmd/go/testdata/script/install_move_not_stale.txt new file mode 100644 index 0000000000000000000000000000000000000000..de191cff2b7d04fdb99f19a11af6dde35769052a --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_move_not_stale.txt @@ -0,0 +1,26 @@ +# Check to see that the distribution is not stale +# even when it's been moved to a different directory. +# Simulate that by creating a symlink to the tree. + +# We use net instead of std because stale std has +# the behavior of checking that all std targets +# are stale rather than any of them. + +[!symlink] skip +[short] skip + +go build net +! stale net + +symlink new -> $GOROOT +env OLDGOROOT=$GOROOT +env GOROOT=$WORK${/}gopath${/}src${/}new +go env GOROOT +stdout $WORK[\\/]gopath[\\/]src[\\/]new +cd new +! stale net + +# Add a control case to check that std is +# stale with an empty cache +env GOCACHE=$WORK${/}gopath${/}cache +stale net diff --git a/go/src/cmd/go/testdata/script/install_msan_and_race_and_asan_require_cgo.txt b/go/src/cmd/go/testdata/script/install_msan_and_race_and_asan_require_cgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..d8f2abaf3f1736da4b1109b7a9c4420df3e7de96 --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_msan_and_race_and_asan_require_cgo.txt @@ -0,0 +1,22 @@ +# Tests Issue #21895 + +env CGO_ENABLED=0 + +[GOOS:darwin] [!short] [race] go build -race triv.go + +[!GOOS:darwin] [race] ! go install -race triv.go +[!GOOS:darwin] [race] stderr '-race requires cgo' +[!GOOS:darwin] [race] ! stderr '-msan' + +[msan] ! go install -msan triv.go +[msan] stderr '-msan requires cgo' +[msan] ! stderr '-race' + +[asan] ! go install -asan triv.go +[asan] stderr '(-asan: the version of $(go env CC) could not be parsed)|(-asan: C compiler is not gcc or clang)|(-asan is not supported with [A-Za-z]+ compiler (\d+)\.(\d+))|(-asan requires cgo)' +[asan] ! stderr '-msan' + +-- triv.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/install_rebuild_removed.txt b/go/src/cmd/go/testdata/script/install_rebuild_removed.txt new file mode 100644 index 0000000000000000000000000000000000000000..5db3778d8eb8b929997e623e8036e01f82a95500 --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_rebuild_removed.txt @@ -0,0 +1,44 @@ +env GO111MODULE=off + +# go command should detect package staleness as source file set changes +go install mypkg +! stale mypkg + +# z.go was not compiled; removing it should NOT make mypkg stale +rm mypkg/z.go +! stale mypkg + +# y.go was compiled; removing it should make mypkg stale +rm mypkg/y.go +stale mypkg + +# go command should detect executable staleness too +go install mycmd +! stale mycmd +rm mycmd/z.go +! stale mycmd +rm mycmd/y.go +stale mycmd + +-- mypkg/x.go -- +package mypkg + +-- mypkg/y.go -- +package mypkg + +-- mypkg/z.go -- +// +build missingtag + +package mypkg + +-- mycmd/x.go -- +package main +func main() {} + +-- mycmd/y.go -- +package main + +-- mycmd/z.go -- +// +build missingtag + +package main diff --git a/go/src/cmd/go/testdata/script/install_relative_gobin_fail.txt b/go/src/cmd/go/testdata/script/install_relative_gobin_fail.txt new file mode 100644 index 0000000000000000000000000000000000000000..aa145249c57b7d917dac35bcf0878dbf8dab9058 --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_relative_gobin_fail.txt @@ -0,0 +1,12 @@ +env GOBIN=. +! go install +stderr 'cannot install, GOBIN must be an absolute path' + +-- go.mod -- +module triv + +go 1.16 +-- triv.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/install_shadow_gopath.txt b/go/src/cmd/go/testdata/script/install_shadow_gopath.txt new file mode 100644 index 0000000000000000000000000000000000000000..148e6cc6147042d7c2334bf8046c89d6700b816e --- /dev/null +++ b/go/src/cmd/go/testdata/script/install_shadow_gopath.txt @@ -0,0 +1,18 @@ +# Tests Issue #3562 +# go get foo.io (not foo.io/subdir) was not working consistently. + +env GO111MODULE=off +env GOPATH=$WORK/gopath1${:}$WORK/gopath2 + +mkdir $WORK/gopath1/src/test +mkdir $WORK/gopath2/src/test +cp main.go $WORK/gopath2/src/test/main.go +cd $WORK/gopath2/src/test + +! go install +stderr 'no install location for.*gopath2.src.test: hidden by .*gopath1.src.test' + +-- main.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/issue36000.txt b/go/src/cmd/go/testdata/script/issue36000.txt new file mode 100644 index 0000000000000000000000000000000000000000..41732751ac02d1d7c2f04cb8bd36e3e02db675d5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/issue36000.txt @@ -0,0 +1,6 @@ +# Tests golang.org/issue/36000 + +[!cgo] skip + +# go env with CGO flags should not make NUL file +go env CGO_CFLAGS diff --git a/go/src/cmd/go/testdata/script/issue53586.txt b/go/src/cmd/go/testdata/script/issue53586.txt new file mode 100644 index 0000000000000000000000000000000000000000..db405cd9e49375dd2504a9aa1f01507c03b9a3a2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/issue53586.txt @@ -0,0 +1,18 @@ +[short] skip # sleeps to make mtime cacheable + +go mod init example + +cd subdir +go mod init example/subdir +sleep 2s # allow go.mod mtime to be cached + +go list -f '{{.Dir}}: {{.ImportPath}}' ./pkg +stdout $PWD${/}pkg': example/subdir/pkg$' + +rm go.mod # expose ../go.mod + +go list -f '{{.Dir}}: {{.ImportPath}}' ./pkg +stdout $PWD${/}pkg': example/subdir/pkg$' + +-- subdir/pkg/pkg.go -- +package pkg diff --git a/go/src/cmd/go/testdata/script/ldflag.txt b/go/src/cmd/go/testdata/script/ldflag.txt new file mode 100644 index 0000000000000000000000000000000000000000..6ceb33bb70e7b75b2ac59044c4ad5c3ff3a5d493 --- /dev/null +++ b/go/src/cmd/go/testdata/script/ldflag.txt @@ -0,0 +1,44 @@ +# Issue #42565 + +[!cgo] skip + +# We can't build package bad, which uses #cgo LDFLAGS. +cd bad +! go build +stderr no-such-warning + +# We can build package ok with the same flags in CGO_LDFLAGS. +env CGO_LDFLAGS=-Wno-such-warning -Wno-unknown-warning-option +cd ../ok +go build + +# Build a main program that actually uses LDFLAGS. +cd .. +go build -ldflags=-v + +# Because we passed -v the Go linker should print the external linker +# command which should include the flag we passed in CGO_LDFLAGS. +stderr no-such-warning + +-- go.mod -- +module ldflag + +-- bad/bad.go -- +package bad + +// #cgo LDFLAGS: -Wno-such-warning -Wno-unknown-warning +import "C" + +func F() {} +-- ok/ok.go -- +package ok + +import "C" + +func F() {} +-- main.go -- +package main + +import _ "ldflag/ok" + +func main() {} diff --git a/go/src/cmd/go/testdata/script/link_external_undef.txt b/go/src/cmd/go/testdata/script/link_external_undef.txt new file mode 100644 index 0000000000000000000000000000000000000000..f3205054599695c5d4eb8266f1287878dec84fd2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/link_external_undef.txt @@ -0,0 +1,48 @@ + +# Test case for issue 47993, in which the linker crashes +# on a bad input instead of issuing an error and exiting. + +# This test requires external linking, so use cgo as a proxy +[!cgo] skip + +! go build -ldflags='-linkmode=external' . +! stderr 'panic' +stderr '^.*undefined symbol in relocation.*' + +-- go.mod -- + +module issue47993 + +go 1.16 + +-- main.go -- + +package main + +type M struct { + b bool +} + +// Note the body-less func def here. This is what causes the problems. +func (m *M) run(fp func()) + +func doit(m *M) { + InAsm() + m.run(func() { + }) +} + +func main() { + m := &M{true} + doit(m) +} + +func InAsm() + +-- main.s -- + +// Add an assembly function so as to leave open the possibility +// that body-less functions in Go might be defined in assembly. + +// Currently we just need an empty file here. + diff --git a/go/src/cmd/go/testdata/script/link_matching_actionid.txt b/go/src/cmd/go/testdata/script/link_matching_actionid.txt new file mode 100644 index 0000000000000000000000000000000000000000..b8d423d027b693503b11e154201b98b68b955d13 --- /dev/null +++ b/go/src/cmd/go/testdata/script/link_matching_actionid.txt @@ -0,0 +1,38 @@ +# Checks that an identical binary is built with -trimpath from the same +# source files, with GOROOT in two different locations. +# Verifies golang.org/issue/38989 + +[short] skip +[!symlink] skip + +# Symlink the compiler to a local path +env GOROOT=$WORK/goroot1 +symlink $GOROOT -> $TESTGO_GOROOT + +# Set up fresh GOCACHE +env GOCACHE=$WORK/gocache1 +mkdir $GOCACHE + +# Build a simple binary +go build -o binary1 -trimpath -x main.go + +# Now repeat the same process with the compiler at a different local path +env GOROOT=$WORK/goroot2 +symlink $GOROOT -> $TESTGO_GOROOT + +env GOCACHE=$WORK/gocache2 +mkdir $GOCACHE + +go build -o binary2 -trimpath -x main.go + +# Check that the binaries match exactly +go tool buildid binary1 +cp stdout buildid1 +go tool buildid binary2 +cp stdout buildid2 +cmp buildid1 buildid2 + + +-- main.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/link_syso_deps.txt b/go/src/cmd/go/testdata/script/link_syso_deps.txt new file mode 100644 index 0000000000000000000000000000000000000000..6bb9005577044c443bd527dcde01653395179552 --- /dev/null +++ b/go/src/cmd/go/testdata/script/link_syso_deps.txt @@ -0,0 +1,55 @@ +# Test that syso in deps is available to cgo. + +[!compiler:gc] skip 'requires syso support' +[!cgo] skip +[short] skip 'invokes system C compiler' + +# External linking is not supported on linux/ppc64. +# See: https://github.com/golang/go/issues/8912 +[GOOS:linux] [GOARCH:ppc64] skip + +cc -c -o syso/x.syso syso/x.c +cc -c -o syso2/x.syso syso2/x.c +go build m/cgo + +-- go.mod -- +module m + +go 1.18 +-- cgo/x.go -- +package cgo + +// extern void f(void); +// extern void g(void); +import "C" + +func F() { + C.f() +} + +func G() { + C.g() +} + +-- cgo/x2.go -- +package cgo + +import _ "m/syso" + +-- syso/x.c -- +//go:build ignore + +void f() {} + +-- syso/x.go -- +package syso + +import _ "m/syso2" + +-- syso2/x.c -- +//go:build ignore + +void g() {} + +-- syso2/x.go -- +package syso2 diff --git a/go/src/cmd/go/testdata/script/link_syso_issue33139.txt b/go/src/cmd/go/testdata/script/link_syso_issue33139.txt new file mode 100644 index 0000000000000000000000000000000000000000..b0d4a7c68c75377b829015da0e16d3e75d755572 --- /dev/null +++ b/go/src/cmd/go/testdata/script/link_syso_issue33139.txt @@ -0,0 +1,45 @@ +# Test that we can use the external linker with a host syso file that is +# embedded in a package, that is referenced by a Go assembly function. +# See issue 33139. + +[!compiler:gc] skip +[!cgo] skip +[short] skip 'invokes system C compiler' + +# External linking is not supported on linux/ppc64. +# See: https://github.com/golang/go/issues/8912 +[GOOS:linux] [GOARCH:ppc64] skip + +cc -c -o syso/objTestImpl.syso syso/src/objTestImpl.c +go build -ldflags='-linkmode=external' ./cmd/main.go + +-- go.mod -- +module m + +go 1.16 +-- syso/objTest.s -- +#include "textflag.h" + +TEXT ·ObjTest(SB), NOSPLIT, $0 + // We do not actually execute this function in the test above, thus + // there is no stack frame setup here. + // We only care about Go build and/or link errors when referencing + // the objTestImpl symbol in the syso file. + JMP objTestImpl(SB) + +-- syso/pkg.go -- +package syso + +func ObjTest() + +-- syso/src/objTestImpl.c -- +void objTestImpl() { /* Empty */ } + +-- cmd/main.go -- +package main + +import "m/syso" + +func main() { + syso.ObjTest() +} diff --git a/go/src/cmd/go/testdata/script/linkname.txt b/go/src/cmd/go/testdata/script/linkname.txt new file mode 100644 index 0000000000000000000000000000000000000000..36ac8ebccd4d11de331a41a6f684d4cfc082f9f3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/linkname.txt @@ -0,0 +1,9 @@ +env GO111MODULE=off + +# check for linker name in error message about linker crash +[!compiler:gc] skip +! go build -ldflags=-crash_for_testing x.go +stderr [\\/]tool[\\/].*[\\/]link + +-- x.go -- +package main; func main() {} diff --git a/go/src/cmd/go/testdata/script/list_all_gobuild.txt b/go/src/cmd/go/testdata/script/list_all_gobuild.txt new file mode 100644 index 0000000000000000000000000000000000000000..92ad7d885660ecc4aaf1be84789b40643013bbf6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_all_gobuild.txt @@ -0,0 +1,42 @@ +# go list all should work with GOOS=linux because all packages build on Linux +env GOOS=linux +env GOARCH=amd64 +go list all + +# go list all should work with GOOS=darwin, but it used to fail because +# in the absence of //go:build support, p looked like it needed q +# (p_test.go was not properly excluded), and q was Linux-only. +# +# Also testing with r and s that +build lines keep working. +env GOOS=darwin +go list all + +-- go.mod -- +go 1.17 +module m + +-- p/p.go -- +package p + +-- p/p_test.go -- +//go:build linux + +package p + +import "m/q" + +-- q/q_linux.go -- +package q + +-- r/r.go -- +package r + +-- r/r_test.go -- +// +build linux + +package r + +import "m/s" + +-- s/s_linux.go -- +package s diff --git a/go/src/cmd/go/testdata/script/list_ambiguous_path.txt b/go/src/cmd/go/testdata/script/list_ambiguous_path.txt new file mode 100644 index 0000000000000000000000000000000000000000..6f22314ffa1a54f00bcf6e6462e9315ff6a02f7c --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_ambiguous_path.txt @@ -0,0 +1,38 @@ +# Ensures that we can correctly list package patterns ending in '.go'. +# See golang.org/issue/34653. + +# A single pattern for a package ending in '.go'. +go list ./foo.go +stdout '^test/foo.go$' + +# Multiple patterns for packages including one ending in '.go'. +go list ./bar ./foo.go +stdout '^test/bar$' +stdout '^test/foo.go$' + +# A single pattern for a Go file. +go list ./a.go +stdout '^command-line-arguments$' + +# A single typo-ed pattern for a Go file. This should +# treat the wrong pattern as if it were a package. +! go list ./foo.go/b.go +stderr '^stat .*[/\\]foo\.go[/\\]b\.go: directory not found$' + +# Multiple patterns for Go files with a typo. This should +# treat the wrong pattern as if it were a nonexistent file. +! go list ./foo.go/a.go ./foo.go/b.go +[GOOS:plan9] stderr 'stat ./foo.go/b.go: ''./foo.go/b.go'' does not exist' +[GOOS:windows] stderr './foo.go/b.go: The system cannot find the file specified' +[!GOOS:plan9] [!GOOS:windows] stderr './foo.go/b.go: no such file or directory' + +-- a.go -- +package main +-- bar/a.go -- +package bar +-- foo.go/a.go -- +package foo.go +-- go.mod -- +module "test" + +go 1.13 diff --git a/go/src/cmd/go/testdata/script/list_bad_import.txt b/go/src/cmd/go/testdata/script/list_bad_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..dbec35069c64ea815a5151716afe13fb458e9d27 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_bad_import.txt @@ -0,0 +1,72 @@ +env GO111MODULE=off +[short] skip + +# This test matches mod_list_bad_import, but in GOPATH mode. +# Please keep them in sync. + +env GO111MODULE=off +cd example.com + +# Without -e, listing an otherwise-valid package with an unsatisfied direct import should fail. +# BUG: Today it succeeds. +go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}} {{range .DepsErrors}}bad dep: {{.Err}}{{end}}' example.com/direct +! stdout ^error +stdout 'incomplete' +stdout 'bad dep: .*example.com[/\\]notfound' + +# Listing with -deps should also fail. +! go list -deps example.com/direct +stderr example.com[/\\]notfound + +# But -e -deps should succeed. +go list -e -deps example.com/direct +stdout example.com/notfound + + +# Listing an otherwise-valid package that imports some *other* package with an +# unsatisfied import should also fail. +# BUG: Today, it succeeds. +go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}} {{range .DepsErrors}}bad dep: {{.Err}}{{end}}' example.com/indirect +! stdout ^error +stdout incomplete +stdout 'bad dep: .*example.com[/\\]notfound' + +# Again, -deps should fail. +! go list -deps example.com/indirect +stderr example.com[/\\]notfound + +# But -deps -e should succeed. +go list -e -deps example.com/indirect +stdout example.com/notfound + + +# Listing the missing dependency directly should fail outright... +! go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}}' example.com/notfound +stderr 'no Go files in .*example.com[/\\]notfound' +! stdout error +! stdout incomplete + +# ...but listing with -e should succeed. +go list -e -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}}' example.com/notfound +stdout error +stdout incomplete + + +# The pattern "all" should match only packages that actually exist, +# ignoring those whose existence is merely implied by imports. +go list -e -f '{{.ImportPath}}' all +stdout example.com/direct +stdout example.com/indirect +! stdout example.com/notfound + + +-- example.com/direct/direct.go -- +package direct +import _ "example.com/notfound" + +-- example.com/indirect/indirect.go -- +package indirect +import _ "example.com/direct" + +-- example.com/notfound/README -- +This directory intentionally left blank. diff --git a/go/src/cmd/go/testdata/script/list_buildmod_reason_issue67587.txt b/go/src/cmd/go/testdata/script/list_buildmod_reason_issue67587.txt new file mode 100644 index 0000000000000000000000000000000000000000..a89f0e4f9db58af39b4d8a313f88156ebb00c6f0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_buildmod_reason_issue67587.txt @@ -0,0 +1,26 @@ +cd thirteen +! go list -deps +stderr '(Go version in go.mod is 1.13, so vendor directory was not used.)' + +cd ../unspecified +! go list -deps +stderr '(Go version in go.mod is unspecified, so vendor directory was not used.)' + +-- thirteen/foo.go -- +package foo + +import _ "github.com/foo/bar" +-- thirteen/go.mod -- +module example.com + +go 1.13 +-- thirteen/vendor/github.com/foo/bar/bar.go -- +package bar +-- unspecified/foo.go -- +package foo + +import _ "github.com/foo/bar" +-- unspecified/go.mod -- +module example.com +-- unspecified/vendor/github.com/foo/bar/bar.go -- +package bar \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_case_collision.txt b/go/src/cmd/go/testdata/script/list_case_collision.txt new file mode 100644 index 0000000000000000000000000000000000000000..181a202989e3c6472b2b8fead1be2eab23c30472 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_case_collision.txt @@ -0,0 +1,41 @@ +# Tests golang.org/issue/4773 + +go list -json example/a +stdout 'case-insensitive import collision' + +! go build example/a +stderr 'case-insensitive import collision' + +# List files explicitly on command line, to encounter case-checking +# logic even on case-insensitive filesystems. +cp b/file.go b/FILE.go # no-op on case-insensitive filesystems +! go list b/file.go b/FILE.go +stderr 'case-insensitive file name collision' + +mkdir a/Pkg # no-op on case-insensitive filesystems +cp a/pkg/pkg.go a/Pkg/pkg.go # no-op on case-insensitive filesystems +! go list example/a/pkg example/a/Pkg + +# Test that the path reported with an indirect import is correct. +cp b/file.go b/FILE.go +[case-sensitive] ! go build example/c +[case-sensitive] stderr '^package example/c\n\timports example/b: case-insensitive file name collision: "FILE.go" and "file.go"$' + +-- go.mod -- +module example + +go 1.16 +-- a/a.go -- +package p +import ( + _ "example/a/pkg" + _ "example/a/Pkg" +) +-- a/pkg/pkg.go -- +package pkg +-- b/file.go -- +package b +-- c/c.go -- +package c + +import _ "example/b" diff --git a/go/src/cmd/go/testdata/script/list_cgo_compiled_importmap.txt b/go/src/cmd/go/testdata/script/list_cgo_compiled_importmap.txt new file mode 100644 index 0000000000000000000000000000000000000000..869333986c18aaf2842882aff2b45eecc63a1708 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_cgo_compiled_importmap.txt @@ -0,0 +1,41 @@ +# Regression test for https://golang.org/issue/46462. +# +# The "runtime/cgo" import found in synthesized .go files (reported in +# the CompiledGoFiles field) should have a corresponding entry in the +# ImportMap field when a runtime/cgo variant (such as a test variant) +# will be used. + +[short] skip # -compiled can be slow (because it compiles things) +[!cgo] skip +[GOOS:darwin] skip # net package does not import "C" on Darwin +[GOOS:windows] skip # net package does not import "C" on Windows +[GOOS:plan9] skip # net package does not import "C" on Plan 9 + +env CGO_ENABLED=1 +env GOFLAGS=-tags=netcgo # Force net to use cgo + + +# "runtime/cgo [runtime.test]" appears in the test dependencies of "runtime", +# because "runtime/cgo" itself depends on "runtime" + +go list -deps -test -compiled -f '{{if eq .ImportPath "net [runtime.test]"}}{{printf "%q" .Imports}}{{end}}' runtime + + # Control case: the explicitly-imported package "sync" is a test variant, + # because "sync" depends on "runtime". +stdout '"sync \[runtime\.test\]"' +! stdout '"sync"' + + # Experiment: the implicitly-imported package "runtime/cgo" is also a test variant, + # because "runtime/cgo" also depends on "runtime". +stdout '"runtime/cgo \[runtime\.test\]"' +! stdout '"runtime/cgo"' + + +# Because the import of "runtime/cgo" in the cgo-generated file actually refers +# to "runtime/cgo [runtime.test]", the latter should be listed in the ImportMap. +# BUG(#46462): Today, it is not. + +go list -deps -test -compiled -f '{{if eq .ImportPath "net [runtime.test]"}}{{printf "%q" .ImportMap}}{{end}}' runtime + +stdout '"sync":"sync \[runtime\.test\]"' # control +stdout '"runtime/cgo":"runtime/cgo \[runtime\.test\]"' # experiment diff --git a/go/src/cmd/go/testdata/script/list_compiled_files_issue28749.txt b/go/src/cmd/go/testdata/script/list_compiled_files_issue28749.txt new file mode 100644 index 0000000000000000000000000000000000000000..e0fb977c8de19396b1c8c311ea43e95fc772a713 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_compiled_files_issue28749.txt @@ -0,0 +1,10 @@ +go list -compiled -f {{.CompiledGoFiles}} . +! stdout 'foo.s' + +-- go.mod -- +module example.com/foo + +go 1.20 +-- foo.go -- +package foo +-- foo.s -- diff --git a/go/src/cmd/go/testdata/script/list_compiled_imports.txt b/go/src/cmd/go/testdata/script/list_compiled_imports.txt new file mode 100644 index 0000000000000000000000000000000000000000..7780b074c1053229a129f6103c15ee17a61eb6b9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_compiled_imports.txt @@ -0,0 +1,31 @@ +env GO111MODULE=off + +[!cgo] skip + +# go list should report import "C" +cd x +go list -f '{{.Imports}}' +! stdout runtime/cgo +! stdout unsafe +! stdout syscall +stdout C +stdout unicode +stdout unicode/utf16 + +# go list -compiled should report imports in compiled files as well, +# adding "runtime/cgo", "unsafe", and "syscall" but not dropping "C". +go list -compiled -f '{{.Imports}}' +stdout runtime/cgo +stdout unsafe +stdout syscall +stdout C +stdout unicode +stdout unicode/utf16 + +-- x/x.go -- +package x +import "C" +import "unicode" // does not use unsafe, syscall, runtime/cgo, unicode/utf16 +-- x/x1.go -- +package x +import "unicode/utf16" // does not use unsafe, syscall, runtime/cgo, unicode diff --git a/go/src/cmd/go/testdata/script/list_compiler_output.txt b/go/src/cmd/go/testdata/script/list_compiler_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..5230bab3faed2dc0dc5c116d6a3ed4ea336f2bf3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_compiler_output.txt @@ -0,0 +1,16 @@ +[short] skip + +go install -gcflags=-m . +stderr 'can inline main' +go list -gcflags=-m -f '{{.Stale}}' . +stdout 'false' +! stderr 'can inline main' + +-- go.mod -- +module example.com/foo + +go 1.20 +-- main.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/list_constraints.txt b/go/src/cmd/go/testdata/script/list_constraints.txt new file mode 100644 index 0000000000000000000000000000000000000000..7115c365f05198c263694b06da65bfb00b1995c0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_constraints.txt @@ -0,0 +1,86 @@ +# Check that files and their imports are not included in 'go list' output +# when they are excluded by build constraints. + +# Linux and cgo files should be included when building in that configuration. +env GOOS=linux +env GOARCH=amd64 +env CGO_ENABLED=1 +go list -f '{{range .GoFiles}}{{.}} {{end}}' +stdout '^cgotag.go empty.go suffix_linux.go tag.go $' +go list -f '{{range .CgoFiles}}{{.}} {{end}}' +stdout '^cgoimport.go $' +go list -f '{{range .Imports}}{{.}} {{end}}' +stdout '^C cgoimport cgotag suffix tag $' + +# Disabling cgo should exclude cgo files and their imports. +env CGO_ENABLED=0 +go list -f '{{range .GoFiles}}{{.}} {{end}}' +stdout 'empty.go suffix_linux.go tag.go' +go list -f '{{range .CgoFiles}}{{.}} {{end}}' +! stdout . +go list -f '{{range .Imports}}{{.}} {{end}}' +stdout '^suffix tag $' + +# Changing OS should exclude linux sources. +env GOOS=darwin +go list -f '{{range .GoFiles}}{{.}} {{end}}' +stdout '^empty.go $' +go list -f '{{range .Imports}}{{.}} {{end}}' +stdout '^$' + +# Enabling a tag should include files that require it. +go list -tags=extra -f '{{range .GoFiles}}{{.}} {{end}}' +stdout '^empty.go extra.go $' +go list -tags=extra -f '{{range .Imports}}{{.}} {{end}}' +stdout '^extra $' + +# Packages that require a tag should not be listed unless the tag is on. +! go list ./tagonly +go list -tags=extra ./tagonly +stdout m/tagonly + +-- go.mod -- +module m + +go 1.13 + +-- empty.go -- +package p + +-- extra.go -- +// +build extra + +package p + +import _ "extra" + +-- suffix_linux.go -- +package p + +import _ "suffix" + +-- tag.go -- +// +build linux + +package p + +import _ "tag" + +-- cgotag.go -- +// +build cgo + +package p + +import _ "cgotag" + +-- cgoimport.go -- +package p + +import "C" + +import _ "cgoimport" + +-- tagonly/tagonly.go -- +// +build extra + +package tagonly diff --git a/go/src/cmd/go/testdata/script/list_dedup_packages.txt b/go/src/cmd/go/testdata/script/list_dedup_packages.txt new file mode 100644 index 0000000000000000000000000000000000000000..30c68dd77fd7866002dc11dba618b98828746501 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_dedup_packages.txt @@ -0,0 +1,31 @@ +# Setup +env GO111MODULE=off +mkdir $WORK/tmp/testdata/src/xtestonly +cp f.go $WORK/tmp/testdata/src/xtestonly/f.go +cp f_test.go $WORK/tmp/testdata/src/xtestonly/f_test.go +env GOPATH=$WORK/tmp/testdata +cd $WORK + +# Check output of go list to ensure no duplicates +go list xtestonly ./tmp/testdata/src/xtestonly/... +cmp stdout $WORK/gopath/src/wantstdout + +-- wantstdout -- +xtestonly +-- f.go -- +package xtestonly + +func F() int { return 42 } +-- f_test.go -- +package xtestonly_test + +import ( + "testing" + "xtestonly" +) + +func TestF(t *testing.T) { + if x := xtestonly.F(); x != 42 { + t.Errorf("f.F() = %d, want 42", x) + } +} diff --git a/go/src/cmd/go/testdata/script/list_empty_import.txt b/go/src/cmd/go/testdata/script/list_empty_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..4d76f098b97b36ef5f5f3bc063e1d6043673ea28 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_empty_import.txt @@ -0,0 +1,9 @@ +! go list a.go +! stdout . +stderr 'invalid import path' +! stderr panic + +-- a.go -- +package a + +import "" diff --git a/go/src/cmd/go/testdata/script/list_empty_importpath.txt b/go/src/cmd/go/testdata/script/list_empty_importpath.txt new file mode 100644 index 0000000000000000000000000000000000000000..0960a7795d12eab37b0a5de5aa047b7e1e4715b6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_empty_importpath.txt @@ -0,0 +1,17 @@ +! go list all +! stderr 'panic' +stderr 'invalid import path' + +# go list produces a package for 'p' but not for '' +go list -e all +cmp stdout wantlist.txt +-- wantlist.txt -- +example.com/e +-- go.mod -- +module example.com/e + +go 1.25 +-- p.go -- +package p + +import "" \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_err_cycle.txt b/go/src/cmd/go/testdata/script/list_err_cycle.txt new file mode 100644 index 0000000000000000000000000000000000000000..44b82a62b0b0ddbcb04a9756739c914a246e5e8f --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_err_cycle.txt @@ -0,0 +1,15 @@ +# Check that we don't get infinite recursion when loading a package with +# an import cycle and another error. Verifies #25830. +! go list +stderr 'found packages a \(a.go\) and b \(b.go\)' + +-- go.mod -- +module errcycle + +go 1.16 +-- a.go -- +package a + +import _ "errcycle" +-- b.go -- +package b \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_err_stack.txt b/go/src/cmd/go/testdata/script/list_err_stack.txt new file mode 100644 index 0000000000000000000000000000000000000000..a7be9fde6d7b9336d9e409be976878c62a11031c --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_err_stack.txt @@ -0,0 +1,27 @@ + +# golang.org/issue/40544: regression in error stacks for parse errors + +env GO111MODULE=off +cd sandbox/foo +go list -e -json . +stdout '"sandbox/foo"' +stdout '"sandbox/bar"' +stdout '"Pos": "..(/|\\\\)bar(/|\\\\)bar.go:1:1"' +stdout '"Err": "expected ''package'', found ackage"' + +env GO111MODULE=on +go list -e -json . +stdout '"sandbox/foo"' +stdout '"sandbox/bar"' +stdout '"Pos": "..(/|\\\\)bar(/|\\\\)bar.go:1:1"' +stdout '"Err": "expected ''package'', found ackage"' + +-- sandbox/go.mod -- +module sandbox + +-- sandbox/foo/foo.go -- +package pkg + +import "sandbox/bar" +-- sandbox/bar/bar.go -- +ackage bar \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_export_e.txt b/go/src/cmd/go/testdata/script/list_export_e.txt new file mode 100644 index 0000000000000000000000000000000000000000..6d5dd39f0bd476df497dfd1dafd2d675674e9412 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_export_e.txt @@ -0,0 +1,30 @@ +! go list -export ./... +stderr '^# example.com/p2\np2'${/}'main\.go:7:.*' +! stderr '^go build ' + +go list -f '{{with .Error}}{{.}}{{end}}' -e -export ./... +! stderr '.' +stdout '^# example.com/p2\np2'${/}'main\.go:7:.*' + +go list -export -e -f '{{.ImportPath}} -- {{.Incomplete}} -- {{.Error}}' ./... +stdout 'example.com/p1 -- false -- ' +stdout 'example.com/p2 -- true -- # example.com/p2' + +go list -e -export -json=Error ./... +stdout '"Err": "# example.com/p2' + +-- go.mod -- +module example.com +-- p1/p1.go -- +package p1 + +const Name = "p1" +-- p2/main.go -- +package main + +import "fmt" +import "example.com/p1" + +func main() { + fmt.Println(p1.Name == 5) +} diff --git a/go/src/cmd/go/testdata/script/list_export_embed.txt b/go/src/cmd/go/testdata/script/list_export_embed.txt new file mode 100644 index 0000000000000000000000000000000000000000..da74998085c60a41c2b58fa7dbf528ff2a8e29d2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_export_embed.txt @@ -0,0 +1,17 @@ +# Regression test for https://go.dev/issue/58885: +# 'go list -json=Export' should not fail due to missing go:embed metadata. + +[short] skip 'runs the compiler to produce export data' + +go list -json=Export -export . + +-- go.mod -- +module example +go 1.20 +-- example.go -- +package example + +import _ "embed" + +//go:embed example.go +var src string diff --git a/go/src/cmd/go/testdata/script/list_find.txt b/go/src/cmd/go/testdata/script/list_find.txt new file mode 100644 index 0000000000000000000000000000000000000000..d450fc95549fa999cf6b21fece61ecc97f3a83ee --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_find.txt @@ -0,0 +1,22 @@ +env GO111MODULE=off + +# go list -find should not report imports + +go list -f {{.Incomplete}} x/y/z... # should probably exit non-zero but never has +stdout true +go list -find -f '{{.Incomplete}} {{.Imports}}' x/y/z... +stdout '^false \[\]' + +# go list -find -compiled should use cached sources the second time it's run. +# It might not find the same cached sources as "go build", but the sources +# should be identical. "go build" derives action IDs (which are used as cache +# keys) from dependencies' action IDs. "go list -find" won't know what the +# dependencies are, so it's can't construct the same action IDs. +[short] skip +go list -find -compiled net +go list -find -compiled -x net +! stderr 'cgo' + +-- x/y/z/z.go -- +package z +import "does/not/exist" diff --git a/go/src/cmd/go/testdata/script/list_find_nodeps.txt b/go/src/cmd/go/testdata/script/list_find_nodeps.txt new file mode 100644 index 0000000000000000000000000000000000000000..e08ce7895093c890355418fa6afa3b7c188ebbe0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_find_nodeps.txt @@ -0,0 +1,49 @@ +# Issue #46092 +# go list -find should always return a package with an empty Deps list + +# The linker loads implicit dependencies +go list -find -f {{.Deps}} ./cmd +stdout '\[\]' + +# Cgo translation may add imports of "unsafe", "runtime/cgo" and "syscall" +go list -find -f {{.Deps}} ./cgo +stdout '\[\]' + +# SWIG adds imports of some standard packages +go list -find -f {{.Deps}} ./swig +stdout '\[\]' + +-- go.mod -- +module listfind + +-- cmd/main.go -- +package main + +func main() {} + +-- cgo/pkg.go -- +package cgopkg + +/* +#include +*/ +import "C" + +func F() { + println(C.INT_MAX) +} + +-- cgo/pkg_notcgo.go -- +//go:build !cgo +// +build !cgo + +package cgopkg + +func F() { + println(0) +} + +-- swig/pkg.go -- +package swigpkg + +-- swig/a.swigcxx -- diff --git a/go/src/cmd/go/testdata/script/list_gofile_in_goroot.txt b/go/src/cmd/go/testdata/script/list_gofile_in_goroot.txt new file mode 100644 index 0000000000000000000000000000000000000000..b4ff3cbf6d24682f168b8491df76d84fd1b2d97f --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_gofile_in_goroot.txt @@ -0,0 +1,76 @@ +# Return an error if the user tries to list a go source file directly in $GOROOT/src. +# Tests golang.org/issue/36587 + +env GOROOT=$WORK/goroot +env GOPATH=$WORK/gopath + +go env GOROOT +stdout $WORK[/\\]goroot + +# switch to GOROOT/src +cd $GOROOT/src + +# In module mode, 'go list ./...' should not treat .go files in GOROOT/src as an +# importable package, since that directory has no valid import path. +env GO111MODULE=on +go list ... +stdout -count=1 '^.+$' +stdout '^fmt$' +! stdout foo + +go list ./... +stdout -count=1 '^.+$' +stdout '^fmt$' +! stdout foo + +go list std +stdout -count=1 '^.+$' +stdout '^fmt$' + +! go list . +stderr '^GOROOT/src is not an importable package$' + +# In GOPATH mode, 'go list ./...' should synthesize a legacy GOPATH-mode path — +# not a standard-library or empty path — for the errant package. +env GO111MODULE=off +go list ./... +stdout -count=2 '^.+$' # Both 'fmt' and GOROOT/src should be listed. +stdout '^fmt$' +[!GOOS:windows] stdout ^_$WORK/goroot/src$ +[GOOS:windows] stdout goroot/src$ # On windows the ":" in the volume name is mangled + +go list ... +! stdout goroot/src + +go list std +! stdout goroot/src + +go list . +[!GOOS:windows] stdout ^_$WORK/goroot/src$ +[GOOS:windows] stdout goroot/src$ + +# switch to GOPATH/src +cd $GOPATH/src + +# GO111MODULE=off,GOPATH +env GO111MODULE=off +go list ./... +[!GOOS:windows] stdout ^_$WORK/gopath/src$ +[GOOS:windows] stdout gopath/src$ + +go list all +! stdout gopath/src + +-- $WORK/goroot/src/go.mod -- +module std + +go 1.14 +-- $WORK/goroot/src/foo.go -- +package foo +-- $WORK/goroot/src/fmt/fmt.go -- +package fmt +-- $WORK/goroot/src/cmd/README -- +This directory must exist in order for the 'cmd' pattern to have something to +match against. +-- $GOPATH/src/foo.go -- +package foo diff --git a/go/src/cmd/go/testdata/script/list_gomod_in_gopath.txt b/go/src/cmd/go/testdata/script/list_gomod_in_gopath.txt new file mode 100644 index 0000000000000000000000000000000000000000..064f33adc36a69f9c551ca07aece88e1a67e8002 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_gomod_in_gopath.txt @@ -0,0 +1,23 @@ +# Issue 46119 + +# When a module is inside a GOPATH workspace, Package.Root should be set to +# Module.Dir instead of $GOPATH/src. + +env GOPATH=$WORK/tmp +cd $WORK/tmp/src/test + +go list -f {{.Root}} +stdout ^$PWD$ + +# Were we really inside a GOPATH workspace? +env GO111MODULE=off +go list -f {{.Root}} +stdout ^$WORK/tmp$ + +-- $WORK/tmp/src/test/go.mod -- +module test + +-- $WORK/tmp/src/test/main.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/list_goroot_symlink.txt b/go/src/cmd/go/testdata/script/list_goroot_symlink.txt new file mode 100644 index 0000000000000000000000000000000000000000..041ae55863e252126a4ba98dbfd34df7211fc832 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_goroot_symlink.txt @@ -0,0 +1,62 @@ +# Regression test for https://go.dev/issue/57754: 'go list' failed if ../src +# relative to the location of the go executable was a symlink to the real src +# directory. (cmd/go expects that ../src is GOROOT/src, but it appears that the +# Debian build of the Go toolchain is attempting to split GOROOT into binary and +# source artifacts in different parent directories.) + +[short] skip 'copies the cmd/go binary' +[!symlink] skip 'tests symlink-specific behavior' +[GOOS:darwin] skip 'Lstat on darwin does not conform to POSIX pathname resolution; see #59586' +[GOOS:ios] skip 'Lstat on ios does not conform to POSIX pathname resolution; see #59586' + +# Ensure that the relative path to $WORK/lib/goroot/src from $PWD is a different +# number of ".." hops than the relative path to it from $WORK/share/goroot/src. + +cd $WORK + +# Construct a fake GOROOT in $WORK/lib/goroot whose src directory is a symlink +# to a subdirectory of $WORK/share. This mimics the directory structure reported +# in https://go.dev/issue/57754. +# +# Symlink everything else to the original $GOROOT to avoid needless copying work. + +mkdir $WORK/lib/goroot +mkdir $WORK/share/goroot +symlink $WORK/share/goroot/src -> $GOROOT${/}src +symlink $WORK/lib/goroot/src -> ../../share/goroot/src +symlink $WORK/lib/goroot/pkg -> $GOROOT${/}pkg + +# Verify that our symlink shenanigans don't prevent cmd/go from finding its +# GOROOT using os.Executable. +# +# To do so, we copy the actual cmd/go executable — which is implemented as the +# cmd/go test binary instead of the original $GOROOT/bin/go, which may be +# arbitrarily stale — into the bin subdirectory of the fake GOROOT, causing +# os.Executable to report a path in that directory. + +mkdir $WORK/lib/goroot/bin +cp $TESTGO_EXE $WORK/lib/goroot/bin/go$GOEXE + +env GOROOT='' # Clear to force cmd/go to find GOROOT itself. +exec $WORK/lib/goroot/bin/go env GOROOT +stdout $WORK${/}lib${/}goroot + +# Now verify that 'go list' can find standard-library packages in the symlinked +# source tree, with paths matching the one reported by 'go env GOROOT'. + +exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' encoding/binary +stdout '^encoding/binary: '$WORK${/}lib${/}goroot${/}src${/}encoding${/}binary'$' + +exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' std +stdout '^encoding/binary: '$WORK${/}lib${/}goroot${/}src${/}encoding${/}binary'$' + +# Most path lookups in GOROOT are not sensitive to symlinks. However, patterns +# involving '...' wildcards must use Walk to check the GOROOT tree, which makes +# them more sensitive to symlinks (because Walk doesn't follow them). +# +# So we check such a pattern to confirm that it works and reports a path relative +# to $GOROOT/src (and not the symlink target). + +exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' .../binary +stdout '^encoding/binary: '$WORK${/}lib${/}goroot${/}src${/}encoding${/}binary'$' +! stderr . diff --git a/go/src/cmd/go/testdata/script/list_ignore.txt b/go/src/cmd/go/testdata/script/list_ignore.txt new file mode 100644 index 0000000000000000000000000000000000000000..2ba25ca29358b28a866e8dfdbb1155274b64c3f5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_ignore.txt @@ -0,0 +1,151 @@ +# go list should skip 'ignore' directives +# See golang.org/issue/42965 + +env ROOT=$WORK${/}gopath${/}src + +# no ignore directive; should not skip any directories. +cp go.mod.orig go.mod +go list -x ./... +stdout 'example/foo/secret' +stdout 'example/pkg/foo' +stdout 'example/pkg/fo$' +! stderr 'ignoring directory' + +# ignored ./foo should be skipped. +cp go.mod.relative go.mod +go list -x ./... +stdout 'example/pkg/foo' +stdout 'example/pkg/fo$' +! stdout 'example/foo/secret' +stderr 'ignoring directory '$ROOT''${/}'foo' +! stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# ignored foo; any foo should be skipped. +cp go.mod.any go.mod +go list -x ./... +stdout 'example/pkg/fo$' +! stdout 'example/pkg/foo' +! stdout 'example/foo/secret' +stderr 'ignoring directory '$ROOT''${/}'foo' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# non-existent ignore; should not skip any directories. +cp go.mod.dne go.mod +go list -x ./... +stdout 'example/foo/secret' +stdout 'example/pkg/foo' +stdout 'example/pkg/fo$' +! stderr 'ignoring directory' + +# ignored fo; should not skip foo/ and should skip fo/ +cp go.mod.partial go.mod +go list -x ./... +! stderr 'ignoring directory '$ROOT''${/}'foo' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'fo$' +! stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# ignored pkg/foo; should skip pkg/foo/ +cp go.mod.tree go.mod +go list -x ./... +stdout 'example/foo/secret' +stdout 'example/pkg/fo$' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# ignored /pkg/foo/; should skip pkg/foo/ +cp go.mod.sep1 go.mod +go list -x ./... +stdout 'example/foo/secret' +stdout 'example/pkg/fo$' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# ignored pkg/foo/; should skip pkg/foo/ +cp go.mod.sep2 go.mod +go list -x ./... +stdout 'example/foo/secret' +stdout 'example/pkg/fo$' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +# ignored /pkg/foo; should skip pkg/foo/ +cp go.mod.sep3 go.mod +go list -x ./... +stdout 'example/foo/secret' +stdout 'example/pkg/fo$' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' + +-- foo/secret/secret.go -- +package secret + +const Secret = "this should be ignored" +-- pkg/foo/foo.go -- +package foo + +const Bar = "Hello from foo!" +-- pkg/fo/fo.go -- +package fo + +const Gar = "Hello from fo!" +-- go.mod.orig -- +module example + +go 1.24 + +-- go.mod.relative -- +module example + +go 1.24 + +ignore ./foo + +-- go.mod.any -- +module example + +go 1.24 + +ignore foo + +-- go.mod.dne -- +module example + +go 1.24 + +ignore bar + +-- go.mod.partial -- +module example + +go 1.24 + +ignore fo + +-- go.mod.tree -- +module example + +go 1.24 + +ignore pkg/foo + +-- go.mod.sep1 -- +module example + +go 1.24 + +ignore /pkg/foo/ + +-- go.mod.sep2 -- +module example + +go 1.24 + +ignore pkg/foo/ + +-- go.mod.sep3 -- +module example + +go 1.24 + +ignore /pkg/foo + +-- main.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/list_ignore_dependency.txt b/go/src/cmd/go/testdata/script/list_ignore_dependency.txt new file mode 100644 index 0000000000000000000000000000000000000000..cafa2845b3f276fad3d28eaad8ffe56cf201fd17 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_ignore_dependency.txt @@ -0,0 +1,76 @@ +# go list should skip 'ignore' directives with respect to module boundaries. +# See golang.org/issue/42965 + +env ROOT=$WORK${/}gopath${/}src + +# Lists all packages known to the Go toolchain. +# Since go list already does not traverse into other modules found in +# subdirectories, it should only ignore the root node_modules. +go list -x all +stdout 'example$' +stdout 'example/depA' +stderr 'ignoring directory '$ROOT''${/}'node_modules' +! stderr 'ignoring directory '$ROOT''${/}'depA'${/}'node_modules' + +# Lists all packages within the current Go module. +# Since go list already does not traverse into other modules found in +# subdirectories, it should only ignore the root node_modules. +go list -x ./... +stdout 'example$' +stderr 'ignoring directory '$ROOT''${/}'node_modules' +! stderr 'ignoring directory '$ROOT''${/}'depA'${/}'node_modules' + +# Lists all packages belonging to the module whose import path starts with +# example. +# In this case, go list will traverse into each module that starts with example. +# So it should ignore the root node_modules and the subdirectories' node_modules. +go list -x example/... +stdout 'example$' +stdout 'example/depA' +stderr 'ignoring directory '$ROOT''${/}'node_modules' +stderr 'ignoring directory '$ROOT''${/}'depA'${/}'node_modules' + +# Entering the submodule should now cause go list to ignore depA/node_modules. +cd depA +go list -x all +stdout 'example/depA' +stderr 'ignoring directory '$ROOT''${/}'depA'${/}'node_modules' +! stderr 'ignoring directory '$ROOT''${/}'node_modules' + +go list -x ./... +stdout 'example/depA' +stderr 'ignoring directory '$ROOT''${/}'depA'${/}'node_modules' +! stderr 'ignoring directory '$ROOT''${/}'node_modules' + +-- depA/go.mod -- +module example/depA + +go 1.24 +ignore ./node_modules +-- depA/depA.go -- +package depA + +const Foo = "This is Foo!" +-- depA/node_modules/some_pkg/index.js -- +console.log("This should be ignored!"); +-- node_modules/some_pkg/index.js -- +console.log("This should be ignored!"); +-- go.mod -- +module example + +go 1.24 + +ignore ./node_modules +require example/depA v1.0.0 +replace example/depA => ./depA + +-- main.go -- +package main +import ( + "fmt" + "example/depA" +) +func main() { + fmt.Println("test") + fmt.Println(depA.Foo) +} diff --git a/go/src/cmd/go/testdata/script/list_ignore_modcache.txt b/go/src/cmd/go/testdata/script/list_ignore_modcache.txt new file mode 100644 index 0000000000000000000000000000000000000000..2cb8ed6ee2450961e7ea2f71e5aef253ad831cb9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_ignore_modcache.txt @@ -0,0 +1,17 @@ +# go list should skip 'ignore' directives for indexed modules in the module cache +# See golang.org/issue/42965 + +env GOMODCACHE=$WORK${/}modcache +go get example.com/ignore/...@v1.0.0 +go list -x example.com/ignore/... +stderr 'ignoring directory '$GOMODCACHE''${/}'example.com'${/}'ignore@v1.0.0'${/}'foo' + +-- go.mod -- +module example + +go 1.24 + +-- main.go -- +package main + +func main() {} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_ignore_workspace.txt b/go/src/cmd/go/testdata/script/list_ignore_workspace.txt new file mode 100644 index 0000000000000000000000000000000000000000..609e97620078d45e40cada9b6e65760ae1baebab --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_ignore_workspace.txt @@ -0,0 +1,89 @@ +# go list should skip 'ignore' directives in workspaces +# See golang.org/issue/42965 + +env ROOT=$WORK${/}gopath${/}src + +# go list ./... should only consider the current module's ignore directive +cd moduleA +go list -x ./... +stdout 'moduleA$' +stdout 'moduleA/pkg$' +stderr 'ignoring directory '$ROOT''${/}'moduleA'${/}'node_modules' + +# go list ./... should only consider the current module's ignore directive +cd ../moduleB +go list -x ./... +stdout 'moduleB$' +! stdout 'moduleB/pkg/helper' +stderr 'ignoring directory '$ROOT''${/}'moduleB'${/}'pkg' + +# go list should respect module boundaries for ignore directives. +# moduleA ignores './node_modules', moduleB ignores 'pkg' +cd .. +go list -x all +stderr 'ignoring directory '$ROOT''${/}'moduleA'${/}'node_modules' +stderr 'ignoring directory '$ROOT''${/}'moduleB'${/}'pkg' +! stderr 'ignoring directory '$ROOT''${/}'moduleA'${/}'pkg' +stdout 'moduleA$' +stdout 'moduleA/pkg$' +stdout 'moduleB$' +stdout 'moduleB/pkg/helper' + +-- go.work -- +go 1.24 + +use ( + ./moduleA + ./moduleB +) + +-- moduleA/go.mod -- +module moduleA + +go 1.24 + +ignore ./node_modules + +-- moduleA/main.go -- +package main + +import ( + "fmt" + "moduleB/pkg/helper" +) + +func main() { + fmt.Println("Running moduleA") + fmt.Println(helper.Message()) + fmt.Println(hello.Hello()) +} +-- moduleA/node_modules/some_pkg/index.js -- +console.log("This should be ignored!"); +-- moduleA/pkg/hello.go -- +package hello + +func Hello() string { + return "Hello from moduleA" +} +-- moduleB/go.mod -- +module moduleB + +go 1.24 + +ignore pkg + +-- moduleB/main.go -- +package main + +import "fmt" + +func main() { + fmt.Println("Running moduleB") +} + +-- moduleB/pkg/helper/helper.go -- +package helper + +func Message() string { + return "Helper from moduleB" +} diff --git a/go/src/cmd/go/testdata/script/list_import_cycle_deps_errors.txt b/go/src/cmd/go/testdata/script/list_import_cycle_deps_errors.txt new file mode 100644 index 0000000000000000000000000000000000000000..e2c5cf97b9e700cd461780294db1f905362a2232 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_import_cycle_deps_errors.txt @@ -0,0 +1,75 @@ +go list -e -deps -json=ImportPath,Error,DepsErrors m/a +cmp stdout want + +-- want -- +{ + "ImportPath": "m/c", + "DepsErrors": [ + { + "ImportStack": [ + "m/a", + "m/b", + "m/c", + "m/a" + ], + "Pos": "", + "Err": "import cycle not allowed" + } + ] +} +{ + "ImportPath": "m/b", + "DepsErrors": [ + { + "ImportStack": [ + "m/a", + "m/b", + "m/c", + "m/a" + ], + "Pos": "", + "Err": "import cycle not allowed" + } + ] +} +{ + "ImportPath": "m/a", + "Error": { + "ImportStack": [ + "m/a", + "m/b", + "m/c", + "m/a" + ], + "Pos": "", + "Err": "import cycle not allowed" + }, + "DepsErrors": [ + { + "ImportStack": [ + "m/a", + "m/b", + "m/c", + "m/a" + ], + "Pos": "", + "Err": "import cycle not allowed" + } + ] +} +-- go.mod -- +module m + +go 1.21 +-- a/a.go -- +package a + +import _ "m/b" +-- b/b.go -- +package b + +import _ "m/c" +-- c/c.go -- +package c + +import _ "m/a" \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_import_err.txt b/go/src/cmd/go/testdata/script/list_import_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..c2b7d7c83e8aa0fdd4e4ff5a185395cf0981337e --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_import_err.txt @@ -0,0 +1,22 @@ +# Test that errors importing packages are reported on the importing package, +# not the imported package. + +env GO111MODULE=off # simplify vendor layout for test + +go list -e -deps -f '{{.ImportPath}}: {{.Error}}' ./importvendor +stdout 'importvendor: importvendor[\\/]p.go:2:8: vendor/p must be imported as p' +stdout 'vendor/p: ' + +go list -e -deps -f '{{.ImportPath}}: {{.Error}}' ./importinternal +stdout 'importinternal: package importinternal\n\timportinternal[\\/]p.go:2:8: use of internal package other/internal/p not allowed' +stdout 'other/internal/p: ' +-- importvendor/p.go -- +package importvendor +import "vendor/p" +-- importinternal/p.go -- +package importinternal +import "other/internal/p" +-- other/internal/p/p.go -- +package p +-- vendor/p/p.go -- +package p \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_importmap.txt b/go/src/cmd/go/testdata/script/list_importmap.txt new file mode 100644 index 0000000000000000000000000000000000000000..3c59cfdd1166576996c92bdb0c4430109e0e3fc2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_importmap.txt @@ -0,0 +1,27 @@ +env GO111MODULE=off + +# gccgo does not have standard packages. +[compiler:gccgo] skip + +# fmt should have no rewritten imports. +# The import from a/b should map c/d to a's vendor directory. +go list -f '{{.ImportPath}}: {{.ImportMap}}' fmt a/b +stdout 'fmt: map\[\]' +stdout 'a/b: map\[c/d:a/vendor/c/d\]' + +# flag [fmt.test] should import fmt [fmt.test] as fmt +# fmt.test should import testing [fmt.test] as testing +# fmt.test should not import a modified os +go list -deps -test -f '{{.ImportPath}} MAP: {{.ImportMap}}{{"\n"}}{{.ImportPath}} IMPORT: {{.Imports}}' fmt +stdout '^flag \[fmt\.test\] MAP: map\[fmt:fmt \[fmt\.test\]\]' +stdout '^fmt\.test MAP: map\[(.* )?testing:testing \[fmt\.test\]' +! stdout '^fmt\.test MAP: map\[(.* )?os:' +stdout '^fmt\.test IMPORT: \[fmt \[fmt\.test\] fmt_test \[fmt\.test\] os reflect testing \[fmt\.test\] testing/internal/testdeps \[fmt\.test\]\]' + + +-- a/b/b.go -- +package b + +import _ "c/d" +-- a/vendor/c/d/d.go -- +package d diff --git a/go/src/cmd/go/testdata/script/list_issue_56509.txt b/go/src/cmd/go/testdata/script/list_issue_56509.txt new file mode 100644 index 0000000000000000000000000000000000000000..b402b2b3973c796037134608f5a940625a33e053 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_issue_56509.txt @@ -0,0 +1,35 @@ +# Test that a directory with an .s file that has a comment that can't +# be parsed isn't matched as a go directory. (This was happening because +# non-go files with unparsable comments were being added to InvalidGoFiles +# leading the package matching code to think there were Go files in the +# directory.) + +cd bar +go list ./... +! stdout . +cd .. + +[short] skip + +# Test that an unparsable .s file is completely ignored when its name +# has build tags that cause it to be filtered out, but produces an error +# when it is included + +env GOARCH=arm64 +env GOOS=linux +go build ./baz + +env GOARCH=amd64 +env GOOS=linux +! go build ./baz + +-- go.mod -- +module example.com/foo + +go 1.20 +-- bar/bar.s -- +;/ +-- baz/baz.go -- +package bar +-- baz/baz_amd64.s -- +;/ diff --git a/go/src/cmd/go/testdata/script/list_issue_59905.txt b/go/src/cmd/go/testdata/script/list_issue_59905.txt new file mode 100644 index 0000000000000000000000000000000000000000..48c40d0d14599b1df6e94e837f4cd24ec66ed5d6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_issue_59905.txt @@ -0,0 +1,88 @@ +# Expect no panic +go list -f '{{if .DepsErrors}}{{.DepsErrors}}{{end}}' -export -e -deps +cmpenv stdout wanterr_59905 + +# Expect no panic (Issue 61816) +cp level1b_61816.txt level1b/pkg.go +go list -f '{{if .DepsErrors}}{{.DepsErrors}}{{end}}' -export -e -deps +cmpenv stdout wanterr_61816 + +-- wanterr_59905 -- +[# test/main/level1a +level1a${/}pkg.go:5:2: level2x redeclared in this block + level1a${/}pkg.go:4:2: other declaration of level2x +level1a${/}pkg.go:5:2: "test/main/level1a/level2y" imported as level2x and not used +level1a${/}pkg.go:8:39: undefined: level2y + # test/main/level1b +level1b${/}pkg.go:5:2: level2x redeclared in this block + level1b${/}pkg.go:4:2: other declaration of level2x +level1b${/}pkg.go:5:2: "test/main/level1b/level2y" imported as level2x and not used +level1b${/}pkg.go:8:39: undefined: level2y +] +-- wanterr_61816 -- +[level1b${/}pkg.go:4:2: package foo is not in std ($GOROOT${/}src${/}foo)] +[# test/main/level1a +level1a${/}pkg.go:5:2: level2x redeclared in this block + level1a${/}pkg.go:4:2: other declaration of level2x +level1a${/}pkg.go:5:2: "test/main/level1a/level2y" imported as level2x and not used +level1a${/}pkg.go:8:39: undefined: level2y + level1b${/}pkg.go:4:2: package foo is not in std ($GOROOT${/}src${/}foo)] +-- level1b_61816.txt -- +package level1b + +import ( + "foo" +) + +func Print() { println(level2x.Value, level2y.Value) } + +-- go.mod -- +module test/main + +go 1.20 +-- main.go -- +package main + +import ( + "test/main/level1a" + "test/main/level1b" +) + +func main() { + level1a.Print() + level1b.Print() +} +-- level1a/pkg.go -- +package level1a + +import ( + "test/main/level1a/level2x" + "test/main/level1a/level2y" +) + +func Print() { println(level2x.Value, level2y.Value) } +-- level1a/level2x/pkg.go -- +package level2x + +var Value = "1a/2x" +-- level1a/level2y/pkg.go -- +package level2x + +var Value = "1a/2y" +-- level1b/pkg.go -- +package level1b + +import ( + "test/main/level1b/level2x" + "test/main/level1b/level2y" +) + +func Print() { println(level2x.Value, level2y.Value) } +-- level1b/level2x/pkg.go -- +package level2x + +var Value = "1b/2x" +-- level1b/level2y/pkg.go -- +package level2x + +var Value = "1b/2y" \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_issue_70600.txt b/go/src/cmd/go/testdata/script/list_issue_70600.txt new file mode 100644 index 0000000000000000000000000000000000000000..8da61e5016ca46a9764b8d9453316729e8f23a65 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_issue_70600.txt @@ -0,0 +1,43 @@ +# Test that the go command does not panic if it tries to read +# a file from the cache that has an index entry, but is missing +# an entry for the output. This test creates that situation by +# running a go list (creating index and output cache entries for +# the module index) and then removing just the output entries. + +[short] skip 'runs go build' + +go build -o roe$GOEXE ./remove_output_entries.go + +# populate new cache +env GOCACHE=$WORK/newcache +go list runtime + +# remove output entries and check the panic doesn't happen +exec ./roe$GOEXE $WORK/newcache +go list runtime + +-- remove_output_entries.go -- +package main + +import ( + "io/fs" + "log" + "os" + "path/filepath" + "strings" +) + +func main() { + cachedir := os.Args[1] + err := filepath.WalkDir(cachedir, func(path string, d fs.DirEntry, err error) error { + if strings.HasSuffix(path, "-d") { // output entries end in "-d" + if err := os.RemoveAll(path); err != nil { + return err + } + } + return nil + }) + if err != nil { + log.Fatal(err) + } +} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_json_fields.txt b/go/src/cmd/go/testdata/script/list_json_fields.txt new file mode 100644 index 0000000000000000000000000000000000000000..7e008eaabf6a003b69430e62bef52f0e6dc7ecfe --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_json_fields.txt @@ -0,0 +1,113 @@ +# Test using -json flag to specify specific fields. + +# Test -json produces "full" output by looking for multiple fields present. +go list -json . +stdout '"Name": "a"' +stdout '"Stale": true' +# Same thing for -json=true +go list -json=true . +stdout '"Name": "a"' +stdout '"Stale": true' + +# Test -json=false produces non-json output. +go list -json=false +cmp stdout want-non-json.txt + +# Test -json= keeps only that field. +go list -json=Name +cmp stdout want-json-name.txt + +# Test -json= with multiple fields. +go list -json=ImportPath,Name,GoFiles,Imports +cmp stdout want-json-multiple.txt + +# Test -json= with Deps outputs the Deps field. +go list -json=Deps +stdout '"Deps": \[' +stdout '"errors",' + +# Test -json= with *EmbedPatterns outputs embed patterns. +cd embed +go list -json=EmbedPatterns,TestEmbedPatterns,XTestEmbedPatterns +stdout '"EmbedPatterns": \[' +stdout '"TestEmbedPatterns": \[' +stdout '"XTestEmbedPatterns": \[' +# Test -json= with *EmbedFiles fails due to broken file reference. +! go list -json=EmbedFiles +stderr 'no matching files found' +! go list -json=TestEmbedFiles +stderr 'no matching files found' +! go list -json=XTestEmbedFiles +stderr 'no matching files found' +cd .. + +[!git] skip + +# Test -json= without Stale skips computing buildinfo +cd repo +exec git init +# Control case: with -json=Stale cmd/go executes git status to compute buildinfo +go list -json=Stale -x +stderr 'git status' +# Test case: without -json=Stale cmd/go skips git status +go list -json=Name -x +! stderr 'git status' + +-- go.mod -- +module example.com/a + +go 1.18 +-- a.go -- +package a + +import "fmt" + +func F() { + fmt.Println("hey there") +} +-- want-non-json.txt -- +example.com/a +-- want-json-name.txt -- +{ + "Name": "a" +} +-- want-json-multiple.txt -- +{ + "ImportPath": "example.com/a", + "Name": "a", + "GoFiles": [ + "a.go" + ], + "Imports": [ + "fmt" + ] +} +-- repo/go.mod -- +module example.com/repo +-- repo/main.go -- +package main + +func main() {} +-- embed/go.mod -- +module example.com/embed +-- embed/embed.go -- +package embed + +import _ "embed" + +//go:embed non-existing-file.txt +var s string +-- embed/embed_test.go -- +package embed + +import _ "embed" + +//go:embed non-existing-file.txt +var s string +-- embed/embed_xtest_test.go -- +package embed_test + +import _ "embed" + +//go:embed non-existing-file.txt +var s string diff --git a/go/src/cmd/go/testdata/script/list_json_issue64946.txt b/go/src/cmd/go/testdata/script/list_json_issue64946.txt new file mode 100644 index 0000000000000000000000000000000000000000..64ff9d9fe3303058dc4256852168b982620bd047 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_json_issue64946.txt @@ -0,0 +1,10 @@ +cd mod +go list -e -json=ImportPath,Error ./foo +stdout '"Err": "no Go files in .*(/|\\\\)src(/|\\\\)mod(/|\\\\)foo"' + +-- mod/go.mod -- +module example.com/foo + +go 1.21 +-- mod/foo/README.md -- +empty \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_json_with_f.txt b/go/src/cmd/go/testdata/script/list_json_with_f.txt new file mode 100644 index 0000000000000000000000000000000000000000..2011a6e808bff68fb7bcace57f3486252a921d92 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_json_with_f.txt @@ -0,0 +1,20 @@ +[short] skip + +# list -json should generate output on stdout +go list -json ./... +stdout . +# list -f should generate output on stdout +go list -f '{{.}}' ./... +stdout . + +# test passing first -json then -f +! go list -json -f '{{.}}' ./... +stderr '^go list -f cannot be used with -json$' + +# test passing first -f then -json +! go list -f '{{.}}' -json ./... +stderr '^go list -f cannot be used with -json$' +-- go.mod -- +module m +-- list_test.go -- +package list_test diff --git a/go/src/cmd/go/testdata/script/list_legacy_mod.txt b/go/src/cmd/go/testdata/script/list_legacy_mod.txt new file mode 100644 index 0000000000000000000000000000000000000000..ab901d7c341ceef4d88e4668bcf29a9dee2c492e --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_legacy_mod.txt @@ -0,0 +1,48 @@ +# In GOPATH mode, module legacy support does path rewriting very similar to vendoring. + +env GO111MODULE=off + +go list -f '{{range .Imports}}{{.}}{{"\n"}}{{end}}' old/p1 +stdout ^new/p1$ + +go list -f '{{range .Imports}}{{.}}{{"\n"}}{{end}}' new/p1 +stdout ^new/p2$ # not new/v2/p2 +! stdout ^new/v2 +stdout ^new/sub/x/v1/y$ # not new/sub/v2/x/v1/y +! stdout ^new/sub/v2 +stdout ^new/sub/inner/x # not new/sub/v2/inner/x + +go build old/p1 new/p1 + +-- new/go.mod -- +module "new/v2" +-- new/new.go -- +package new + +import _ "new/v2/p2" +-- new/p1/p1.go -- +package p1 + +import _ "old/p2" +import _ "new/v2" +import _ "new/v2/p2" +import _ "new/sub/v2/x/v1/y" // v2 is module, v1 is directory in module +import _ "new/sub/inner/x" // new/sub/inner/go.mod overrides new/sub/go.mod +-- new/p2/p2.go -- +package p2 +-- new/sub/go.mod -- +module new/sub/v2 +-- new/sub/inner/go.mod -- +module new/sub/inner +-- new/sub/inner/x/x.go -- +package x +-- new/sub/x/v1/y/y.go -- +package y +-- old/p1/p1.go -- +package p1 + +import _ "old/p2" +import _ "new/p1" +import _ "new" +-- old/p2/p2.go -- +package p2 diff --git a/go/src/cmd/go/testdata/script/list_linkshared.txt b/go/src/cmd/go/testdata/script/list_linkshared.txt new file mode 100644 index 0000000000000000000000000000000000000000..baae1e2be83c899d27eef765e3e4dd7ab27881fb --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_linkshared.txt @@ -0,0 +1,16 @@ +env GO111MODULE=on + +# golang.org/issue/35759: 'go list -linkshared' +# panicked if invoked on a test-only package. + +[!buildmode:shared] skip + +go list -f '{{.ImportPath}}: {{.Target}} {{.Shlib}}' -linkshared . +stdout '^example.com: $' + +-- go.mod -- +module example.com + +go 1.14 +-- x.go -- +package x diff --git a/go/src/cmd/go/testdata/script/list_load_err.txt b/go/src/cmd/go/testdata/script/list_load_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..f1b9205f9904b7898eeb1a35773a10e78d0e2e8f --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_load_err.txt @@ -0,0 +1,95 @@ +# go list -e -deps should list imports from any file it can read, even if +# other files in the same package cause go/build.Import to return an error. +# Verifies golang.org/issue/38568 + +go list -e -deps ./scan +stdout m/want + +go list -e -deps ./multi +stdout m/want + +go list -e -deps ./constraint +stdout m/want + +[cgo] go list -e -test -deps ./cgotest +[cgo] stdout m/want + +[cgo] go list -e -deps ./cgoflag +[cgo] stdout m/want + + +# go list -e should include files with errors in GoFiles, TestGoFiles, and +# other lists, assuming they match constraints. +# Verifies golang.org/issue/39986 +go list -e -f '{{range .GoFiles}}{{.}},{{end}}' ./scan +stdout '^good.go,scan.go,$' + +go list -e -f '{{range .GoFiles}}{{.}},{{end}}' ./multi +stdout '^a.go,b.go,$' + +go list -e -f '{{range .GoFiles}}{{.}},{{end}}' ./constraint +stdout '^good.go,$' +go list -e -f '{{range .IgnoredGoFiles}}{{.}},{{end}}' ./constraint +stdout '^constraint.go,$' + +[cgo] go list -e -f '{{range .XTestGoFiles}}{{.}},{{end}}' ./cgotest +[cgo] stdout '^cgo_test.go,$' + +[cgo] go list -e -f '{{range .GoFiles}}{{.}},{{end}}' ./cgoflag +[cgo] stdout '^cgoflag.go,$' + +-- go.mod -- +module m + +go 1.14 + +-- want/want.go -- +package want + +-- scan/scan.go -- +// scan error +ʕ◔ϖ◔ʔ + +-- scan/good.go -- +package scan + +import _ "m/want" + +-- multi/a.go -- +package a + +-- multi/b.go -- +package b + +import _ "m/want" + +-- constraint/constraint.go -- +// +build !!nope + +package constraint + +-- constraint/good.go -- +package constraint + +import _ "m/want" + +-- cgotest/cgo_test.go -- +package cgo_test + +// cgo is not allowed in tests. +// See golang.org/issue/18647 + +import "C" +import ( + "testing" + _ "m/want" +) + +func Test(t *testing.T) {} + +-- cgoflag/cgoflag.go -- +package cgoflag + +// #cgo ʕ◔ϖ◔ʔ: + +import _ "m/want" diff --git a/go/src/cmd/go/testdata/script/list_modindex_dupactionid.txt b/go/src/cmd/go/testdata/script/list_modindex_dupactionid.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a9d32b6a8178aac41eb67fd0606a84caa3c98f5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_modindex_dupactionid.txt @@ -0,0 +1,100 @@ +# This is a regression test for #652435. It checks that we don't generate +# multiple action entry ids for the same index file. That was happening +# previously because we sometimes generated the action id with unclean +# paths (and the rest of the time with clean paths) for the same package. +# This test will use a go program ('check') to check the cache that there are +# no two action entry files that point to the same object id. + +[short] skip 'builds and runs a go program' +sleep 2s # Sleep so that the unpacked files are > 2 seconds old. The index won't be used if the modified times on the files are newer. +go build -o check$GOEXE check.go +cd mod +env GOCACHE=$WORK/newcache # Run list command in a clean cache. +go list all +exec ../check$GOEXE + +-- mod/go.mod -- +module example.com/foo +-- mod/foo.go -- +package foo +-- check.go -- +package main + +import ( + "errors" + "log" + "os" + "path/filepath" + "strings" +) + +func main() { + cachedir := os.Getenv("GOCACHE") + if cachedir == "" { + log.Fatal("GOCACHE env var is empty; expected it to be set") + } + + // Read the top level cache directory. The cache directory contains directories with + // each of the possible two hex digit prefixes (00-FF) of a cache entry's id. + // Those directories in turn contain files with the hex id followed by either + // "-a" for the action entries or "-d" for the object entries. We want to check + // if two action entries point to the same object entry so we'll iterate through + // all the "-a" files and see if any two of them refer to the same object id + // (corresponding to a "-d" file). + dirs, err := os.ReadDir(cachedir) + if err != nil { + log.Fatal(err) + } + + seen := map[string]string{} // object id -> action id + + for _, entry := range dirs { + if entry.IsDir() && len(entry.Name()) == 2 { + prefixdir := filepath.Join(cachedir, entry.Name()) + entries, err := os.ReadDir(prefixdir) + if err != nil { + log.Fatal(err) + } + + for _, entry := range entries { + if !strings.HasSuffix(entry.Name(), "-a") { + // not an action id entry + continue + } + actionEntryFile := filepath.Join(prefixdir, entry.Name()) + objid, err := objectid(actionEntryFile) + if err != nil { + log.Fatal(err) + } + if other, ok := seen[objid]; ok { + log.Printf("found two action entry files (%s, %s) pointing to the same object id: %s", other, entry.Name(), objid) + os.Exit(1) + } + seen[objid] = entry.Name() + } + } + } +} + +// objectid returns the object id that the given actionEntryFile points to. +func objectid(actionEntryFile string) (string, error) { + // See cmd/go/internal/cache.(*DiskCache).get for the code that reads + // from the action entry files. The following is based on that function. + const ( + HashSize = 32 + hexSize = HashSize * 2 + entrySize = 2 + 1 + hexSize + 1 + hexSize + 1 + 20 + 1 + 20 + 1 + ) + + entry, err := os.ReadFile(actionEntryFile) + if err != nil { + return "", err + } + if len(entry) < entrySize { + return "", errors.New("entry file incomplete") + } + if entry[0] != 'v' || entry[1] != '1' || entry[2] != ' ' || entry[3+hexSize] != ' ' || entry[3+hexSize+1+hexSize] != ' ' || entry[3+hexSize+1+hexSize+1+20] != ' ' || entry[entrySize-1] != '\n' { + return "", errors.New("invalid header") + } + return string(entry[3+hexSize+1 : 3+hexSize+1+hexSize]), nil +} diff --git a/go/src/cmd/go/testdata/script/list_module_when_error.txt b/go/src/cmd/go/testdata/script/list_module_when_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..844164cd6a27628c9061dc3c59ffb989e8e714a4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_module_when_error.txt @@ -0,0 +1,19 @@ +# The Module field should be populated even if there is an error loading the package. + +env GO111MODULE=on + +go list -e -f {{.Module}} +stdout '^mod.com$' + +-- go.mod -- +module mod.com + +go 1.16 + +-- blah.go -- +package blah + +import _ "embed" + +//go:embed README.md +var readme string diff --git a/go/src/cmd/go/testdata/script/list_n_cover.txt b/go/src/cmd/go/testdata/script/list_n_cover.txt new file mode 100644 index 0000000000000000000000000000000000000000..a85f62f5227efd40cfe78df0a90193f6d92c125e --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_n_cover.txt @@ -0,0 +1,20 @@ +# Adding -cover to "go test -n" should not cause failures, +# see issue 67952. In the regular (no "-n") case for an +# empty package test action for the package will look for +# a static meta-data file produced by the cover tool +# during the build action; when "-n" is in effect that +# meta-data file doesn't exist, so the code that reads +# the meta-data file has to be stubbed out. + +go test -vet=off -n -cover ./f + +-- go.mod -- +module M + +go 1.21 +-- f/f.go -- +package f + +func Id() int { + return 42 +} diff --git a/go/src/cmd/go/testdata/script/list_overlay.txt b/go/src/cmd/go/testdata/script/list_overlay.txt new file mode 100644 index 0000000000000000000000000000000000000000..1153975345a9feb286b88f4c9410194922882b24 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_overlay.txt @@ -0,0 +1,63 @@ +# Test listing with overlays + +# Overlay in an existing directory +go list -overlay overlay.json -f '{{.GoFiles}}' . +stdout '^\[f.go\]$' + +# Overlays in a non-existing directory +go list -overlay overlay.json -f '{{.GoFiles}}' ./dir +stdout '^\[g.go\]$' + +# Overlays in an existing directory with already existing files +go list -overlay overlay.json -f '{{.GoFiles}}' ./dir2 +stdout '^\[h.go i.go\]$' + +# Overlay that removes a file from a directory +! go list ./dir3 # contains a file without a package statement +go list -overlay overlay.json -f '{{.GoFiles}}' ./dir3 # overlay removes that file + +# Walking through an overlay +go list -overlay overlay.json ./... +cmp stdout want-list.txt + +# TODO(#39958): assembly files, C files, files that require cgo preprocessing + +-- want-list.txt -- +m +m/dir +m/dir2 +m/dir3 +-- go.mod -- +// TODO(#39958): Support and test overlays including go.mod itself (especially if mod=readonly) +module m + +go 1.16 + +-- dir2/h.go -- +package dir2 + +-- dir3/good.go -- +package dir3 +-- dir3/bad.go -- +// no package statement +-- overlay.json -- +{ + "Replace": { + "f.go": "overlay/f_go", + "dir/g.go": "overlay/dir_g_go", + "dir2/i.go": "overlay/dir2_i_go", + "dir3/bad.go": "" + } +} +-- overlay/f_go -- +package m + +func f() { +} +-- overlay/dir_g_go -- +package m + +func g() { +} +-- overlay/dir2_i_go -- +package dir2 diff --git a/go/src/cmd/go/testdata/script/list_panic_issue68737.txt b/go/src/cmd/go/testdata/script/list_panic_issue68737.txt new file mode 100644 index 0000000000000000000000000000000000000000..db059c8fedc464d84d452237b79c821e37ddac35 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_panic_issue68737.txt @@ -0,0 +1,7 @@ +# Issue #68737: Don't panic if the import path string doesn't appear +# in the import error. The string may not appear because it may be +# escaped when quoted as part of the error message. + +! go run '' # Quote contains 0x01 byte +! stderr panic +stderr 'malformed import path "\\x01": invalid char ''\\x01''' diff --git a/go/src/cmd/go/testdata/script/list_parse_err.txt b/go/src/cmd/go/testdata/script/list_parse_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a3eb02c045977f0b059e042ca88bd43b9bf85d5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_parse_err.txt @@ -0,0 +1,45 @@ +# 'go list' without -e should fail and print errors on stderr. +! go list ./p +stderr '^p[/\\]b.go:2:2: expected ''package'', found ''EOF''$' +! go list -f '{{range .Imports}}{{.}} {{end}}' ./p +stderr '^p[/\\]b.go:2:2: expected ''package'', found ''EOF''$' +! go list -test ./t +stderr '^go: can''t load test package: t[/\\]t_test.go:8:1: expected declaration, found Ê•' +! go list -test -f '{{range .Imports}}{{.}} {{end}}' ./t +stderr '^go: can''t load test package: t[/\\]t_test.go:8:1: expected declaration, found Ê•' + +# 'go list -e' should report imports, even if some files have parse errors +# before the import block. +go list -e -f '{{range .Imports}}{{.}} {{end}}' ./p +stdout '^fmt ' + +# 'go list' should report the position of the error if there's only one. +go list -e -f '{{.Error.Pos}} => {{.Error.Err}}' ./p +stdout 'b.go:[0-9:]+ => expected ''package'', found ''EOF''' + +# 'go test' should report the position of the error if there's only one. +go list -e -test -f '{{if .Error}}{{.Error.Pos}} => {{.Error.Err}}{{end}}' ./t +stdout 't_test.go:[0-9:]+ => expected declaration, found Ê•' + +-- go.mod -- +module m + +go 1.13 + +-- p/a.go -- +package a + +import "fmt" + +-- p/b.go -- +// no package statement + +-- t/t_test.go -- +package t + +import "testing" + +func Test(t *testing.T) {} + +// scan error +ʕ◔ϖ◔ʔ diff --git a/go/src/cmd/go/testdata/script/list_pattern_work.txt b/go/src/cmd/go/testdata/script/list_pattern_work.txt new file mode 100644 index 0000000000000000000000000000000000000000..bb2911abc1622de37ca561ca9103a8fcab6e1850 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_pattern_work.txt @@ -0,0 +1,79 @@ +cd m +go list all +stdout 'example.com/dep' +stdout 'example.com/m/a' +stdout 'example.com/m/b' +go list work +! stdout 'example.com/dep' +stdout 'example.com/m/a' +stdout 'example.com/m/b' + +cd ../n +go list all +stdout 'example.com/n/c' +stdout 'example.com/n/d' +stdout 'unsafe' +go list work +stdout 'example.com/n/c' +stdout 'example.com/n/d' +! stdout 'unsafe' + +cd ../w +go list all +stdout 'example.com/dep' +stdout 'example.com/m/a' +stdout 'example.com/m/b' +stdout 'example.com/n/c' +stdout 'example.com/n/d' +stdout 'unsafe' +go list work +! stdout 'example.com/dep' +stdout 'example.com/m/a' +stdout 'example.com/m/b' +stdout 'example.com/n/c' +stdout 'example.com/n/d' +! stdout 'unsafe' + +-- m/go.mod -- +module example.com/m + +go 1.24 + +require example.com/dep v1.0.0 +replace example.com/dep v1.0.0 => ../dep +-- m/a/a.go -- +package a +-- m/b/b.go -- +package b + +import _ "example.com/dep" +-- n/go.mod -- +module example.com/n + +go 1.24 +-- n/c/c.go -- +package c +-- n/d/d.go -- +package d + +import _ "unsafe" +-- w/go.work -- +go 1.24 + +use ( + ../m + ../n +) +-- dep/go.mod -- +module example.com/dep + +go 1.24 +-- dep/dep.go -- +package dep +-- want_w_all.txt -- +example.com/dep +example.com/work/a +example.com/work/b +-- want_w_all.txt -- +example.com/work/a +example.com/work/b diff --git a/go/src/cmd/go/testdata/script/list_perm.txt b/go/src/cmd/go/testdata/script/list_perm.txt new file mode 100644 index 0000000000000000000000000000000000000000..14d6f7211d4a2518ebbaf465705afd2a45fe0e0c --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_perm.txt @@ -0,0 +1,83 @@ +env GO111MODULE=on + +# Establish baseline behavior, before mucking with file permissions. + +go list ./noread/... +stdout '^example.com/noread$' + +go list example.com/noread/... +stdout '^example.com/noread$' + +go list ./empty/... +stderr 'matched no packages' + +# Make the directory ./noread unreadable, and verify that 'go list' reports an +# explicit error for a pattern that should match it (rather than treating it as +# equivalent to an empty directory). + +[root] stop # Root typically ignores file permissions. +[GOOS:windows] skip # Does not have Unix-style directory permissions. +[GOOS:plan9] skip # Might not have Unix-style directory permissions. + +chmod 000 noread + +# Check explicit paths. + +! go list ./noread +! stdout '^example.com/noread$' +! stderr 'matched no packages' + +! go list example.com/noread +! stdout '^example.com/noread$' +! stderr 'matched no packages' + +# Check filesystem-relative patterns. + +! go list ./... +! stdout '^example.com/noread$' +! stderr 'matched no packages' +stderr '^pattern ./...: ' + +! go list ./noread/... +! stdout '^example.com/noread$' +! stderr 'matched no packages' +stderr '^pattern ./noread/...: ' + + +# Check module-prefix patterns. + +! go list example.com/... +! stdout '^example.com/noread$' +! stderr 'matched no packages' +stderr '^pattern example.com/...: ' + +! go list example.com/noread/... +! stdout '^example.com/noread$' +! stderr 'matched no packages' +stderr '^pattern example.com/noread/...: ' + + +[short] stop + +# Check global patterns, which should still +# fail due to errors in the local module. + +! go list all +! stdout '^example.com/noread$' +! stderr 'matched no packages' +stderr '^pattern all: ' + +! go list ... +! stdout '^example.com/noread$' +! stderr 'matched no packages' +stderr '^pattern ...: ' + + +-- go.mod -- +module example.com +go 1.15 +-- noread/noread.go -- +// Package noread exists, but will be made unreadable. +package noread +-- empty/README.txt -- +This directory intentionally left empty. diff --git a/go/src/cmd/go/testdata/script/list_pgo_issue66218.txt b/go/src/cmd/go/testdata/script/list_pgo_issue66218.txt new file mode 100644 index 0000000000000000000000000000000000000000..9e9cd6c4845c1c3d5d150386bffe8310536af476 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_pgo_issue66218.txt @@ -0,0 +1,28 @@ +# Test that pgo properly splits off the Imports field so that list doesn't alias +# the non-pgo variant's slice when it modifies the pgo variant's Imports field to +# add the [.ForMain] suffix. + +go list -f 'ImportPath: "{{.ImportPath}}", Imports: "{{.Imports}}", ImportMap: "{{.ImportMap}}"' m/a m/b +cmp stdout want + +-- want -- +ImportPath: "m/a", Imports: "[m/b [m/a]]", ImportMap: "map[m/b:m/b [m/a]]" +ImportPath: "m/b", Imports: "[m/c]", ImportMap: "map[]" +-- go.mod -- +module m + +go 1.23 + +-- a/a.go -- +package main + +import _ "m/b" +-- a/default.pgo -- +-- b/b.go -- +package a + +import _ "m/c" + +-- c/c.go -- +package c + diff --git a/go/src/cmd/go/testdata/script/list_pkgconfig_error.txt b/go/src/cmd/go/testdata/script/list_pkgconfig_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..c0e91a581504185ef37bc95a4a3a3d1f32ed3fde --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_pkgconfig_error.txt @@ -0,0 +1,16 @@ +[!cgo] skip 'test verifies cgo pkg-config errors' +[!exec:pkg-config] skip 'test requires pkg-config tool' + +! go list -export . +stderr '^# example\n# \[pkg-config .*\]\n(.*\n)*(Package .* not found)|(could not find package .*)' + +-- go.mod -- +module example +go 1.20 +-- example.go -- +package example + +// #cgo pkg-config: libnot-a-valid-cgo-library +import "C" + +package main() {} diff --git a/go/src/cmd/go/testdata/script/list_replace_absolute_windows.txt b/go/src/cmd/go/testdata/script/list_replace_absolute_windows.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b71921e4e51821effcd4ef65f27837aedaaa4e2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_replace_absolute_windows.txt @@ -0,0 +1,38 @@ +# Test a replacement with an absolute path (so the path isn't +# cleaned by having filepath.Abs called on it). This checks +# whether the modindex logic cleans the modroot path before using +# it. + +[!GOOS:windows] skip +[short] skip + +go run print_go_mod.go # use this program to write a go.mod with an absolute path +cp stdout go.mod + +go list -modfile=go.mod all +-- print_go_mod.go -- +//go:build ignore +package main + +import ( + "fmt" + "os" +) + +func main() { + work := os.Getenv("WORK") +fmt.Printf(`module example.com/mod + +require b.com v0.0.0 + +replace b.com => %s\gopath\src/modb +`, work) +} +-- a.go -- +package a + +import _ "b.com/b" +-- modb/go.mod -- +module b.com +-- modb/b/b.go -- +package b diff --git a/go/src/cmd/go/testdata/script/list_reserved.txt b/go/src/cmd/go/testdata/script/list_reserved.txt new file mode 100644 index 0000000000000000000000000000000000000000..b9c5361492be9cfce28f3d94c204cc11be2cdcb9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_reserved.txt @@ -0,0 +1,7 @@ +# https://golang.org/issue/37641: the paths "example" and "test" are reserved +# for end users, and must never exist in the standard library. + +go list example/... test/... +stderr 'go: warning: "example/..." matched no packages$' +stderr 'go: warning: "test/..." matched no packages$' +! stdout . diff --git a/go/src/cmd/go/testdata/script/list_retractions_issue66403.txt b/go/src/cmd/go/testdata/script/list_retractions_issue66403.txt new file mode 100644 index 0000000000000000000000000000000000000000..717d129d4cd4fa8e3dbca649416eb4a24dc667d3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_retractions_issue66403.txt @@ -0,0 +1,20 @@ +# For issue #66403, go list -u -m all should not fail if a module +# with retractions has a newer version. + +env TESTGO_VERSION=go1.21 +env TESTGO_VERSION_SWITCH=switch +go list -u -m example.com/retract/newergoversion +stdout 'example.com/retract/newergoversion v1.0.0' +! stdout 'v1.2.0' + +-- go.mod -- +module example.com/m + +go 1.22 + +require example.com/retract/newergoversion v1.0.0 + +-- main.go -- +package main + +import _ "example.com/retract/newergoversion" \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_shadow.txt b/go/src/cmd/go/testdata/script/list_shadow.txt new file mode 100644 index 0000000000000000000000000000000000000000..660508de9ff83c1b75b8814682823d866109ca9b --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_shadow.txt @@ -0,0 +1,25 @@ +env GO111MODULE=off +env GOPATH=$WORK/gopath/src/shadow/root1${:}$WORK/gopath/src/shadow/root2 + +# The math in root1 is not "math" because the standard math is. +go list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./shadow/root1/src/math +stdout '^\(.*(\\|/)src(\\|/)shadow(\\|/)root1(\\|/)src(\\|/)math\) \('$GOROOT'(\\|/)?src(\\|/)math\)$' + +# The foo in root1 is "foo". +go list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./shadow/root1/src/foo +stdout '^\(foo\) \(\)$' + +# The foo in root2 is not "foo" because the foo in root1 got there first. +go list -f '({{.ImportPath}}) ({{.ConflictDir}})' ./shadow/root2/src/foo +stdout '^\(.*gopath(\\|/)src(\\|/)shadow(\\|/)root2(\\|/)src(\\|/)foo\) \('$WORK'(\\|/)?gopath(\\|/)src(\\|/)shadow(\\|/)root1(\\|/)src(\\|/)foo\)$' + +# The error for go install should mention the conflicting directory. +! go install -n ./shadow/root2/src/foo +stderr 'go: no install location for '$WORK'(\\|/)?gopath(\\|/)src(\\|/)shadow(\\|/)root2(\\|/)src(\\|/)foo: hidden by '$WORK'(\\|/)?gopath(\\|/)src(\\|/)shadow(\\|/)root1(\\|/)src(\\|/)foo' + +-- shadow/root1/src/foo/foo.go -- +package foo +-- shadow/root1/src/math/math.go -- +package math +-- shadow/root2/src/foo/foo.go -- +package foo \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_split_main.txt b/go/src/cmd/go/testdata/script/list_split_main.txt new file mode 100644 index 0000000000000000000000000000000000000000..74e7d5d74c2b3eea2351b3bc5f9489478d102510 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_split_main.txt @@ -0,0 +1,25 @@ +# This test checks that a "main" package with an external test package +# is recompiled only once. +# Verifies golang.org/issue/34321. + +env GO111MODULE=off + +go list -e -test -deps -f '{{if not .Standard}}{{.ImportPath}}{{end}}' pkg +cmp stdout want + +-- $GOPATH/src/pkg/pkg.go -- +package main + +func main() {} + +-- $GOPATH/src/pkg/pkg_test.go -- +package main + +import "testing" + +func Test(t *testing.T) {} + +-- want -- +pkg +pkg [pkg.test] +pkg.test diff --git a/go/src/cmd/go/testdata/script/list_std.txt b/go/src/cmd/go/testdata/script/list_std.txt new file mode 100644 index 0000000000000000000000000000000000000000..64c47664a88f5319fa9ecd71e4d927f39d5a5373 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_std.txt @@ -0,0 +1,25 @@ +env GO111MODULE=off + +[!compiler:gc] skip +[short] skip + +# Listing GOROOT should only find standard packages. +cd $GOROOT/src +go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' ./... +! stdout . + +# Standard packages should include cmd, but not cmd/vendor. +go list ./... +stdout cmd/compile +! stdout vendor/golang.org +! stdout cmd/vendor + +# In GOPATH mode, packages vendored into GOROOT should be reported as standard. +go list -f '{{if .Standard}}{{.ImportPath}}{{end}}' std cmd +stdout golang.org/x/net/http2/hpack +stdout cmd/vendor/golang\.org/x/arch/x86/x86asm + +# However, vendored packages should not match wildcard patterns beginning with cmd. +go list cmd/... +stdout cmd/compile +! stdout cmd/vendor diff --git a/go/src/cmd/go/testdata/script/list_std_vendor.txt b/go/src/cmd/go/testdata/script/list_std_vendor.txt new file mode 100644 index 0000000000000000000000000000000000000000..834babe674d9d97ca9f8b49658c35ae64365d3c0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_std_vendor.txt @@ -0,0 +1,33 @@ +# https://golang.org/issue/44725: packages in std should have the same +# dependencies regardless of whether they are listed from within or outside +# GOROOT/src. + +# Control case: net, viewed from outside the 'std' module, +# should depend on vendor/golang.org/… instead of golang.org/…. + +go list -deps net +stdout '^vendor/golang.org/x/net' +! stdout '^golang.org/x/net' +cp stdout $WORK/net-deps.txt + + +# It should still report the same package dependencies when viewed from +# within GOROOT/src. + +cd $GOROOT/src + +go list -deps net +stdout '^vendor/golang.org/x/net' +! stdout '^golang.org/x/net' +cmp stdout $WORK/net-deps.txt + + +# However, 'go mod' and 'go get' subcommands should report the original module +# dependencies, not the vendored packages. + +[!net:golang.org] stop + +env GOPROXY= +env GOWORK=off +go mod why -m golang.org/x/net +stdout '^# golang.org/x/net\nnet\ngolang.org/x/net' diff --git a/go/src/cmd/go/testdata/script/list_swigcxx.txt b/go/src/cmd/go/testdata/script/list_swigcxx.txt new file mode 100644 index 0000000000000000000000000000000000000000..731c1e5a7bcf4f7955ae7ee77fa2bd368ce0e51b --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_swigcxx.txt @@ -0,0 +1,30 @@ +# go list should not report SWIG-generated C++ files in CompiledGoFiles. + +[!exec:swig] skip +[!exec:g++] skip +[!cgo] skip + +# CompiledGoFiles should contain 4 files: +# a.go +# _cgo_import.go [gc only] +# _cgo_gotypes.go +# a.cgo1.go +# +# These names we see here, other than a.go, will be from the build cache, +# so we just count them. + +go list -f '{{.CompiledGoFiles}}' -compiled=true example/swig + +stdout a\.go +[compiler:gc] stdout -count=3 $GOCACHE +[compiler:gccgo] stdout -count=2 $GOCACHE + +-- go.mod -- +module example + +go 1.16 + +-- swig/a.go -- +package swig + +-- swig/a.swigcxx -- diff --git a/go/src/cmd/go/testdata/script/list_symlink.txt b/go/src/cmd/go/testdata/script/list_symlink.txt new file mode 100644 index 0000000000000000000000000000000000000000..f74ca86f37b9b927b660b7144bade5c0d075468c --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_symlink.txt @@ -0,0 +1,12 @@ +[!symlink] skip +env GO111MODULE=off + +mkdir $WORK/tmp/src +symlink $WORK/tmp/src/dir1 -> $WORK/tmp +cp p.go $WORK/tmp/src/dir1/p.go +env GOPATH=$WORK/tmp +go list -f '{{.Root}}' dir1 +stdout '^'$WORK/tmp'$' + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/script/list_symlink_dotdotdot.txt b/go/src/cmd/go/testdata/script/list_symlink_dotdotdot.txt new file mode 100644 index 0000000000000000000000000000000000000000..8df198248425d43db3f79df591d9ca441208ec19 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_symlink_dotdotdot.txt @@ -0,0 +1,20 @@ +[!symlink] skip + +symlink $WORK/gopath/src/sym -> $WORK/gopath/src/tree +symlink $WORK/gopath/src/tree/squirrel -> $WORK/gopath/src/dir2 # this symlink should not be followed +cd sym +go list ./... +cmp stdout $WORK/gopath/src/want_list.txt +-- tree/go.mod -- +module example.com/tree + +go 1.20 +-- tree/tree.go -- +package tree +-- tree/branch/branch.go -- +package branch +-- dir2/squirrel.go -- +package squirrel +-- want_list.txt -- +example.com/tree +example.com/tree/branch diff --git a/go/src/cmd/go/testdata/script/list_symlink_internal.txt b/go/src/cmd/go/testdata/script/list_symlink_internal.txt new file mode 100644 index 0000000000000000000000000000000000000000..f756a56a3ff7907fbe8003c615826c9286baa5ad --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_symlink_internal.txt @@ -0,0 +1,27 @@ +[!symlink] skip +env GO111MODULE=off + +mkdir $WORK/tmp/gopath/src/dir1/internal/v +cp p.go $WORK/tmp/gopath/src/dir1/p.go +cp v.go $WORK/tmp/gopath/src/dir1/internal/v/v.go +symlink $WORK/tmp/symdir1 -> $WORK/tmp/gopath/src/dir1 +env GOPATH=$WORK/tmp/gopath +cd $WORK/tmp/symdir1 +go list -f '{{.Root}}' . +stdout '^'$WORK/tmp/gopath'$' + +# All of these should succeed, not die in internal-handling code. +go run p.go & +go build & +go install & + +wait + +-- p.go -- +package main + +import _ `dir1/internal/v` + +func main() {} +-- v.go -- +package v diff --git a/go/src/cmd/go/testdata/script/list_symlink_issue35941.txt b/go/src/cmd/go/testdata/script/list_symlink_issue35941.txt new file mode 100644 index 0000000000000000000000000000000000000000..eb12bde6ceff5c919c3c49a03be0958653f73c7a --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_symlink_issue35941.txt @@ -0,0 +1,18 @@ +[!symlink] skip +env GO111MODULE=off + +# Issue 35941: suppress symlink warnings when running 'go list all'. +symlink goproj/css -> $GOPATH/src/css + +go list all +! stderr 'warning: ignoring symlink' + +# Show symlink warnings when patterns contain '...'. +go list goproj/... +stderr 'warning: ignoring symlink' + +-- goproj/a.go -- +package a + +-- css/index.css -- +body {} diff --git a/go/src/cmd/go/testdata/script/list_symlink_vendor_issue14054.txt b/go/src/cmd/go/testdata/script/list_symlink_vendor_issue14054.txt new file mode 100644 index 0000000000000000000000000000000000000000..8e63a5a2594be02b38a5ceaf0ac6928b3d406400 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_symlink_vendor_issue14054.txt @@ -0,0 +1,28 @@ +[!symlink] skip +env GO111MODULE=off + +mkdir $WORK/tmp/gopath/src/dir1/vendor/v +cp p.go $WORK/tmp/gopath/src/dir1/p.go +cp v.go $WORK/tmp/gopath/src/dir1/vendor/v/v.go +symlink $WORK/tmp/symdir1 -> $WORK/tmp/gopath/src/dir1 +env GOPATH=$WORK/tmp/gopath +cd $WORK/tmp/symdir1 + +go list -f '{{.Root}}' . +stdout '^'$WORK/tmp/gopath'$' + +# All of these should succeed, not die in vendor-handling code. +go run p.go & +go build & +go install & + +wait + +-- p.go -- +package main + +import _ `v` + +func main () {} +-- v.go -- +package v diff --git a/go/src/cmd/go/testdata/script/list_symlink_vendor_issue15201.txt b/go/src/cmd/go/testdata/script/list_symlink_vendor_issue15201.txt new file mode 100644 index 0000000000000000000000000000000000000000..19f21382503c0e34602f3530569df3a906f6ccb9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_symlink_vendor_issue15201.txt @@ -0,0 +1,21 @@ +[!symlink] skip +env GO111MODULE=off + +mkdir $WORK/tmp/gopath/src/x/y/_vendor/src/x +symlink $WORK/tmp/gopath/src/x/y/_vendor/src/x/y -> ../../.. +mkdir $WORK/tmp/gopath/src/x/y/_vendor/src/x/y/w +cp w.go $WORK/tmp/gopath/src/x/y/w/w.go +symlink $WORK/tmp/gopath/src/x/y/w/vendor -> ../_vendor/src +mkdir $WORK/tmp/gopath/src/x/y/_vendor/src/x/y/z +cp z.go $WORK/tmp/gopath/src/x/y/z/z.go + +env GOPATH=$WORK/tmp/gopath/src/x/y/_vendor${:}$WORK/tmp/gopath +cd $WORK/tmp/gopath/src +go list ./... + +-- w.go -- +package w + +import "x/y/z" +-- z.go -- +package z diff --git a/go/src/cmd/go/testdata/script/list_template_context_function.txt b/go/src/cmd/go/testdata/script/list_template_context_function.txt new file mode 100644 index 0000000000000000000000000000000000000000..70c47c87f8e27c973c3b38db639b39781216ace3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_template_context_function.txt @@ -0,0 +1,15 @@ +# This is a script test conversion of TestListTemplateContextFunction +# originally added in CL 20010, which fixed #14547. +# Test the ability to use the build context in the go list template. + +go list -f '{{context.GOARCH}} {{context.GOOS}} {{context.GOROOT}} {{context.GOPATH}}' +cmpenv stdout want.txt + +go list -f '{{context.CgoEnabled}} {{context.UseAllFiles}} {{context.Compiler}} {{context.BuildTags}} {{context.ReleaseTags}} {{context.InstallSuffix}}' + +-- go.mod -- +module foo +-- foo.go -- +package foo +-- want.txt -- +$GOARCH $GOOS $GOROOT $GOPATH diff --git a/go/src/cmd/go/testdata/script/list_test.txt b/go/src/cmd/go/testdata/script/list_test.txt new file mode 100644 index 0000000000000000000000000000000000000000..f65cd80db2b651776e054bfadce90721fa48b4e2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_test.txt @@ -0,0 +1,33 @@ +# This is a script test conversion of TestGoListTest which was added in +# CL 107916, which added support for go list -test. +# Test the behavior of go list -test. + +[compiler:gccgo] skip 'gccgo does not have standard packages' + +go list -test -deps bytes +stdout '^bytes.test$' # test main +stdout '^bytes$' # real bytes +stdout '^bytes \[bytes.test\]$' # test copy of bytes +stdout 'testing \[bytes.test\]$' # test copy of testing +! stdout ^testing$ # should not have real testing + +go list -test bytes +stdout '^bytes.test$' # test main +stdout '^bytes$' # real bytes +stdout '^bytes \[bytes.test\]$' # test copy of bytes +! stdout '^testing \[bytes.test\]$' # should not have test copy of testing +! stdout '^testing$' # should not have real testing + +go list -test cmd/buildid cmd/gofmt +stdout '^cmd/buildid$' # cmd/buildid +stdout '^cmd/gofmt$' # cmd/gofmt +stdout '^cmd/gofmt\.test$' # cmd/gofmt test +! stdout '^cmd/buildid\.test$' # should not have cmd/buildid test +! stdout '^testing' # should not have real testing + +go list -test runtime/cgo +stdout '^runtime/cgo$' # runtime/cgo + +go list -deps -f '{{if .DepOnly}}{{.ImportPath}}{{end}}' sort +stdout '^internal/reflectlite$' # internal/reflectlite +! stdout '^sort' # should not have sort diff --git a/go/src/cmd/go/testdata/script/list_test_cycle.txt b/go/src/cmd/go/testdata/script/list_test_cycle.txt new file mode 100644 index 0000000000000000000000000000000000000000..7480e6111dd8ce7551fc53b6cac223c3b826a078 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_test_cycle.txt @@ -0,0 +1,34 @@ +go list ./p +stdout 'example/p' + +! go list -json=ImportPath -test ./p +cmp stderr wanterr.txt + +! go list -json=ImportPath,Deps -test ./p +cmp stderr wanterr.txt + +! go list -json=ImportPath,Deps -deps -test ./p +cmp stderr wanterr.txt + +! go list -json=ImportPath -deps -test ./p +cmp stderr wanterr.txt + +-- wanterr.txt -- +go: can't load test package: package example/p + imports example/q from p_test.go + imports example/r from q.go + imports example/p from r.go: import cycle not allowed in test +-- go.mod -- +module example +go 1.20 +-- p/p.go -- +package p +-- p/p_test.go -- +package p +import "example/q" +-- q/q.go -- +package q +import "example/r" +-- r/r.go -- +package r +import "example/p" diff --git a/go/src/cmd/go/testdata/script/list_test_e.txt b/go/src/cmd/go/testdata/script/list_test_e.txt new file mode 100644 index 0000000000000000000000000000000000000000..263892ba63f901b559ac5c4088956763243c6397 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_test_e.txt @@ -0,0 +1,11 @@ +env GO111MODULE=off + +# issue 25980: crash in go list -e -test +go list -e -test -deps -f '{{.Error}}' p +stdout '^p[/\\]d_test.go:2:8: cannot find package "d" in any of:' + +-- p/d.go -- +package d +-- p/d_test.go -- +package d_test +import _ "d" diff --git a/go/src/cmd/go/testdata/script/list_test_err.txt b/go/src/cmd/go/testdata/script/list_test_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..02bd6a16d41caf4b20af6cd38cf3748613cab41d --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_test_err.txt @@ -0,0 +1,118 @@ +env GO111MODULE=off + +# issue 28491: errors in test source files should not prevent +# "go list -test" from returning useful information. + +# go list -e prints information for all test packages. +# The syntax error is shown in the package error field. +go list -e -test -deps -f '{{.ImportPath}} {{.Error | printf "%q"}}' syntaxerr +stdout 'pkgdep ' +stdout 'testdep_a ' +stdout 'testdep_b ' +stdout 'syntaxerr ' +stdout 'syntaxerr \[syntaxerr.test\] ' +stdout 'syntaxerr_test \[syntaxerr.test\] ' +stdout 'syntaxerr\.test "[^"]*expected declaration' +! stderr 'expected declaration' + +[short] stop + +go list -e -test -deps -f '{{.ImportPath}} {{.Error | printf "%q"}}' nameerr +stdout 'pkgdep ' +stdout 'testdep_a ' +stdout 'testdep_b ' +stdout 'nameerr\.test "[^"]*wrong signature for TestBad' +! stderr 'wrong signature for TestBad' + +# go list prints a useful error for generic test functions +! go list -test -deps genericerr +stderr 'wrong signature for TestGeneric, test functions cannot have type parameters' + +go list -e -test -deps -f '{{.ImportPath}} {{.Error | printf "%q"}}' cycleerr +stdout 'cycleerr ' +stdout 'testdep_a ' +stdout 'testdep_cycle \[cycleerr.test\] ' +stdout 'cycleerr \[cycleerr.test\] "[^"]*import cycle not allowed in test' +! stderr 'import cycle not allowed in test' + +-- syntaxerr/syntaxerr.go -- +package syntaxerr + +import _ "pkgdep" + +-- syntaxerr/syntaxerr_ie_test.go -- +package syntaxerr + +!!!syntax error + +-- syntaxerr/syntaxerr_xe_test.go -- +package syntaxerr_test + +!!!syntax error + +-- syntaxerr/syntaxerr_i_test.go -- +package syntaxerr + +import _ "testdep_a" + +-- syntaxerr/syntaxerr_x_test.go -- +package syntaxerr + +import _ "testdep_b" + +-- nameerr/nameerr.go -- +package nameerr + +import _ "pkgdep" + +-- nameerr/nameerr_i_test.go -- +package nameerr + +import ( + _ "testdep_a" + "testing" +) + +func TestBad(t *testing.B) {} + +-- nameerr/nameerr_x_test.go -- +package nameerr_test + +import ( + _ "testdep_b" + "testing" +) + +func TestBad(t *testing.B) {} + +-- genericerr/genericerr.go -- +package genericerr + +-- genericerr/genericerr_test.go -- +package genericerr + +import "testing" + +func TestGeneric[T any](t *testing.T) {} + +-- cycleerr/cycleerr_test.go -- +package cycleerr + +import ( + _ "testdep_a" + _ "testdep_cycle" +) + +-- pkgdep/pkgdep.go -- +package pkgdep + +-- testdep_a/testdep_a.go -- +package testdep_a + +-- testdep_b/testdep_b.go -- +package testdep_b + +-- testdep_cycle/testdep_cycle.go -- +package testdep_cycle + +import _ "cycleerr" diff --git a/go/src/cmd/go/testdata/script/list_test_imports.txt b/go/src/cmd/go/testdata/script/list_test_imports.txt new file mode 100644 index 0000000000000000000000000000000000000000..0342eba86238d245819ab5b45b84bff0703f5fa7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_test_imports.txt @@ -0,0 +1,21 @@ +env GO111MODULE=off + +# issue 26880: list with tests has wrong variant in imports +go list -test -f '{{.ImportPath}}:{{with .Imports}} {{join . ", "}}{{end}}' a b +cmp stdout imports.txt + +-- a/a.go -- +package a; import _ "b" +-- b/b.go -- +package b +-- b/b_test.go -- +package b +-- b/b_x_test.go -- +package b_test; import _ "a" + +-- imports.txt -- +a: b +b: +b.test: b [b.test], b_test [b.test], os, reflect, testing, testing/internal/testdeps +b [b.test]: +b_test [b.test]: a [b.test] diff --git a/go/src/cmd/go/testdata/script/list_test_non_go_files.txt b/go/src/cmd/go/testdata/script/list_test_non_go_files.txt new file mode 100644 index 0000000000000000000000000000000000000000..6b2b6336a6c803f6ace98deb2ab047db4c3a8cdc --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_test_non_go_files.txt @@ -0,0 +1,13 @@ +env GO111MODULE=off + +# issue 29899: handling files with non-Go extension +go list -e -test -json -- c.c x.go +stdout '"Err": "named files must be .go files: c.c"' + +! go list -test -json -- c.c x.go +stderr '^named files must be \.go files: c\.c$' + +-- x.go -- +package main +-- c.c -- +package c diff --git a/go/src/cmd/go/testdata/script/list_test_simple.txt b/go/src/cmd/go/testdata/script/list_test_simple.txt new file mode 100644 index 0000000000000000000000000000000000000000..cb2d5ea30c0b9c330d7aec2ec7d978f37e02c4c8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_test_simple.txt @@ -0,0 +1,67 @@ +[short] skip + +# Test +go test -list=Test +stdout TestSimple + +# Benchmark +go test -list=Benchmark +stdout BenchmarkSimple + +# Examples +go test -list=Example +stdout Example_simple +stdout Example_withEmptyOutput + +-- go.mod -- +module m + +go 1.16 +-- bench_test.go -- +package testlist + +import ( + "fmt" + "testing" +) + +func BenchmarkSimplefunc(b *testing.B) { + b.StopTimer() + b.StartTimer() + for i := 0; i < b.N; i++ { + _ = fmt.Sprint("Test for bench") + } +} +-- example_test.go -- +package testlist + +import ( + "fmt" +) + +func Example_simple() { + fmt.Println("Test with Output.") + + // Output: Test with Output. +} + +func Example_withEmptyOutput() { + fmt.Println("") + + // Output: +} + +func Example_noOutput() { + _ = fmt.Sprint("Test with no output") +} +-- test_test.go -- +package testlist + +import ( + "fmt" + "testing" +) + +func TestSimple(t *testing.T) { + _ = fmt.Sprint("Test simple") +} diff --git a/go/src/cmd/go/testdata/script/list_testdata.txt b/go/src/cmd/go/testdata/script/list_testdata.txt new file mode 100644 index 0000000000000000000000000000000000000000..d62dd55c7d2caf2a7f5a7f6c5022dd74855f5fd6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_testdata.txt @@ -0,0 +1,11 @@ +# Issue 65406. The testdata directory in GOROOT/src +# shouldn't be treated as a standard package. + +go list -f '{{.ImportPath}} {{.Dir}}' testdata +! stderr 'found package testdata in multiple modules' +stdout 'testdata '$WORK${/}'gopath'${/}'src' + +-- go.mod -- +module testdata +-- p.go -- +package p \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_tool.txt b/go/src/cmd/go/testdata/script/list_tool.txt new file mode 100644 index 0000000000000000000000000000000000000000..5b14b018b884dd9833f14e261a29ced85fc63202 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_tool.txt @@ -0,0 +1,82 @@ +go list tool +stdout example.com/foo/cmd +stdout example.com/dependency/cmd/bar +go list all +stdout example.com/foo/cmd +stdout example.com/foo/lib +stdout example.com/dependency/cmd/bar + +cd workspace +go list tool +stdout example.com/foo/cmd +stdout example.com/dependency/cmd/bar +stdout example.com/dependency/cmd/baz +go list all +stdout example.com/foo/cmd +stdout example.com/foo/lib +stdout example.com/other +stdout example.com/dependency/cmd/bar +stdout example.com/dependency/cmd/baz + +cd ../invalid_path +! go list all +stderr 'malformed tool path' + +-- go.mod -- +module example.com/foo + +go 1.24 + +tool example.com/foo/cmd/eg +tool example.com/dependency/cmd/bar + +replace example.com/dependency => ./dependency + +require example.com/dependency v1.0.0 + +-- lib/main.go -- +package lib + +-- cmd/eg/main.go -- +package main + +func main(){} + +-- dependency/go.mod -- +module example.com/dependency + +go 1.24 +-- dependency/cmd/bar/main.go -- +package main + +func main(){} +-- dependency/cmd/baz/main.go -- +package main + +func main() {} +-- other/go.mod -- +module example.com/other + +go 1.24 + +tool example.com/dependency/cmd/baz + +replace example.com/dependency => ../dependency + +require example.com/dependency v1.0.0 +-- other/lib.go -- +package other +-- workspace/go.work -- +go 1.24 + +use ( + ../ + ../other +) + +-- invalid_path/go.mod -- +module example.com/invalid_path + +go 1.24 + +tool ./invalid_path diff --git a/go/src/cmd/go/testdata/script/list_toolexec_stderr_issue22588.txt b/go/src/cmd/go/testdata/script/list_toolexec_stderr_issue22588.txt new file mode 100644 index 0000000000000000000000000000000000000000..dd2eaed2a1f1b2ccd7336d405916ba998ed1ef82 --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_toolexec_stderr_issue22588.txt @@ -0,0 +1,11 @@ +# This is a script test conversion of TestIssue22588 which was added in CL 76017. +# Test that the stderr of a tool run under toolexec doesn't affect caching. + +# Don't get confused by stderr coming from tools. +[!exec:/usr/bin/time] skip + +! stale runtime 'must be non-stale to compare staleness under -toolexec' + +go list -f '{{.Stale}}' runtime +go list -toolexec /usr/bin/time -f '{{.Stale}}' runtime +stdout 'false' # runtime should not be reported as stale \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/list_wildcard_skip_nonmatching.txt b/go/src/cmd/go/testdata/script/list_wildcard_skip_nonmatching.txt new file mode 100644 index 0000000000000000000000000000000000000000..02b1088297025857f00394e075116fde918ad49e --- /dev/null +++ b/go/src/cmd/go/testdata/script/list_wildcard_skip_nonmatching.txt @@ -0,0 +1,17 @@ +# Test that wildcards don't look in useless directories. + +# First make sure that badpkg fails the list of '...'. +! go list ./... +stderr badpkg + +# Check that the list of './goodpkg...' succeeds. That implies badpkg was skipped. +go list ./goodpkg... + +-- go.mod -- +module m + +go 1.16 +-- goodpkg/x.go -- +package goodpkg +-- badpkg/x.go -- +pkg badpkg diff --git a/go/src/cmd/go/testdata/script/load_test_pkg_err.txt b/go/src/cmd/go/testdata/script/load_test_pkg_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..d088ee40f3996e1001b85cb532e3456a1fc22cf4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/load_test_pkg_err.txt @@ -0,0 +1,30 @@ +# Tests issue 37971. Check that tests are still loaded even when the package has an error. + +go list -e -test d +cmp stdout want_stdout + +go list -e -test -deps d +stdout golang.org/fake/d + +-- want_stdout -- +d +d.test +d_test [d.test] +-- go.mod -- +module d + +go 1.16 +-- d.go -- +package d + +import "net/http" + +const d = http.MethodGet +func Get() string { return d; } +-- d2.go -- +-- d_test.go -- +package d_test + +import "testing" +import "golang.org/fake/d" +func TestD(t *testing.T) { d.Get(); } diff --git a/go/src/cmd/go/testdata/script/malformed_gosum_issue62345.txt b/go/src/cmd/go/testdata/script/malformed_gosum_issue62345.txt new file mode 100644 index 0000000000000000000000000000000000000000..23c41beae90ae39e3aa01cb7640195223515eb3c --- /dev/null +++ b/go/src/cmd/go/testdata/script/malformed_gosum_issue62345.txt @@ -0,0 +1,51 @@ +! go mod download +stderr '^malformed go.sum:\n.*go.sum:3: wrong number of fields 5\n$' + +go mod tidy +cmp go.sum go.sum.after-tidy + +-- go.mod -- +module m + +go 1.20 + +require rsc.io/quote v1.5.2 + +require ( + golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect + rsc.io/sampler v1.3.0 // indirect + rsc.io/testonly v1.0.0 // indirect +) + +-- go.sum -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2 # invalid line +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/testonly v1.0.0 h1:K/VWHdO+Jv7woUXG0GzVNx1czBXUt3Ib1deaMn+xk64= +rsc.io/testonly v1.0.0/go.mod h1:OqmGbIFOcF+XrFReLOGZ6BhMM7uMBiQwZsyNmh74SzY= + +-- main.go -- +package main + +import ( + "fmt" + + "rsc.io/quote" +) + +func main() { + fmt.Println(quote.Hello()) +} + +-- go.sum.after-tidy -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/testonly v1.0.0 h1:K/VWHdO+Jv7woUXG0GzVNx1czBXUt3Ib1deaMn+xk64= +rsc.io/testonly v1.0.0/go.mod h1:OqmGbIFOcF+XrFReLOGZ6BhMM7uMBiQwZsyNmh74SzY= diff --git a/go/src/cmd/go/testdata/script/mod_all.txt b/go/src/cmd/go/testdata/script/mod_all.txt new file mode 100644 index 0000000000000000000000000000000000000000..b71a920870a9bb7ffd2ad3668e10af24eb98991c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_all.txt @@ -0,0 +1,531 @@ +# This test illustrates the relationship between the 'all' pattern and +# the dependencies of the main module. + +# The package import graph used in this test looks like: +# +# main --------- a --------- b +# | | +# | a_test ---- c +# | | +# | c_test ---- d +# | +# main_test ---- t --------- u +# | +# t_test ---- w +# | +# w_test ---- x +# +# main/testonly_test ---- q --------- r +# | +# q_test ---- s +# +# And the module dependency graph looks like: +# +# main --- a.1 ---- b.1 +# \ \ \ +# \ \ c.1 -- d.1 +# \ \ +# \ t.1 ---- u.1 +# \ \ +# \ w.1 -- x.1 +# \ +# q.1 ---- r.1 +# \ +# s.1 + +env PKGFMT='{{if .Module}}{{.ImportPath}}{{end}}' +env MODFMT='{{.Path}}' + + +# 'go list -deps' lists packages and tests in the main module, +# along with their transitive dependencies. + +go list -f $PKGFMT -deps ./... +stdout -count=4 '^.' +stdout '^example.com/a$' +stdout '^example.com/b$' +stdout '^example.com/main$' +stdout '^example.com/main/testonly' + + +# 'go list -deps -test' lists transitive imports of tests and non-tests in the +# main module. + +go list -f $PKGFMT -deps -test ./... +stdout -count=13 '^.' +stdout '^example.com/a$' +stdout '^example.com/b$' +stdout '^example.com/main$' +stdout '^example.com/main.test$' +stdout '^example.com/main \[example.com/main.test\]$' +stdout '^example.com/main_test \[example.com/main.test\]$' +stdout '^example.com/main/testonly$' +stdout '^example.com/main/testonly.test$' +stdout '^example.com/main/testonly_test \[example.com/main/testonly.test\]$' +stdout '^example.com/q$' +stdout '^example.com/r$' +stdout '^example.com/t$' +stdout '^example.com/u$' + + +# 'go list all' lists the fixpoint of iterating 'go list -deps -test' starting +# with the packages in the main module, then reducing to only the non-test +# variants of those packages. + +go list -f $PKGFMT all +stdout -count=13 '^.' +stdout '^example.com/a$' +stdout '^example.com/b$' +stdout '^example.com/c$' +stdout '^example.com/d$' +stdout '^example.com/main$' +stdout '^example.com/main/testonly$' +stdout '^example.com/q$' +stdout '^example.com/r$' +stdout '^example.com/s$' +stdout '^example.com/t$' +stdout '^example.com/u$' +stdout '^example.com/w$' +stdout '^example.com/x$' + + +# 'go list -test all' is equivalent to 'go list -test $(go list all)' +# and both should include tests for every package in 'all'. + +go list -test -f $PKGFMT example.com/a example.com/b example.com/c example.com/d example.com/main example.com/main/testonly example.com/q example.com/r example.com/s example.com/t example.com/u example.com/w example.com/x +cp stdout list-test-explicit.txt + +go list -test -f $PKGFMT all +cmp stdout list-test-explicit.txt +stdout -count=36 '^.' +stdout '^example.com/a$' +stdout '^example.com/b$' +stdout '^example.com/c$' +stdout '^example.com/d$' +stdout '^example.com/main$' +stdout '^example.com/main/testonly$' +stdout '^example.com/q$' +stdout '^example.com/r$' +stdout '^example.com/s$' +stdout '^example.com/t$' +stdout '^example.com/u$' +stdout '^example.com/w$' +stdout '^example.com/x$' +stdout '^example.com/a.test$' +stdout '^example.com/a_test \[example.com/a.test\]$' +stdout '^example.com/b.test$' +stdout '^example.com/b_test \[example.com/b.test\]$' +stdout '^example.com/c.test$' +stdout '^example.com/c_test \[example.com/c.test\]$' +stdout '^example.com/main.test$' +stdout '^example.com/main \[example.com/main.test\]$' +stdout '^example.com/main_test \[example.com/main.test\]$' +stdout '^example.com/main/testonly.test$' +stdout '^example.com/main/testonly_test \[example.com/main/testonly.test\]$' +stdout '^example.com/q.test$' +stdout '^example.com/q_test \[example.com/q.test\]$' +stdout '^example.com/r.test$' +stdout '^example.com/r_test \[example.com/r.test\]$' +stdout '^example.com/s.test$' +stdout '^example.com/s_test \[example.com/s.test\]$' +stdout '^example.com/t.test$' +stdout '^example.com/t_test \[example.com/t.test\]$' +stdout '^example.com/u.test$' +stdout '^example.com/u_test \[example.com/u.test\]$' +stdout '^example.com/w.test$' +stdout '^example.com/w_test \[example.com/w.test\]$' + + +# 'go list -m all' covers the packages in 'go list -test -deps all'. + +go list -m -f $MODFMT all +stdout -count=12 '^.' +stdout '^example.com/a$' +stdout '^example.com/b$' +stdout '^example.com/c$' +stdout '^example.com/d$' +stdout '^example.com/main$' +stdout '^example.com/q$' +stdout '^example.com/r$' +stdout '^example.com/s$' +stdout '^example.com/t$' +stdout '^example.com/u$' +stdout '^example.com/w$' +stdout '^example.com/x$' + + +# 'go mod vendor' copies in only the packages transitively imported by the main +# module, and omits their tests. As a result, the 'all' and '...' patterns +# report fewer packages when using '-mod=vendor'. + +go mod vendor + +go list -f $PKGFMT -mod=vendor all +stdout -count=8 '^.' +stdout '^example.com/a$' +stdout '^example.com/b$' +stdout '^example.com/main$' +stdout '^example.com/main/testonly$' +stdout '^example.com/q$' +stdout '^example.com/r$' +stdout '^example.com/t$' +stdout '^example.com/u$' + +go list -test -f $PKGFMT -mod=vendor all +stdout -count=13 '^.' +stdout '^example.com/a$' +stdout '^example.com/b$' +stdout '^example.com/main$' +stdout '^example.com/main/testonly$' +stdout '^example.com/q$' +stdout '^example.com/r$' +stdout '^example.com/t$' +stdout '^example.com/u$' +stdout '^example.com/main.test$' +stdout '^example.com/main \[example.com/main.test\]$' +stdout '^example.com/main_test \[example.com/main.test\]$' +stdout '^example.com/main/testonly.test$' +stdout '^example.com/main/testonly_test \[example.com/main/testonly.test\]$' + +rm vendor + +# Convert all modules to go 1.17 to enable lazy loading. +go mod edit -go=1.17 a/go.mod +go mod edit -go=1.17 b/go.mod +go mod edit -go=1.17 c/go.mod +go mod edit -go=1.17 d/go.mod +go mod edit -go=1.17 q/go.mod +go mod edit -go=1.17 r/go.mod +go mod edit -go=1.17 s/go.mod +go mod edit -go=1.17 t/go.mod +go mod edit -go=1.17 u/go.mod +go mod edit -go=1.17 w/go.mod +go mod edit -go=1.17 x/go.mod +go mod edit -go=1.17 +cmp go.mod go.mod.beforetidy +go mod tidy +cmp go.mod go.mod.aftertidy + +# With lazy loading, 'go list all' with neither -mod=vendor nor -test should +# match -mod=vendor without -test in 1.15. + +go list -f $PKGFMT all +stdout -count=8 '^.' +stdout '^example.com/a$' +stdout '^example.com/b$' +stdout '^example.com/main$' +stdout '^example.com/main/testonly$' +stdout '^example.com/q$' +stdout '^example.com/r$' +stdout '^example.com/t$' +stdout '^example.com/u$' + +# 'go list -test all' should expand that to include the test variants of the +# packages in 'all', but not the dependencies of outside tests. + +go list -test -f $PKGFMT all +stdout -count=25 '^.' +stdout '^example.com/a$' +stdout '^example.com/b$' +stdout '^example.com/main$' +stdout '^example.com/main/testonly$' +stdout '^example.com/q$' +stdout '^example.com/r$' +stdout '^example.com/t$' +stdout '^example.com/u$' +stdout '^example.com/a.test$' +stdout '^example.com/a_test \[example.com/a.test\]$' +stdout '^example.com/b.test$' +stdout '^example.com/b_test \[example.com/b.test\]$' +stdout '^example.com/main.test$' +stdout '^example.com/main \[example.com/main.test\]$' +stdout '^example.com/main_test \[example.com/main.test\]$' +stdout '^example.com/main/testonly.test$' +stdout '^example.com/main/testonly_test \[example.com/main/testonly.test\]$' +stdout '^example.com/q.test$' +stdout '^example.com/q_test \[example.com/q.test\]$' +stdout '^example.com/r.test$' +stdout '^example.com/r_test \[example.com/r.test\]$' +stdout '^example.com/t.test$' +stdout '^example.com/t_test \[example.com/t.test\]$' +stdout '^example.com/u.test$' +stdout '^example.com/u_test \[example.com/u.test\]$' + +# 'go list -test -deps all' should include the dependencies of those tests, +# but not the tests of the dependencies of outside tests. + +go list -test -deps -f $PKGFMT all +stdout -count=28 '^.' +stdout '^example.com/a$' +stdout '^example.com/b$' +stdout '^example.com/c$' +stdout '^example.com/main$' +stdout '^example.com/main/testonly$' +stdout '^example.com/q$' +stdout '^example.com/r$' +stdout '^example.com/s$' +stdout '^example.com/t$' +stdout '^example.com/u$' +stdout '^example.com/w$' +stdout '^example.com/a.test$' +stdout '^example.com/a_test \[example.com/a.test\]$' +stdout '^example.com/b.test$' +stdout '^example.com/b_test \[example.com/b.test\]$' +stdout '^example.com/main.test$' +stdout '^example.com/main \[example.com/main.test\]$' +stdout '^example.com/main_test \[example.com/main.test\]$' +stdout '^example.com/main/testonly.test$' +stdout '^example.com/main/testonly_test \[example.com/main/testonly.test\]$' +stdout '^example.com/q.test$' +stdout '^example.com/q_test \[example.com/q.test\]$' +stdout '^example.com/r.test$' +stdout '^example.com/r_test \[example.com/r.test\]$' +stdout '^example.com/t.test$' +stdout '^example.com/t_test \[example.com/t.test\]$' +stdout '^example.com/u.test$' +stdout '^example.com/u_test \[example.com/u.test\]$' + +# 'go list -m all' should cover all of the modules providing packages in +# 'go list -test -deps all', but should exclude modules d and x, +# which are not relevant to the main module and are outside of the +# lazy-loading horizon. + +go list -m -f $MODFMT all +stdout -count=10 '^.' +stdout '^example.com/a$' +stdout '^example.com/b$' +stdout '^example.com/c$' +! stdout '^example.com/d$' +stdout '^example.com/main$' +stdout '^example.com/q$' +stdout '^example.com/r$' +stdout '^example.com/s$' +stdout '^example.com/t$' +stdout '^example.com/u$' +stdout '^example.com/w$' +! stdout '^example.com/x$' + +-- go.mod -- +module example.com/main + +// Note: this go.mod file initially specifies go 1.15, +// but includes some redundant roots so that it +// also already obeys the 1.17 lazy loading invariants. +go 1.15 + +require ( + example.com/a v0.1.0 + example.com/b v0.1.0 // indirect + example.com/q v0.1.0 + example.com/r v0.1.0 // indirect + example.com/t v0.1.0 + example.com/u v0.1.0 // indirect +) + +replace ( + example.com/a v0.1.0 => ./a + example.com/b v0.1.0 => ./b + example.com/c v0.1.0 => ./c + example.com/d v0.1.0 => ./d + example.com/q v0.1.0 => ./q + example.com/r v0.1.0 => ./r + example.com/s v0.1.0 => ./s + example.com/t v0.1.0 => ./t + example.com/u v0.1.0 => ./u + example.com/w v0.1.0 => ./w + example.com/x v0.1.0 => ./x +) +-- main.go -- +package main + +import _ "example.com/a" + +func main() {} +-- main_test.go -- +package main_test + +import _ "example.com/t" +-- testonly/testonly_test.go -- +package testonly_test + +import _ "example.com/q" +-- a/go.mod -- +module example.com/a + +go 1.15 + +require ( + example.com/b v0.1.0 + example.com/c v0.1.0 +) +-- a/a.go -- +package a + +import _ "example.com/b" +-- a/a_test.go -- +package a_test + +import _ "example.com/c" +-- b/go.mod -- +module example.com/b + +go 1.15 +-- b/b.go -- +package b +-- b/b_test.go -- +package b_test +-- c/go.mod -- +module example.com/c + +go 1.15 + +require example.com/d v0.1.0 +-- c/c.go -- +package c +-- c/c_test.go -- +package c_test + +import _ "example.com/d" +-- d/go.mod -- +module example.com/d + +go 1.15 +-- d/d.go -- +package d +-- q/go.mod -- +module example.com/q + +go 1.15 + +require ( + example.com/r v0.1.0 + example.com/s v0.1.0 +) +-- q/q.go -- +package q +import _ "example.com/r" +-- q/q_test.go -- +package q_test +import _ "example.com/s" +-- r/go.mod -- +module example.com/r + +go 1.15 +-- r/r.go -- +package r +-- r/r_test.go -- +package r_test +-- s/go.mod -- +module example.com/s + +go 1.15 +-- s/s.go -- +package s +-- s/s_test.go -- +package s_test +-- t/go.mod -- +module example.com/t + +go 1.15 + +require ( + example.com/u v0.1.0 + example.com/w v0.1.0 +) +-- t/t.go -- +package t + +import _ "example.com/u" +-- t/t_test.go -- +package t_test + +import _ "example.com/w" +-- u/go.mod -- +module example.com/u + +go 1.15 +-- u/u.go -- +package u +-- u/u_test.go -- +package u_test +-- w/go.mod -- +module example.com/w + +go 1.15 + +require example.com/x v0.1.0 +-- w/w.go -- +package w +-- w/w_test.go -- +package w_test + +import _ "example.com/x" +-- x/go.mod -- +module example.com/x + +go 1.15 +-- x/x.go -- +package x +-- go.mod.beforetidy -- +module example.com/main + +// Note: this go.mod file initially specifies go 1.15, +// but includes some redundant roots so that it +// also already obeys the 1.17 lazy loading invariants. +go 1.17 + +require ( + example.com/a v0.1.0 + example.com/b v0.1.0 // indirect + example.com/q v0.1.0 + example.com/r v0.1.0 // indirect + example.com/t v0.1.0 + example.com/u v0.1.0 // indirect +) + +replace ( + example.com/a v0.1.0 => ./a + example.com/b v0.1.0 => ./b + example.com/c v0.1.0 => ./c + example.com/d v0.1.0 => ./d + example.com/q v0.1.0 => ./q + example.com/r v0.1.0 => ./r + example.com/s v0.1.0 => ./s + example.com/t v0.1.0 => ./t + example.com/u v0.1.0 => ./u + example.com/w v0.1.0 => ./w + example.com/x v0.1.0 => ./x +) +-- go.mod.aftertidy -- +module example.com/main + +// Note: this go.mod file initially specifies go 1.15, +// but includes some redundant roots so that it +// also already obeys the 1.17 lazy loading invariants. +go 1.17 + +require ( + example.com/a v0.1.0 + example.com/q v0.1.0 + example.com/t v0.1.0 +) + +require ( + example.com/b v0.1.0 // indirect + example.com/r v0.1.0 // indirect + example.com/u v0.1.0 // indirect +) + +replace ( + example.com/a v0.1.0 => ./a + example.com/b v0.1.0 => ./b + example.com/c v0.1.0 => ./c + example.com/d v0.1.0 => ./d + example.com/q v0.1.0 => ./q + example.com/r v0.1.0 => ./r + example.com/s v0.1.0 => ./s + example.com/t v0.1.0 => ./t + example.com/u v0.1.0 => ./u + example.com/w v0.1.0 => ./w + example.com/x v0.1.0 => ./x +) diff --git a/go/src/cmd/go/testdata/script/mod_alt_goroot.txt b/go/src/cmd/go/testdata/script/mod_alt_goroot.txt new file mode 100644 index 0000000000000000000000000000000000000000..32f94c53038084994e351fa5f157c16955ddbf65 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_alt_goroot.txt @@ -0,0 +1,20 @@ +env GO111MODULE=on + +# If the working directory is a different GOROOT, then the 'std' module should be +# treated as an ordinary module (with an ordinary module prefix). +# It should not override packages in GOROOT, but should not fail the command. +# See golang.org/issue/30756. +go list -e -deps -f '{{.ImportPath}} {{.Dir}}' ./bytes +stdout ^std/bytes.*$PWD[/\\]bytes +stdout '^bytes/modified' + +-- go.mod -- +module std + +go 1.12 +-- bytes/bytes.go -- +package bytes + +import _"bytes/modified" +-- bytes/modified/modified.go -- +package modified diff --git a/go/src/cmd/go/testdata/script/mod_ambiguous_import.txt b/go/src/cmd/go/testdata/script/mod_ambiguous_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..feaf5d273d6bf12eeb41bbdc07242034c0a34f15 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_ambiguous_import.txt @@ -0,0 +1,48 @@ +env GO111MODULE=on + +cd $WORK + +# An import provided by two different modules should be flagged as an error. +! go build ./importx +stderr '^importx[/\\]importx.go:2:8: ambiguous import: found package example.com/a/x in multiple modules:\n\texample.com/a v0.1.0 \('$WORK'[/\\]a[/\\]x\)\n\texample.com/a/x v0.1.0 \('$WORK'[/\\]ax\)$' + +# However, it should not be an error if that import is unused. +go build ./importy + +# An import provided by both the main module and the vendor directory +# should be flagged as an error only when -mod=vendor is set. +mkdir vendor/example.com/m/importy +cp $WORK/importy/importy.go vendor/example.com/m/importy/importy.go +go build example.com/m/importy +! go build -mod=vendor example.com/m/importy +stderr '^ambiguous import: found package example.com/m/importy in multiple directories:\n\t'$WORK'[/\\]importy\n\t'$WORK'[/\\]vendor[/\\]example.com[/\\]m[/\\]importy$' + +-- $WORK/go.mod -- +module example.com/m +go 1.13 +require ( + example.com/a v0.1.0 + example.com/a/x v0.1.0 +) +replace ( + example.com/a v0.1.0 => ./a + example.com/a/x v0.1.0 => ./ax +) +-- $WORK/importx/importx.go -- +package importx +import _ "example.com/a/x" +-- $WORK/importy/importy.go -- +package importy +import _ "example.com/a/y" +-- $WORK/a/go.mod -- +module example.com/a +go 1.14 +-- $WORK/a/x/x.go -- +package x +-- $WORK/a/y/y.go -- +package y +-- $WORK/ax/go.mod -- +module example.com/a/x +go 1.14 +-- $WORK/ax/x.go -- +package x diff --git a/go/src/cmd/go/testdata/script/mod_auth.txt b/go/src/cmd/go/testdata/script/mod_auth.txt new file mode 100644 index 0000000000000000000000000000000000000000..5e2b7a918fa6df17147728d4b02ff11215a15554 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_auth.txt @@ -0,0 +1,35 @@ +[short] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off +env GOVCS='*:off' + +# Without credentials, downloading a module from a path that requires HTTPS +# basic auth should fail. +env NETRC=$WORK/empty +! go mod tidy +stderr '^\tserver response: ACCESS DENIED, buddy$' +stderr '^\tserver response: File\? What file\?$' + +# With credentials from a netrc file, it should succeed. +env NETRC=$WORK/netrc +go mod tidy +go list all +stdout vcs-test.golang.org/auth/or401 +stdout vcs-test.golang.org/auth/or404 + +-- go.mod -- +module private.example.com +-- main.go -- +package useprivate + +import ( + _ "vcs-test.golang.org/auth/or401" + _ "vcs-test.golang.org/auth/or404" +) +-- $WORK/empty -- +-- $WORK/netrc -- +machine vcs-test.golang.org + login aladdin + password opensesame diff --git a/go/src/cmd/go/testdata/script/mod_bad_domain.txt b/go/src/cmd/go/testdata/script/mod_bad_domain.txt new file mode 100644 index 0000000000000000000000000000000000000000..86aa96e7d46a42070e85ca61be431158b60f60d6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_bad_domain.txt @@ -0,0 +1,47 @@ +env GO111MODULE=on + +# explicit get should report errors about bad names +! go get appengine +stderr '^go: malformed module path "appengine": missing dot in first path element$' +! go get x/y.z +stderr 'malformed module path "x/y.z": missing dot in first path element' + + +# 'go list -m' should report errors about module names, never GOROOT. +! go list -m -versions appengine +stderr 'malformed module path "appengine": missing dot in first path element' +! go list -m -versions x/y.z +stderr 'malformed module path "x/y.z": missing dot in first path element' + + +# build should report all unsatisfied imports, +# but should be more definitive about non-module import paths +! go build ./useappengine +stderr '^useappengine[/\\]x.go:2:8: cannot find package$' +! go build ./usenonexistent +stderr '^usenonexistent[/\\]x.go:2:8: no required module provides package nonexistent.rsc.io; to add it:\n\tgo get nonexistent.rsc.io$' + + +# 'get -d' should be similarly definitive + +go get ./useappengine # TODO(#41315): This should fail. + # stderr '^useappengine[/\\]x.go:2:8: cannot find package$' + +! go get ./usenonexistent +stderr '^go: x/usenonexistent imports\n\tnonexistent.rsc.io: cannot find module providing package nonexistent.rsc.io$' + + +# go mod vendor and go mod tidy should ignore appengine imports. +rm usenonexistent/x.go +go mod tidy +go mod vendor + +-- go.mod -- +module x + +-- useappengine/x.go -- +package useappengine +import _ "appengine" // package does not exist +-- usenonexistent/x.go -- +package usenonexistent +import _ "nonexistent.rsc.io" // domain does not exist diff --git a/go/src/cmd/go/testdata/script/mod_bad_filenames.txt b/go/src/cmd/go/testdata/script/mod_bad_filenames.txt new file mode 100644 index 0000000000000000000000000000000000000000..eb556f4c7cf5e1246aa59264d13c96fe62e27aa5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_bad_filenames.txt @@ -0,0 +1,11 @@ +env GO111MODULE=on + +! go get rsc.io/badfile1 rsc.io/badfile2 rsc.io/badfile3 rsc.io/badfile4 rsc.io/badfile5 +! stderr 'unzip.*badfile1' +stderr 'unzip.*badfile2[\\/]@v[\\/]v1.0.0.zip:.*malformed file path "☺.go": invalid char ''☺''' +stderr 'unzip.*badfile3[\\/]@v[\\/]v1.0.0.zip: rsc.io[\\/]badfile3@v1.0.0[\\/]x\?y.go: malformed file path "x\?y.go": invalid char ''\?''' +stderr 'unzip.*badfile4[\\/]@v[\\/]v1.0.0.zip: rsc.io[\\/]badfile4@v1.0.0[\\/]x[\\/]y.go: case-insensitive file name collision: "x/Y.go" and "x/y.go"' +stderr 'unzip.*badfile5[\\/]@v[\\/]v1.0.0.zip: rsc.io[\\/]badfile5@v1.0.0[\\/]x[\\/]Y[\\/]zz[\\/]ww.go: case-insensitive file name collision: "x/y" and "x/Y"' + +-- go.mod -- +module x diff --git a/go/src/cmd/go/testdata/script/mod_build_info_err.txt b/go/src/cmd/go/testdata/script/mod_build_info_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..8d7bd0c3878868f3d32bba7012e31b485a5da5f4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_build_info_err.txt @@ -0,0 +1,33 @@ +# This test verifies that line numbers are included in module import errors. +# Verifies golang.org/issue/34393. + +go list -e -mod=mod -deps -f '{{with .Error}}{{.Pos}}: {{.Err}}{{end}}' ./main +stdout '^bad[/\\]bad.go:3:8: malformed import path "ðŸ§.example.com/string": invalid char ''ðŸ§''$' + +# TODO(#26909): This should include an import stack. +# (Today it includes only a file and line.) +! go build ./main +stderr '^bad[/\\]bad.go:3:8: malformed import path "ðŸ§.example.com/string": invalid char ''ðŸ§''$' + +# TODO(#41688): This should include a file and line, and report the reason for the error.. +# (Today it includes only an import stack.) +! go get ./main +stderr '^go: m/main imports\n\tm/bad imports\n\tðŸ§.example.com/string: malformed import path "ðŸ§.example.com/string": invalid char ''ðŸ§''$' + + +-- go.mod -- +module m + +go 1.13 + +-- main/main.go -- +package main + +import _ "m/bad" + +func main() {} + +-- bad/bad.go -- +package bad + +import _ "ðŸ§.example.com/string" diff --git a/go/src/cmd/go/testdata/script/mod_build_tags.txt b/go/src/cmd/go/testdata/script/mod_build_tags.txt new file mode 100644 index 0000000000000000000000000000000000000000..ae1d605e1f2f1227bbdea8c70c55f69941b6074f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_build_tags.txt @@ -0,0 +1,33 @@ +# Test that build tags are used. +# golang.org/issue/24053. + +env GO111MODULE=on + +cd x +! go list -f {{.GoFiles}} +stderr 'build constraints exclude all Go files' + +go list -f {{.GoFiles}} -tags tag1 +stdout '\[x.go\]' + +go list -f {{.GoFiles}} -tags tag2 +stdout '\[y\.go\]' + +go list -f {{.GoFiles}} -tags 'tag1 tag2' +stdout '\[x\.go y\.go\]' + +go list -f {{.GoFiles}} -tags tag1,tag2 # commas allowed as of Go 1.13 +stdout '\[x\.go y\.go\]' + +-- x/go.mod -- +module x + +-- x/x.go -- +// +build tag1 + +package y + +-- x/y.go -- +// +build tag2 + +package y diff --git a/go/src/cmd/go/testdata/script/mod_build_trimpath_issue48557.txt b/go/src/cmd/go/testdata/script/mod_build_trimpath_issue48557.txt new file mode 100644 index 0000000000000000000000000000000000000000..859eafcf84dff71d478735102d6777d09ec54f85 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_build_trimpath_issue48557.txt @@ -0,0 +1,52 @@ +# Regression test for issue #48557. +# Since builds in module mode do not support relative imports at all, the build +# ID for (and other contents of) a binary built with -trimpath in module mode +# should not depend on its working directory, even if the binary is specified as +# a list of relative source files. + +[short] skip # links and runs binaries + +env GOFLAGS=-trimpath +env GOCACHE=$WORK/gocache + + +# When we build a binary in module mode with -trimpath, the -D flag (for the +# "local import prefix") should not be passed to it. + +cd $WORK/tmp/foo +go build -x -o a.exe main.go +stderr ${/}compile$GOEXE.*' -nolocalimports' +! stderr ${/}compile$GOEXE.*' -D[ =]' + +go tool buildid a.exe +cp stdout ../foo-buildid.txt +go version a.exe +cp stdout ../foo-version.txt +cd .. + + +# On the second build — in a different directory but with -trimpath — the +# compiler should not be invoked, since the cache key should be identical. +# Only the linker and buildid tool should be needed. + +mkdir bar +cp foo/main.go bar/main.go +cd bar +go build -x -o a.exe main.go +! stderr ${/}compile$GOEXE + +go tool buildid a.exe +cp stdout ../bar-buildid.txt +go version a.exe +cp stdout ../bar-version.txt +cd .. + +cmp bar-buildid.txt foo-buildid.txt +cmp bar-version.txt foo-version.txt +cmp bar/a.exe foo/a.exe + + +-- $WORK/tmp/foo/main.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_build_versioned.txt b/go/src/cmd/go/testdata/script/mod_build_versioned.txt new file mode 100644 index 0000000000000000000000000000000000000000..f55041834aefe874bb195b4ce77999545846a668 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_build_versioned.txt @@ -0,0 +1,17 @@ +env GO111MODULE=on +[short] skip + +go get rsc.io/fortune/v2 + +# The default executable name shouldn't be v2$GOEXE +go build rsc.io/fortune/v2 +! exists v2$GOEXE +exists fortune$GOEXE + +# The default test binary name shouldn't be v2.test$GOEXE +go test -c rsc.io/fortune/v2 +! exists v2.test$GOEXE +exists fortune.test$GOEXE + +-- go.mod -- +module scratch diff --git a/go/src/cmd/go/testdata/script/mod_cache_dir.txt b/go/src/cmd/go/testdata/script/mod_cache_dir.txt new file mode 100644 index 0000000000000000000000000000000000000000..4045928a9781b7e5cbb826508be511f551f395b3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_cache_dir.txt @@ -0,0 +1,11 @@ +env GO111MODULE=on + +# Go should reject relative paths in GOMODCACHE environment. + +env GOMODCACHE="~/test" +! go install example.com/tools/cmd/hello@latest +stderr 'must be absolute path' + +env GOMODCACHE="./test" +! go install example.com/tools/cmd/hello@latest +stderr 'must be absolute path' diff --git a/go/src/cmd/go/testdata/script/mod_cache_rw.txt b/go/src/cmd/go/testdata/script/mod_cache_rw.txt new file mode 100644 index 0000000000000000000000000000000000000000..151bdfb791f6b289240e510c361f6a1b509e342f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_cache_rw.txt @@ -0,0 +1,58 @@ +# Regression test for golang.org/issue/31481. + +env GO111MODULE=on + +# golang.org/issue/31481: an explicit flag should make directories in the module +# cache writable in order to work around the historical inability of 'rm -rf' to +# forcibly remove files in unwritable directories. +go get -modcacherw rsc.io/quote@v1.5.2 +cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/extraneous_file.go + +# After adding an extraneous file, 'go mod verify' should fail. +! go mod verify + +# However, files within those directories should still be read-only to avoid +# accidental mutations. +[!root] ! cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod + +# If all 'go' commands ran with the flag, the system's 'rm' binary +# should be able to remove the module cache if the '-rf' flags are set. +[!GOOS:windows] [exec:rm] exec rm -rf $GOPATH/pkg/mod +[!GOOS:windows] [!exec:rm] go clean -modcache +[GOOS:windows] [exec:cmd.exe] exec cmd.exe /c rmdir /s /q $GOPATH\pkg\mod +[GOOS:windows] [!exec:cmd.exe] go clean -modcache +! exists $GOPATH/pkg/mod + +# The directories in the module cache should by default be unwritable, +# so that tests and tools will not accidentally add extraneous files to them. +# Windows does not respect FILE_ATTRIBUTE_READONLY on directories, according +# to MSDN, so there we disable testing whether the directory itself is +# unwritable. +go get rsc.io/quote@latest +[!root] ! cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod +[!GOOS:windows] [!root] ! cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/extraneous_file.go +! exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/extraneous_file.go + + +# Repeat part of the test with 'go mod download' instead of 'go get' to verify +# -modcacherw is supported on 'go mod' subcommands. +go clean -modcache +go mod download -modcacherw rsc.io/quote +cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/extraneous_file.go +! go mod verify +[!root] ! cp $WORK/extraneous.txt $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod + +# Repeat part of the test with 'go tool' +go mod edit -tool example.com/tools/cmd/hello -require example.com/tools@v1.0.0 +go mod download -modcacherw example.com/tools +go clean -modcache +go tool -modcacherw hello +cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/tools@v1.0.0/extraneous_file.go +! go mod verify +[!root] ! cp $WORK/extraneous.txt $GOPATH/pkg/mod/example.com/tools@v1.0.0/cmd/hello/hello.go + + +-- $WORK/extraneous.txt -- +module oops +-- go.mod -- +module golang.org/issue/31481 diff --git a/go/src/cmd/go/testdata/script/mod_case.txt b/go/src/cmd/go/testdata/script/mod_case.txt new file mode 100644 index 0000000000000000000000000000000000000000..d3fb11dfa332168acb0ffa4188800d4bbb4a7d60 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_case.txt @@ -0,0 +1,25 @@ +env GO111MODULE=on + +go get +go list -m all +stdout '^rsc.io/quote v1.5.2' +stdout '^rsc.io/QUOTE v1.5.2' + +go list -f 'DIR {{.Dir}} DEPS {{.Deps}}' rsc.io/QUOTE/QUOTE +stdout 'DEPS.*rsc.io/quote' +stdout 'DIR.*!q!u!o!t!e' + +go get rsc.io/QUOTE@v1.5.3-PRE +go list -m all +stdout '^rsc.io/QUOTE v1.5.3-PRE' + +go list -f '{{.Dir}}' rsc.io/QUOTE/QUOTE +stdout '!q!u!o!t!e@v1.5.3-!p!r!e' + +-- go.mod -- +module x + +-- use.go -- +package use + +import _ "rsc.io/QUOTE/QUOTE" diff --git a/go/src/cmd/go/testdata/script/mod_case_cgo.txt b/go/src/cmd/go/testdata/script/mod_case_cgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..7c768a096395d93ec984a73eaf712c0ba389ba78 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_case_cgo.txt @@ -0,0 +1,11 @@ +[!cgo] skip + +env GO111MODULE=on + +go get rsc.io/CGO +[short] stop + +go build rsc.io/CGO + +-- go.mod -- +module x diff --git a/go/src/cmd/go/testdata/script/mod_clean_cache.txt b/go/src/cmd/go/testdata/script/mod_clean_cache.txt new file mode 100644 index 0000000000000000000000000000000000000000..2b8e820653b810307677dbc1c2060e9f4b3f27a5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_clean_cache.txt @@ -0,0 +1,61 @@ +env GO111MODULE=on + +# 'mod download' should download the module to the cache. +go mod download rsc.io/quote@v1.5.0 +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip + +# '-n' should print commands but not actually execute them. +go clean -modcache -n +stdout '^rm -rf .*pkg.mod$' +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip + +# 'go clean -modcache' should actually delete the files. +go clean -modcache +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip + +# 'go clean -r -modcache' should clean only the dependencies that are within the +# main module. +# BUG(golang.org/issue/28680): Today, it cleans across module boundaries. +cd r +exists ./test.out +exists ../replaced/test.out +go clean -r -modcache +! exists ./test.out +! exists ../replaced/test.out # BUG: should still exist + +# 'go clean -modcache' should not download anything before cleaning. +go mod edit -require rsc.io/quote@v1.99999999.0-not-a-real-version +go clean -modcache +! stderr 'finding rsc.io' +go mod edit -droprequire rsc.io/quote + +! go clean -modcache m +stderr 'go: clean -modcache cannot be used with package arguments' + +-- go.mod -- +module m +-- m.go -- +package m + +-- r/go.mod -- +module example.com/r +require example.com/r/replaced v0.0.0 +replace example.com/r/replaced => ../replaced +-- r/r.go -- +package r +import _ "example.com/r/replaced" +-- r/test.out -- +DELETE ME + +-- replaced/go.mod -- +module example.com/r/replaced +-- replaced/replaced.go -- +package replaced +-- replaced/test.out -- +DO NOT DELETE diff --git a/go/src/cmd/go/testdata/script/mod_concurrent.txt b/go/src/cmd/go/testdata/script/mod_concurrent.txt new file mode 100644 index 0000000000000000000000000000000000000000..e2224d659b23a53dc28092a3eb153a5b0648a655 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_concurrent.txt @@ -0,0 +1,32 @@ +env GO111MODULE=on + +# Concurrent builds should succeed, even if they need to download modules. +go get ./x ./y +go build ./x & +go build ./y +wait + +# Concurrent builds should update go.sum to the union of the hashes for the +# modules they read. +cmp go.sum go.sum.want + +-- go.mod -- +module golang.org/issue/26794 + +require ( + golang.org/x/text v0.3.0 + rsc.io/sampler v1.0.0 +) +-- x/x.go -- +package x + +import _ "golang.org/x/text/language" +-- y/y.go -- +package y + +import _ "rsc.io/sampler" +-- go.sum.want -- +golang.org/x/text v0.3.0 h1:ivTorhoiROmZ1mcs15mO2czVF0uy0tnezXpBVNzgrmA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/sampler v1.0.0 h1:SRJnjyQ07sAtq6G4RcfJEmz8JxqLyj3PoGXG2VhbDWo= +rsc.io/sampler v1.0.0/go.mod h1:cqxpM3ZVz9VtirqxZPmrWzkQ+UkiNiGtkrN+B+i8kx8= diff --git a/go/src/cmd/go/testdata/script/mod_convert_git.txt b/go/src/cmd/go/testdata/script/mod_convert_git.txt new file mode 100644 index 0000000000000000000000000000000000000000..6ff1eb51cb088b50e6f947de7d862a6d98406b34 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_convert_git.txt @@ -0,0 +1,40 @@ +env GO111MODULE=on + +# We should not create a go.mod file unless the user ran 'go mod init' explicitly. +# However, we should suggest 'go mod init' if we can find an alternate config file. +cd $WORK/test/x +! go list . +stderr 'found .git/config in .*[/\\]test' +stderr '\s*cd \.\. && go mod init' + +# The command we suggested should succeed. +cd .. +go mod init +go list -m all +stdout '^m$' + +# We should not suggest creating a go.mod file in $GOROOT, even though there may be a .git/config there. +cd $GOROOT +! go list . +! stderr 'go mod init' + +# We should also not suggest creating a go.mod file in $GOROOT if its own +# .git/config has been stripped away and we find one in a parent directory. +# (https://golang.org/issue/34191) +env GOROOT=$WORK/parent/goroot +cd $GOROOT +! go list . +! stderr 'go mod init' + +cd $GOROOT/doc +! go list . +! stderr 'go mod init' + +-- $WORK/test/.git/config -- +-- $WORK/test/x/x.go -- +package x // import "m/x" +-- $WORK/parent/.git/config -- +-- $WORK/parent/goroot/README -- +This directory isn't really a GOROOT, but let's pretend that it is. +-- $WORK/parent/goroot/doc/README -- +This is a subdirectory of our fake GOROOT. diff --git a/go/src/cmd/go/testdata/script/mod_deprecate_message.txt b/go/src/cmd/go/testdata/script/mod_deprecate_message.txt new file mode 100644 index 0000000000000000000000000000000000000000..1fb12468a508af901d1972ad8a343791e80493c7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_deprecate_message.txt @@ -0,0 +1,73 @@ +# When there is a short single-line message, 'go get' should print it all. +go get short +stderr '^go: module short is deprecated: short$' +go list -m -u -f '{{.Deprecated}}' short +stdout '^short$' + +# When there is a multi-line message, 'go get' should print the first line. +go get multiline +stderr '^go: module multiline is deprecated: first line$' +! stderr 'second line' +go list -m -u -f '{{.Deprecated}}' multiline +stdout '^first line\nsecond line.$' + +# When there is a long message, 'go get' should print a placeholder. +go get long +stderr '^go: module long is deprecated: \(message omitted: too long\)$' +go list -m -u -f '{{.Deprecated}}' long +stdout '^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$' + +# When a message contains unprintable characters, 'go get' should say that +# without printing the message. +go get unprintable +stderr '^go: module unprintable is deprecated: \(message omitted: contains non-printable characters\)$' +go list -m -u -f '{{.Deprecated}}' unprintable +stdout '^message contains ASCII BEL\x07$' + +-- go.mod -- +module use + +go 1.16 + +require ( + short v0.0.0 + multiline v0.0.0 + long v0.0.0 + unprintable v0.0.0 +) + +replace ( + short v0.0.0 => ./short + multiline v0.0.0 => ./multiline + long v0.0.0 => ./long + unprintable v0.0.0 => ./unprintable +) +-- short/go.mod -- +// Deprecated: short +module short + +go 1.16 +-- short/short.go -- +package short +-- multiline/go.mod -- +// Deprecated: first line +// second line. +module multiline + +go 1.16 +-- multiline/multiline.go -- +package multiline +-- long/go.mod -- +// Deprecated: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +module long + +go 1.16 +-- long/long.go -- +package long +-- unprintable/go.mod -- +// Deprecated: message contains ASCII BEL +module unprintable + +go 1.16 +-- unprintable/unprintable.go -- +package unprintable diff --git a/go/src/cmd/go/testdata/script/mod_dir.txt b/go/src/cmd/go/testdata/script/mod_dir.txt new file mode 100644 index 0000000000000000000000000000000000000000..05548f63668aae086b7c909449ea0bd5df2a552b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_dir.txt @@ -0,0 +1,20 @@ +# The directory named go.mod should be ignored + +env GO111MODULE=on + +cd $WORK/sub + +go list . +stdout 'x/sub' + +mkdir go.mod +exists go.mod + +go list . +stdout 'x/sub' + +-- $WORK/go.mod -- +module x + +-- $WORK/sub/x.go -- +package x \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_doc.txt b/go/src/cmd/go/testdata/script/mod_doc.txt new file mode 100644 index 0000000000000000000000000000000000000000..bf0a19d770bfb55fed9839ba36406492c399401b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_doc.txt @@ -0,0 +1,90 @@ +# go doc should find module documentation + +env GO111MODULE=on +env GOFLAGS=-mod=mod +[short] skip + +# Check when module x is inside GOPATH/src. +go doc y +stdout 'Package y is.*alphabet' +stdout 'import "x/y"' +go doc x/y +stdout 'Package y is.*alphabet' +! go doc quote.Hello +stderr 'doc: symbol quote is not a type' # because quote is not in local cache +go list rsc.io/quote # now it is +go doc quote.Hello +stdout 'Hello returns a greeting' +go doc quote +stdout 'Package quote collects pithy sayings.' + +# Double-check when module x is outside GOPATH/src. +env GOPATH=$WORK/emptygopath +go doc x/y +stdout 'Package y is.*alphabet' +go doc y +stdout 'Package y is.*alphabet' + +# Triple-check when module x is outside GOPATH/src, +# but other packages with same import paths are in GOPATH/src. +# Since go doc is running in module mode here, packages in active module +# should be preferred over packages in GOPATH. See golang.org/issue/28992. +env GOPATH=$WORK/gopath2 +go doc x/y +! stdout 'Package y is.*GOPATH' +stdout 'Package y is.*alphabet' +go doc rsc.io/quote +! stdout 'Package quote is located in a GOPATH workspace.' +stdout 'Package quote collects pithy sayings.' + +# Check that a sensible error message is printed when a package is not found. +env GOPROXY=off +! go doc example.com/hello +stderr '^doc: cannot find module providing package example.com/hello: module lookup disabled by GOPROXY=off$' + +# When in a module with a vendor directory, doc should use the vendored copies +# of the packages. 'std' and 'cmd' are convenient examples of such modules. +# +# When in those modules, the "// import" comment should refer to the same import +# path used in source code, not to the absolute path relative to GOROOT. + +cd $GOROOT/src +env GOFLAGS= +env GOWORK=off +go doc cryptobyte +stdout '// import "golang.org/x/crypto/cryptobyte"' + +cd $GOROOT/src/cmd/go +go doc modfile +stdout '// import "golang.org/x/mod/modfile"' + +# When outside of the 'std' module, its vendored packages +# remain accessible using the 'vendor/' prefix, but report +# the correct "// import" comment as used within std. +cd $GOPATH +go doc vendor/golang.org/x/crypto/cryptobyte +stdout '// import "vendor/golang.org/x/crypto/cryptobyte"' + +go doc cmd/vendor/golang.org/x/mod/modfile +stdout '// import "cmd/vendor/golang.org/x/mod/modfile"' + +-- go.mod -- +module x +require rsc.io/quote v1.5.2 + +-- y/y.go -- +// Package y is the next to last package of the alphabet. +package y + +-- x.go -- +package x + +-- $WORK/gopath2/src/x/y/y.go -- +// Package y is located in a GOPATH workspace. +package y +-- $WORK/gopath2/src/rsc.io/quote/quote.go -- +// Package quote is located in a GOPATH workspace. +package quote + +// Hello is located in a GOPATH workspace. +func Hello() string { return "" } diff --git a/go/src/cmd/go/testdata/script/mod_doc_path.txt b/go/src/cmd/go/testdata/script/mod_doc_path.txt new file mode 100644 index 0000000000000000000000000000000000000000..83d53926eed4743a7944aae1a42cd32ac0f3f961 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_doc_path.txt @@ -0,0 +1,30 @@ +# cmd/doc should use GOROOT to locate the 'go' command, +# not use whatever is in $PATH. + +# Remove 'go' from $PATH. (It can still be located via $GOROOT/bin/go, and the +# test script's built-in 'go' command still knows where to find it.) +env PATH='' +[GOOS:plan9] env path='' + +go doc p.X + +-- go.mod -- +module example + +go 1.19 + +require example.com/p v0.1.0 + +replace example.com/p => ./pfork +-- example.go -- +package example + +import _ "example.com/p" +-- pfork/go.mod -- +module example.com/p + +go 1.19 +-- pfork/p.go -- +package p + +const X = 42 diff --git a/go/src/cmd/go/testdata/script/mod_domain_root.txt b/go/src/cmd/go/testdata/script/mod_domain_root.txt new file mode 100644 index 0000000000000000000000000000000000000000..c13029d534163e0f58b7e2de27d989cc7fadcf96 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_domain_root.txt @@ -0,0 +1,12 @@ +# Module paths that are domain roots should resolve. +# (example.com not example.com/something) + +env GO111MODULE=on +go get + +-- go.mod -- +module x + +-- x.go -- +package x +import _ "example.com" diff --git a/go/src/cmd/go/testdata/script/mod_dot.txt b/go/src/cmd/go/testdata/script/mod_dot.txt new file mode 100644 index 0000000000000000000000000000000000000000..aa24986c72da31d0d48c5db3b364de8b8bab5925 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_dot.txt @@ -0,0 +1,132 @@ +env GOWORK=off +env GO111MODULE=on + +# golang.org/issue/32917 and golang.org/issue/28459: 'go build' and 'go test' +# in an empty directory should refer to the path '.' and should not attempt +# to resolve an external module. +cd dir +! go get +stderr '^go: no package to get in current directory$' +! go get . +stderr '^go: .: no package to get in current directory$' +! go get ./subdir +stderr '^go: \.[/\\]subdir \('$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]subdir\) is not a package in module rooted at '$WORK'[/\\]gopath[/\\]src[/\\]dir$' +! go list +! stderr 'cannot find module providing package' +stderr '^no Go files in '$WORK'[/\\]gopath[/\\]src[/\\]dir$' + +cd subdir +! go list +! stderr 'cannot find module providing package' +stderr '^no Go files in '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]subdir$' +cd .. + +# golang.org/issue/30590: if a package is found in the filesystem +# but is not in the main module, the error message should not say +# "cannot find module providing package", and we shouldn't try +# to find a module providing the package. +! go list ./othermodule +! stderr 'cannot find module providing package' +stderr '^main module \(example\.com\) does not contain package example.com/othermodule$' + +# golang.org/issue/27122: 'go build' of a nonexistent directory should produce +# a helpful "no Go files" error message, not a generic "unknown import path". +! go list ./subdir +stderr '^no Go files in '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]subdir$' + +# golang.org/issue/29280: 'go list -e' for a nonexistent directory should +# report a nonexistent package with an error. +go list -e -json ./subdir +stdout '"Incomplete": true' + +# golang.org/issue/28155: 'go list ./testdata' should not synthesize underscores. +go list ./testdata +stdout '^example.com/testdata' + +# golang.org/issue/32921: vendor directories should only be accepted as directories +# if the directory would actually be used to load the package. +! go list ./vendor/nonexist +stderr '^no Go files in '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]vendor[/\\]nonexist$' + +! go list ./vendor/pkg +stderr '^without -mod=vendor, directory '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]vendor[/\\]pkg has no package path$' + +! go list -mod=vendor ./vendor/nonexist +stderr '^no Go files in '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]vendor[/\\]nonexist$' + +! go list -mod=vendor ./vendor/unlisted +stderr '^directory '$WORK'[/\\]gopath[/\\]src[/\\]dir[/\\]vendor[/\\]unlisted is not a package listed in vendor/modules.txt$' + +go list -mod=vendor ./vendor/pkg +stdout '^pkg$' + +# Packages within GOROOT should resolve as in any other module, +# except that -mod=vendor is implied by default. +cd $GOROOT/src +! go list . +stderr '^no Go files in '$GOROOT'[/\\]src$' + +! go list ./builtin +stderr '^"builtin" is a pseudo-package, not an importable package$' + +! go list ./debug +! stderr 'cannot find module providing package' +stderr '^no Go files in '$GOROOT'[/\\]src[/\\]debug$' + +! go list ./golang.org/x/tools/cmd/goimports +! stderr 'cannot find module providing package' +stderr '^stat '$GOROOT'[/\\]src[/\\]golang.org[/\\]x[/\\]tools[/\\]cmd[/\\]goimports: directory not found' + +go list ./vendor/golang.org/x/net/http2/hpack +stdout '^golang.org/x/net/http2/hpack$' + +# golang.org/issue/30756: packages in other GOROOTs should not get the special +# prefixless treatment of GOROOT itself. +cd $WORK/othergoroot/src +! go list . +stderr '^no Go files in '$WORK'[/\\]othergoroot[/\\]src$' + +go list ./builtin +stdout '^std/builtin$' # Only the "std" in actual $GOROOT is special, and only its "builtin" is special. + +! go list ./bytes +! stderr 'cannot find module providing package' +stderr '^no Go files in '$WORK'[/\\]othergoroot[/\\]src[/\\]bytes$' + +! go list ./vendor/golang.org/x/net/http2/hpack +stderr '^without -mod=vendor, directory '$WORK'[/\\]othergoroot[/\\]src[/\\]vendor[/\\]golang.org[/\\]x[/\\]net[/\\]http2[/\\]hpack has no package path$' + +-- dir/go.mod -- +module example.com +go 1.13 +-- dir/subdir/README -- +There are no Go source files in this directory. +-- dir/othermodule/go.mod -- +module example.com/othermodule +go 1.13 +-- dir/othermodule/om.go -- +package othermodule +-- dir/testdata/td.go -- +package testdata +-- dir/vendor/modules.txt -- +# pkg v0.0.0 +pkg +-- dir/vendor/nonexist/README -- +There are no Go source files here either. +-- dir/vendor/pkg/pkg.go -- +package pkg +-- dir/vendor/unlisted/unlisted.go -- +package unlisted +-- emptyroot/go.mod -- +module example.com/emptyroot +-- emptyroot/pkg/pkg.go -- +package pkg +-- $WORK/othergoroot/src/go.mod -- +module std +go 1.13 +-- $WORK/othergoroot/src/builtin/builtin.go -- +package builtin +-- $WORK/othergoroot/src/bytes/README -- +There are no Go source files in this directory. +-- $WORK/othergoroot/src/vendor/golang.org/x/net/http2/hpack -- +package hpack diff --git a/go/src/cmd/go/testdata/script/mod_download.txt b/go/src/cmd/go/testdata/script/mod_download.txt new file mode 100644 index 0000000000000000000000000000000000000000..154e68338b6b3e2f2bdfd63e3d789c7f664dd1e9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download.txt @@ -0,0 +1,214 @@ +env GO111MODULE=on + +# download with version should print nothing. +# It should not load retractions from the .mod file from the latest version. +go mod download rsc.io/quote@v1.5.0 +! stdout . +! stderr . +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.info +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod + +# download of an invalid path should report the error +[short] skip +! go mod download this.domain.is.invalid/somemodule@v1.0.0 +stderr 'this.domain.is.invalid' +! go mod download -json this.domain.is.invalid/somemodule@v1.0.0 +stdout '"Error": ".*this.domain.is.invalid.*"' + +# download -json with version should print JSON +go mod download -json 'rsc.io/quote@<=v1.5.0' +stdout '^\t"Path": "rsc.io/quote"' +stdout '^\t"Version": "v1.5.0"' +stdout '^\t"Info": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.info"' +stdout '^\t"GoMod": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.mod"' +stdout '^\t"Zip": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.zip"' +stdout '^\t"Sum": "h1:6fJa6E\+wGadANKkUMlZ0DhXFpoKlslOQDCo259XtdIE="' # hash of testdata/mod version, not real version! +stdout '^\t"GoModSum": "h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe\+TKr0="' +! stdout '"Error"' + +# download queries above should not have added to go.mod. +go list -m all +! stdout rsc.io + +# download query should have downloaded go.mod for the highest release version +# in order to find retractions when resolving the query '@<=v1.5.0'. +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.info +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip + +# add to go.mod so we can test non-query downloads +go mod edit -require rsc.io/quote@v1.5.3-pre1 +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip + +# module loading will page in the info and mod files +go list -m -mod=mod all +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip + +# download will fetch and unpack the zip file +go mod download +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip +exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1 + +# download repopulates deleted files and directories independently. +rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info +go mod download +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info +rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod +go mod download +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod +rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip +go mod download +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip +rm -r $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1 +go mod download +exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1 + +# download reports the locations of downloaded files +go mod download -json +stdout '^\t"Path": "rsc.io/quote"' +stdout '^\t"Version": "v1.5.3-pre1"' +stdout '^\t"Info": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.info"' +stdout '^\t"GoMod": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.mod"' +stdout '^\t"Zip": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.zip"' +stdout '^\t"Dir": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)rsc.io(\\\\|/)quote@v1.5.3-pre1"' + +# download will follow replacements +go mod edit -require rsc.io/quote@v1.5.1 -replace rsc.io/quote@v1.5.1=rsc.io/quote@v1.5.2 +go mod download +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.1.zip +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip + +# download will not follow replacements for explicit module queries +go mod download -json rsc.io/quote@v1.5.1 +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.1.zip + +# download reports errors encountered when locating modules +! go mod download bad/path +stderr '^go: module bad/path: not a known dependency$' +! go mod download bad/path@latest +stderr '^go: bad/path@latest: malformed module path "bad/path": missing dot in first path element$' +! go mod download rsc.io/quote@v1.999.999 +stderr '^go: rsc.io/quote@v1.999.999: reading .*/v1.999.999.info: 404 Not Found$' +! go mod download -json bad/path +stdout '^\t"Error": "module bad/path: not a known dependency"' + +# download main module produces a warning or error +go mod download m +stderr '^go: skipping download of m that resolves to the main module\n' +! go mod download m@latest +stderr '^go: m@latest: malformed module path "m": missing dot in first path element$' + +# download without arguments updates go.mod and go.sum after loading the +# build list, but does not save sums for downloaded zips. +cd update +cp go.mod.orig go.mod +! exists go.sum +go mod download +cmp go.mod.update go.mod +cmp go.sum.update go.sum +cp go.mod.orig go.mod +rm go.sum + +# download with arguments (even "all") does update go.mod and go.sum. +go mod download rsc.io/sampler +cmp go.mod.update go.mod +grep '^rsc.io/sampler v1.3.0 ' go.sum +cp go.mod.orig go.mod +rm go.sum + +go mod download all +cmp go.mod.update go.mod +grep '^rsc.io/sampler v1.3.0 ' go.sum + +# https://golang.org/issue/44435: At go 1.17 or higher, 'go mod download' +# (without arguments) should only download the modules explicitly required in +# the go.mod file, not (presumed-irrelevant) transitive dependencies. +# +# (If the go.mod file is inconsistent, the version downloaded should be the +# selected version from the broader graph, but the go.mod file will also be +# updated to list the correct versions. If at some point we change 'go mod +# download' to stop updating for consistency, then it should fail if the +# requirements are inconsistent.) + +rm go.sum +cp go.mod.orig go.mod +go mod edit -go=1.17 +cp go.mod.update go.mod.go117 +go mod edit -go=1.17 go.mod.go117 + +go clean -modcache +go mod download +cmp go.mod go.mod.go117 + +go list -e -m all +stdout '^rsc.io/quote v1.5.2$' +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip +stdout '^rsc.io/sampler v1.3.0$' +! exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.2.1.zip +exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.3.0.zip +stdout '^golang\.org/x/text v0.0.0-20170915032832-14c0d48ead0c$' +! exists $GOPATH/pkg/mod/cache/download/golang.org/x/text/@v/v0.0.0-20170915032832-14c0d48ead0c.zip +cmp go.mod go.mod.go117 + +# However, 'go mod download all' continues to download the selected version +# of every module reported by 'go list -m all'. + +cp go.mod.orig go.mod +go mod edit -go=1.17 +go clean -modcache +go mod download all +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip +! exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.2.1.zip +exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.3.0.zip +exists $GOPATH/pkg/mod/cache/download/golang.org/x/text/@v/v0.0.0-20170915032832-14c0d48ead0c.zip +cmp go.mod go.mod.go117 + +cd .. + +# allow go mod download without go.mod +env GO111MODULE=auto +rm go.mod +rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip +go mod download rsc.io/quote@v1.2.1 +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip + +# download -x with version should print +# the underlying commands such as contacting GOPROXY. +go mod download -x rsc.io/quote@v1.0.0 +! stdout . +stderr 'get '$GOPROXY + +-- go.mod -- +module m + +-- update/go.mod.orig -- +module m + +go 1.16 + +require ( + rsc.io/quote v1.5.2 + rsc.io/sampler v1.2.1 // older version than in build list +) +-- update/go.mod.update -- +module m + +go 1.16 + +require ( + rsc.io/quote v1.5.2 + rsc.io/sampler v1.3.0 // older version than in build list +) +-- update/go.sum.update -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/go/src/cmd/go/testdata/script/mod_download_concurrent_read.txt b/go/src/cmd/go/testdata/script/mod_download_concurrent_read.txt new file mode 100644 index 0000000000000000000000000000000000000000..c2c8b1826fbd5a59ff61111916c9b649a494ba2c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_concurrent_read.txt @@ -0,0 +1,110 @@ +# This test simulates a process watching for changes and reading files in +# module cache as a module is extracted. +# +# Before Go 1.16, we extracted each module zip to a temporary directory with +# a random name, then renamed that into place with os.Rename. On Windows, +# this failed with ERROR_ACCESS_DENIED when another process (usually an +# anti-virus scanner) opened files in the temporary directory. This test +# simulates that behavior, verifying golang.org/issue/36568. +# +# Since 1.16, we extract to the final directory, but we create a .partial file +# so that if we crash, other processes know the directory is incomplete. + +[!GOOS:windows] skip +[short] skip + +go run downloader.go + +-- go.mod -- +module example.com/m + +go 1.14 + +-- downloader.go -- +package main + +import ( + "fmt" + "log" + "os" + "os/exec" + "path/filepath" +) + +func main() { + if err := run(); err != nil { + log.Fatal(err) + } +} + +// run repeatedly downloads a module while opening files in the module cache +// in a background goroutine. +// +// run uses a different temporary module cache in each iteration so that we +// don't need to clean the cache or synchronize closing files after each +// iteration. +func run() (err error) { + tmpDir, err := os.MkdirTemp("", "") + if err != nil { + return err + } + defer func() { + if rmErr := os.RemoveAll(tmpDir); err == nil && rmErr != nil { + err = rmErr + } + }() + for i := 0; i < 10; i++ { + gopath := filepath.Join(tmpDir, fmt.Sprintf("gopath%d", i)) + var err error + done := make(chan struct{}) + go func() { + err = download(gopath) + close(done) + }() + readCache(gopath, done) + if err != nil { + return err + } + } + return nil +} + +// download downloads a module into the given cache using 'go mod download'. +func download(gopath string) error { + cmd := exec.Command("go", "mod", "download", "-modcacherw", "rsc.io/quote@v1.5.2") + cmd.Stderr = os.Stderr + cmd.Env = append(os.Environ(), "GOPATH="+gopath) + return cmd.Run() +} + +// readCache repeatedly globs for go.mod files in the given cache, then opens +// those files for reading. When the done chan is closed, readCache closes +// files and returns. +func readCache(gopath string, done <-chan struct{}) { + files := make(map[string]*os.File) + defer func() { + for _, f := range files { + f.Close() + } + }() + + pattern := filepath.Join(gopath, "pkg/mod/rsc.io/quote@v1.5.2*/go.mod") + for { + select { + case <-done: + return + default: + } + + names, _ := filepath.Glob(pattern) + for _, name := range names { + if files[name] != nil { + continue + } + f, _ := os.Open(name) + if f != nil { + files[name] = f + } + } + } +} diff --git a/go/src/cmd/go/testdata/script/mod_download_exec_toolchain.txt b/go/src/cmd/go/testdata/script/mod_download_exec_toolchain.txt new file mode 100644 index 0000000000000000000000000000000000000000..78b62aa7f0ae063cb5f69b2ba0fbff07f8baa8d3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_exec_toolchain.txt @@ -0,0 +1,105 @@ +env TESTGO_VERSION=go1.21 +env TESTGO_VERSION_SWITCH=switch + +# First, test 'go mod download' outside of a module. +# +# There is no go.mod file into which we can record the selected toolchain, +# so unfortunately these version switches won't be as reproducible as other +# go commands, but that's still preferable to failing entirely or downloading +# a module zip that we don't understand. + +# GOTOOLCHAIN=auto should run the newer toolchain +env GOTOOLCHAIN=auto +go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest +stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$' +! stderr '\(running' + +# GOTOOLCHAIN=min+auto should run the newer toolchain +env GOTOOLCHAIN=go1.21+auto +go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest +stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$' +! stderr '\(running' + +# GOTOOLCHAIN=go1.21 should NOT run the newer toolchain +env GOTOOLCHAIN=go1.21 +! go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest +! stderr switching +stderr 'rsc.io/needgo122@v0.0.1 requires go >= 1.22' +stderr 'rsc.io/needgo123@v0.0.1 requires go >= 1.23' +stderr 'rsc.io/needall@v0.0.1 requires go >= 1.23' +stderr 'requires go >= 1.23' +! stderr 'requires go >= 1.21' # that's us! + + +# JSON output should be emitted exactly once, +# and non-JSON output should go to stderr instead of stdout. +env GOTOOLCHAIN=auto +go mod download -json rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest +stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$' +! stderr '\(running' +stdout -count=1 '"Path": "rsc.io/needgo121",' +stdout -count=1 '"Path": "rsc.io/needgo122",' +stdout -count=1 '"Path": "rsc.io/needgo123",' +stdout -count=1 '"Path": "rsc.io/needall",' + +# GOTOOLCHAIN=go1.21 should write the errors in the JSON Error fields, not to stderr. +env GOTOOLCHAIN=go1.21 +! go mod download -json rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest +! stderr switching +stdout -count=1 '"Error": "rsc.io/needgo122@v0.0.1 requires go .*= 1.22 \(running go 1.21; GOTOOLCHAIN=go1.21\)"' +stdout -count=1 '"Error": "rsc.io/needgo123@v0.0.1 requires go .*= 1.23 \(running go 1.21; GOTOOLCHAIN=go1.21\)"' +stdout -count=1 '"Error": "rsc.io/needall@v0.0.1 requires go .*= 1.23 \(running go 1.21; GOTOOLCHAIN=go1.21\)"' +! stdout '"Error": "rsc.io/needgo121' # We can handle this one. +! stderr . + + +# Within a module, 'go mod download' of explicit versions should upgrade if +# needed to perform the download, but should not change the main module's +# toolchain version (because the downloaded modules are still not required by +# the main module). + +cd example +cp go.mod go.mod.orig + +env GOTOOLCHAIN=auto +go mod download rsc.io/needgo121@latest rsc.io/needgo122@latest rsc.io/needgo123@latest rsc.io/needall@latest +stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$' +! stderr '\(running' +cmp go.mod go.mod.orig + + +# However, 'go mod download' without arguments should fix up the +# 'go' and 'toolchain' lines to be consistent with the existing +# requirements in the module graph. + +go mod edit -require=rsc.io/needall@v0.0.1 +cp go.mod go.mod.121 + +# If an upgrade is needed, GOTOOLCHAIN=go1.21 should cause +# the command to fail without changing go.mod. + +env GOTOOLCHAIN=go1.21 +! go mod download +stderr 'rsc.io/needall@v0.0.1 requires go >= 1.23' +! stderr switching +cmp go.mod go.mod.121 + +# If an upgrade is needed, GOTOOLCHAIN=auto should perform +# the upgrade and record the resulting toolchain version. + +env GOTOOLCHAIN=auto +go mod download +stderr '^go: module rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$' +cmp go.mod go.mod.final + + +-- example/go.mod -- +module example + +go 1.21 +-- example/go.mod.final -- +module example + +go 1.23 + +require rsc.io/needall v0.0.1 diff --git a/go/src/cmd/go/testdata/script/mod_download_git_bareRepository.txt b/go/src/cmd/go/testdata/script/mod_download_git_bareRepository.txt new file mode 100644 index 0000000000000000000000000000000000000000..a61283ca49b646ea0ffe24d2f2313cea1781ae7f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_git_bareRepository.txt @@ -0,0 +1,28 @@ +[short] skip +[!git] skip + +# Redirect git to a test-specific .gitconfig. +# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer. +# For older git versions we also set $HOME. +env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig +env HOME=$WORK${/}home${/}gopher +exec git config --global --show-origin user.name +stdout 'Go Gopher' + +env GOPRIVATE=vcs-test.golang.org + +go mod download -x + +-- go.mod -- +module test + +go 1.18 + +require vcs-test.golang.org/git/gitrepo1.git v1.2.3 + +-- $WORK/home/gopher/.gitconfig -- +[user] + name = Go Gopher + email = gopher@golang.org +[safe] + bareRepository = explicit diff --git a/go/src/cmd/go/testdata/script/mod_download_git_bareRepository_sha256.txt b/go/src/cmd/go/testdata/script/mod_download_git_bareRepository_sha256.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f391e200e77fa303c564770e752c63e59b236c7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_git_bareRepository_sha256.txt @@ -0,0 +1,31 @@ +[short] skip +[!git] skip +[!git-sha256] skip + +# This is a git sha256-mode copy of mod_download_git_bareRepository + +# Redirect git to a test-specific .gitconfig. +# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer. +# For older git versions we also set $HOME. +env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig +env HOME=$WORK${/}home${/}gopher +exec git config --global --show-origin user.name +stdout 'Go Gopher' + +env GOPRIVATE=vcs-test.golang.org + +go mod download -x + +-- go.mod -- +module test + +go 1.18 + +require vcs-test.golang.org/git/gitrepo-sha256.git v1.2.3 + +-- $WORK/home/gopher/.gitconfig -- +[user] + name = Go Gopher + email = gopher@golang.org +[safe] + bareRepository = explicit diff --git a/go/src/cmd/go/testdata/script/mod_download_git_decorate_full.txt b/go/src/cmd/go/testdata/script/mod_download_git_decorate_full.txt new file mode 100644 index 0000000000000000000000000000000000000000..9afd347746641e3684ec4c6e63dbee68413d51fe --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_git_decorate_full.txt @@ -0,0 +1,34 @@ +env GO111MODULE=on + +[short] skip +[!git] skip + +# Redirect git to a test-specific .gitconfig. +# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer. +# For older git versions we also set $HOME. +env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig +env HOME=$WORK${/}home${/}gopher +exec git config --global --show-origin user.name +stdout 'Go Gopher' + +env GOPROXY=direct + +exec git config --get log.decorate +stdout 'full' + +# Test that Git log with user's global config '~/gitconfig' has log.decorate=full +# go mod download has an error 'v1.x.y is not a tag' +# with go1.16.14: +# `go1.16.14 list -m vcs-test.golang.org/git/gitrepo1.git@v1.2.3` +# will output with error: +# go list -m: vcs-test.golang.org/git/gitrepo1.git@v1.2.3: invalid version: unknown revision v1.2.3 +# See golang/go#51312. +go list -m vcs-test.golang.org/git/gitrepo1.git@v1.2.3 +stdout 'vcs-test.golang.org/git/gitrepo1.git v1.2.3' + +-- $WORK/home/gopher/.gitconfig -- +[user] + name = Go Gopher + email = gopher@golang.org +[log] + decorate = full diff --git a/go/src/cmd/go/testdata/script/mod_download_hash.txt b/go/src/cmd/go/testdata/script/mod_download_hash.txt new file mode 100644 index 0000000000000000000000000000000000000000..5677e69a5d53494038a2a071aae493796d2849c0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_hash.txt @@ -0,0 +1,24 @@ +env GO111MODULE=on + +# Testing mod download with non semantic versions; turn off proxy. +[!net:rsc.io] skip +[!git] skip +env GOPROXY=direct +env GOSUMDB=off + +go mod download rsc.io/quote@a91498bed0a73d4bb9c1fb2597925f7883bc40a7 +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-0.20180709162918-a91498bed0a7.info +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-0.20180709162918-a91498bed0a7.mod +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-0.20180709162918-a91498bed0a7.zip + +go mod download rsc.io/quote@master +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-0.20180709162918-a91498bed0a7.info +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-0.20180709162918-a91498bed0a7.mod +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-0.20180709162918-a91498bed0a7.zip + + +-- go.mod -- +module m + +-- m.go -- +package m diff --git a/go/src/cmd/go/testdata/script/mod_download_insecure_redirect.txt b/go/src/cmd/go/testdata/script/mod_download_insecure_redirect.txt new file mode 100644 index 0000000000000000000000000000000000000000..20a6ac2aa03ad660ef261e87a55aafe4eacac142 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_insecure_redirect.txt @@ -0,0 +1,32 @@ +# golang.org/issue/29591: 'go get' was following plain-HTTP redirects even without -insecure (now replaced by GOINSECURE). + +[short] skip +[!git] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +! go mod download vcs-test.golang.org/insecure/go/insecure@latest +stderr 'redirected .* to insecure URL' + +# insecure host +env GOINSECURE=vcs-test.golang.org +go clean -modcache +go mod download vcs-test.golang.org/insecure/go/insecure@latest + +# insecure glob host +env GOINSECURE=*.golang.org +go clean -modcache +go mod download vcs-test.golang.org/insecure/go/insecure@latest + +# insecure multiple host +env GOINSECURE=somewhere-else.com,*.golang.org +go clean -modcache +go mod download vcs-test.golang.org/insecure/go/insecure@latest + +# different insecure host does not fetch +env GOINSECURE=somewhere-else.com +go clean -modcache +! go mod download vcs-test.golang.org/insecure/go/insecure@latest +stderr 'redirected .* to insecure URL' diff --git a/go/src/cmd/go/testdata/script/mod_download_issue51114.txt b/go/src/cmd/go/testdata/script/mod_download_issue51114.txt new file mode 100644 index 0000000000000000000000000000000000000000..a28d467bb8b1ce44f5b9ebda4d6b439196459d72 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_issue51114.txt @@ -0,0 +1,29 @@ +[!net:github.com] skip +[!git] skip + +# Redirect git to a test-specific .gitconfig. +# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer. +# For older git versions we also set $HOME. +env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig +env HOME=$WORK${/}home${/}gopher +exec git config --global --show-origin user.name +stdout 'Go Gopher' + +env GOPROXY=direct + +! go mod download +stderr '^go: github\.com/golang/notexist/subdir@v0.1.0: reading github\.com/golang/notexist/subdir/go\.mod at revision subdir/v0\.1\.0: ' + +-- go.mod -- +module test + +go 1.18 + +require github.com/golang/notexist/subdir v0.1.0 + +-- $WORK/home/gopher/.gitconfig -- +[user] + name = Go Gopher + email = gopher@golang.org +[url "git@github.com:"] + insteadOf = https://github.com/ diff --git a/go/src/cmd/go/testdata/script/mod_download_json.txt b/go/src/cmd/go/testdata/script/mod_download_json.txt new file mode 100644 index 0000000000000000000000000000000000000000..9555adf8c4e4657537ac1ce99ec4a9c7f7767332 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_json.txt @@ -0,0 +1,9 @@ +env GO111MODULE=on +env GOSUMDB=$sumdb' '$proxy/sumdb-wrong + +# download -json with version should print JSON on sumdb failure +! go mod download -json 'rsc.io/quote@<=v1.5.0' +stdout '"Error": ".*verifying (module|go.mod)' + +-- go.mod -- +module m diff --git a/go/src/cmd/go/testdata/script/mod_download_partial.txt b/go/src/cmd/go/testdata/script/mod_download_partial.txt new file mode 100644 index 0000000000000000000000000000000000000000..617b1fd8e363e3bb98a605a021024677d5e507d5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_partial.txt @@ -0,0 +1,69 @@ +# Download modules and populate go.sum. +go get -modcacherw +exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod + +# 'go mod verify' should fail if we delete a file. +go mod verify +rm $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod +! go mod verify + +# Create a .partial file to simulate an failure extracting the zip file. +cp empty $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.partial + +# 'go mod verify' should not fail, since the module hasn't been completely +# ingested into the cache. +go mod verify + +# 'go list' should not load packages from the directory. +# NOTE: the message "directory $dir outside main module or its selected dependencies" +# is reported for directories not in the main module, active modules in the +# module cache, or local replacements. In this case, the directory is in the +# right place, but it's incomplete, so 'go list' acts as if it's not an +# active module. +! go list $GOPATH/pkg/mod/rsc.io/quote@v1.5.2 +stderr 'outside main module or its selected dependencies' + +# 'go list -m' should not print the directory. +go list -m -f '{{.Dir}}' rsc.io/quote +! stdout . + +# 'go mod download' should re-extract the module and remove the .partial file. +go mod download -modcacherw rsc.io/quote +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.partial +exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod + +# 'go list' should succeed. +go list $GOPATH/pkg/mod/rsc.io/quote@v1.5.2 +stdout '^rsc.io/quote$' + +# 'go list -m' should print the directory. +go list -m -f '{{.Dir}}' rsc.io/quote +stdout 'pkg[/\\]mod[/\\]rsc.io[/\\]quote@v1.5.2' + +# go mod verify should fail if we delete a file. +go mod verify +rm $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/go.mod +! go mod verify + +# 'go mod download' should not leave behind a directory or a .partial file +# if there is an error extracting the zip file. +rm $GOPATH/pkg/mod/rsc.io/quote@v1.5.2 +cp empty $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip +! go mod download +stderr 'not a valid zip file' +! exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.2 +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.partial + +-- go.mod -- +module m + +go 1.14 + +require rsc.io/quote v1.5.2 + +-- use.go -- +package use + +import _ "rsc.io/quote" + +-- empty -- diff --git a/go/src/cmd/go/testdata/script/mod_download_private_vcs.txt b/go/src/cmd/go/testdata/script/mod_download_private_vcs.txt new file mode 100644 index 0000000000000000000000000000000000000000..5c8d93a978d7fe18782de963a64c987d6251c4d8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_private_vcs.txt @@ -0,0 +1,48 @@ +env GO111MODULE=on + +# Testing stderr for git ls-remote; turn off proxy. +[!net:github.com] skip +[!git] skip +env GOPROXY=direct + +# Redirect git to a test-specific .gitconfig. +# GIT_CONFIG_GLOBAL suffices for git 2.32.0 and newer. +# For older git versions we also set $HOME. +env GIT_CONFIG_GLOBAL=$WORK${/}home${/}gopher${/}.gitconfig +env HOME=$WORK${/}home${/}gopher +exec git config --global --show-origin user.name +stdout 'Go Gopher' + +! go mod download github.com/golang/nonexist@latest +stderr 'Confirm the import path was entered correctly.' +stderr 'If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.' +! stdout . + +# Fetching a nonexistent commit should return an "unknown revision" +# error message. +! go mod download github.com/golang/term@86186f3aba07ed0212cfb944f3398997d2d07c6b +stderr '^go: github.com/golang/term@86186f3aba07ed0212cfb944f3398997d2d07c6b: invalid version: unknown revision 86186f3aba07ed0212cfb944f3398997d2d07c6b$' +! stdout . + +! go mod download github.com/golang/nonexist@master +stderr '^Confirm the import path was entered correctly.$' +stderr '^If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.$' +! stderr 'unknown revision' +! stdout . + +[!exec:false] stop + +# Test that Git clone errors will be shown to the user instead of a generic +# "unknown revision" error. To do this we want to force git ls-remote to return +# an error we don't already have special handling for. See golang/go#42751. +exec git config --global url.git@github.com.insteadOf https://github.com/ +env GIT_SSH_COMMAND=false +! go install github.com/golang/nonexist@master +stderr 'fatal: Could not read from remote repository.' +! stderr 'unknown revision' +! stdout . + +-- $WORK/home/gopher/.gitconfig -- +[user] + name = Go Gopher + email = gopher@golang.org diff --git a/go/src/cmd/go/testdata/script/mod_download_replace_file.txt b/go/src/cmd/go/testdata/script/mod_download_replace_file.txt new file mode 100644 index 0000000000000000000000000000000000000000..f6ab4fe91f0960cd4f133050b344907ddebbacf8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_replace_file.txt @@ -0,0 +1,16 @@ +# This test checks that 'go mod download' produces no output for +# the main module (when specified implicitly) and for a module replaced +# with a file path. +# Verifies golang.org/issue/35505. +go mod download -json all +cmp stdout no-output + +-- go.mod -- +module example.com/a + +require example.com/b v1.0.0 + +replace example.com/b => ./local/b +-- local/b/go.mod -- +module example.com/b +-- no-output -- diff --git a/go/src/cmd/go/testdata/script/mod_download_svn.txt b/go/src/cmd/go/testdata/script/mod_download_svn.txt new file mode 100644 index 0000000000000000000000000000000000000000..c11b4f978149767e0c75b86701fc3fbca7facdf4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_svn.txt @@ -0,0 +1,29 @@ +[short] skip +[!exec:svn] skip + +# 'go mod download' will fall back to svn+ssh once svn fails over protocols like https. +# If vcs-test.golang.org isn't in the user's known_hosts file, this will result +# in an ssh prompt, which will stop 'go test' entirely +# +# Unfortunately, there isn't a way to globally disable host checking for ssh, +# without modifying the real system's or user's configs. Changing $HOME won't +# affect ssh either, as it ignores the environment variable entirely. +# +# However, a useful trick is pointing SVN_SSH to a program that doesn't exist, +# resulting in svn skipping ssh entirely. Alternatives like +# SVN_SSH="ssh -o StrictHostKeyChecking=no" didn't avoid the prompt. +env SVN_SSH="svn_do_not_use_ssh" + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +# Attempting to get a module zip using svn should succeed. +go mod download vcs-test.golang.org/svn/hello.svn@000000000001 +exists $GOPATH/pkg/mod/cache/download/vcs-test.golang.org/svn/hello.svn/@v/v0.0.0-20170922011245-000000000001.zip + +# Attempting to get a nonexistent module using svn should fail with a +# reasonable message instead of a panic. +! go mod download vcs-test.golang.org/svn/nonexistent.svn@latest +! stderr panic +stderr 'go: module vcs-test.golang.org/svn/nonexistent.svn: no matching versions for query "latest"$' diff --git a/go/src/cmd/go/testdata/script/mod_download_too_many_redirects.txt b/go/src/cmd/go/testdata/script/mod_download_too_many_redirects.txt new file mode 100644 index 0000000000000000000000000000000000000000..a6b5a59054872926ed3fceb269e8899bc89c38d2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_download_too_many_redirects.txt @@ -0,0 +1,10 @@ +env GO111MODULE=on +env GOPROXYBASE=$GOPROXY +env GOPROXY=$GOPROXYBASE/redirect/11 +env GOSUMDB=off + +! go mod download rsc.io/quote@v1.2.0 +stderr 'stopped after 10 redirects' + +env GOPROXY=$GOPROXYBASE/redirect/9 +go mod download rsc.io/quote@v1.2.0 diff --git a/go/src/cmd/go/testdata/script/mod_e.txt b/go/src/cmd/go/testdata/script/mod_e.txt new file mode 100644 index 0000000000000000000000000000000000000000..6497e6c22b215b4dd2f02dac7071f764897c1a6b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_e.txt @@ -0,0 +1,96 @@ +cp go.mod go.mod.orig + + +# If a dependency cannot be resolved, 'go mod tidy' fails with an error message +# explaining the problem and does not update the go.mod file. +# TODO(bcmills): Ideally, with less redundancy than these error messages! + +! go mod tidy + +stderr '^go: example.com/untidy imports\n\texample.net/directnotfound: cannot find module providing package example.net/directnotfound: module example.net/directnotfound: reading http://.*: 404 Not Found$' + +stderr '^go: example.com/untidy imports\n\texample.net/m imports\n\texample.net/indirectnotfound: cannot find module providing package example.net/indirectnotfound: module example.net/indirectnotfound: reading http://.*: 404 Not Found$' + +stderr '^go: example.com/untidy tested by\n\texample.com/untidy.test imports\n\texample.net/directtestnotfound: cannot find module providing package example.net/directtestnotfound: module example.net/directtestnotfound: reading http://.*: 404 Not Found$' + +stderr '^go: example.com/untidy imports\n\texample.net/m tested by\n\texample.net/m.test imports\n\texample.net/indirecttestnotfound: cannot find module providing package example.net/indirecttestnotfound: module example.net/indirecttestnotfound: reading http://.*: 404 Not Found$' + +cmp go.mod.orig go.mod + + +# If a dependency cannot be resolved, 'go mod vendor' fails with an error message +# explaining the problem, does not update the go.mod file, and does not create +# the vendor directory. + +! go mod vendor + +stderr '^go: example.com/untidy imports\n\texample.net/directnotfound: no required module provides package example.net/directnotfound; to add it:\n\tgo get example.net/directnotfound$' + +stderr '^go: example.com/untidy imports\n\texample.net/m: module example.net/m provides package example.net/m and is replaced but not required; to add it:\n\tgo get example.net/m@v0.1.0$' + +stderr '^go: example.com/untidy tested by\n\texample.com/untidy.test imports\n\texample.net/directtestnotfound: no required module provides package example.net/directtestnotfound; to add it:\n\tgo get example.net/directtestnotfound$' + +! stderr 'indirecttestnotfound' # Vendor prunes test dependencies. + +cmp go.mod.orig go.mod +! exists vendor + + +# 'go mod tidy' still logs the errors, but succeeds and updates go.mod. + +go mod tidy -e +stderr -count=4 'cannot find module providing package' +cmp go.mod.final go.mod + + +# 'go mod vendor -e' still logs the errors, but creates a vendor directory +# and exits with status 0. +# 'go mod vendor -e' does not update go.mod and will not vendor packages that +# would require changing go.mod, for example, by adding a requirement. +cp go.mod.orig go.mod +go mod vendor -e +stderr -count=2 'no required module provides package' +stderr '^go: example.com/untidy imports\n\texample.net/m: module example.net/m provides package example.net/m and is replaced but not required; to add it:\n\tgo get example.net/m@v0.1.0$' +exists vendor/modules.txt +! exists vendor/example.net + +go mod edit -require example.net/m@v0.1.0 +go mod vendor -e +stderr -count=3 'no required module provides package' +exists vendor/modules.txt +exists vendor/example.net/m/m.go + +-- go.mod -- +module example.com/untidy +go 1.16 +replace example.net/m v0.1.0 => ./m +-- go.mod.final -- +module example.com/untidy + +go 1.16 + +replace example.net/m v0.1.0 => ./m + +require example.net/m v0.1.0 +-- untidy.go -- +package untidy + +import ( + _ "example.net/m" + _ "example.net/directnotfound" +) +-- untidy_test.go -- +package untidy_test + +import _ "example.net/directtestnotfound" +-- m/go.mod -- +module example.net/m +go 1.16 +-- m/m.go -- +package m + +import _ "example.net/indirectnotfound" +-- m/m_test.go -- +package m_test + +import _ "example.net/indirecttestnotfound" diff --git a/go/src/cmd/go/testdata/script/mod_edit.txt b/go/src/cmd/go/testdata/script/mod_edit.txt new file mode 100644 index 0000000000000000000000000000000000000000..6b7dd2c2c5e21cdfbb2017627c68235810ea45df --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_edit.txt @@ -0,0 +1,408 @@ +env GO111MODULE=on + +# Test that go mod edits and related mod flags work. +# Also test that they can use a dummy name that isn't resolvable. golang.org/issue/24100 + +# go mod init +! go mod init +stderr 'cannot determine module path' +! exists go.mod + +go mod init x.x/y/z +stderr 'creating new go.mod: module x.x/y/z' +cmpenv go.mod $WORK/go.mod.init + +! go mod init +cmpenv go.mod $WORK/go.mod.init + +# go mod edits +go mod edit -droprequire=x.1 -require=x.1@v1.0.0 -require=x.2@v1.1.0 -droprequire=x.2 -exclude='x.1 @ v1.2.0' -exclude=x.1@v1.2.1 -exclude=x.1@v2.0.0+incompatible -replace=x.1@v1.3.0=y.1@v1.4.0 -replace='x.1@v1.4.0 = ../z' -retract=v1.6.0 -retract=[v1.1.0,v1.2.0] -retract=[v1.3.0,v1.4.0] -retract=v1.0.0 +cmpenv go.mod $WORK/go.mod.edit1 +go mod edit -droprequire=x.1 -dropexclude=x.1@v1.2.1 -dropexclude=x.1@v2.0.0+incompatible -dropreplace=x.1@v1.3.0 -require=x.3@v1.99.0 -dropretract=v1.0.0 -dropretract=[v1.1.0,v1.2.0] +cmpenv go.mod $WORK/go.mod.edit2 + +# -exclude and -retract reject invalid versions. +! go mod edit -exclude=example.com/m@bad +stderr '^go: -exclude=example.com/m@bad: version "bad" invalid: must be of the form v1.2.3$' +! go mod edit -retract=bad +stderr '^go: -retract=bad: version "bad" invalid: must be of the form v1.2.3$' + +! go mod edit -exclude=example.com/m@v2.0.0 +stderr '^go: -exclude=example.com/m@v2\.0\.0: version "v2\.0\.0" invalid: should be v2\.0\.0\+incompatible \(or module example\.com/m/v2\)$' + +! go mod edit -exclude=example.com/m/v2@v1.0.0 +stderr '^go: -exclude=example.com/m/v2@v1\.0\.0: version "v1\.0\.0" invalid: should be v2, not v1$' + +! go mod edit -exclude=gopkg.in/example.v1@v2.0.0 +stderr '^go: -exclude=gopkg\.in/example\.v1@v2\.0\.0: version "v2\.0\.0" invalid: should be v1, not v2$' + +cmpenv go.mod $WORK/go.mod.edit2 + +# go mod edit -json +go mod edit -json +cmpenv stdout $WORK/go.mod.json + +# go mod edit -json (retractions with rationales) +go mod edit -json $WORK/go.mod.retractrationale +cmp stdout $WORK/go.mod.retractrationale.json + +# go mod edit -json (deprecation) +go mod edit -json $WORK/go.mod.deprecation +cmp stdout $WORK/go.mod.deprecation.json + +# go mod edit -json (empty mod file) +go mod edit -json $WORK/go.mod.empty +cmp stdout $WORK/go.mod.empty.json + +# go mod edit -replace +go mod edit -replace=x.1@v1.3.0=y.1/v2@v2.3.5 -replace=x.1@v1.4.0=y.1/v2@v2.3.5 +cmpenv go.mod $WORK/go.mod.edit3 +go mod edit -replace=x.1=y.1/v2@v2.3.6 +cmpenv go.mod $WORK/go.mod.edit4 +go mod edit -dropreplace=x.1 +cmpenv go.mod $WORK/go.mod.edit5 +go mod edit -replace=x.1=../y.1/@v2 +cmpenv go.mod $WORK/go.mod.edit6 +! go mod edit -replace=x.1=y.1/@v2 +stderr '^go: -replace=x.1=y.1/@v2: invalid new path: malformed import path "y.1/": trailing slash$' + +# go mod edit -fmt +cp $WORK/go.mod.badfmt go.mod +go mod edit -fmt -print # -print should avoid writing file +cmpenv stdout $WORK/go.mod.goodfmt +cmp go.mod $WORK/go.mod.badfmt +go mod edit -fmt # without -print, should write file (and nothing to stdout) +! stdout . +cmpenv go.mod $WORK/go.mod.goodfmt + +# go mod edit -module +cd $WORK/m +go mod init a.a/b/c +go mod edit -module x.x/y/z +cmpenv go.mod go.mod.edit + +# golang.org/issue/30513: don't require go-gettable module paths. +cd $WORK/local +go mod init foo +go mod edit -module local-only -require=other-local@v1.0.0 -replace other-local@v1.0.0=./other +cmpenv go.mod go.mod.edit + +# go mod edit -godebug +cd $WORK/g +cp go.mod.start go.mod +go mod edit -godebug key=value +cmpenv go.mod go.mod.edit +go mod edit -dropgodebug key2 +cmpenv go.mod go.mod.edit +go mod edit -dropgodebug key +cmpenv go.mod go.mod.start + +# go mod edit -tool +cd $WORK/h +cp go.mod.start go.mod +go mod edit -tool example.com/tool +cmpenv go.mod go.mod.edit +go mod edit -droptool example.com/tool2 +cmpenv go.mod go.mod.edit +go mod edit -droptool example.com/tool +cmpenv go.mod go.mod.start + +# go mod edit -ignore +cd $WORK/i +cp go.mod.start go.mod +go mod edit -ignore example.com/ignore +cmpenv go.mod go.mod.edit +go mod edit -dropignore example.com/ignore2 +cmpenv go.mod go.mod.edit +go mod edit -dropignore example.com/ignore +cmpenv go.mod go.mod.start + +-- x.go -- +package x + +-- w/w.go -- +package w + +-- $WORK/go.mod.init -- +module x.x/y/z + +go $goversion +-- $WORK/go.mod.edit1 -- +module x.x/y/z + +go $goversion + +require x.1 v1.0.0 + +exclude ( + x.1 v1.2.0 + x.1 v1.2.1 + x.1 v2.0.0+incompatible +) + +replace ( + x.1 v1.3.0 => y.1 v1.4.0 + x.1 v1.4.0 => ../z +) + +retract ( + v1.6.0 + [v1.3.0, v1.4.0] + [v1.1.0, v1.2.0] + v1.0.0 +) +-- $WORK/go.mod.edit2 -- +module x.x/y/z + +go $goversion + +exclude x.1 v1.2.0 + +replace x.1 v1.4.0 => ../z + +retract ( + v1.6.0 + [v1.3.0, v1.4.0] +) + +require x.3 v1.99.0 +-- $WORK/go.mod.json -- +{ + "Module": { + "Path": "x.x/y/z" + }, + "Go": "$goversion", + "Require": [ + { + "Path": "x.3", + "Version": "v1.99.0" + } + ], + "Exclude": [ + { + "Path": "x.1", + "Version": "v1.2.0" + } + ], + "Replace": [ + { + "Old": { + "Path": "x.1", + "Version": "v1.4.0" + }, + "New": { + "Path": "../z" + } + } + ], + "Retract": [ + { + "Low": "v1.6.0", + "High": "v1.6.0" + }, + { + "Low": "v1.3.0", + "High": "v1.4.0" + } + ], + "Tool": null, + "Ignore": null +} +-- $WORK/go.mod.edit3 -- +module x.x/y/z + +go $goversion + +exclude x.1 v1.2.0 + +replace ( + x.1 v1.3.0 => y.1/v2 v2.3.5 + x.1 v1.4.0 => y.1/v2 v2.3.5 +) + +retract ( + v1.6.0 + [v1.3.0, v1.4.0] +) + +require x.3 v1.99.0 +-- $WORK/go.mod.edit4 -- +module x.x/y/z + +go $goversion + +exclude x.1 v1.2.0 + +replace x.1 => y.1/v2 v2.3.6 + +retract ( + v1.6.0 + [v1.3.0, v1.4.0] +) + +require x.3 v1.99.0 +-- $WORK/go.mod.edit5 -- +module x.x/y/z + +go $goversion + +exclude x.1 v1.2.0 + +retract ( + v1.6.0 + [v1.3.0, v1.4.0] +) + +require x.3 v1.99.0 +-- $WORK/go.mod.edit6 -- +module x.x/y/z + +go $goversion + +exclude x.1 v1.2.0 + +retract ( + v1.6.0 + [v1.3.0, v1.4.0] +) + +require x.3 v1.99.0 + +replace x.1 => ../y.1/@v2 +-- $WORK/local/go.mod.edit -- +module local-only + +go $goversion + +require other-local v1.0.0 + +replace other-local v1.0.0 => ./other +-- $WORK/go.mod.badfmt -- +module x.x/y/z + +go 1.10 + +exclude x.1 v1.2.0 + +replace x.1 => y.1/v2 v2.3.6 + +require x.3 v1.99.0 + +retract [ "v1.8.1" , "v1.8.2" ] +-- $WORK/go.mod.goodfmt -- +module x.x/y/z + +go 1.10 + +exclude x.1 v1.2.0 + +replace x.1 => y.1/v2 v2.3.6 + +require x.3 v1.99.0 + +retract [v1.8.1, v1.8.2] +-- $WORK/m/go.mod.edit -- +module x.x/y/z + +go $goversion +-- $WORK/go.mod.retractrationale -- +module x.x/y/z + +go 1.15 + +// a +retract v1.0.0 + +// b +retract ( + v1.0.1 + v1.0.2 // c +) +-- $WORK/go.mod.retractrationale.json -- +{ + "Module": { + "Path": "x.x/y/z" + }, + "Go": "1.15", + "Require": null, + "Exclude": null, + "Replace": null, + "Retract": [ + { + "Low": "v1.0.0", + "High": "v1.0.0", + "Rationale": "a" + }, + { + "Low": "v1.0.1", + "High": "v1.0.1", + "Rationale": "b" + }, + { + "Low": "v1.0.2", + "High": "v1.0.2", + "Rationale": "c" + } + ], + "Tool": null, + "Ignore": null +} +-- $WORK/go.mod.deprecation -- +// Deprecated: and the new one is not ready yet +module m +-- $WORK/go.mod.deprecation.json -- +{ + "Module": { + "Path": "m", + "Deprecated": "and the new one is not ready yet" + }, + "Require": null, + "Exclude": null, + "Replace": null, + "Retract": null, + "Tool": null, + "Ignore": null +} +-- $WORK/go.mod.empty -- +-- $WORK/go.mod.empty.json -- +{ + "Module": { + "Path": "" + }, + "Require": null, + "Exclude": null, + "Replace": null, + "Retract": null, + "Tool": null, + "Ignore": null +} +-- $WORK/g/go.mod.start -- +module g + +go 1.10 +-- $WORK/g/go.mod.edit -- +module g + +go 1.10 + +godebug key=value +-- $WORK/h/go.mod.start -- +module g + +go 1.24 +-- $WORK/h/go.mod.edit -- +module g + +go 1.24 + +tool example.com/tool +-- $WORK/i/go.mod.start -- +module g + +go 1.24 +-- $WORK/i/go.mod.edit -- +module g + +go 1.24 + +ignore example.com/ignore \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_edit_go.txt b/go/src/cmd/go/testdata/script/mod_edit_go.txt new file mode 100644 index 0000000000000000000000000000000000000000..007760df5d7a4e0bfba7053a7f9df6ace1e25224 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_edit_go.txt @@ -0,0 +1,26 @@ +# Test support for go mod edit -go to set language version. + +env GO111MODULE=on +! go build +stderr ' type alias requires' +go mod edit -go=1.9 +grep 'go 1.9' go.mod +go build + +# Reverting the version should force a rebuild and error instead of using +# the cached 1.9 build. (https://golang.org/issue/37804) +go mod edit -go=1.8 +! go build +stderr 'type alias requires' + +# go=none should drop the line +go mod edit -go=none +! grep go go.mod + +-- go.mod -- +module m +go 1.8 + +-- alias.go -- +package alias +type T = int diff --git a/go/src/cmd/go/testdata/script/mod_edit_issue75105.txt b/go/src/cmd/go/testdata/script/mod_edit_issue75105.txt new file mode 100644 index 0000000000000000000000000000000000000000..8984daee2559c720b5655fd282cfe70e8f71c01e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_edit_issue75105.txt @@ -0,0 +1,36 @@ +env GO111MODULE=on + +go mod edit -godebug 'http2debug=2' +cmp go.mod go.mod.edit.want1 + +go mod edit -json +cmp stdout go.mod.edit.want2 +-- go.mod -- +module foo + +go 1.25.0 +-- go.mod.edit.want1 -- +module foo + +go 1.25.0 + +godebug http2debug=2 +-- go.mod.edit.want2 -- +{ + "Module": { + "Path": "foo" + }, + "Go": "1.25.0", + "GoDebug": [ + { + "Key": "http2debug", + "Value": "2" + } + ], + "Require": null, + "Exclude": null, + "Replace": null, + "Retract": null, + "Tool": null, + "Ignore": null +} diff --git a/go/src/cmd/go/testdata/script/mod_edit_no_modcache.txt b/go/src/cmd/go/testdata/script/mod_edit_no_modcache.txt new file mode 100644 index 0000000000000000000000000000000000000000..ced15bb3018aa2e9e71eab690f6de7e2a4af349d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_edit_no_modcache.txt @@ -0,0 +1,15 @@ +# 'go mod edit' opportunistically locks the side-lock file in the module cache, +# for compatibility with older versions of the 'go' command. +# It does not otherwise depend on the module cache, so it should not +# fail if the module cache directory cannot be created. + +[root] skip + +mkdir $WORK/readonly +chmod 0555 $WORK/readonly +env GOPATH=$WORK/readonly/nonexist + +go mod edit -go=1.17 + +-- go.mod -- +module example.com/m diff --git a/go/src/cmd/go/testdata/script/mod_edit_toolchain.txt b/go/src/cmd/go/testdata/script/mod_edit_toolchain.txt new file mode 100644 index 0000000000000000000000000000000000000000..bb544be344d4f1a6f5b0cdaf128afc66311a971e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_edit_toolchain.txt @@ -0,0 +1,18 @@ +# Test support for go mod edit -toolchain to set toolchain to use + +env GOTOOLCHAIN=local +env GO111MODULE=on + +! grep toolchain go.mod +go mod edit -toolchain=go1.9 +grep 'toolchain go1.9' go.mod + +go mod edit -toolchain=default +grep 'toolchain default' go.mod + +go mod edit -toolchain=none +! grep toolchain go.mod + +-- go.mod -- +module m +go 1.8 diff --git a/go/src/cmd/go/testdata/script/mod_empty_err.txt b/go/src/cmd/go/testdata/script/mod_empty_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..4b4a0076e0f72c753476ed3f0dd260d7b4fe416a --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_empty_err.txt @@ -0,0 +1,36 @@ +# This test checks error messages for non-existent packages in module mode. +# Veries golang.org/issue/35414 +env GO111MODULE=on +cd $WORK + +go list -e -f {{.Error}} . +stdout 'no Go files in '$WORK + +go list -e -f {{.Error}} ./empty +stdout 'no Go files in '$WORK${/}'empty' + +go list -e -f {{.Error}} ./exclude +stdout 'build constraints exclude all Go files in '$WORK${/}'exclude' + +go list -e -f {{.Error}} ./missing +stdout 'stat '$WORK'[/\\]missing: directory not found' + +# use 'go build -n' because 'go list' reports no error. +! go build -n ./testonly +stderr 'example.com/m/testonly: no non-test Go files in '$WORK${/}'testonly' + +-- $WORK/go.mod -- +module example.com/m + +go 1.14 + +-- $WORK/empty/empty.txt -- +-- $WORK/exclude/exclude.go -- +// +build exclude + +package exclude +-- $WORK/testonly/testonly_test.go -- +package testonly_test +-- $WORK/excluded-stdout -- +package ./excluded: cannot find package "." in: + $WORK/excluded diff --git a/go/src/cmd/go/testdata/script/mod_enabled.txt b/go/src/cmd/go/testdata/script/mod_enabled.txt new file mode 100644 index 0000000000000000000000000000000000000000..39f1ece8cb8eea2ce1e65715ed6dce0d681957b7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_enabled.txt @@ -0,0 +1,93 @@ +# GO111MODULE=auto should trigger any time a go.mod exists in a parent directory. +env GO111MODULE=auto + +cd $GOPATH/src/x/y/z +go env GOMOD +stdout $GOPATH[/\\]src[/\\]x[/\\]y[/\\]z[/\\]go.mod +go list -m -f {{.GoMod}} +stdout $GOPATH[/\\]src[/\\]x[/\\]y[/\\]z[/\\]go.mod + +cd $GOPATH/src/x/y/z/w +go env GOMOD +stdout $GOPATH[/\\]src[/\\]x[/\\]y[/\\]z[/\\]go.mod + +cd $GOPATH/src/x/y +go env GOMOD +! stdout . + +cd $GOPATH/foo +go env GOMOD +stdout foo[/\\]go.mod +go list -m -f {{.GoMod}} +stdout foo[/\\]go.mod + +cd $GOPATH/foo/bar/baz +go env GOMOD +stdout foo[/\\]go.mod + +# GO111MODULE unset should be equivalent to on. +env GO111MODULE= + +cd $GOPATH/src/x/y/z +go env GOMOD +stdout $GOPATH[/\\]src[/\\]x[/\\]y[/\\]z[/\\]go.mod + +cd $GOPATH/src/x/y +go env GOMOD +stdout 'NUL|/dev/null' + +# GO111MODULE=on should trigger everywhere +env GO111MODULE=on + +cd $GOPATH/src/x/y/z +go env GOMOD +stdout z[/\\]go.mod + +cd $GOPATH/src/x/y/z/w +go env GOMOD +stdout z[/\\]go.mod + +cd $GOPATH/src/x/y +go env GOMOD +stdout 'NUL|/dev/null' +go list -m +stdout '^command-line-arguments$' + +cd $GOPATH/foo +go env GOMOD +stdout foo[/\\]go.mod + +cd $GOPATH/foo/bar/baz +go env GOMOD +stdout foo[/\\]go.mod + +# GO111MODULE=off should trigger nowhere +env GO111MODULE=off + +cd $GOPATH/src/x/y/z +go env GOMOD +! stdout .+ + +cd $GOPATH/foo +go env GOMOD +! stdout .+ + +cd $GOPATH/foo/bar/baz +go env GOMOD +! stdout .+ + +# GO111MODULE=auto should ignore and warn about /tmp/go.mod +env GO111MODULE=auto +cp $GOPATH/src/x/y/z/go.mod $WORK/tmp/go.mod +mkdir $WORK/tmp/mydir +cd $WORK/tmp/mydir +go env GOMOD +! stdout .+ +stderr '^go: warning: ignoring go.mod in system temp root ' + +-- $GOPATH/src/x/y/z/go.mod -- +module x/y/z +-- $GOPATH/src/x/y/z/w/w.txt -- +-- $GOPATH/foo/go.mod -- +module example.com/mod +-- $GOPATH/foo/bar/baz/quux.txt -- diff --git a/go/src/cmd/go/testdata/script/mod_errors_pos.txt b/go/src/cmd/go/testdata/script/mod_errors_pos.txt new file mode 100644 index 0000000000000000000000000000000000000000..48f92d763cab8b2a6feebaa9cd6adbf5a85e7593 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_errors_pos.txt @@ -0,0 +1,11 @@ +# Test case for #67623 in go.mod files: make sure the error for +# an unknown godebug is printed on a line starting with the file +# and line number, so it can be easily parsed by tools. + +! go list +stderr '^go.mod:3: unknown godebug "foo"$' + +-- go.mod -- +module example.com/bar + +godebug foo=1 \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_exclude_go121.txt b/go/src/cmd/go/testdata/script/mod_exclude_go121.txt new file mode 100644 index 0000000000000000000000000000000000000000..51c8a00a435321c63183214ac11faaa265449f95 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_exclude_go121.txt @@ -0,0 +1,34 @@ +# go.dev/issue/60028: use semver sort in exclude block in 1.21 +cp $WORK/go.mod.badfmtexclude go.mod +go mod edit -go=1.20 +cmp go.mod $WORK/go.mod.goodfmtexclude120 +go mod edit -go=1.21 +cmp go.mod $WORK/go.mod.goodfmtexclude121 + +-- $WORK/go.mod.badfmtexclude -- +module x.x/y/z +exclude ( + x.1 v1.11.0 + x.1 v1.10.0 + x.1 v1.9.0 +) +-- $WORK/go.mod.goodfmtexclude120 -- +module x.x/y/z + +go 1.20 + +exclude ( + x.1 v1.10.0 + x.1 v1.11.0 + x.1 v1.9.0 +) +-- $WORK/go.mod.goodfmtexclude121 -- +module x.x/y/z + +go 1.21 + +exclude ( + x.1 v1.9.0 + x.1 v1.10.0 + x.1 v1.11.0 +) diff --git a/go/src/cmd/go/testdata/script/mod_file_proxy.txt b/go/src/cmd/go/testdata/script/mod_file_proxy.txt new file mode 100644 index 0000000000000000000000000000000000000000..ebc28a0015a324211b144f3929482b40b2289093 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_file_proxy.txt @@ -0,0 +1,36 @@ +[short] skip + +# Allow (cached) downloads for -mod=readonly. +env GO111MODULE=on +env GOPATH=$WORK/gopath1 +cd $WORK/x +go mod edit -fmt +go list -mod=readonly +env GOPROXY=file:///nonexist +go list +grep v1.5.1 $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/list + +# Use download cache as file:/// proxy. +env GOPATH=$WORK/gopath2 +[GOOS:windows] env GOPROXY=file:///C:/nonexist +[!GOOS:windows] env GOPROXY=file:///nonexist +! go list +[GOOS:windows] env GOPROXY=file:///$WORK/gopath1/pkg/mod/cache/download +[!GOOS:windows] env GOPROXY=file://$WORK/gopath1/pkg/mod/cache/download +go list +grep v1.5.1 $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/list + +-- $WORK/x/go.mod -- +module x +go 1.13 +require rsc.io/quote v1.5.1 +-- $WORK/x/x.go -- +package x +import _ "rsc.io/quote" +-- $WORK/x/go.sum -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.1 h1:ZE3OgnVGrhXtFkGw90HwW992ZRqcdli/33DLqEYsoxA= +rsc.io/quote v1.5.1/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/go/src/cmd/go/testdata/script/mod_fileproxy_vcs_missing_issue51589.txt b/go/src/cmd/go/testdata/script/mod_fileproxy_vcs_missing_issue51589.txt new file mode 100644 index 0000000000000000000000000000000000000000..633bd8b7b11634ba9a109e5315720d2b29ac78cf --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_fileproxy_vcs_missing_issue51589.txt @@ -0,0 +1,42 @@ +# This test checks that "go mod tidy -e" do not panic when +# using a file goproxy that is missing some modules. +# Verifies golang.org/issue/51589 + +# download the modules first +env GO111MODULE=on +env GOPATH=$WORK/gopath +cd $WORK/x +go mod tidy + +# Use download cache as file:/// proxy. +[GOOS:windows] env GOPROXY=file:///$WORK/gopath/pkg/mod/cache/download +[!GOOS:windows] env GOPROXY=file://$WORK/gopath/pkg/mod/cache/download +rm $WORK/gopath/pkg/mod/cache/download/golang.org/x/text/ +go mod tidy -e +stderr '^go: rsc.io/sampler@v1.3.0 requires\n\tgolang.org/x/text@.*: reading file://.*/pkg/mod/cache/download/golang.org/x/text/.*' +! stderr 'signal SIGSEGV: segmentation violation' + +-- $WORK/x/go.mod -- +module example.com/mod + +go 1.17 + +require rsc.io/quote v1.5.2 + +require ( + golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect + rsc.io/sampler v1.3.0 // indirect +) + +-- $WORK/x/x.go -- +package mod + +import ( + "fmt" + + "rsc.io/quote" +) + +func Echo() { + fmt.Println(quote.Hello()) +} diff --git a/go/src/cmd/go/testdata/script/mod_find.txt b/go/src/cmd/go/testdata/script/mod_find.txt new file mode 100644 index 0000000000000000000000000000000000000000..748713cdf37c0c8ddb760b5bcf814327b2c6dcf1 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_find.txt @@ -0,0 +1,98 @@ +env GO111MODULE=on + +# Derive module path from import comment. +cd $WORK/x +exists x.go +go mod init +stderr 'module x' + +# Import comment works even with CRLF line endings. +rm go.mod +replace '\n' '\r\n' x.go +go mod init +stderr 'module x' + +# Derive module path from location inside GOPATH. +# 'go mod init' should succeed if modules are not explicitly disabled. +cd $GOPATH/src/example.com/x/y +go mod init +stderr 'module example.com/x/y$' +rm go.mod + +# go mod init rejects a zero-length go.mod file +cp $devnull go.mod # can't use touch to create it because Windows +! go mod init +stderr 'go.mod already exists' + +# Empty directory outside GOPATH fails. +mkdir $WORK/empty +cd $WORK/empty +! go mod init +stderr 'cannot determine module path for source directory' +rm go.mod + +# Empty directory inside GOPATH/src uses location inside GOPATH. +mkdir $GOPATH/src/empty +cd $GOPATH/src/empty +go mod init +stderr 'empty' +rm go.mod + +# In Plan 9, directories are automatically created in /n. +# For example, /n/go.mod always exist, but it's a directory. +# Test that we ignore directories when trying to find go.mod. +cd $WORK/gomoddir +! go list . +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + +[!symlink] stop + +# gplink1/src/empty where gopathlink -> GOPATH +symlink $WORK/gopathlink -> gopath +cd $WORK/gopathlink/src/empty +go mod init +rm go.mod + +# GOPATH/src/link where link -> out of GOPATH +symlink $GOPATH/src/link -> $WORK/empty +cd $WORK/empty +! go mod init +cd $GOPATH/src/link +go mod init +stderr link +rm go.mod + +# GOPATH/src/empty where GOPATH itself is a symlink +env GOPATH=$WORK/gopathlink +cd $GOPATH/src/empty +go mod init +rm go.mod +cd $WORK/gopath/src/empty +go mod init +rm go.mod + +# GOPATH/src/link where GOPATH and link are both symlinks +cd $GOPATH/src/link +go mod init +stderr link +rm go.mod + +# Too hard: doesn't match unevaluated nor completely evaluated. (Only partially evaluated.) +# Whether this works depends on which OS we are running on. +# cd $WORK/gopath/src/link +# ! go mod init + +-- $WORK/x/x.go -- +package x // import "x" + +-- $GOPATH/src/example.com/x/y/y.go -- +package y +-- $GOPATH/src/example.com/x/y/z/z.go -- +package z +-- $GOPATH/src/example.com/x/y/z/Godeps/Godeps.json -- +{"ImportPath": "unexpected.com/z"} + +-- $WORK/gomoddir/go.mod/README.txt -- +../go.mod is a directory, not a file. +-- $WORK/gomoddir/p.go -- +package p diff --git a/go/src/cmd/go/testdata/script/mod_fs_patterns.txt b/go/src/cmd/go/testdata/script/mod_fs_patterns.txt new file mode 100644 index 0000000000000000000000000000000000000000..c834ce851e04d616b7fb9a42e178db65f7a1cdbb --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_fs_patterns.txt @@ -0,0 +1,97 @@ +env GO111MODULE=on + +# File system pattern searches should skip sub-modules and vendor directories. +cd x + +# all packages +go list all +stdout ^m$ +stdout ^m/vendor$ +! stdout vendor/ +stdout ^m/y$ +! stdout ^m/y/z + +# path pattern +go list m/... +stdout ^m$ +stdout ^m/vendor$ +! stdout vendor/ +stdout ^m/y$ +! stdout ^m/y/z + +# directory pattern +go list ./... +stdout ^m$ +stdout ^m/vendor$ +! stdout vendor/ +stdout ^m/y$ +! stdout ^m/y/z + +# non-existent directory should not prompt lookups +! go build -mod=readonly example.com/nonexist +stderr 'import lookup disabled' + +! go build -mod=readonly ./nonexist +! stderr 'import lookup disabled' +stderr '^stat '$GOPATH'[/\\]src[/\\]x[/\\]nonexist: directory not found' + +! go build -mod=readonly ./go.mod +! stderr 'import lookup disabled' +stderr 'main module \(m\) does not contain package m/go.mod' + + +# File system paths and patterns should allow the '@' character. +cd ../@at +go list $PWD +stdout '^at$' +go list $PWD/... +stdout '^at$' + +# The '@' character is not allowed in directory paths that are part of +# a package path. +cd ../badat/bad@ +! go list . +stderr 'current directory outside main module or its selected dependencies' +! go list $PWD +stderr 'current directory outside main module or its selected dependencies' +! go list $PWD/... +stderr 'current directory outside main module or its selected dependencies' + +-- x/go.mod -- +module m + +-- x/x.go -- +package x + +-- x/vendor/v/v.go -- +package v +import _ "golang.org/x/crypto" + +-- x/vendor/v.go -- +package main + +-- x/y/y.go -- +package y + +-- x/y/z/go.mod -- +syntax error! + +-- x/y/z/z.go -- +package z + +-- x/y/z/w/w.go -- +package w + +-- @at/go.mod -- +module at + +go 1.14 +-- @at/at.go -- +package at + +-- badat/go.mod -- +module badat + +go 1.14 +-- badat/bad@/bad.go -- +package bad diff --git a/go/src/cmd/go/testdata/script/mod_get_ambiguous_arg.txt b/go/src/cmd/go/testdata/script/mod_get_ambiguous_arg.txt new file mode 100644 index 0000000000000000000000000000000000000000..92149933686a6fc5e7bdbd9733ac8e414c49c808 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_ambiguous_arg.txt @@ -0,0 +1,107 @@ +go mod tidy +cp go.mod go.mod.orig + +# If there is no sensible *package* meaning for 'm/p', it should refer +# to *module* m/p. + +go get m/p # @latest +go list -m all +stdout '^m/p v0.3.0 ' +! stdout '^m ' + +cp go.mod.orig go.mod + +go get m/p@v0.1.0 +go list -m all +stdout '^m/p v0.1.0 ' +! stdout '^m ' + +# When feasible, the argument 'm/p' in 'go get m/p' refers to *package* m/p, +# which is in module m. +# +# (It only refers to *module* m/p if there is no such package at the +# requested version.) + +go get m/p@v0.2.0 +go list -m all +stdout '^m v0.2.0 ' +stdout '^m/p v0.1.0 ' # unchanged from the previous case + +# Repeating the above with module m/p already in the module graph does not +# change its meaning. + +go get m/p@v0.2.0 +go list -m all +stdout '^m v0.2.0 ' +stdout '^m/p v0.1.0 ' + +-- go.mod -- +module example.com + +go 1.16 + +replace ( + m v0.1.0 => ./m01 + m v0.2.0 => ./m02 + m v0.3.0 => ./m03 + m/p v0.1.0 => ./mp01 + m/p v0.2.0 => ./mp02 + m/p v0.3.0 => ./mp03 +) +-- m01/go.mod -- +module m + +go 1.16 +-- m01/README.txt -- +Module m at v0.1.0 does not yet contain package p. + +-- m02/go.mod -- +module m + +go 1.16 + +require m/p v0.1.0 +-- m02/p/p.go -- +// Package p is present in module m, but not module m/p. +package p + +-- m03/go.mod -- +module m + +go 1.16 + +require m/p v0.1.0 +-- m03/README.txt -- +Module m at v0.3.0 no longer contains package p. + +-- mv2/go.mod -- +module m/v2 + +go 1.16 +-- mv2/README.txt -- +This module is m/v2. It doesn't actually need to exist, +but it explains how module m could plausibly exist +and still contain package p at 'latest' even when module +m/p also exists. + +-- mp01/go.mod -- +module m/p + +go 1.16 +-- mp01/README.txt -- +This module is m/p. +Package m/p does not exist in this module. +-- mp02/go.mod -- +module m/p + +go 1.16 +-- mp02/README.txt -- +This module is m/p. +Package m/p does not exist in this module. +-- mp03/go.mod -- +module m/p + +go 1.16 +-- mp03/README.txt -- +This module is m/p. +Package m/p does not exist in this module. diff --git a/go/src/cmd/go/testdata/script/mod_get_ambiguous_import.txt b/go/src/cmd/go/testdata/script/mod_get_ambiguous_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..f08e540441dde8a21f624acf1cc0a850e47e3688 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_ambiguous_import.txt @@ -0,0 +1,60 @@ +go list -m all +stdout '^example.net/m v0.1.0 ' +! stdout '^example.net/m/p ' +cp go.mod go.mod.orig + +# Upgrading example.net/m/p without also upgrading example.net/m +# causes the import of package example.net/m/p to be ambiguous. +# +# TODO(#27899): Should we automatically upgrade example.net/m to v0.2.0 +# to resolve the conflict? +! go get example.net/m/p@v1.0.0 +stderr '^go: example.net/m/p: ambiguous import: found package example.net/m/p in multiple modules:\n\texample.net/m v0.1.0 \(.*[/\\]m1[/\\]p\)\n\texample.net/m/p v1.0.0 \(.*[/\\]p0\)\n\z' +cmp go.mod go.mod.orig + +# Upgrading both modules simultaneously resolves the ambiguous upgrade. +# Note that this command line mixes a module path (example.net/m) +# and a package path (example.net/m/p) in the same command. +go get example.net/m@v0.2.0 example.net/m/p@v1.0.0 + +go list -m all +stdout '^example.net/m v0.2.0 ' +stdout '^example.net/m/p v1.0.0 ' + +-- go.mod -- +module example.net/importer + +go 1.16 + +require ( + example.net/m v0.1.0 +) + +replace ( + example.net/m v0.1.0 => ./m1 + example.net/m v0.2.0 => ./m2 + example.net/m/p v1.0.0 => ./p0 +) +-- importer.go -- +package importer +import _ "example.net/m/p" +-- m1/go.mod -- +module example.net/m + +go 1.16 +-- m1/p/p.go -- +package p +-- m2/go.mod -- +module example.net/m + +go 1.16 +-- m2/README.txt -- +Package p has been moved to module …/m/p. +Module …/m/p does not require any version of module …/m. + +-- p0/go.mod -- +module example.net/m/p + +go 1.16 +-- p0/p.go -- +package p diff --git a/go/src/cmd/go/testdata/script/mod_get_ambiguous_pkg.txt b/go/src/cmd/go/testdata/script/mod_get_ambiguous_pkg.txt new file mode 100644 index 0000000000000000000000000000000000000000..1641196007b8e166a685f00d292207a72b69d25c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_ambiguous_pkg.txt @@ -0,0 +1,87 @@ +# Both example.net/ambiguous v0.1.0 and example.net/ambiguous/pkg v0.1.0 exist. +# 'go mod tidy' would arbitrarily choose the one with the longer path, +# but 'go mod tidy' also arbitrarily chooses the latest version. + +cp go.mod go.mod.orig + + +# From a clean slate, 'go get' currently does the same thing as 'go mod tidy': +# it resolves the package from the module with the longest matching prefix. + +go get example.net/ambiguous/nested/pkg@v0.1.0 +go list -m all +stdout '^example.net/ambiguous/nested v0.1.0$' +! stdout '^example.net/ambiguous ' + + +# From an initial state that already depends on the shorter path, +# the same 'go get' command should (somewhat arbitrarily) keep the +# existing path, since it is a valid interpretation of the command. + +cp go.mod.orig go.mod +go mod edit -require=example.net/ambiguous@v0.1.0 + +go get example.net/ambiguous/nested/pkg@v0.1.0 +go list -m all +stdout '^example.net/ambiguous v0.1.0$' +! stdout '^example.net/ambiguous/nested ' + + +# The user should be able to make the command unambiguous by explicitly +# upgrading the conflicting module... + +go get example.net/ambiguous@v0.2.0 example.net/ambiguous/nested/pkg@v0.1.0 +go list -m all +stdout '^example.net/ambiguous/nested v0.1.0$' +stdout '^example.net/ambiguous v0.2.0$' + + +# ...or by explicitly NOT adding the conflicting module. + +cp go.mod.orig go.mod +go mod edit -require=example.net/ambiguous@v0.1.0 + +go get example.net/ambiguous/nested/pkg@v0.1.0 example.net/ambiguous/nested@none +go list -m all +! stdout '^example.net/ambiguous/nested ' +stdout '^example.net/ambiguous v0.1.0$' + + +# The user should also be able to fix it by *downgrading* the conflicting module +# away. + +cp go.mod.orig go.mod +go mod edit -require=example.net/ambiguous@v0.1.0 + +go get example.net/ambiguous@none example.net/ambiguous/nested/pkg@v0.1.0 +go list -m all +stdout '^example.net/ambiguous/nested v0.1.0$' +! stdout '^example.net/ambiguous ' + + +# In contrast, if we do the same thing tacking a wildcard pattern ('/...') on +# the end of the package path, we get different behaviors depending on the +# initial state, and no error. (This seems to contradict the “same meaning +# regardless of the initial state†point above, but maybe that's ok?) + +cp go.mod.orig go.mod + +go get example.net/ambiguous/nested/pkg/...@v0.1.0 +go list -m all +stdout '^example.net/ambiguous/nested v0.1.0$' +! stdout '^example.net/ambiguous ' + + +cp go.mod.orig go.mod +go mod edit -require=example.net/ambiguous@v0.1.0 + +go get example.net/ambiguous/nested/pkg/...@v0.1.0 +go list -m all +! stdout '^example.net/ambiguous/nested ' +stdout '^example.net/ambiguous v0.1.0$' + + +-- go.mod -- +module test + +go 1.16 diff --git a/go/src/cmd/go/testdata/script/mod_get_boost.txt b/go/src/cmd/go/testdata/script/mod_get_boost.txt new file mode 100644 index 0000000000000000000000000000000000000000..105dc2e2b3a0cc62e098fe10993113b06f48f0f0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_boost.txt @@ -0,0 +1,96 @@ +# If 'go get -u' finds an upgrade candidate that isn't viable, +# but some other upgraded module's requirement moves past it +# (for example, to a higher prerelease), then we should accept +# the transitive upgrade instead of trying lower roots. + +go get -v -u . example.net/b@v0.1.0 +cmp go.mod go.mod.want + +-- go.mod -- +module example + +go 1.17 + +require ( + example.net/a v0.1.0 + example.net/b v0.1.0 + example.net/c v0.1.0 +) + +replace ( + example.net/a v0.1.0 => ./a1 + example.net/a v0.2.0-pre => ./a2p + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c1 + example.net/c v0.2.0 => ./c2 +) +-- go.mod.want -- +module example + +go 1.17 + +require ( + example.net/a v0.2.0-pre + example.net/b v0.1.0 + example.net/c v0.2.0 +) + +replace ( + example.net/a v0.1.0 => ./a1 + example.net/a v0.2.0-pre => ./a2p + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c1 + example.net/c v0.2.0 => ./c2 +) +-- example.go -- +package example + +import ( + _ "example.net/a" + _ "example.net/b" + _ "example.net/c" +) +-- a1/go.mod -- +module example.net/a + +go 1.17 + +require example.net/b v0.2.0 +-- a1/a.go -- +package a + +import _ "example.net/b" +-- a2p/go.mod -- +module example.net/a + +go 1.17 +-- a2p/a.go -- +package a +-- b/go.mod -- +module example.net/b + +go 1.17 +-- b/b.go -- +package b +-- c1/go.mod -- +module example.net/c + +go 1.17 + +require example.net/a v0.1.0 +-- c1/c.go -- +package c + +import _ "example.net/a" +-- c2/go.mod -- +module example.net/c + +go 1.17 + +require example.net/a v0.2.0-pre +-- c2/c.go -- +package c + +import _ "example.net/c" diff --git a/go/src/cmd/go/testdata/script/mod_get_changes.txt b/go/src/cmd/go/testdata/script/mod_get_changes.txt new file mode 100644 index 0000000000000000000000000000000000000000..12a112b4d87af75c8302dad7e5c1eedfbfec8a09 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_changes.txt @@ -0,0 +1,70 @@ +# When adding a requirement, 'go get' prints a message for the requirement +# and for changed explicit dependencies. 'go get' does not print messages +# for changed indirect dependencies. +go list -m all +! stdout golang.org/x/text +go get rsc.io/quote@v1.5.2 +stderr '^go: added rsc.io/quote v1.5.2$' +stderr '^go: upgraded rsc.io/sampler v1.0.0 => v1.3.0$' +! stderr '^go get.*golang.org/x/text' +go list -m all +stdout golang.org/x/text +cmp go.mod go.mod.upgrade + +# When removing a requirement, 'go get' prints a message for the requiremnent +# and for changed explicit dependencies. 'go get' does not print messages +# for changed indirect dependencies. +go get rsc.io/sampler@none +stderr '^go: downgraded rsc.io/quote v1.5.2 => v1.3.0$' +stderr '^go: removed rsc.io/sampler v1.3.0$' +! stderr '^go get.*golang.org/x/text' +cmp go.mod go.mod.downgrade + +# When removing or downgrading a requirement, 'go get' also prints a message +# for explicit dependencies removed as a consequence. +cp go.mod.usequote go.mod +go get rsc.io/quote@v1.5.1 +stderr '^go: downgraded rsc.io/quote v1.5.2 => v1.5.1$' +stderr '^go: removed usequote v0.0.0$' + +-- go.mod -- +module m + +go 1.16 + +require rsc.io/sampler v1.0.0 +-- go.sum -- +rsc.io/sampler v1.0.0 h1:SRJnjyQ07sAtq6G4RcfJEmz8JxqLyj3PoGXG2VhbDWo= +rsc.io/sampler v1.0.0/go.mod h1:cqxpM3ZVz9VtirqxZPmrWzkQ+UkiNiGtkrN+B+i8kx8= +-- go.mod.upgrade -- +module m + +go 1.16 + +require ( + rsc.io/quote v1.5.2 // indirect + rsc.io/sampler v1.3.0 +) +-- go.mod.downgrade -- +module m + +go 1.16 + +require ( + golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect + rsc.io/quote v1.3.0 // indirect +) +-- go.mod.usequote -- +module m + +go 1.16 + +require usequote v0.0.0 + +replace usequote => ./usequote +-- usequote/go.mod -- +module usequote + +go 1.16 + +require rsc.io/quote v1.5.2 diff --git a/go/src/cmd/go/testdata/script/mod_get_commit.txt b/go/src/cmd/go/testdata/script/mod_get_commit.txt new file mode 100644 index 0000000000000000000000000000000000000000..76650f3bd36c4953d442c1e2885515c5444c5e8c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_commit.txt @@ -0,0 +1,50 @@ +env GO111MODULE=on +[short] skip + +# @commit should resolve + +# golang.org/x/text/language@commit should resolve. +# Because of -d, the compiler should not run. +go get -x golang.org/x/text/language@14c0d48 +! stderr 'compile|cp|gccgo .*language\.a$' + +# go get should skip build with no Go files in root +go get golang.org/x/text@14c0d48 + +# dropping -d, we should see a build. +[short] skip + +env GOCACHE=$WORK/gocache # Looking for compile commands, so need a clean cache. + +go build -x golang.org/x/text/language +stderr 'compile|cp|gccgo .*language\.a$' + +go list -f '{{.Stale}}' golang.org/x/text/language +stdout ^false + +# install after build should not run the compiler again. +go install -x golang.org/x/text/language +! stderr 'compile|cp|gccgo .*language\.a$' + +# we should see an error for unknown packages. +! go get -x golang.org/x/text/foo@14c0d48 +stderr '^go: module golang.org/x/text@14c0d48 found \(v0.3.0\), but does not contain package golang.org/x/text/foo$' + +# get pseudo-version should record that version +go get rsc.io/quote@v0.0.0-20180214005840-23179ee8a569 +grep 'rsc.io/quote v0.0.0-20180214005840-23179ee8a569' go.mod + +# but as commit should record as v1.5.1 +go get rsc.io/quote@23179ee8 +grep 'rsc.io/quote v1.5.1' go.mod + +# go mod edit -require does not interpret commits +go mod edit -require rsc.io/quote@23179ee +grep 'rsc.io/quote 23179ee' go.mod + +# but other commands fix them +go list -m -mod=mod all +grep 'rsc.io/quote v1.5.1' go.mod + +-- go.mod -- +module x diff --git a/go/src/cmd/go/testdata/script/mod_get_deprecate_install.txt b/go/src/cmd/go/testdata/script/mod_get_deprecate_install.txt new file mode 100644 index 0000000000000000000000000000000000000000..03258f52966fc745f3a1e01ac0b182e285c18b13 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_deprecate_install.txt @@ -0,0 +1,42 @@ +[short] skip + +env GO111MODULE=on + +# 'go get' outside a module prints an error. +! go get example.com/cmd/a +stderr '^go: go.mod file not found in current directory or any parent directory.$' +stderr '^\t''go get'' is no longer supported outside a module.$' + +cp go.mod.orig go.mod + +# 'go get' inside a module with a non-main package does not print a message. +# This will stop building in the future, but it's the command we want to use. +go get rsc.io/quote +! stderr deprecated +! stderr 'no longer installs' +cp go.mod.orig go.mod + +# 'go get' inside a module with an executable does not print a message. +# In 1.16 and 1.17, 'go get' did print a message in this case suggesting the +# use of -d. In 1.18, -d is a no-op, and we'd like to begin discouraging +# its use. +go get example.com/cmd/a +! stderr deprecated +! stderr 'no longer installs' +cp go.mod.orig go.mod + +# 'go get' should not print a warning for a main package inside the main module. +# The intent is most likely to update the dependencies of that package. +# 'go install' would be used otherwise. +go get m +! stderr . +cp go.mod.orig go.mod + +-- go.mod.orig -- +module m + +go 1.17 +-- main.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_get_deprecated.txt b/go/src/cmd/go/testdata/script/mod_get_deprecated.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec7bcfdb997e2e57218f11108430f09f46ab1862 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_deprecated.txt @@ -0,0 +1,66 @@ +# 'go get pkg' should not show a deprecation message for an unrelated module. +go get ./use/nothing +! stderr 'module.*is deprecated' + +# 'go get pkg' should show a deprecation message for the module providing pkg. +go get example.com/deprecated/a +stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$' +go get example.com/deprecated/a@v1.0.0 +stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$' + +# 'go get pkg' should show a deprecation message for a module providing +# packages directly imported by pkg. +go get ./use/a +stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$' + +# 'go get pkg' may show a deprecation message for an indirectly required module +# if it provides a package named on the command line. +go get ./use/b +! stderr 'module.*is deprecated' +go get local/use +! stderr 'module.*is deprecated' +go get example.com/deprecated/b +stderr '^go: module example.com/deprecated/b is deprecated: in example.com/deprecated/b@v1.9.0$' + +# 'go get pkg' does not show a deprecation message for a module providing a +# directly imported package if the module is no longer deprecated in its +# latest version, even if the module is deprecated in its current version. +go get ./use/undeprecated +! stderr 'module.*is deprecated' + +-- go.mod -- +module m + +go 1.17 + +require ( + example.com/deprecated/a v1.0.0 + example.com/undeprecated v1.0.0 + local v0.0.0 +) + +replace local v0.0.0 => ./local +-- use/nothing/nothing.go -- +package nothing +-- use/a/a.go -- +package a + +import _ "example.com/deprecated/a" +-- use/b/b.go -- +package b + +import _ "local/use" +-- use/undeprecated/undeprecated.go -- +package undeprecated + +import _ "example.com/undeprecated" +-- local/go.mod -- +module local + +go 1.17 + +require example.com/deprecated/b v1.0.0 +-- local/use/use.go -- +package use + +import _ "example.com/deprecated/b" diff --git a/go/src/cmd/go/testdata/script/mod_get_direct.txt b/go/src/cmd/go/testdata/script/mod_get_direct.txt new file mode 100644 index 0000000000000000000000000000000000000000..2c895764460c1035979b8100fca8f630d7669ba5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_direct.txt @@ -0,0 +1,19 @@ +# Regression test for golang.org/issue/34092: with an empty module cache, +# 'GOPROXY=direct go get golang.org/x/tools/gopls@master' did not correctly +# resolve the pseudo-version for its dependency on golang.org/x/tools. + +[short] skip +[!git] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +go list -m vcs-test.golang.org/git/tagtests.git@master +! stdout 'v0.0.0-' + +-- go.mod -- +module example.com + +go 1.14 +-- go.sum -- diff --git a/go/src/cmd/go/testdata/script/mod_get_downadd_indirect.txt b/go/src/cmd/go/testdata/script/mod_get_downadd_indirect.txt new file mode 100644 index 0000000000000000000000000000000000000000..0f5ba992da204ed28a6854cb29b0e6807f348e34 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_downadd_indirect.txt @@ -0,0 +1,81 @@ +# This test illustrates a case where downgrading one module may upgrade another. +# Compare to the downcross2 test case in cmd/go/internal/mvs/mvs_test.go. + +# The initial package import graph used in this test looks like: +# +# a ---- b ---- d +# +# The module dependency graph originally looks like: +# +# a ---- b.2 ---- d.2 +# +# b.1 ---- c.1 +# +# If we downgrade module d to version 1, we must downgrade b as well. +# If that downgrade selects b version 1, we will add a new dependency on module c. + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod.orig go.mod + +go get example.com/d@v0.1.0 +go list -m all +stdout '^example.com/b v0.1.0 ' +stdout '^example.com/c v0.1.0 ' +stdout '^example.com/d v0.1.0 ' + +-- go.mod -- +module example.com/a + +go 1.15 + +require example.com/b v0.2.0 + +replace ( + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0 => ./b2 + example.com/c v0.1.0 => ./c + example.com/d v0.1.0 => ./d + example.com/d v0.2.0 => ./d +) +-- a.go -- +package a + +import _ "example.com/b" + +-- b1/go.mod -- +module example.com/b + +go 1.15 + +require example.com/c v0.1.0 +-- b1/b.go -- +package b + +import _ "example.com/c" + +-- b2/go.mod -- +module example.com/b + +go 1.15 + +require example.com/d v0.2.0 +-- b2/b.go -- +package b + +import _ "example.com/d" + +-- c/go.mod -- +module example.com/c + +go 1.15 + +-- c/c.go -- +package c + +-- d/go.mod -- +module example.com/d + +go 1.15 +-- d/d.go -- +package d diff --git a/go/src/cmd/go/testdata/script/mod_get_downgrade.txt b/go/src/cmd/go/testdata/script/mod_get_downgrade.txt new file mode 100644 index 0000000000000000000000000000000000000000..2eed56d9b71b899dac731e794e6bc18a50815653 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_downgrade.txt @@ -0,0 +1,56 @@ +env GO111MODULE=on +[short] skip + +# downgrade sampler should downgrade quote +cp go.mod.orig go.mod +go get rsc.io/sampler@v1.0.0 +go list -m all +stdout 'rsc.io/quote v1.4.0' +stdout 'rsc.io/sampler v1.0.0' + +# downgrade sampler away should downgrade quote further +go get rsc.io/sampler@none +go list -m all +stdout 'rsc.io/quote v1.3.0' + +# downgrade should report inconsistencies and not change go.mod +go get rsc.io/quote@v1.5.1 +go list -m all +stdout 'rsc.io/quote v1.5.1' +stdout 'rsc.io/sampler v1.3.0' + +! go get rsc.io/sampler@v1.0.0 rsc.io/quote@v1.5.2 golang.org/x/text@none +! stderr add|remove|upgrad|downgrad +stderr '^go: rsc.io/quote@v1.5.2 requires rsc.io/sampler@v1.3.0, not rsc.io/sampler@v1.0.0$' + +go list -m all +stdout 'rsc.io/quote v1.5.1' +stdout 'rsc.io/sampler v1.3.0' + +# go get -u args should limit upgrades +cp go.mod.empty go.mod +go get -u rsc.io/quote@v1.4.0 rsc.io/sampler@v1.0.0 +go list -m all +stdout 'rsc.io/quote v1.4.0' +stdout 'rsc.io/sampler v1.0.0' +! stdout golang.org/x/text + +# downgrading away quote should also downgrade away latemigrate/v2, +# since there are no older versions. v2.0.0 is incompatible. +cp go.mod.orig go.mod +go list -m -versions example.com/latemigrate/v2 +stdout v2.0.0 # proxy may serve incompatible versions +go get rsc.io/quote@none +go list -m all +! stdout 'example.com/latemigrate/v2' + +-- go.mod.orig -- +module x +require ( + rsc.io/quote v1.5.1 + example.com/latemigrate/v2 v2.0.1 +) +-- go.mod.empty -- +module x +-- x.go -- +package x diff --git a/go/src/cmd/go/testdata/script/mod_get_downgrade_missing.txt b/go/src/cmd/go/testdata/script/mod_get_downgrade_missing.txt new file mode 100644 index 0000000000000000000000000000000000000000..4486a671baefe3cca880ee5d40fb2f0500aae91b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_downgrade_missing.txt @@ -0,0 +1,43 @@ +cp go.mod go.mod.orig + +# getting a specific version of a module along with a pattern +# not yet present in that module should report the version mismatch +# rather than a "matched no packages" warning. + +! go get example.net/pkgadded@v1.1.0 example.net/pkgadded/subpkg/... +stderr '^go: example.net/pkgadded@v1.1.0 conflicts with example.net/pkgadded/subpkg/...@upgrade \(v1.2.0\)$' +! stderr 'matched no packages' +cmp go.mod.orig go.mod + + +# A wildcard pattern should match the pattern with that path. + +go get example.net/pkgadded/...@v1.0.0 +go list -m all +stdout '^example.net/pkgadded v1.0.0' +cp go.mod.orig go.mod + + +# If we need to resolve a transitive dependency of a package, +# and another argument constrains away the version that provides that +# package, then 'go get' should fail with a useful error message. + +! go get example.net/pkgadded@v1.0.0 . +stderr '^go: example.com/m imports\n\texample.net/pkgadded/subpkg: cannot find module providing package example.net/pkgadded/subpkg$' +! stderr 'example.net/pkgadded v1\.2\.0' +cmp go.mod.orig go.mod + +go get example.net/pkgadded@v1.0.0 +! go list -deps -mod=readonly . +stderr '^m.go:3:8: cannot find module providing package example\.net/pkgadded/subpkg: ' + +-- go.mod -- +module example.com/m + +go 1.16 + +require example.net/pkgadded v1.2.0 +-- m.go -- +package m + +import _ "example.net/pkgadded/subpkg" diff --git a/go/src/cmd/go/testdata/script/mod_get_downup_artifact.txt b/go/src/cmd/go/testdata/script/mod_get_downup_artifact.txt new file mode 100644 index 0000000000000000000000000000000000000000..111a54f8f7370cacb24af0852354e88246185921 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_downup_artifact.txt @@ -0,0 +1,159 @@ +# This test illustrates a case where an upgrade–downgrade–upgrade cycle can +# result in upgrades of otherwise-irrelevant dependencies. +# +# This case has no corresponding test in the mvs package, because it is an +# artifact that results from the composition of *multiple* MVS operations. + +# The initial package import graph used in the test looks like: +# +# m ---- a +# | | +# +----- b +# | | +# +----- c +# | +# +----- d +# +# b version 2 adds its own import of package d. +# +# The module dependency graph initially looks like: +# +# m ---- a.1 +# | | +# +----- b.1 +# | | +# +----- c.1 +# | +# +----- d.1 +# +# b.2 ---- c.2 +# | +# +------ d.2 +# | +# +------ e.1 +# +# If we upgrade module b to version 2, we will upgrade c and d and add a new +# dependency on e. If b version 2 is disallowed because of any of those +# dependencies, the other dependencies should not be upgraded as a side-effect. + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod go.mod.orig + +go list -m all +stdout '^example.com/a v0.1.0 ' +stdout '^example.com/b v0.1.0 ' +stdout '^example.com/c v0.1.0 ' +stdout '^example.com/d v0.1.0 ' +! stdout '^example.com/e ' + +# b is imported by a, so the -u flag would normally upgrade it to v0.2.0. +# However, that would conflict with the explicit c@v0.1.0 constraint, +# so b must remain at v0.1.0. +# +# If we're not careful, we might temporarily add b@v0.2.0 and pull in its +# upgrades of module d and addition of module e, which are not relevant to +# b@v0.1.0 and should not be added to the main module's dependencies. + +go get -u example.com/a@latest example.com/c@v0.1.0 + +go list -m all +stdout '^example.com/a v0.1.0 ' +stdout '^example.com/b v0.1.0 ' +stdout '^example.com/c v0.1.0 ' +stdout '^example.com/d v0.1.0 ' +! stdout '^example.com/e ' + +-- go.mod -- +module example.com/m + +go 1.16 + +require ( + example.com/a v0.1.0 + example.com/b v0.1.0 + example.com/c v0.1.0 + example.com/d v0.1.0 +) + +replace ( + example.com/a v0.1.0 => ./a1 + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0 => ./b2 + example.com/c v0.1.0 => ./c + example.com/c v0.2.0 => ./c + example.com/d v0.1.0 => ./d + example.com/d v0.2.0 => ./d + example.com/e v0.1.0 => ./e +) +-- m.go -- +package m + +import ( + _ "example.com/a" + _ "example.com/b" + _ "example.com/c" + _ "example.com/d" +) + +-- a1/go.mod -- +module example.com/a + +go 1.16 + +require example.com/b v0.1.0 +-- a1/a.go -- +package a + +import _ "example.com/b" + +-- b1/go.mod -- +module example.com/b + +go 1.16 + +require example.com/c v0.1.0 +-- b1/b.go -- +package b + +import _ "example.com/c" + +-- b2/go.mod -- +module example.com/b + +go 1.16 + +require ( + example.com/c v0.2.0 + example.com/d v0.2.0 + example.com/e v0.1.0 +) +-- b2/b.go -- +package b + +import ( + "example.com/c" + "example.com/d" + "example.com/e" +) + +-- c/go.mod -- +module example.com/c + +go 1.16 +-- c/c.go -- +package c + +-- d/go.mod -- +module example.com/d + +go 1.16 +-- d/d.go -- +package d + +-- e/go.mod -- +module example.com/e + +go 1.16 +-- e/e.go -- +package e diff --git a/go/src/cmd/go/testdata/script/mod_get_downup_indirect.txt b/go/src/cmd/go/testdata/script/mod_get_downup_indirect.txt new file mode 100644 index 0000000000000000000000000000000000000000..432e626003d0a1beb188cda05a879319c7aedaba --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_downup_indirect.txt @@ -0,0 +1,149 @@ +# This test illustrates a case where downgrading one module may upgrade another. +# Compare to the downcross1 test case in cmd/go/internal/mvs/mvs_test.go. + +# The package import graph used in this test looks like: +# +# a ---- b +# \ \ +# \ \ +# ----- c ---- d +# +# The module dependency graph originally looks like: +# +# a ---- b.2 +# \ \ +# \ \ +# ----- c.1 ---- d.2 +# +# b.1 ---- c.2 +# +# If we downgrade module d to version 1, we must downgrade b as well. +# If that downgrade selects b version 1, we will upgrade module c to version 2. + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod.orig go.mod + +# Downgrading d to version 1 downgrades b, which upgrades c. +go get example.com/d@v0.1.0 +go list -m all +stdout '^example.com/b v0.1.0 ' +stdout '^example.com/c v0.2.0 ' +stdout '^example.com/d v0.1.0 ' +cmp go.mod go.mod.down1 + +# Restoring c to version 1 upgrades d to meet c's requirements. +go get example.com/c@v0.1.0 +go list -m all +! stdout '^example.com/b ' +stdout '^example.com/c v0.1.0 ' +stdout '^example.com/d v0.2.0 ' +cmp go.mod go.mod.down2 + +# If a user explicitly requests the incompatible versions together, +# 'go get' should explain why they are not compatible. +! go get example.com/c@v0.1.0 example.com/d@v0.1.0 +stderr '^go: example\.com/c@v0\.1\.0 requires example\.com/d@v0\.2\.0, not example\.com/d@v0\.1\.0' + +-- go.mod -- +module example.com/a + +go 1.15 + +require ( + example.com/b v0.2.0 + example.com/c v0.1.0 +) + +replace ( + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0 => ./b2 + example.com/c v0.1.0 => ./c1 + example.com/c v0.2.0 => ./c2 + example.com/d v0.1.0 => ./d + example.com/d v0.2.0 => ./d +) +-- go.mod.down1 -- +module example.com/a + +go 1.15 + +require ( + example.com/b v0.1.0 + example.com/c v0.2.0 + example.com/d v0.1.0 // indirect +) + +replace ( + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0 => ./b2 + example.com/c v0.1.0 => ./c1 + example.com/c v0.2.0 => ./c2 + example.com/d v0.1.0 => ./d + example.com/d v0.2.0 => ./d +) +-- go.mod.down2 -- +module example.com/a + +go 1.15 + +require example.com/c v0.1.0 + +replace ( + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0 => ./b2 + example.com/c v0.1.0 => ./c1 + example.com/c v0.2.0 => ./c2 + example.com/d v0.1.0 => ./d + example.com/d v0.2.0 => ./d +) +-- a.go -- +package a + +import ( + _ "example.com/b" + _ "example.com/c" +) + +-- b1/go.mod -- +module example.com/b + +go 1.15 + +require example.com/c v0.2.0 +-- b1/b.go -- +package b + +import _ "example.com/c" + +-- b2/go.mod -- +module example.com/b + +go 1.15 + +require example.com/c v0.1.0 +-- b2/b.go -- +package b + +import _ "example.com/c" + +-- c1/go.mod -- +module example.com/c + +go 1.15 + +require example.com/d v0.2.0 +-- c1/c.go -- +package c + +-- c2/go.mod -- +module example.com/c + +go 1.15 +-- c2/c.go -- +package c + +-- d/go.mod -- +module example.com/d + +go 1.15 diff --git a/go/src/cmd/go/testdata/script/mod_get_downup_indirect_pruned.txt b/go/src/cmd/go/testdata/script/mod_get_downup_indirect_pruned.txt new file mode 100644 index 0000000000000000000000000000000000000000..cac6b96790da4793c4d3680e578d770af77c5f09 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_downup_indirect_pruned.txt @@ -0,0 +1,154 @@ +# This test illustrates a case where downgrading one module may upgrade another. +# This is the same as mod_get_downup_indirect, but using modules +# with graph pruning enabled (go ≥ 1.17). +# Compare to the downcross1 test case in cmd/go/internal/mvs/mvs_test.go. + +# The package import graph used in this test looks like: +# +# a ---- b +# \ \ +# \ \ +# ----- c ---- d +# +# The module dependency graph originally looks like: +# +# a ---- b.2 +# \ \ +# \ \ +# ----- c.1 ---- d.2 +# +# b.1 ---- c.2 +# +# If we downgrade module d to version 1, we must downgrade b as well. +# If that downgrade selects b version 1, we will upgrade module c to version 2. + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod.orig go.mod + +# Downgrading d to version 1 downgrades b, which upgrades c. +go get -v example.com/d@v0.1.0 +go list -m all +stdout '^example.com/b v0.1.0 ' +stdout '^example.com/c v0.2.0 ' +stdout '^example.com/d v0.1.0 ' +cmp go.mod go.mod.down1 + +# Restoring c to version 1 upgrades d to meet c's requirements. +go get example.com/c@v0.1.0 +go list -m all +! stdout '^example.com/b ' +stdout '^example.com/c v0.1.0 ' +stdout '^example.com/d v0.2.0 ' +cmp go.mod go.mod.down2 + +# If a user explicitly requests the incompatible versions together, +# 'go get' should explain why they are not compatible. +! go get example.com/c@v0.1.0 example.com/d@v0.1.0 +stderr '^go: example\.com/c@v0\.1\.0 requires example\.com/d@v0\.2\.0, not example\.com/d@v0\.1\.0' + +-- go.mod -- +module example.com/a + +go 1.17 + +require ( + example.com/b v0.2.0 + example.com/c v0.1.0 +) + +replace ( + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0 => ./b2 + example.com/c v0.1.0 => ./c1 + example.com/c v0.2.0 => ./c2 + example.com/d v0.1.0 => ./d + example.com/d v0.2.0 => ./d +) +-- go.mod.down1 -- +module example.com/a + +go 1.17 + +require ( + example.com/b v0.1.0 + example.com/c v0.2.0 +) + +require example.com/d v0.1.0 // indirect + +replace ( + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0 => ./b2 + example.com/c v0.1.0 => ./c1 + example.com/c v0.2.0 => ./c2 + example.com/d v0.1.0 => ./d + example.com/d v0.2.0 => ./d +) +-- go.mod.down2 -- +module example.com/a + +go 1.17 + +require example.com/c v0.1.0 + +require example.com/d v0.2.0 // indirect + +replace ( + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0 => ./b2 + example.com/c v0.1.0 => ./c1 + example.com/c v0.2.0 => ./c2 + example.com/d v0.1.0 => ./d + example.com/d v0.2.0 => ./d +) +-- a.go -- +package a + +import ( + _ "example.com/b" + _ "example.com/c" +) + +-- b1/go.mod -- +module example.com/b + +go 1.17 + +require example.com/c v0.2.0 +-- b1/b.go -- +package b + +import _ "example.com/c" + +-- b2/go.mod -- +module example.com/b + +go 1.17 + +require example.com/c v0.1.0 +-- b2/b.go -- +package b + +import _ "example.com/c" + +-- c1/go.mod -- +module example.com/c + +go 1.17 + +require example.com/d v0.2.0 +-- c1/c.go -- +package c + +-- c2/go.mod -- +module example.com/c + +go 1.17 +-- c2/c.go -- +package c + +-- d/go.mod -- +module example.com/d + +go 1.17 diff --git a/go/src/cmd/go/testdata/script/mod_get_downup_pseudo_artifact.txt b/go/src/cmd/go/testdata/script/mod_get_downup_pseudo_artifact.txt new file mode 100644 index 0000000000000000000000000000000000000000..b678a177b521e32619b4afd6058e839813026327 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_downup_pseudo_artifact.txt @@ -0,0 +1,129 @@ +# This test illustrates a case where an upgrade–downgrade–upgrade cycle could +# add extraneous dependencies due to another module depending on an +# otherwise-unlisted version (such as a pseudo-version). +# +# This case corresponds to the "downhiddenartifact" test in the mvs package. + +# The initial package import graph used in the test looks like: +# +# a --- b +# \ \ +# \ \ +# c --- d +# +# The module dependency graph initially looks like: +# +# a --- b.3 +# \ \ +# \ \ +# c.2 --- d.2 +# +# c.1 --- b.2 (pseudo) +# +# b.1 --- e.1 + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod.orig go.mod + +# When we downgrade d.2 to d.1, no dependency on e should be added +# because nothing else in the module or import graph requires it. +go get example.net/d@v0.1.0 + +go list -m all +stdout '^example.net/b v0.2.1-0.20210219000000-000000000000 ' +stdout '^example.net/c v0.1.0 ' +stdout '^example.net/d v0.1.0 ' +! stdout '^example.net/e ' + +-- go.mod -- +module example.net/a + +go 1.16 + +require ( + example.net/b v0.3.0 + example.net/c v0.2.0 +) + +replace ( + example.net/b v0.1.0 => ./b1 + example.net/b v0.2.1-0.20210219000000-000000000000 => ./b2 + example.net/b v0.3.0 => ./b3 + example.net/c v0.1.0 => ./c1 + example.net/c v0.2.0 => ./c2 + example.net/d v0.1.0 => ./d + example.net/d v0.2.0 => ./d + example.net/e v0.1.0 => ./e +) +-- a.go -- +package a + +import ( + _ "example.net/b" + _ "example.net/c" +) + +-- b1/go.mod -- +module example.net/b + +go 1.16 + +require example.net/e v0.1.0 +-- b1/b.go -- +package b + +import _ "example.net/e" + +-- b2/go.mod -- +module example.net/b + +go 1.16 +-- b2/b.go -- +package b + +-- b3/go.mod -- +module example.net/b + +go 1.16 + +require example.net/d v0.2.0 +-- b3/b.go -- +package b + +import _ "example.net/d" +-- c1/go.mod -- +module example.net/c + +go 1.16 + +require example.net/b v0.2.1-0.20210219000000-000000000000 +-- c1/c.go -- +package c + +import _ "example.net/b" + +-- c2/go.mod -- +module example.net/c + +go 1.16 + +require example.net/d v0.2.0 +-- c2/c.go -- +package c + +import _ "example.net/d" + +-- d/go.mod -- +module example.net/d + +go 1.16 +-- d/d.go -- +package d + +-- e/go.mod -- +module example.net/e + +go 1.16 +-- e/e.go -- +package e diff --git a/go/src/cmd/go/testdata/script/mod_get_errors.txt b/go/src/cmd/go/testdata/script/mod_get_errors.txt new file mode 100644 index 0000000000000000000000000000000000000000..981d6f08a9a0e1887fd03725aaf5b44db4ce310e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_errors.txt @@ -0,0 +1,57 @@ +cp go.mod go.mod.orig + + +# 'go get' should fail, without updating go.mod, if the transitive dependencies +# of the requested package (by default, the package in the current directory) +# cannot be resolved. + +! go get +stderr '^go: example.com/m imports\n\texample.com/badimport imports\n\texample.net/oops: cannot find module providing package example.net/oops$' +cmp go.mod.orig go.mod + +cd importsyntax + + +# A syntax error in a dependency prevents the compiler from needing that +# dependency's imports, so 'go get' should not report an error when those +# imports cannot be resolved: it has all of the dependencies that the compiler +# needs, and the user did not request to run the compiler. + +go get +cmp ../go.mod.syntax-d ../go.mod + + +-- go.mod -- +module example.com/m + +go 1.16 + +replace example.com/badimport v0.1.0 => ./badimport +-- go.mod.syntax-d -- +module example.com/m + +go 1.16 + +replace example.com/badimport v0.1.0 => ./badimport + +require example.com/badimport v0.1.0 +-- m.go -- +package m + +import _ "example.com/badimport" +-- importsyntax/importsyntax.go -- +package importsyntax + +import _ "example.com/badimport/syntaxerror" +-- badimport/go.mod -- +module example.com/badimport + +go 1.16 +-- badimport/badimport.go -- +package badimport + +import "example.net/oops" +-- badimport/syntaxerror/syntaxerror.go -- +pack-age syntaxerror // sic + +import "example.net/oops" diff --git a/go/src/cmd/go/testdata/script/mod_get_exec_toolchain.txt b/go/src/cmd/go/testdata/script/mod_get_exec_toolchain.txt new file mode 100644 index 0000000000000000000000000000000000000000..79df80e841af694cddcc4a4a79165216a3a86b90 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_exec_toolchain.txt @@ -0,0 +1,145 @@ +env TESTGO_VERSION=go1.21 +env TESTGO_VERSION_SWITCH=switch + +# GOTOOLCHAIN=auto should run the newer toolchain +env GOTOOLCHAIN=auto +cp go.mod.new go.mod +go get rsc.io/needgo121 rsc.io/needgo122 rsc.io/needgo123 rsc.io/needall +stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$' +! stderr '\(running' +stderr '^go: added rsc.io/needall v0.0.1' +grep 'go 1.23' go.mod +! grep toolchain go.mod + +# GOTOOLCHAIN=min+auto should run the newer toolchain +env GOTOOLCHAIN=go1.21+auto +cp go.mod.new go.mod +go get rsc.io/needgo121 rsc.io/needgo122 rsc.io/needgo123 rsc.io/needall +stderr '^go: rsc.io/needall@v0.0.1 requires go >= 1.23; switching to go1.23.9$' +! stderr '\(running' +stderr '^go: added rsc.io/needall v0.0.1' +grep 'go 1.23' go.mod +! grep toolchain go.mod + +# GOTOOLCHAIN=go1.21 should NOT run the newer toolchain +env GOTOOLCHAIN=go1.21 +cp go.mod.new go.mod +! go get rsc.io/needgo121 rsc.io/needgo122 rsc.io/needgo123 rsc.io/needall +! stderr switching +stderr 'rsc.io/needgo122@v0.0.1 requires go >= 1.22' +stderr 'rsc.io/needgo123@v0.0.1 requires go >= 1.23' +stderr 'rsc.io/needall@v0.0.1 requires go >= 1.23' +stderr 'requires go >= 1.23' +! stderr 'requires go >= 1.21' # that's us! +cmp go.mod go.mod.new + +# GOTOOLCHAIN=local should NOT run the newer toolchain +env GOTOOLCHAIN=local +cp go.mod.new go.mod +! go get rsc.io/needgo121 rsc.io/needgo122 rsc.io/needgo123 rsc.io/needall +! stderr switching +stderr 'rsc.io/needgo122@v0.0.1 requires go >= 1.22' +stderr 'rsc.io/needgo123@v0.0.1 requires go >= 1.23' +stderr 'rsc.io/needall@v0.0.1 requires go >= 1.23' +stderr 'requires go >= 1.23' +! stderr 'requires go >= 1.21' # that's us! +cmp go.mod go.mod.new + +# go get go@1.22 should resolve to the latest 1.22 +env GOTOOLCHAIN=local +cp go.mod.new go.mod +! go get go@1.22 +stderr '^go: updating go.mod requires go >= 1.22.9 \(running go 1.21; GOTOOLCHAIN=local\)' + +env GOTOOLCHAIN=auto +cp go.mod.new go.mod +go get go@1.22 +stderr '^go: updating go.mod requires go >= 1.22.9; switching to go1.22.9$' + +# go get go@1.22rc1 should use 1.22rc1 exactly, not a later release. +env GOTOOLCHAIN=local +cp go.mod.new go.mod +! go get go@1.22rc1 +stderr '^go: updating go.mod requires go >= 1.22rc1 \(running go 1.21; GOTOOLCHAIN=local\)' + +env GOTOOLCHAIN=auto +cp go.mod.new go.mod +go get go@1.22rc1 +stderr '^go: updating go.mod requires go >= 1.22rc1; switching to go1.22.9$' +stderr '^go: upgraded go 1.1 => 1.22rc1$' +! stderr '^go: added toolchain$' + +# go get go@1.22.1 should use 1.22.1 exactly, not a later release. +env GOTOOLCHAIN=local +cp go.mod.new go.mod +! go get go@1.22.1 +stderr '^go: updating go.mod requires go >= 1.22.1 \(running go 1.21; GOTOOLCHAIN=local\)' + +env GOTOOLCHAIN=auto +cp go.mod.new go.mod +go get go@1.22.1 +stderr '^go: updating go.mod requires go >= 1.22.1; switching to go1.22.9$' +stderr '^go: upgraded go 1.1 => 1.22.1$' +! stderr '^go: added toolchain$' + +# go get needgo122 (says 'go 1.22') should use 1.22.0, the earliest release we have available +# (ignoring prereleases). +env GOTOOLCHAIN=local +cp go.mod.new go.mod +! go get rsc.io/needgo122 +stderr '^go: rsc.io/needgo122@v0.0.1 requires go >= 1.22 \(running go 1.21; GOTOOLCHAIN=local\)' + +env GOTOOLCHAIN=auto +cp go.mod.new go.mod +go get rsc.io/needgo122 +stderr '^go: upgraded go 1.1 => 1.22$' +stderr '^go: rsc.io/needgo122@v0.0.1 requires go >= 1.22; switching to go1.22.9$' +! stderr '^go: added toolchain$' + +# go get needgo1223 (says 'go 1.22.3') should use go 1.22.3 +env GOTOOLCHAIN=local +cp go.mod.new go.mod +! go get rsc.io/needgo1223 +stderr '^go: rsc.io/needgo1223@v0.0.1 requires go >= 1.22.3 \(running go 1.21; GOTOOLCHAIN=local\)' + +env GOTOOLCHAIN=auto +cp go.mod.new go.mod +go get rsc.io/needgo1223 +stderr '^go: upgraded go 1.1 => 1.22.3$' +stderr '^go: rsc.io/needgo1223@v0.0.1 requires go >= 1.22.3; switching to go1.22.9$' +! stderr '^go: added toolchain$' + +# go get needgo124 (says 'go 1.24') should use go 1.24rc1, the only version available +env GOTOOLCHAIN=local +cp go.mod.new go.mod +! go get rsc.io/needgo124 +stderr '^go: rsc.io/needgo124@v0.0.1 requires go >= 1.24 \(running go 1.21; GOTOOLCHAIN=local\)' + +env GOTOOLCHAIN=auto +cp go.mod.new go.mod +go get rsc.io/needgo124 +stderr '^go: rsc.io/needgo124@v0.0.1 requires go >= 1.24; switching to go1.24rc1$' +stderr '^go: upgraded go 1.1 => 1.24$' +! stderr '^go: added toolchain$' + +# The -C flag should not happen more than once due to switching. +mkdir dir dir/dir +cp go.mod.new go.mod +cp go.mod.new dir/go.mod +cp go.mod.new dir/dir/go.mod +cp p.go dir/p.go +cp p.go dir/dir/p.go +go get -C dir rsc.io/needgo124 +stderr '^go: rsc.io/needgo124@v0.0.1 requires go >= 1.24; switching to go1.24rc1$' +stderr '^go: upgraded go 1.1 => 1.24$' +! stderr '^go: added toolchain1$' +cmp go.mod.new go.mod +cmp go.mod.new dir/dir/go.mod +grep 'go 1.24$' dir/go.mod + +-- go.mod.new -- +module m +go 1.1 + +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/script/mod_get_extra.txt b/go/src/cmd/go/testdata/script/mod_get_extra.txt new file mode 100644 index 0000000000000000000000000000000000000000..083e03678e48f1ebc0ffa5b1baece7841e8d258a --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_extra.txt @@ -0,0 +1,69 @@ +cp go.mod go.mod.orig + +# The -u flag should not (even temporarily) upgrade modules whose versions are +# determined by explicit queries to any version other than the explicit one. +# Otherwise, 'go get -u' could introduce spurious dependencies. + +go get -u example.net/a@v0.1.0 example.net/b@v0.1.0 +go list -m all +stdout '^example.net/a v0.1.0 ' +stdout '^example.net/b v0.1.0 ' +! stdout '^example.net/c ' + + +# TODO(bcmills): This property does not yet hold for modules added for +# missing packages when the newly-added module matches a wildcard. + +cp go.mod.orig go.mod + +go get -u example.net/a@v0.1.0 example.net/b/...@v0.1.0 +go list -m all +stdout '^example.net/a v0.1.0 ' +stdout '^example.net/b v0.1.0 ' +stdout '^example.net/c ' # BUG, but a minor and rare one + + +-- go.mod -- +module example + +go 1.15 + +replace ( + example.net/a v0.1.0 => ./a1 + example.net/b v0.1.0 => ./b1 + example.net/b v0.2.0 => ./b2 + example.net/c v0.1.0 => ./c1 + example.net/c v0.2.0 => ./c1 +) + +-- a1/go.mod -- +module example.net/a + +go 1.15 + +// example.net/a needs a dependency on example.net/b, but lacks a requirement +// on it (perhaps due to a missed file in a VCS commit). +-- a1/a.go -- +package a +import _ "example.net/b" + +-- b1/go.mod -- +module example.net/b + +go 1.15 +-- b1/b.go -- +package b + +-- b2/go.mod -- +module example.net/b + +go 1.15 + +require example.net/c v0.1.0 +-- b2/b.go -- +package b + +-- c1/go.mod -- +module example.net/c + +go 1.15 diff --git a/go/src/cmd/go/testdata/script/mod_get_fallback.txt b/go/src/cmd/go/testdata/script/mod_get_fallback.txt new file mode 100644 index 0000000000000000000000000000000000000000..a5119b6efe2d2f1c86f10578d77c015ded14207d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_fallback.txt @@ -0,0 +1,16 @@ +env GO111MODULE=on + +[!net:golang.org] skip +[!net:proxy.golang.org] skip + +env GOPROXY=https://proxy.golang.org,direct +env GOSUMDB=off + +go get -x -v golang.org/x/tools/cmd/goimports +stderr '# get https://proxy.golang.org/golang.org/x/tools/@v/list' +! stderr '# get https://golang.org' + +-- go.mod -- +module m + +go 1.18 diff --git a/go/src/cmd/go/testdata/script/mod_get_fossil.txt b/go/src/cmd/go/testdata/script/mod_get_fossil.txt new file mode 100644 index 0000000000000000000000000000000000000000..830e0de7aa2ad5b772dfefd6dad14eb66eea6298 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_fossil.txt @@ -0,0 +1,28 @@ +[short] skip +[!exec:fossil] skip + +# Regression test for 'go get' to ensure repositories +# provided by fossil v2.12 and up are able to be fetched +# and parsed correctly. +# Verifies golang.org/issue/42323. + + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +# 'go get' for the fossil repo will fail if fossil +# is unable to determine your fossil user. Easiest +# way to set it for use by 'go get' is specifying +# a any non-empty $USER; the value doesn't otherwise matter. +env USER=fossiluser +env FOSSIL_HOME=$WORK/home + +# Attempt to get the latest version of a fossil repo. +go get vcs-test.golang.org/fossil/hello.fossil +! stderr 'unexpected response from fossil info' +grep 'vcs-test.golang.org/fossil/hello.fossil' go.mod + +-- go.mod -- +module x +-- $WORK/home/.fossil -- diff --git a/go/src/cmd/go/testdata/script/mod_get_future.txt b/go/src/cmd/go/testdata/script/mod_get_future.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f1c777d967953db1f562669ec10127f862c2773 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_future.txt @@ -0,0 +1,13 @@ +env TESTGO_VERSION=go1.21 +env GOTOOLCHAIN=local +! go mod download rsc.io/future@v1.0.0 +stderr '^go: rsc.io/future@v1.0.0 requires go >= 1.999 \(running go 1.21; GOTOOLCHAIN=local\)$' + +-- go.mod -- +module m +go 1.21 + +-- x.go -- +package p + +import "rsc.io/future/foo" diff --git a/go/src/cmd/go/testdata/script/mod_get_go_file.txt b/go/src/cmd/go/testdata/script/mod_get_go_file.txt new file mode 100644 index 0000000000000000000000000000000000000000..c81e491b947ecbe93955979ad978dfba8be7497d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_go_file.txt @@ -0,0 +1,73 @@ +# Tests Issue #38478 +# Tests that go get in GOMOD mode returns a specific error if the argument +# ends with '.go', has no version, and either has no slash or refers to an +# existing file. + +env GO111MODULE=on + +# argument doesn't have .go suffix and has no version +! go get test +! stderr 'arguments must be package or module paths' +! stderr 'exists as a file, but ''go get'' requires package arguments' + +# argument has .go suffix and has version +! go get test.go@v1.0.0 +! stderr 'arguments must be package or module paths' +! stderr 'exists as a file, but ''go get'' requires package arguments' + +# argument has .go suffix, is a file and exists +! go get test.go +stderr 'go: test.go: arguments must be package or module paths' + +# argument has .go suffix, doesn't exist and has no slashes +! go get test_missing.go +stderr 'arguments must be package or module paths' + +# argument has .go suffix, is a file and exists in sub-directory +! go get test/test.go +stderr 'go: test/test.go exists as a file, but ''go get'' requires package arguments' + +# argument has .go suffix, doesn't exist and has slashes +! go get test/test_missing.go +! stderr 'arguments must be package or module paths' +! stderr 'exists as a file, but ''go get'' requires package arguments' + +# argument has .go suffix, is a symlink and exists +[symlink] symlink test_sym.go -> test.go +[symlink] ! go get test_sym.go +[symlink] stderr 'go: test_sym.go: arguments must be package or module paths' +[symlink] rm test_sym.go + +# argument has .go suffix, is a symlink and exists in sub-directory +[symlink] symlink test/test_sym.go -> test.go +[symlink] ! go get test/test_sym.go +[symlink] stderr 'go: test/test_sym.go exists as a file, but ''go get'' requires package arguments' +[symlink] rm test_sym.go + +# argument has .go suffix, is a directory and exists +mkdir test_dir.go +! go get test_dir.go +stderr 'go: test_dir.go: arguments must be package or module paths' +rm test_dir.go + +# argument has .go suffix, is a directory and exists in sub-directory +mkdir test/test_dir.go +! go get test/test_dir.go +! stderr 'arguments must be package or module paths' +! stderr 'exists as a file, but ''go get'' requires package arguments' +rm test/test_dir.go + + +-- go.mod -- +module m + +go 1.18 + +-- test.go -- +package main +func main() {println("test")} + + +-- test/test.go -- +package main +func main() {println("test")} diff --git a/go/src/cmd/go/testdata/script/mod_get_hash.txt b/go/src/cmd/go/testdata/script/mod_get_hash.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec5549defe08c7855720413a4bb9e79871df48ae --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_hash.txt @@ -0,0 +1,19 @@ +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off +[!net:golang.org] skip +[!git] skip + +# fetch commit hash reachable from refs/heads/* and refs/tags/* is OK +go list -m golang.org/x/time@8be79e1e0910c292df4e79c241bb7e8f7e725959 # on master branch + +# fetch other commit hash, even with a non-standard ref, is not OK +! go list -m golang.org/x/time@334d83c35137ac2b376c1dc3e4c7733791855a3a # refs/changes/24/41624/3 +stderr 'unknown revision' +! go list -m golang.org/x/time@v0.0.0-20170424233410-334d83c35137 +stderr 'unknown revision' +! go list -m golang.org/x/time@334d83c35137 +stderr 'unknown revision' + +-- go.mod -- +module m diff --git a/go/src/cmd/go/testdata/script/mod_get_incompatible.txt b/go/src/cmd/go/testdata/script/mod_get_incompatible.txt new file mode 100644 index 0000000000000000000000000000000000000000..5a7d70637180af3eb4c7c5483c102c47819523c8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_incompatible.txt @@ -0,0 +1,26 @@ +env GO111MODULE=on + +go get x +go list -m all +stdout 'rsc.io/breaker v2.0.0\+incompatible' + +cp go.mod2 go.mod +go get rsc.io/breaker@7307b30 +go list -m all +stdout 'rsc.io/breaker v2.0.0\+incompatible' + +go get rsc.io/breaker@v2.0.0 +go list -m all +stdout 'rsc.io/breaker v2.0.0\+incompatible' + +-- go.mod -- +module x + +-- go.mod2 -- +module x +require rsc.io/breaker v1.0.0 + +-- x.go -- +package x +import "rsc.io/breaker" +var _ = breaker.XX diff --git a/go/src/cmd/go/testdata/script/mod_get_indirect.txt b/go/src/cmd/go/testdata/script/mod_get_indirect.txt new file mode 100644 index 0000000000000000000000000000000000000000..fa7edf22d7b997d0abd8648023d86488229e9b51 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_indirect.txt @@ -0,0 +1,59 @@ +env GO111MODULE=on +[short] skip + +# get -u should not upgrade anything, since the package +# in the current directory doesn't import anything. +go get -u +go list -m all +stdout 'quote v1.5.1$' +grep 'rsc.io/quote v1.5.1$' go.mod + +# get -u should find quote v1.5.2 once there is a use. +cp $WORK/tmp/usequote.go x.go +go get -u +go list -m all +stdout 'quote v1.5.2$' +grep 'rsc.io/quote v1.5.2$' go.mod + +# it should also update x/text later than requested by v1.5.2 +go list -m -f '{{.Path}} {{.Version}}{{if .Indirect}} // indirect{{end}}' all +stdout '^golang.org/x/text [v0-9a-f\.-]+ // indirect' +grep 'golang.org/x/text [v0-9a-f\.-]+ // indirect' go.mod + +# importing an empty module root as a package does not remove indirect tag. +cp $WORK/tmp/usetext.go x.go +go list -e +grep 'golang.org/x/text v0.3.0 // indirect$' go.mod + +# indirect tag should be removed upon seeing direct import. +cp $WORK/tmp/uselang.go x.go +go get +grep 'rsc.io/quote v1.5.2$' go.mod +grep 'golang.org/x/text [v0-9a-f\.-]+$' go.mod + +# indirect tag should be added by go mod tidy +cp $WORK/tmp/usequote.go x.go +go mod tidy +grep 'rsc.io/quote v1.5.2$' go.mod +grep 'golang.org/x/text [v0-9a-f\.-]+ // indirect' go.mod + +# requirement should be dropped entirely if not needed +cp $WORK/tmp/uselang.go x.go +go mod tidy +! grep rsc.io/quote go.mod +grep 'golang.org/x/text [v0-9a-f\.-]+$' go.mod + +-- go.mod -- +module x +require rsc.io/quote v1.5.1 +-- x.go -- +package x +-- $WORK/tmp/usetext.go -- +package x +import _ "golang.org/x/text" +-- $WORK/tmp/uselang.go -- +package x +import _ "golang.org/x/text/language" +-- $WORK/tmp/usequote.go -- +package x +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_get_insecure_redirect.txt b/go/src/cmd/go/testdata/script/mod_get_insecure_redirect.txt new file mode 100644 index 0000000000000000000000000000000000000000..a503c914e39a38a6852b23e4bcbcad3350f814a7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_insecure_redirect.txt @@ -0,0 +1,19 @@ +# golang.org/issue/29591: 'go get' was following plain-HTTP redirects even without -insecure (now replaced by GOINSECURE). +# golang.org/issue/61877: 'go get' would panic in case of an insecure redirect in module mode + +[!git] skip + +env GOPRIVATE=vcs-test.golang.org + +! go get -d vcs-test.golang.org/insecure/go/insecure +stderr 'redirected .* to insecure URL' + +[short] stop 'builds a git repo' + +env GOINSECURE=vcs-test.golang.org/insecure/go/insecure +go get -d vcs-test.golang.org/insecure/go/insecure + +-- go.mod -- +module example +go 1.21 + diff --git a/go/src/cmd/go/testdata/script/mod_get_issue37438.txt b/go/src/cmd/go/testdata/script/mod_get_issue37438.txt new file mode 100644 index 0000000000000000000000000000000000000000..9392e73a174bd69e8efdfe49753f28f2f7d0d6fd --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_issue37438.txt @@ -0,0 +1,37 @@ +# Regression test for https://golang.org/issue/37438. +# +# If a path exists at the requested version, but does not exist at the +# version of the module that is already required and does not exist at +# the version that would be selected by 'go mod tidy', then +# 'go get foo@requested' should resolve the requested version, +# not error out on the (unrelated) latest one. + +go get example.net/a/p@v0.2.0 + +-- go.mod -- +module example + +go 1.15 + +require example.net/a v0.1.0 + +replace ( + example.net/a v0.1.0 => ./a1 + example.net/a v0.2.0 => ./a2 + example.net/a v0.3.0 => ./a1 +) + +-- a1/go.mod -- +module example.net/a + +go 1.15 +-- a1/README -- +package example.net/a/p does not exist at this version. + +-- a2/go.mod -- +module example.net/a + +go 1.15 +-- a2/p/p.go -- +// Package p exists only at v0.2.0. +package p diff --git a/go/src/cmd/go/testdata/script/mod_get_issue47650.txt b/go/src/cmd/go/testdata/script/mod_get_issue47650.txt new file mode 100644 index 0000000000000000000000000000000000000000..8561b21df048a5db881bb6668f2a04626f899dd5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_issue47650.txt @@ -0,0 +1,29 @@ +# Regression test for https://go.dev/issue/47650: +# 'go get' with a pseudo-version of a non-root package within a module +# erroneously rejected the pseudo-version as invalid, because it did not fetch +# enough commit history to validate the pseudo-version base. + +[short] skip 'creates and uses a git repository' +[!git] skip + +env GOPRIVATE=vcs-test.golang.org + +# If we request a package in a subdirectory of a module by commit hash, we +# successfully resolve it to a pseudo-version derived from a tag on the parent +# commit. +cp go.mod go.mod.orig +go get -x vcs-test.golang.org/git/issue47650.git/cmd/issue47650@21535ef346c3 +stderr '^go: added vcs-test.golang.org/git/issue47650.git v0.1.1-0.20210811175200-21535ef346c3$' + +# Explicitly requesting that same version should succeed, fetching additional +# history for the requested commit as needed in order to validate the +# pseudo-version base. +go clean -modcache +cp go.mod.orig go.mod +go get -x vcs-test.golang.org/git/issue47650.git/cmd/issue47650@v0.1.1-0.20210811175200-21535ef346c3 +stderr '^go: added vcs-test.golang.org/git/issue47650.git v0.1.1-0.20210811175200-21535ef346c3$' + +-- go.mod -- +module example + +go 1.20 diff --git a/go/src/cmd/go/testdata/script/mod_get_issue47979.txt b/go/src/cmd/go/testdata/script/mod_get_issue47979.txt new file mode 100644 index 0000000000000000000000000000000000000000..848ee3aa09a9ad3d696b0ed30c37ed3332666145 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_issue47979.txt @@ -0,0 +1,117 @@ +# Regression test for https://golang.org/issue/47979: +# +# An argument to 'go get' that results in an upgrade to a different existing +# root should be allowed, and should not panic the 'go' command. + +cp go.mod go.mod.orig + + +# Transitive upgrades from upgraded roots should not prevent +# 'go get -u' from performing upgrades. + +cp go.mod.orig go.mod +go get -u . +cmp go.mod go.mod.want + + +# 'go get' of a specific version should allow upgrades of +# every dependency (transitively) required by that version, +# including dependencies that are pulled into the module +# graph by upgrading other root requirements +# (in this case, example.net/indirect). + +cp go.mod.orig go.mod +go get example.net/a@v0.2.0 +cmp go.mod go.mod.want + + +-- go.mod -- +module golang.org/issue47979 + +go 1.17 + +replace ( + example.net/a v0.1.0 => ./a1 + example.net/a v0.2.0 => ./a2 + example.net/indirect v0.1.0 => ./indirect1 + example.net/indirect v0.2.0 => ./indirect2 + example.net/other v0.1.0 => ./other + example.net/other v0.2.0 => ./other +) + +require ( + example.net/a v0.1.0 + example.net/other v0.1.0 +) + +require example.net/indirect v0.1.0 // indirect +-- go.mod.want -- +module golang.org/issue47979 + +go 1.17 + +replace ( + example.net/a v0.1.0 => ./a1 + example.net/a v0.2.0 => ./a2 + example.net/indirect v0.1.0 => ./indirect1 + example.net/indirect v0.2.0 => ./indirect2 + example.net/other v0.1.0 => ./other + example.net/other v0.2.0 => ./other +) + +require ( + example.net/a v0.2.0 + example.net/other v0.2.0 +) + +require example.net/indirect v0.2.0 // indirect +-- issue.go -- +package issue + +import _ "example.net/a" +-- useother/useother.go -- +package useother + +import _ "example.net/other" +-- a1/go.mod -- +module example.net/a + +go 1.17 + +require example.net/indirect v0.1.0 +-- a1/a.go -- +package a +-- a2/go.mod -- +module example.net/a + +go 1.17 + +require example.net/indirect v0.2.0 +-- a2/a.go -- +package a + +import "example.net/indirect" +-- indirect1/go.mod -- +module example.net/indirect + +go 1.17 + +require example.net/other v0.1.0 +-- indirect1/indirect.go -- +package indirect +-- indirect2/go.mod -- +module example.net/indirect + +go 1.17 + +require example.net/other v0.2.0 +-- indirect2/indirect.go -- +package indirect + +import "example.net/other" +-- other/go.mod -- +module example.net/other + +go 1.17 +-- other/other.go -- +package other diff --git a/go/src/cmd/go/testdata/script/mod_get_issue48511.txt b/go/src/cmd/go/testdata/script/mod_get_issue48511.txt new file mode 100644 index 0000000000000000000000000000000000000000..0ba486d35bd6cecc2d8a6f4236c42613e445f7be --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_issue48511.txt @@ -0,0 +1,68 @@ +# Regression test for https://golang.org/issue/48511: +# requirement minimization was accidentally replacing previous +# versions of the main module, causing dependencies to be +# spuriously dropping during requirement minimization and +# leading to an infinite loop. + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod go.mod.orig + +go get -u=patch ./... +cmp go.mod go.mod.want + +-- go.mod -- +module example.net/m + +go 1.16 + +replace ( + example.net/a v0.1.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.1.1 => ./b + example.net/m v0.1.0 => ./m1 +) + +require example.net/a v0.1.0 +-- go.mod.want -- +module example.net/m + +go 1.16 + +replace ( + example.net/a v0.1.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.1.1 => ./b + example.net/m v0.1.0 => ./m1 +) + +require ( + example.net/a v0.1.0 + example.net/b v0.1.1 // indirect +) +-- m.go -- +package m + +import "example.net/a" +-- m1/go.mod -- +module example.net/m + +go 1.16 + +require example.net/b v0.1.0 +-- a/go.mod -- +module example.net/a + +go 1.16 + +require example.net/m v0.1.0 +-- a/a.go -- +package a + +import "example.net/b" +-- b/go.mod -- +module example.net/b + +go 1.16 +-- b/b.go -- +package b diff --git a/go/src/cmd/go/testdata/script/mod_get_issue56494.txt b/go/src/cmd/go/testdata/script/mod_get_issue56494.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e4d4af834620df13b5d5493c6eebc97f2dc0d79 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_issue56494.txt @@ -0,0 +1,134 @@ +# Regression test for https://go.dev/issue/56494: +# 'go get' in module mode was failing to prune out dependencies +# through modules whose versions are too low to be selected. + +# Initially, modules "a", "b", and "c" are unrelated. +# +# The package import graph at v1 of everything looks like: +# +# m --- a +# | +# + --- b +# | +# + --- c +# +# At v2, package "a" adds imports of "b" and "c" +# (and a requirement on "c" v2): +# +# a --- b +# | +# + --- c +# +# And "b" adds an import of "a/sub" (in module "a"): +# +# b --- a/sub +# +# At v3, "a" no longer imports (nor requires) "c": +# +# a --- b + +# So upgrading to a3 adds a dependency on b2, +# b2 adds a dependency on a2 (for "a/sub"), +# and a2 (but not a3) would add a dependency on c2. +# Since a2 is lower than a3 it cannot possibly be selected when +# upgrading to a3: normally a2 is pruned out of a3's module graph, +# so 'go get' should prune it out too, and c should remain at c1 +# without error. + +go get a@v0.3.0 + +go list -m c +stdout '^c v0.1.0 ' + +-- go.mod -- +module m + +go 1.19 + +require ( + a v0.1.0 + b v0.1.0 + c v0.1.0 +) + +replace ( + a v0.1.0 => ./a1 + a v0.2.0 => ./a2 + a v0.3.0 => ./a3 + b v0.1.0 => ./b1 + b v0.2.0 => ./b2 + c v0.1.0 => ./c1 + c v0.2.0 => ./c2 +) +-- m.go -- +package m + +import ( + _ "a" + _ "b" + _ "c" +) +-- a1/go.mod -- +module a + +go 1.19 +-- a1/a.go -- +package a +-- a2/go.mod -- +module a + +go 1.19 + +require ( + b v0.1.0 + c v0.2.0 +) +-- a2/a.go -- +package a + +import ( + _ "b" + _ "c" +) +-- a2/sub/sub.go -- +package sub +-- a3/go.mod -- +module a + +go 1.19 + +require b v0.2.0 +-- a3/a.go -- +package a + +import _ "b" +-- a3/sub/sub.go -- +package sub +-- b1/go.mod -- +module b + +go 1.19 +-- b1/b.go -- +package b +-- b2/go.mod -- +module b + +go 1.19 + +require a v0.2.0 +-- b2/b.go -- +package b + +import "a/sub" +-- c1/go.mod -- +module c + +go 1.19 +-- c1/c.go -- +package c +-- c2/go.mod -- +module c + +go 1.19 +-- c2/c.go -- +package c diff --git a/go/src/cmd/go/testdata/script/mod_get_issue60490.txt b/go/src/cmd/go/testdata/script/mod_get_issue60490.txt new file mode 100644 index 0000000000000000000000000000000000000000..e0ac26a8751e58be17eecd7d7e47139bdb6ebe59 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_issue60490.txt @@ -0,0 +1,48 @@ +# Regression test for https://go.dev/issue/60490: 'go get' should not cause an +# infinite loop for cycles introduced in the pruned module graph. + +go get example.net/c@v0.1.0 + +-- go.mod -- +module example + +go 1.19 + +require ( + example.net/a v0.1.0 + example.net/b v0.1.0 +) + +replace ( + example.net/a v0.1.0 => ./a1 + example.net/a v0.2.0 => ./a2 + example.net/b v0.1.0 => ./b1 + example.net/b v0.2.0 => ./b2 + example.net/c v0.1.0 => ./c1 +) +-- a1/go.mod -- +module example.net/a + +go 1.19 +-- a2/go.mod -- +module example.net/a + +go 1.19 + +require example.net/b v0.2.0 +-- b1/go.mod -- +module example.net/b + +go 1.19 +-- b2/go.mod -- +module example.net/b + +go 1.19 + +require example.net/a v0.2.0 +-- c1/go.mod -- +module example.net/c + +go 1.19 + +require example.net/a v0.2.0 diff --git a/go/src/cmd/go/testdata/script/mod_get_issue65363.txt b/go/src/cmd/go/testdata/script/mod_get_issue65363.txt new file mode 100644 index 0000000000000000000000000000000000000000..d5835611b1e3a01530cc3827a527e024e8a3f776 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_issue65363.txt @@ -0,0 +1,77 @@ +! go get -v example.net/a@v0.1.0 +! stderr panic +stderr 'example.net/d@v0.1.0 requires\n\texample.net/invalid' + +-- go.mod -- +module example + +replace ( + example.net/a v0.1.0 => ./a + example.net/b v0.1.0 => ./b1 + example.net/b v0.2.0 => ./b2 + example.net/c v0.1.0 => ./c1 + example.net/c v0.2.0 => ./c2 + example.net/d v0.1.0 => ./d +) + +require ( + example.net/b v0.1.0 +) +-- a/go.mod -- +module example.net/a + +go 1.18 + +require example.net/b v0.2.0 +-- a/a.go -- +package a + +import _ "example.net/b" +-- b1/go.mod -- +module example.net/b + +go 1.16 +-- b1/b.go -- +package b +-- b2/go.mod -- +module example.net/b + +go 1.16 + +require example.net/c v0.2.0 +-- b2/b.go -- +package b +-- b2/b_test.go -- +package b_test + +import _ "example.net/c" +-- c1/go.mod -- +module example.net/c + +go 1.18 +-- c1/c.go -- +package c +-- c2/go.mod -- +module example.net/c + +go 1.18 + +require example.net/d v0.1.0 +-- c2/c.go -- +package c +-- c2/c_test.go -- +package c_test + +import _ "example.net/d" +-- d/go.mod -- +module example.net/d + +go 1.18 + +require example.net/invalid v0.1.0 +-- d/d.go -- +package d +-- d/d_test.go -- +package d + +import _ "example.net/invalid" diff --git a/go/src/cmd/go/testdata/script/mod_get_latest_pseudo.txt b/go/src/cmd/go/testdata/script/mod_get_latest_pseudo.txt new file mode 100644 index 0000000000000000000000000000000000000000..00da0c316469f9bd3d5e54f8bd67eb931b53047c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_latest_pseudo.txt @@ -0,0 +1,10 @@ +# Check that we can build a module with no tagged versions by querying +# "@latest" through a proxy. +# Verifies golang.org/issue/32636 + +env GO111MODULE=on + +go mod init m +go get example.com/notags +go list -m all +stdout '^example.com/notags v0.0.0-20190507143103-cc8cbe209b64$' diff --git a/go/src/cmd/go/testdata/script/mod_get_lazy_indirect.txt b/go/src/cmd/go/testdata/script/mod_get_lazy_indirect.txt new file mode 100644 index 0000000000000000000000000000000000000000..1cef9d1c0cf1e21bd8b5875c3940827573618190 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_lazy_indirect.txt @@ -0,0 +1,44 @@ +# https://golang.org/issue/45979: after 'go get' on a package, +# that package should be importable without error. + + +# We start out with an unresolved dependency. +# 'go list' suggests that we run 'go get' on that dependency. + +! go list -deps . +stderr '^m.go:3:8: no required module provides package rsc\.io/quote; to add it:\n\tgo get rsc.io/quote$' + + +# When we run the suggested 'go get' command, the new dependency can be used +# immediately. +# +# 'go get' marks the new dependency as 'indirect', because it doesn't scan +# enough source code to know whether it is direct, and it is easier and less +# invasive to remove an incorrect indirect mark (e.g. using 'go get') than to +# add one that is missing ('go mod tidy' or 'go mod vendor'). + +go get rsc.io/quote +grep 'rsc.io/quote v\d+\.\d+\.\d+ // indirect$' go.mod +! grep 'rsc.io/quote v\d+\.\d+\.\d+$' go.mod + +go list -deps . +! stderr . +[!short] go build . +[!short] ! stderr . + + +# 'go get .' (or 'go mod tidy') removes the indirect mark. + +go get . +grep 'rsc.io/quote v\d+\.\d+\.\d+$' go.mod +! grep 'rsc.io/quote v\d+\.\d+\.\d+ // indirect$' go.mod + + +-- go.mod -- +module example.com/m + +go 1.17 +-- m.go -- +package m + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_get_lazy_upgrade_lazy.txt b/go/src/cmd/go/testdata/script/mod_get_lazy_upgrade_lazy.txt new file mode 100644 index 0000000000000000000000000000000000000000..3dae383de1e57bd5c9d664c290da73470c0fedab --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_lazy_upgrade_lazy.txt @@ -0,0 +1,68 @@ +# Check that 'go get -u' will upgrade a dependency (direct or indirect) +# when the main module and the dependency are both lazy. +# Verifies #47768. + +# Check that go.mod is tidy, and an upgrade is available. +cp go.mod go.mod.orig +go mod tidy +cmp go.mod go.mod.orig + +go list -m -u example.com/lazyupgrade +stdout '^example.com/lazyupgrade v0.1.0 \[v0.1.1\] => ./lazyupgrade@v0.1.0$' + +# 'go get -u' on a package that directly imports the dependency should upgrade. +go get -u ./usedirect +go list -m example.com/lazyupgrade +stdout '^example.com/lazyupgrade v0.1.1 => ./lazyupgrade@v0.1.1$' +cp go.mod.orig go.mod + +# 'go get -u' on a package that indirectly imports the dependency should upgrade. +go get -u ./useindirect +go list -m example.com/lazyupgrade +stdout '^example.com/lazyupgrade v0.1.1 => ./lazyupgrade@v0.1.1$' + +-- go.mod -- +module use + +go 1.17 + +require ( + direct v0.0.0 + example.com/lazyupgrade v0.1.0 +) + +replace ( + direct => ./direct + example.com/lazyupgrade v0.1.0 => ./lazyupgrade@v0.1.0 + example.com/lazyupgrade v0.1.1 => ./lazyupgrade@v0.1.1 +) +-- usedirect/usedirect.go -- +package use + +import _ "example.com/lazyupgrade" +-- useindirect/useindirect.go -- +package use + +import _ "direct" +-- direct/go.mod -- +module direct + +go 1.17 + +require example.com/lazyupgrade v0.1.0 +-- direct/direct.go -- +package direct + +import _ "example.com/lazyupgrade" +-- lazyupgrade@v0.1.0/go.mod -- +module example.com/lazyupgrade + +go 1.17 +-- lazyupgrade@v0.1.0/lazyupgrade.go -- +package lazyupgrade +-- lazyupgrade@v0.1.1/go.mod -- +module example.com/lazyupgrade + +go 1.17 +-- lazyupgrade@v0.1.1/lazyupgrade.go -- +package lazyupgrade diff --git a/go/src/cmd/go/testdata/script/mod_get_local.txt b/go/src/cmd/go/testdata/script/mod_get_local.txt new file mode 100644 index 0000000000000000000000000000000000000000..4c81d16a1fe072058a6cd4aeb5abcc6fc1ab519d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_local.txt @@ -0,0 +1,62 @@ +# Test 'go get' with a local module with a name that is not valid for network lookup. +[short] skip + +env GO111MODULE=on +go mod edit -fmt +cp go.mod go.mod.orig + +# 'go get -u' within the main module should work, even if it has a local-only name. +cp go.mod.orig go.mod +go get -u ./... +grep 'rsc.io/quote.*v1.5.2' go.mod +grep 'golang.org/x/text.*v0.3.0' go.mod +cp go.mod go.mod.implicitmod + +# 'go get -u local/...' should be equivalent to 'go get -u ./...' +# (assuming no nested modules) +cp go.mod.orig go.mod +go get -u local/... +cmp go.mod go.mod.implicitmod + +# For the main module, @patch should be a no-op. +cp go.mod.orig go.mod +go get -u local/...@patch +cmp go.mod go.mod.implicitmod + +# 'go get -u' in the empty root of the main module should fail. +# 'go get -u .' should also fail. +cp go.mod.orig go.mod +! go get -u +! go get -u . + +# 'go get -u .' within a package in the main module updates the dependencies +# of that package. +cp go.mod.orig go.mod +cd uselang +go get -u . +cd .. +grep 'rsc.io/quote.*v1.3.0' go.mod +grep 'golang.org/x/text.*v0.3.0' go.mod +cp go.mod go.mod.dotpkg + +# 'go get -u' with an explicit package in the main module updates the +# dependencies of that package. +cp go.mod.orig go.mod +go get -u local/uselang +cmp go.mod go.mod.dotpkg + +-- go.mod -- +module local + +require ( + golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c + rsc.io/quote v1.3.0 +) + +-- uselang/uselang.go -- +package uselang +import _ "golang.org/x/text/language" + +-- usequote/usequote.go -- +package usequote +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_get_main.txt b/go/src/cmd/go/testdata/script/mod_get_main.txt new file mode 100644 index 0000000000000000000000000000000000000000..cddd5f70826eb406a18e9efb55ed018f241f4ab0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_main.txt @@ -0,0 +1,51 @@ +env GO111MODULE=on +cp go.mod.orig go.mod + +# relative and absolute paths must be within the main module. +! go get .. +stderr '^go: \.\. \('$WORK'[/\\]gopath\) is not within module rooted at '$WORK'[/\\]gopath[/\\]src$' +! go get $WORK +stderr '^go: '$WORK' is not within module rooted at '$WORK'[/\\]gopath[/\\]src$' +! go get ../... +stderr '^go: \.\./\.\.\. \('$WORK'[/\\]gopath([/\\]...)?\) is not within module rooted at '$WORK'[/\\]gopath[/\\]src$' +! go get $WORK/... +stderr '^go: '$WORK'[/\\]\.\.\. is not within module rooted at '$WORK'[/\\]gopath[/\\]src$' + +# @patch and @latest within the main module refer to the current version. +# The main module won't be upgraded, but missing dependencies will be added. +go get rsc.io/x +grep 'rsc.io/quote v1.5.2' go.mod +go get rsc.io/x@upgrade +grep 'rsc.io/quote v1.5.2' go.mod +cp go.mod.orig go.mod +go get rsc.io/x@patch +grep 'rsc.io/quote v1.5.2' go.mod +cp go.mod.orig go.mod + + +# Upgrading a package pattern not contained in the main module should not +# attempt to upgrade the main module. +go get rsc.io/quote/...@v1.5.1 +grep 'rsc.io/quote v1.5.1' go.mod + + +# The main module cannot be updated to a specific version. +! go get rsc.io@v0.1.0 +stderr '^go: can''t request version "v0.1.0" of the main module \(rsc.io\)$' + +# A package in the main module can't be upgraded either. +! go get rsc.io/x@v0.1.0 +stderr '^go: package rsc.io/x is in the main module, so can''t request version v0.1.0$' + +# Nor can a pattern matching packages in the main module. +! go get rsc.io/x/...@latest +stderr '^go: pattern rsc.io/x/... matches package rsc.io/x in the main module, so can''t request version latest$' + +-- go.mod.orig -- +module rsc.io + +go 1.13 +-- x/x.go -- +package x + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_get_major.txt b/go/src/cmd/go/testdata/script/mod_get_major.txt new file mode 100644 index 0000000000000000000000000000000000000000..4e0febbca26e252c0f18c99ded531b2739cb23bd --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_major.txt @@ -0,0 +1,23 @@ +[short] skip +[!git] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +# golang.org/issue/34383: if a module path ends in a major-version suffix, +# ensure that 'direct' mode can resolve the package to a module. + +go get vcs-test.golang.org/git/v3pkg.git/v3@v3.0.0 + +go list -m vcs-test.golang.org/git/v3pkg.git/v3 +stdout '^vcs-test.golang.org/git/v3pkg.git/v3 v3.0.0$' + +go get vcs-test.golang.org/git/empty-v2-without-v1.git/v2@v2.0.0 + +go list -m vcs-test.golang.org/git/empty-v2-without-v1.git/v2 +stdout '^vcs-test.golang.org/git/empty-v2-without-v1.git/v2 v2.0.0$' + +-- go.mod -- +module example.com +go 1.13 diff --git a/go/src/cmd/go/testdata/script/mod_get_missing_ziphash.txt b/go/src/cmd/go/testdata/script/mod_get_missing_ziphash.txt new file mode 100644 index 0000000000000000000000000000000000000000..5934251e4b8b74688a40d060c261147b77a3e6d1 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_missing_ziphash.txt @@ -0,0 +1,55 @@ +# Test that if the module cache contains an extracted source directory but not +# a ziphash, 'go build' complains about a missing sum, and 'go get' adds +# the sum. Verifies #44749. + +# With a tidy go.sum, go build succeeds. This also populates the module cache. +cp go.sum.tidy go.sum +go build -n use +env GOPROXY=off +env GOSUMDB=off + +# Control case: if we delete the hash for rsc.io/quote v1.5.2, +# 'go build' reports an error. 'go get' adds the sum. +cp go.sum.bug go.sum +! go build -n use +stderr '^use.go:3:8: missing go.sum entry for module providing package rsc.io/quote \(imported by use\); to add:\n\tgo get use$' +go get use +cmp go.sum go.sum.tidy +go build -n use + +# If we delete the hash *and* the ziphash file, we should see the same behavior. +cp go.sum.bug go.sum +rm $WORK/gopath/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.ziphash +! go build -n use +stderr '^use.go:3:8: missing go.sum entry for module providing package rsc.io/quote \(imported by use\); to add:\n\tgo get use$' +go get use +cmp go.sum go.sum.tidy +go build -n use + +-- go.mod -- +module use + +go 1.16 + +require rsc.io/quote v1.5.2 +-- go.sum.tidy -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/testonly v1.0.0 h1:K/VWHdO+Jv7woUXG0GzVNx1czBXUt3Ib1deaMn+xk64= +rsc.io/testonly v1.0.0/go.mod h1:OqmGbIFOcF+XrFReLOGZ6BhMM7uMBiQwZsyNmh74SzY= +-- go.sum.bug -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/testonly v1.0.0 h1:K/VWHdO+Jv7woUXG0GzVNx1czBXUt3Ib1deaMn+xk64= +rsc.io/testonly v1.0.0/go.mod h1:OqmGbIFOcF+XrFReLOGZ6BhMM7uMBiQwZsyNmh74SzY= +-- use.go -- +package use + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_get_moved.txt b/go/src/cmd/go/testdata/script/mod_get_moved.txt new file mode 100644 index 0000000000000000000000000000000000000000..cc35b4c8fa945910c44e2f8351794ea61b850b84 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_moved.txt @@ -0,0 +1,40 @@ +env GO111MODULE=on +[short] skip + +# A 'go get' that worked at a previous version should continue to work at that version, +# even if the package was subsequently moved into a submodule. +go mod init example.com/foo +go get example.com/split/subpkg@v1.0.0 +go list -m all +stdout 'example.com/split v1.0.0' + +# A 'go get' that simultaneously upgrades away conflicting package definitions is not ambiguous. +go get example.com/split/subpkg@v1.1.0 + +# A 'go get' without an upgrade should find the package. +rm go.mod +go mod init example.com/foo +go get example.com/split/subpkg +go list -m all +stdout 'example.com/split/subpkg v1.1.0' + + +# A 'go get' that worked at a previous version should continue to work at that version, +# even if the package was subsequently moved into a parent module. +rm go.mod +go mod init example.com/foo +go get example.com/join/subpkg@v1.0.0 +go list -m all +stdout 'example.com/join/subpkg v1.0.0' + +# A 'go get' that simultaneously upgrades away conflicting package definitions is not ambiguous. +# (A wildcard pattern applies to both packages and modules, +# because we define wildcard matching to apply after version resolution.) +go get example.com/join/subpkg/...@v1.1.0 + +# A 'go get' without an upgrade should find the package. +rm go.mod +go mod init example.com/foo +go get example.com/join/subpkg@v1.1.0 +go list -m all +stdout 'example.com/join v1.1.0' diff --git a/go/src/cmd/go/testdata/script/mod_get_newcycle.txt b/go/src/cmd/go/testdata/script/mod_get_newcycle.txt new file mode 100644 index 0000000000000000000000000000000000000000..4f5229e57e9cb5a6dad78746e31803843688451f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_newcycle.txt @@ -0,0 +1,14 @@ +env GO111MODULE=on + +# Download modules to avoid stderr chatter +go mod download example.com@v1.0.0 +go mod download example.com/newcycle/a@v1.0.0 +go mod download example.com/newcycle/a@v1.0.1 +go mod download example.com/newcycle/b@v1.0.0 + +go mod init m +! go get example.com/newcycle/a@v1.0.0 +cmp stderr stderr-expected + +-- stderr-expected -- +go: example.com/newcycle/a@v1.0.0 indirectly requires example.com/newcycle/a@v1.0.1, not example.com/newcycle/a@v1.0.0 diff --git a/go/src/cmd/go/testdata/script/mod_get_none.txt b/go/src/cmd/go/testdata/script/mod_get_none.txt new file mode 100644 index 0000000000000000000000000000000000000000..5aec209f59fe6fa54ffa3f67ce9d31d73fb665de --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_none.txt @@ -0,0 +1,12 @@ +env GO111MODULE=on + +go mod init example.com/foo + +# 'go get bar@none' should be a no-op if module bar is not active. +go get example.com/bar@none +go list -m all +! stdout example.com/bar + +go get example.com/bar@none +go list -m all +! stdout example.com/bar diff --git a/go/src/cmd/go/testdata/script/mod_get_nopkgs.txt b/go/src/cmd/go/testdata/script/mod_get_nopkgs.txt new file mode 100644 index 0000000000000000000000000000000000000000..e2bfdf30a8d86005556f0efcff252063eb4b65b2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_nopkgs.txt @@ -0,0 +1,48 @@ +cd subdir + +# 'go get' on empty patterns that are necessarily local to the module +# should warn that the patterns are empty, exactly once. + +go get ./... +stderr -count=1 'matched no packages' + +go get ./... +stderr -count=1 'matched no packages' + +# 'go get' on patterns that could conceivably match nested modules +# should report a module resolution error. + +go get example.net/emptysubdir/... # control case + +! go get example.net/emptysubdir/subdir/... +! stderr 'matched no packages' +stderr '^go: example\.net/emptysubdir/subdir/\.\.\.: module example\.net/emptysubdir/subdir: reading http://.*: 404 Not Found\n\tserver response: 404 page not found\n\z' + +# It doesn't make sense to 'go get' a path in the standard library, +# since the standard library necessarily can't have unresolved imports. +# +# TODO(#30241): Maybe that won't always be the case? +# +# For that case, we emit a "malformed module path" error message, +# which isn't ideal either. + +! go get builtin/... # in GOROOT/src, but contains no packages +stderr '^go: builtin/...: malformed module path "builtin": missing dot in first path element$' + +cd ../subdirmod +go get work +stderr -count=1 'matched no packages' + +-- go.mod -- +module example.net/emptysubdir + +go 1.16 +-- emptysubdir.go -- +// Package emptysubdir has a subdirectory containing no packages. +package emptysubdir +-- subdir/README.txt -- +This module intentionally does not contain any p +-- subdirmod/go.mod -- +module example.net/emptysubdir/subdirmod + +go 1.16 diff --git a/go/src/cmd/go/testdata/script/mod_get_patch.txt b/go/src/cmd/go/testdata/script/mod_get_patch.txt new file mode 100644 index 0000000000000000000000000000000000000000..35cc276c5c36839788d2e7dd60be4f122d9d648b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_patch.txt @@ -0,0 +1,130 @@ +# This test examines the behavior of 'go get …@patch' +# See also mod_upgrade_patch.txt (focused on "-u=patch" specifically) +# and mod_get_patchmod.txt (focused on module/package ambiguities). + +cp go.mod go.mod.orig + +# example.net/b@patch refers to the patch for the version of b that was selected +# at the start of 'go get', not the version after applying other changes. + +! go get example.net/a@v0.2.0 example.net/b@patch +stderr '^go: example.net/a@v0.2.0 requires example.net/b@v0.2.0, not example.net/b@patch \(v0.1.1\)$' +cmp go.mod go.mod.orig + + +# -u=patch changes the default version for other arguments to '@patch', +# but they continue to be resolved against the originally-selected version, +# not the updated one. +# +# TODO(#42360): Reconsider the change in defaults. + +! go get -u=patch example.net/a@v0.2.0 example.net/b +stderr '^go: example.net/a@v0.2.0 requires example.net/b@v0.2.0, not example.net/b@patch \(v0.1.1\)$' +cmp go.mod go.mod.orig + + +# -u=patch refers to the patches for the selected versions of dependencies *after* +# applying other version changes, not the versions that were selected at the start. +# However, it should not patch versions determined by explicit arguments. + +go get -u=patch example.net/a@v0.2.0 +go list -m all +stdout '^example.net/a v0.2.0 ' +stdout '^example.net/b v0.2.1 ' + + +# "-u=patch all" should be equivalent to "all@patch", and should fail if the +# patched versions result in a higher-than-patch upgrade. + +cp go.mod.orig go.mod +! go get -u=patch all +stderr '^go: example.net/a@v0.1.1 \(matching all@patch\) requires example.net/b@v0.2.0, not example.net/b@v0.1.1 \(matching all@patch\)$' +cmp go.mod go.mod.orig + + +# On the other hand, "-u=patch ./..." should patch-upgrade dependencies until +# they reach a fixed point, even if that results in higher-than-patch upgrades. + +go get -u=patch ./... +go list -m all +stdout '^example.net/a v0.1.1 ' +stdout '^example.net/b v0.2.1 ' + + +-- go.mod -- +module example + +go 1.16 + +require ( + example.net/a v0.1.0 + example.net/b v0.1.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a10 + example.net/a v0.1.1 => ./a11 + example.net/a v0.2.0 => ./a20 + example.net/a v0.2.1 => ./a21 + example.net/b v0.1.0 => ./b + example.net/b v0.1.1 => ./b + example.net/b v0.2.0 => ./b + example.net/b v0.2.1 => ./b + example.net/b v0.3.0 => ./b + example.net/b v0.3.1 => ./b +) +-- example.go -- +package example + +import _ "example.net/a" + +-- a10/go.mod -- +module example.net/a + +go 1.16 + +require example.net/b v0.1.0 +-- a10/a.go -- +package a + +import _ "example.net/b" + +-- a11/go.mod -- +module example.net/a + +go 1.16 + +require example.net/b v0.2.0 // upgraded +-- a11/a.go -- +package a + +import _ "example.net/b" + +-- a20/go.mod -- +module example.net/a + +go 1.16 + +require example.net/b v0.2.0 +-- a20/a.go -- +package a + +import _ "example.net/b" + +-- a21/go.mod -- +module example.net/a + +go 1.16 + +require example.net/b v0.2.0 // not upgraded +-- a21/a.go -- +package a + +import _ "example.net/b" + +-- b/go.mod -- +module example.net/b + +go 1.16 +-- b/b.go -- +package b diff --git a/go/src/cmd/go/testdata/script/mod_get_patchbound.txt b/go/src/cmd/go/testdata/script/mod_get_patchbound.txt new file mode 100644 index 0000000000000000000000000000000000000000..e4d3c491f45611f45919ef3aca1c3a0d26efe6dd --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_patchbound.txt @@ -0,0 +1,84 @@ +# -u=patch will patch dependencies as far as possible, but not so far that they +# conflict with other command-line arguments. + +go list -m all +stdout '^example.net/a v0.1.0 ' +stdout '^example.net/b v0.1.0 ' + +go get -u=patch example.net/a@v0.2.0 +go list -m all +stdout '^example.net/a v0.2.0 ' +stdout '^example.net/b v0.1.1 ' # not v0.1.2, which requires …/a v0.3.0. + +-- go.mod -- +module example + +go 1.16 + +require ( + example.net/a v0.1.0 + example.net/b v0.1.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a + example.net/a v0.2.0 => ./a + example.net/a v0.3.0 => ./a + example.net/b v0.1.0 => ./b10 + example.net/b v0.1.1 => ./b11 + example.net/b v0.1.2 => ./b12 +) +-- example.go -- +package example + +import _ "example.net/a" + +-- a/go.mod -- +module example.net/a + +go 1.16 + +require example.net/b v0.1.0 +-- a/a.go -- +package a + +import _ "example.net/b" + +-- b10/go.mod -- +module example.net/b + +go 1.16 + +require example.net/a v0.1.0 +-- b10/b.go -- +package b +-- b10/b_test.go -- +package b_test + +import _ "example.net/a" + +-- b11/go.mod -- +module example.net/b + +go 1.16 + +require example.net/a v0.2.0 +-- b11/b.go -- +package b +-- b11/b_test.go -- +package b_test + +import _ "example.net/a" + +-- b12/go.mod -- +module example.net/b + +go 1.16 + +require example.net/a v0.3.0 +-- b12/b.go -- +package b +-- b12/b_test.go -- +package b_test + +import _ "example.net/a" diff --git a/go/src/cmd/go/testdata/script/mod_get_patchcycle.txt b/go/src/cmd/go/testdata/script/mod_get_patchcycle.txt new file mode 100644 index 0000000000000000000000000000000000000000..9f180d6b95a33276159c34c0a9747be2e988846a --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_patchcycle.txt @@ -0,0 +1,64 @@ +# If a patch of a module requires a higher version of itself, +# it should be reported as its own conflict. +# +# This case is weird and unlikely to occur often at all, but it should not +# spuriously succeed. +# (It used to print v0.1.1 but then silently upgrade to v0.2.0.) + +! go get example.net/a@patch +stderr '^go: example.net/a@patch \(v0.1.1\) indirectly requires example.net/a@v0.2.0, not example.net/a@patch \(v0.1.1\)$' # TODO: A mention of b v0.1.0 would be nice. + +-- go.mod -- +module example + +go 1.16 + +require example.net/a v0.1.0 + +replace ( + example.net/a v0.1.0 => ./a10 + example.net/a v0.1.1 => ./a11 + example.net/a v0.2.0 => ./a20 + example.net/b v0.1.0 => ./b10 +) +-- example.go -- +package example + +import _ "example.net/a" + +-- a10/go.mod -- +module example.net/a + +go 1.16 +-- a10/a.go -- +package a + +-- a11/go.mod -- +module example.net/a + +go 1.16 + +require example.net/b v0.1.0 +-- a11/a.go -- +package a + +import _ "example.net/b" + +-- a20/go.mod -- +module example.net/a + +go 1.16 +-- a20/a.go -- +package a + + +-- b10/go.mod -- +module example.net/b + +go 1.16 + +require example.net/a v0.2.0 +-- b10/b.go -- +package b + +import _ "example.net/a" diff --git a/go/src/cmd/go/testdata/script/mod_get_patchmod.txt b/go/src/cmd/go/testdata/script/mod_get_patchmod.txt new file mode 100644 index 0000000000000000000000000000000000000000..28277310aa15e5041c137d69dcc2bbdf9cefb242 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_patchmod.txt @@ -0,0 +1,82 @@ +# example.net/pkgremoved@v0.1.0 refers to a package. +go get example.net/pkgremoved@v0.1.0 + +go list example.net/pkgremoved +stdout '^example.net/pkgremoved' + +cp go.mod go.mod.orig + + +# When we resolve a new dependency on example.net/other, +# it will change the meaning of the path "example.net/pkgremoved" +# from a package (at v0.1.0) to only a module (at v0.2.0). +# +# If we simultaneously 'get' that module at the query "patch", the module should +# be constrained to the latest patch of its originally-selected version (v0.1.0), +# not upgraded to the latest patch of the new transitive dependency. + +! go get example.net/pkgremoved@patch example.net/other@v0.1.0 +stderr '^go: example.net/other@v0.1.0 requires example.net/pkgremoved@v0.2.0, not example.net/pkgremoved@patch \(v0.1.1\)$' +cmp go.mod.orig go.mod + + +# However, we should be able to patch from a package to a module and vice-versa. + +# Package to module ... + +go get example.net/pkgremoved@v0.3.0 +go list example.net/pkgremoved +stdout 'example.net/pkgremoved' + +go get example.net/pkgremoved@patch +! go list example.net/pkgremoved + +# ... and module to package. + +go get example.net/pkgremoved@v0.4.0 +! go list example.net/pkgremoved + +go get example.net/pkgremoved@patch +go list example.net/pkgremoved +stdout 'example.net/pkgremoved' + + +-- go.mod -- +module example + +go 1.16 + +replace ( + example.net/other v0.1.0 => ./other + + example.net/pkgremoved v0.1.0 => ./prpkg + example.net/pkgremoved v0.1.1 => ./prpkg + + example.net/pkgremoved v0.2.0 => ./prmod + example.net/pkgremoved v0.2.1 => ./prmod + + example.net/pkgremoved v0.3.0 => ./prpkg + example.net/pkgremoved v0.3.1 => ./prmod + + example.net/pkgremoved v0.4.0 => ./prmod + example.net/pkgremoved v0.4.1 => ./prpkg +) +-- other/go.mod -- +module example.net/other + +go 1.16 + +require example.net/pkgremoved v0.2.0 +-- other/other.go -- +package other +-- prpkg/go.mod -- +module example.net/pkgremoved + +go 1.16 +-- prpkg/pkgremoved.go -- +package pkgremoved +-- prmod/go.mod -- +module example.net/pkgremoved +-- prmod/README.txt -- +Package pkgremoved was removed in v0.2.0 and v0.3.1, +and added in v0.1.0 and v0.4.1. diff --git a/go/src/cmd/go/testdata/script/mod_get_patterns.txt b/go/src/cmd/go/testdata/script/mod_get_patterns.txt new file mode 100644 index 0000000000000000000000000000000000000000..891353fd4b9a0b6ef59098a609bbe97ddc2112ae --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_patterns.txt @@ -0,0 +1,42 @@ +env GO111MODULE=on +[short] skip + +# If a pattern doesn't match any packages provided by modules +# in the build list, we assume the pattern matches a single module +# whose path is a prefix of the part of the pattern before "...". +cp go.mod.orig go.mod +go get rsc.io/quote/... +grep 'require rsc.io/quote' go.mod + +cp go.mod.orig go.mod +! go get rsc.io/quote/x... +stderr 'go: module rsc.io/quote@upgrade found \(v1.5.2\), but does not contain packages matching rsc.io/quote/x...' +! grep 'require rsc.io/quote' go.mod + +! go get rsc.io/quote/x/... +stderr 'go: module rsc.io/quote@upgrade found \(v1.5.2\), but does not contain packages matching rsc.io/quote/x/...' +! grep 'require rsc.io/quote' go.mod + +# If a pattern matches no packages within a module, the module should not +# be upgraded, even if the module path is a prefix of the pattern. +cp go.mod.orig go.mod +go mod edit -require example.com/nest@v1.0.0 +go get example.com/nest/sub/y... +grep 'example.com/nest/sub v1.0.0' go.mod +grep 'example.com/nest v1.0.0' go.mod + +# However, if the pattern matches the module path itself, the module +# should be upgraded even if it contains no matching packages. +go get example.com/n...t +grep 'example.com/nest v1.1.0' go.mod +grep 'example.com/nest/sub v1.0.0' go.mod + +-- go.mod.orig -- +module m + +go 1.13 + +-- use/use.go -- +package use + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_get_pkgtags.txt b/go/src/cmd/go/testdata/script/mod_get_pkgtags.txt new file mode 100644 index 0000000000000000000000000000000000000000..8cb41ad2f246543cc7173eb5a8acd661e148370e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_pkgtags.txt @@ -0,0 +1,130 @@ +# https://golang.org/issue/44106 +# 'go get' should fetch the transitive dependencies of packages regardless of +# tags, but shouldn't error out if the package is missing tag-guarded +# dependencies. + +# Control case: just adding the top-level module to the go.mod file does not +# fetch its dependencies. + +go mod edit -require example.net/tools@v0.1.0 +! go list -deps example.net/cmd/tool +stderr '^module example\.net/cmd provides package example\.net/cmd/tool and is replaced but not required; to add it:\n\tgo get example\.net/cmd@v0\.1\.0$' +go mod edit -droprequire example.net/tools + + +# 'go get' makes a best effort to fetch those dependencies, but shouldn't +# error out if dependencies of tag-guarded files are missing. + +go get example.net/tools@v0.1.0 +! stderr 'no Go source files' + +! go list example.net/tools +stderr '^package example.net/tools: build constraints exclude all Go files in .*[/\\]tools$' + +go list -tags=tools -e -deps example.net/tools +stdout '^example.net/cmd/tool$' +stdout '^example.net/missing$' + +go list -deps example.net/cmd/tool + +! go list example.net/missing +stderr '^no required module provides package example.net/missing; to add it:\n\tgo get example.net/missing$' + + +# https://golang.org/issue/33526: 'go get' without '-d' should succeed +# for a module whose root is a constrained-out package. +# +# Ideally it should silently succeed, but today it logs the "no Go source files" +# error and succeeds anyway. + +go get example.net/tools@v0.1.0 +! stderr . + +! go build example.net/tools +stderr '^package example.net/tools: build constraints exclude all Go files in .*[/\\]tools$' + + +# https://golang.org/issue/29268 +# 'go get' should fetch modules whose roots contain test-only packages, but +# without the -t flag shouldn't error out if the test has missing dependencies. + +go get example.net/testonly@v0.1.0 + +# With the -t flag, the test dependencies must resolve successfully. +! go get -t example.net/testonly@v0.1.0 +stderr '^go: example.net/testonly tested by\n\texample.net/testonly\.test imports\n\texample.net/missing: cannot find module providing package example.net/missing$' + + +# 'go get' should succeed for a module path that does not contain a package, +# but fail for a non-package subdirectory of a module. + +! go get example.net/missing/subdir@v0.1.0 +stderr '^go: module example.net/missing@v0.1.0 found \(replaced by ./missing\), but does not contain package example.net/missing/subdir$' + +go get example.net/missing@v0.1.0 + + +# Getting the subdirectory should continue to fail even if the corresponding +# module is already present in the build list. + +! go get example.net/missing/subdir@v0.1.0 +stderr '^go: module example.net/missing@v0.1.0 found \(replaced by ./missing\), but does not contain package example.net/missing/subdir$' + + +-- go.mod -- +module example.net/m + +go 1.15 + +replace ( + example.net/tools v0.1.0 => ./tools + example.net/cmd v0.1.0 => ./cmd + example.net/testonly v0.1.0 => ./testonly + example.net/missing v0.1.0 => ./missing +) + +-- tools/go.mod -- +module example.net/tools + +go 1.15 + +// Requirements intentionally omitted. + +-- tools/tools.go -- +// +build tools + +package tools + +import ( + _ "example.net/cmd/tool" + _ "example.net/missing" +) + +-- cmd/go.mod -- +module example.net/cmd + +go 1.16 +-- cmd/tool/tool.go -- +package main + +func main() {} + +-- testonly/go.mod -- +module example.net/testonly + +go 1.15 +-- testonly/testonly_test.go -- +package testonly_test + +import _ "example.net/missing" + +func Test(t *testing.T) {} + +-- missing/go.mod -- +module example.net/missing + +go 1.15 +-- missing/README.txt -- +There are no Go source files here. +-- missing/subdir/README.txt -- +There are no Go source files here either. diff --git a/go/src/cmd/go/testdata/script/mod_get_prefer_incompatible.txt b/go/src/cmd/go/testdata/script/mod_get_prefer_incompatible.txt new file mode 100644 index 0000000000000000000000000000000000000000..06e2fc686029184d8b15cfa2f0b4e39edb8aad7f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_prefer_incompatible.txt @@ -0,0 +1,29 @@ +# Verifies golang.org/issue/37574. + +# If we are already using an +incompatible version, we shouldn't look up +# a lower compatible version when upgrading. +cp go.mod go.mod.orig +go mod tidy +cmp go.mod.orig go.mod +grep '^example.com/incompatiblewithsub v2\.0\.0\+incompatible' go.sum +! grep '^example.com/incompatiblewithsub v1.0.0' go.sum + +go get example.com/incompatiblewithsub/sub +cmp go.mod.orig go.mod +! grep '^example.com/incompatiblewithsub v1.0.0' go.sum + +# TODO(golang.org/issue/31580): the 'go get' command above should not change +# go.sum. However, as part of the query above, we download example.com@v1.0.0, +# an unrelated module, since it's a possible prefix. The sum for that module +# should not be written to go.sum. + +-- go.mod -- +module m + +go 1.15 + +require example.com/incompatiblewithsub v2.0.0+incompatible +-- use.go -- +package use + +import _ "example.com/incompatiblewithsub/sub" diff --git a/go/src/cmd/go/testdata/script/mod_get_promote_implicit.txt b/go/src/cmd/go/testdata/script/mod_get_promote_implicit.txt new file mode 100644 index 0000000000000000000000000000000000000000..03f6810e354a0a3e56a112a424b499ffdb7d1fcb --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_promote_implicit.txt @@ -0,0 +1,92 @@ +cp go.mod.orig go.mod + +# If we list a package in an implicit dependency imported from the main module, +# we should get an error because the dependency should have an explicit +# requirement. +go list -m indirect-with-pkg +stdout '^indirect-with-pkg v1.0.0 => ./indirect-with-pkg$' +! go list ./use-indirect +stderr '^package m/use-indirect imports indirect-with-pkg from implicitly required module; to add missing requirements, run:\n\tgo get indirect-with-pkg@v1.0.0$' + +# We can promote the implicit requirement by getting the importing package. +# NOTE: the hint recommends getting the imported package (tested below) since +# it's more obvious and doesn't require -d. However, that adds an '// indirect' +# comment on the requirement. +go get m/use-indirect +cmp go.mod go.mod.use +cp go.mod.orig go.mod + +# We can also promote implicit requirements using 'go get' on them, or their +# packages. This gives us "// indirect" requirements, since 'go get' doesn't +# know they're needed by the main module. See #43131 for the rationale. +# The hint above recommends this because it's more obvious usage and doesn't +# require the -d flag. +go get indirect-with-pkg indirect-without-pkg +cmp go.mod go.mod.indirect + +-- go.mod.orig -- +module m + +go 1.16 + +require direct v1.0.0 + +replace ( + direct v1.0.0 => ./direct + indirect-with-pkg v1.0.0 => ./indirect-with-pkg + indirect-without-pkg v1.0.0 => ./indirect-without-pkg +) +-- go.mod.use -- +module m + +go 1.16 + +require ( + direct v1.0.0 + indirect-with-pkg v1.0.0 +) + +replace ( + direct v1.0.0 => ./direct + indirect-with-pkg v1.0.0 => ./indirect-with-pkg + indirect-without-pkg v1.0.0 => ./indirect-without-pkg +) +-- go.mod.indirect -- +module m + +go 1.16 + +require ( + direct v1.0.0 + indirect-with-pkg v1.0.0 // indirect + indirect-without-pkg v1.0.0 // indirect +) + +replace ( + direct v1.0.0 => ./direct + indirect-with-pkg v1.0.0 => ./indirect-with-pkg + indirect-without-pkg v1.0.0 => ./indirect-without-pkg +) +-- use-indirect/use-indirect.go -- +package use + +import _ "indirect-with-pkg" +-- direct/go.mod -- +module direct + +go 1.16 + +require ( + indirect-with-pkg v1.0.0 + indirect-without-pkg v1.0.0 +) +-- indirect-with-pkg/go.mod -- +module indirect-with-pkg + +go 1.16 +-- indirect-with-pkg/p.go -- +package p +-- indirect-without-pkg/go.mod -- +module indirect-without-pkg + +go 1.16 diff --git a/go/src/cmd/go/testdata/script/mod_get_pseudo.txt b/go/src/cmd/go/testdata/script/mod_get_pseudo.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b3585107fa748a2b5138cdd1cc0d763f28865b0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_pseudo.txt @@ -0,0 +1,83 @@ +env GO111MODULE=on + +[!git] skip +[short] skip + +# Testing git->module converter's generation of +incompatible tags; turn off proxy. +env GOPROXY=direct +env GOSUMDB=off + +# We can resolve the @master branch without unshallowing the local repository +# (even with older gits), so try that before we do anything else. +# (This replicates https://golang.org/issue/26713 with git 2.7.4.) +go get vcs-test.golang.org/git/legacytest.git@master +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v2\.0\.1-0\.\d{14}-7303f7796364\+incompatible$' + +# get should include incompatible tags in "latest" calculation. +go mod edit -droprequire vcs-test.golang.org/git/legacytest.git +go get vcs-test.golang.org/git/legacytest.git@latest +go list +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v2\.0\.0\+incompatible$' + +# v2.0.1-0.pseudo+incompatible +go get ...test.git@7303f77 +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v2\.0\.1-0\.\d{14}-7303f7796364\+incompatible$' + +# v2.0.0+incompatible by tag+incompatible +go get ...test.git@v2.0.0+incompatible +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v2\.0\.0\+incompatible$' + +# v2.0.0+incompatible by tag +go get ...test.git@v2.0.0 +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v2\.0\.0\+incompatible$' + +# v2.0.0+incompatible by hash (back on master) +go get ...test.git@d7ae1e4 +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v2\.0\.0\+incompatible$' + +# v1.2.1-0.pseudo +go get ...test.git@d2d4c3e +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v1\.2\.1-0\.\d{14}-d2d4c3ea6623$' + +# v1.2.0 +go get ...test.git@9f6f860 +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v1\.2\.0$' + +# v1.1.0-pre.0.pseudo +go get ...test.git@fb3c628 +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v1\.1\.0-pre\.0\.\d{14}-fb3c628075e3$' + +# v1.1.0-pre (no longer on master) +go get ...test.git@731e3b1 +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v1\.1\.0-pre$' + +# v1.0.1-0.pseudo +go get ...test.git@fa4f5d6 +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v1\.0\.1-0\.\d{14}-fa4f5d6a71c6$' + +# v1.0.0 +go get ...test.git@7fff7f3 +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v1\.0\.0$' + +# v0.0.0-pseudo +go get ...test.git@52853eb +go list -m all +stdout '^vcs-test.golang.org/git/legacytest.git v0\.0\.0-\d{14}-52853eb7b552$' + +-- go.mod -- +module x +-- x.go -- +package x +import "vcs-test.golang.org/git/legacytest.git" diff --git a/go/src/cmd/go/testdata/script/mod_get_pseudo_hg.txt b/go/src/cmd/go/testdata/script/mod_get_pseudo_hg.txt new file mode 100644 index 0000000000000000000000000000000000000000..308fa621c13f7d6a52540df5a5e069112cf87a5d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_pseudo_hg.txt @@ -0,0 +1,81 @@ +env GO111MODULE=on + +[!exec:hg] skip +[short] skip + +# Testing hg->module converter's generation of +incompatible tags; turn off proxy. +env GOPROXY=direct +env GOSUMDB=off + +# get default +go get vcs-test.golang.org/hg/legacytest.hg@default +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v1\.2\.1-0\.20180717164942-2840708d1294$' + +# get should include incompatible tags in "latest" calculation. +go mod edit -droprequire vcs-test.golang.org/hg/legacytest.hg +go get vcs-test.golang.org/hg/legacytest.hg@latest +go list +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v2\.0\.0\+incompatible$' + +# v2.0.1-0.pseudo+incompatible +go get ...test.hg@d6ad6040 +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v2\.0\.1-0\.\d{14}-d6ad604046f6\+incompatible$' + +# v2.0.0+incompatible by tag+incompatible +go get ...test.hg@v2.0.0+incompatible +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v2\.0\.0\+incompatible$' + +# v2.0.0+incompatible by tag +go get ...test.hg@v2.0.0 +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v2\.0\.0\+incompatible$' + +# v2.0.0+incompatible by hash (back on master) +go get ...test.hg@e64782f +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v2\.0\.0\+incompatible$' + +# v1.2.1-0.pseudo +go get ...test.hg@ed9a22e +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v1\.2\.1-0\.\d{14}-ed9a22ebb8a1$' + +# v1.2.0 +go get ...test.hg@07462d +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v1\.2\.0$' + +# v1.1.0-pre.0.pseudo +go get ...test.hg@accb16 +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v1\.1\.0-pre\.0\.\d{14}-accb169a3696$' + +# v1.1.0-pre (no longer on master) +go get ...test.hg@90da67a9 +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v1\.1\.0-pre$' + +# v1.0.1-0.pseudo +go get ...test.hg@c6260a +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v1\.0\.1-0\.\d{14}-c6260ab8dc3e$' + +# v1.0.0 +go get ...test.hg@d6ad17 +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v1\.0\.0$' + +# v0.0.0-pseudo +go get ...test.hg@ee0106d +go list -m all +stdout '^vcs-test.golang.org/hg/legacytest.hg v0\.0\.0-\d{14}-ee0106da3c7c$' + +-- go.mod -- +module x +-- x.go -- +package x +import "vcs-test.golang.org/hg/legacytest.hg" diff --git a/go/src/cmd/go/testdata/script/mod_get_pseudo_other_branch.txt b/go/src/cmd/go/testdata/script/mod_get_pseudo_other_branch.txt new file mode 100644 index 0000000000000000000000000000000000000000..6019b45a2c8be4260d9c5d9d82f001918c4c3a30 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_pseudo_other_branch.txt @@ -0,0 +1,67 @@ +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +# Testing that a pseudo-version is based on the semantically-latest +# tag that appears in any commit that is a (transitive) parent of the commit +# supplied to 'go get', regardless of branches + +[short] skip +[!git] skip + +# For this test repository: +# tag v0.2.1 is most recent tag on master itself +# tag v0.2.2 is on branch2, which was then merged to master +# master is a merge commit with both tags as parents +# +# The pseudo-version hence sorts immediately after v0.2.2 rather +# than v0.2.1, even though the v0.2.2 tag is not on master. + +go get vcs-test.golang.org/git/tagtests.git@master +go list -m all +stdout '^vcs-test.golang.org/git/tagtests.git v0.2.3-0\.' + +-- go.mod -- +module x + +go 1.12 +-- x.go -- +package x + +import _ "vcs-test.golang.org/git/tagtests.git" +-- gen_testtags.sh -- +#!/bin/bash + +# This is not part of the test. +# Run this to generate and update the repository on vcs-test.golang.org. + +set -euo pipefail +cd "$(dirname "$0")" +rm -rf tagtests +mkdir tagtests +cd tagtests + +git init +echo module vcs-test.golang.org/git/tagtests.git >go.mod +echo package tagtests >tagtests.go +git add go.mod tagtests.go +git commit -m 'create module tagtests' + +git branch b + +echo v0.2.1 >v0.2.1 +git add v0.2.1 +git commit -m v0.2.1 +git tag v0.2.1 + +git checkout b +echo v0.2.2 >v0.2.2 +git add v0.2.2 +git commit -m v0.2.2 +git tag v0.2.2 + +git checkout master +git merge b -m merge + +zip -r ../tagtests.zip . +gsutil cp ../tagtests.zip gs://vcs-test/git/tagtests.zip diff --git a/go/src/cmd/go/testdata/script/mod_get_pseudo_prefix.txt b/go/src/cmd/go/testdata/script/mod_get_pseudo_prefix.txt new file mode 100644 index 0000000000000000000000000000000000000000..ac3233e040656b12de49ce3e33c3f259c7cd5f6d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_pseudo_prefix.txt @@ -0,0 +1,64 @@ +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +# Testing that a pseudo-version is based on the semantically-latest +# prefixed tag in any commit that is a parent of the commit supplied +# to 'go get', when using a repo with go.mod in a sub directory. + +[short] skip +[!git] skip + +# For this test repository go.mod resides in sub/ (only): +# master is not tagged +# tag v0.2.0 is most recent tag before master +# tag sub/v0.0.10 is most recent tag before v0.2.0 +# +# The pseudo-version is based on sub/v0.0.10, since v0.2.0 doesn't +# contain the prefix. +go get vcs-test.golang.org/git/prefixtagtests.git/sub +go list -m all +stdout '^vcs-test.golang.org/git/prefixtagtests.git/sub v0.0.10$' + +go get -u vcs-test.golang.org/git/prefixtagtests.git/sub@master +go list -m all +stdout '^vcs-test.golang.org/git/prefixtagtests.git/sub v0.0.11-0\.' + +-- go.mod -- +module x + +go 1.12 +-- x.go -- +package x + +import _ "vcs-test.golang.org/prefixtagtests.git/sub" +-- gen_prefixtagtests.sh -- +#!/bin/bash + +# This is not part of the test. +# Run this to generate and update the repository on vcs-test.golang.org. + +set -euo pipefail +cd "$(dirname "$0")" +rm -rf prefixtagtests +mkdir prefixtagtests +cd prefixtagtests + +git init +mkdir sub +echo module vcs-test.golang.org/git/prefixtagtests.git/sub >sub/go.mod +echo package sub >sub/sub.go +git add sub +git commit -m 'create module sub' +for i in v0.1.0 sub/v0.0.9 sub/v0.0.10 v0.2.0; do + echo $i >status + git add status + git commit -m $i + git tag $i +done +echo 'after last tag' >status +git add status +git commit -m 'after last tag' + +zip -r ../prefixtagtests.zip . +gsutil cp ../prefixtagtests.zip gs://vcs-test/git/prefixtagtests.zip diff --git a/go/src/cmd/go/testdata/script/mod_get_replaced.txt b/go/src/cmd/go/testdata/script/mod_get_replaced.txt new file mode 100644 index 0000000000000000000000000000000000000000..c31d5be4ef9dde3a4301f40607d5e88884b6cd36 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_replaced.txt @@ -0,0 +1,111 @@ +cp go.mod go.mod.orig + +env oldGOPROXY=$GOPROXY + +# If a wildcard replacement exists for an otherwise-nonexistent module, +# 'go get' should resolve it to the minimum valid pseudo-version. + +go mod edit -replace=example.com/x=./x +go get example.com/x + +go list -m example.com/x +stdout '^example.com/x v0.0.0-00010101000000-000000000000 ' + +# If specific-version replacements exist, the highest matching version should be used. +go mod edit -replace=example.com/x@v0.1.0=./x +go mod edit -replace=example.com/x@v0.2.0=./x + +go get example.com/x +go list -m example.com/x +stdout '^example.com/x v0.2.0 ' + +go get example.com/x@v1.3.1 +go list -m rsc.io/quote +stdout '^rsc.io/quote v1.4.0' + + +# Replacements should allow 'go get' to work even with dotless module paths. + +cp go.mod.orig go.mod + +! go list example +stderr '^package example is not in std \(.*\)$' +! go get example +stderr '^go: malformed module path "example": missing dot in first path element$' + +go mod edit -replace example@v0.1.0=./example + +! go list example +stderr '^module example provides package example and is replaced but not required; to add it:\n\tgo get example@v0.1.0$' + +go get example +go list -m example +stdout '^example v0.1.0 ' + + +-- go.mod -- +module example.com + +go 1.16 +-- x/go.mod -- +module example.com/x + +go 1.16 +-- x/x.go -- +package x +-- example/go.mod -- +module example +go 1.16 +-- example/example.go -- +package example diff --git a/go/src/cmd/go/testdata/script/mod_get_retract.txt b/go/src/cmd/go/testdata/script/mod_get_retract.txt new file mode 100644 index 0000000000000000000000000000000000000000..9757989666728eb3050c3c63a8cd37fce848f6cb --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_retract.txt @@ -0,0 +1,59 @@ +# 'go get pkg' should not upgrade to a retracted version. +cp go.mod.orig go.mod +go mod edit -require example.com/retract/self/prev@v1.1.0 +go get example.com/retract/self/prev +go list -m example.com/retract/self/prev +stdout '^example.com/retract/self/prev v1.1.0$' + +# 'go get pkg' should not downgrade from a retracted version when no higher +# version is available. +cp go.mod.orig go.mod +go mod edit -require example.com/retract/self/prev@v1.9.0 +go get example.com/retract/self/prev +stderr '^go: warning: example.com/retract/self/prev@v1.9.0: retracted by module author: self$' +stderr '^go: to switch to the latest unretracted version, run:\n\tgo get example.com/retract/self/prev@latest\n$' +go list -m example.com/retract/self/prev +stdout '^example.com/retract/self/prev v1.9.0$' + +# 'go get pkg@latest' should downgrade from a retracted version. +cp go.mod.orig go.mod +go mod edit -require example.com/retract/self/prev@v1.9.0 +go get example.com/retract/self/prev@latest +go list -m example.com/retract/self/prev +stdout '^example.com/retract/self/prev v1.1.0$' + +# 'go get pkg@version' should update to a specific version, even if that +# version is retracted. +cp go.mod.orig go.mod +go get example.com/retract@v1.0.0-bad +stderr '^go: warning: example.com/retract@v1.0.0-bad: retracted by module author: bad$' +go list -m example.com/retract +stdout '^example.com/retract v1.0.0-bad$' + +# 'go get -u' should not downgrade from a retracted version when no higher +# version is available. +cp go.mod.orig go.mod +go mod edit -require example.com/retract/self/prev@v1.9.0 +go get -u ./use +stderr '^go: warning: example.com/retract/self/prev@v1.9.0: retracted by module author: self$' +go list -m example.com/retract/self/prev +stdout '^example.com/retract/self/prev v1.9.0$' + +# 'go get' should warn if a module needed to build named packages is retracted. +# 'go get' should not warn about unrelated modules. +go get ./empty +! stderr retracted +go get ./use +stderr '^go: warning: example.com/retract/self/prev@v1.9.0: retracted by module author: self$' + +-- go.mod.orig -- +module example.com/use + +go 1.15 + +-- use/use.go -- +package use + +import _ "example.com/retract/self/prev" +-- empty/empty.go -- +package empty diff --git a/go/src/cmd/go/testdata/script/mod_get_retract_ambiguous.txt b/go/src/cmd/go/testdata/script/mod_get_retract_ambiguous.txt new file mode 100644 index 0000000000000000000000000000000000000000..4b4f5da03cdba618d7abed6d297c71af5572f8e9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_retract_ambiguous.txt @@ -0,0 +1,10 @@ +! go get example.com/retract/ambiguous/other +stderr 'ambiguous import: found package example.com/retract/ambiguous/nested in multiple modules:' +stderr '^go: warning: example.com/retract/ambiguous/nested@v1.9.0-bad: retracted by module author: nested modules are bad$' + +-- go.mod -- +module example.com/use + +go 1.16 + +require example.com/retract/ambiguous/nested v1.9.0-bad diff --git a/go/src/cmd/go/testdata/script/mod_get_split.txt b/go/src/cmd/go/testdata/script/mod_get_split.txt new file mode 100644 index 0000000000000000000000000000000000000000..6c2f00d37e11a108bfbfeaad33dd1e91d0693230 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_split.txt @@ -0,0 +1,157 @@ +cp go.mod go.mod.orig + + +# 'go get' on a package already provided by the build list should update +# the module already in the build list, not fail with an ambiguous import error. + +go get example.net/split/nested@patch +go list -m all +stdout '^example.net/split v0.2.1 ' +! stdout '^example.net/split/nested' + +# We should get the same behavior if we use a pattern that matches only that package. + +cp go.mod.orig go.mod + +go get example.net/split/nested/...@patch +go list -m all +stdout '^example.net/split v0.2.1 ' +! stdout '^example.net/split/nested' + + +# If we request a version for which the package only exists in one particular module, +# we should add that one particular module but not resolve import ambiguities. +# +# In particular, if the module that previously provided the package has a +# matching version, but does not itself match the pattern and contains no +# matching packages, we should not change its version. (We should *not* downgrade +# module example.net/split to v0.1.0, despite the fact that +# example.net/split v0.2.0 currently provides the package with the requested path.) +# +# TODO(#27899): Maybe we should resolve the ambiguities by upgrading. + +cp go.mod.orig go.mod + +! go get example.net/split/nested@v0.1.0 +stderr '^go: example.net/split/nested: ambiguous import: found package example.net/split/nested in multiple modules:\n\texample.net/split v0.2.0 \(.*split.2[/\\]nested\)\n\texample.net/split/nested v0.1.0 \(.*nested.1\)$' + +# A wildcard that matches packages in some module at its selected version +# but not at the requested version should fail. +# +# We can't set the module to the selected version, because that version doesn't +# even match the query: if we ran the same query twice, we wouldn't consider the +# module to match the wildcard during the second call, so why should we consider +# it to match during the first one? ('go get' should be idempotent, and if we +# did that then it would not be.) +# +# But we also can't leave it where it is: the user requested that we set everything +# matching the pattern to the given version, and right now we have packages +# that match the pattern but *not* the version. +# +# That only leaves two options: we can set the module to an arbitrary version +# (perhaps 'latest' or 'none'), or we can report an error and the let the user +# disambiguate. We would rather not choose arbitrarily, so we do the latter. +# +# TODO(#27899): Should we instead upgrade or downgrade to an arbitrary version? + +! go get example.net/split/nested/...@v0.1.0 +stderr '^go: example.net/split/nested/\.\.\.@v0.1.0 matches packages in example.net/split@v0.2.0 but not example.net/split@v0.1.0: specify a different version for module example.net/split$' + +cmp go.mod go.mod.orig + + +# If another argument resolves the ambiguity, we should be ok again. + +go get example.net/split@none example.net/split/nested@v0.1.0 +go list -m all +! stdout '^example.net/split ' +stdout '^example.net/split/nested v0.1.0 ' + +cp go.mod.orig go.mod + +go get example.net/split@v0.3.0 example.net/split/nested@v0.1.0 +go list -m all +stdout '^example.net/split v0.3.0 ' +stdout '^example.net/split/nested v0.1.0 ' + + +# If a pattern applies to modules and to packages, we should set all matching +# modules to the version indicated by the pattern, and also resolve packages +# to match the pattern if possible. + +cp go.mod.orig go.mod +go get example.net/split/nested@v0.0.0 + +go get example.net/...@v0.1.0 +go list -m all +stdout '^example.net/split v0.1.0 ' +stdout '^example.net/split/nested v0.1.0 ' + +go get example.net/... +go list -m all +stdout '^example.net/split v0.3.0 ' +stdout '^example.net/split/nested v0.2.0 ' + + +# @none applies to all matching module paths, +# regardless of whether they contain any packages. + +go get example.net/...@none +go list -m all +! stdout '^example.net' + +# Starting from no dependencies, a wildcard can resolve to an empty module with +# the same prefix even if it contains no packages. + +go get example.net/...@none +go get example.net/split/...@v0.1.0 +go list -m all +stdout '^example.net/split v0.1.0 ' + + +-- go.mod -- +module m + +go 1.16 + +require example.net/split v0.2.0 + +replace ( + example.net/split v0.1.0 => ./split.1 + example.net/split v0.2.0 => ./split.2 + example.net/split v0.2.1 => ./split.2 + example.net/split v0.3.0 => ./split.3 + example.net/split/nested v0.0.0 => ./nested.0 + example.net/split/nested v0.1.0 => ./nested.1 + example.net/split/nested v0.2.0 => ./nested.2 +) +-- split.1/go.mod -- +module example.net/split + +go 1.16 +-- split.2/go.mod -- +module example.net/split + +go 1.16 +-- split.2/nested/nested.go -- +package nested +-- split.3/go.mod -- +module example.net/split + +go 1.16 +-- nested.0/go.mod -- +module example.net/split/nested + +go 1.16 +-- nested.1/go.mod -- +module example.net/split/nested + +go 1.16 +-- nested.1/nested.go -- +package nested +-- nested.2/go.mod -- +module example.net/split/nested + +go 1.16 +-- nested.2/nested.go -- +package nested diff --git a/go/src/cmd/go/testdata/script/mod_get_subdir.txt b/go/src/cmd/go/testdata/script/mod_get_subdir.txt new file mode 100644 index 0000000000000000000000000000000000000000..d31ecda881266d436f01805f3752e310d9ba5ec8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_subdir.txt @@ -0,0 +1,77 @@ +# golang.org/issue/34055 +# Starting in Go 1.25, go-import meta tag support an optional subdirectory paramater. +# The corresponding go-import meta tag is specified as +# +# and contains the module in vcs-test.golang.org/git/gitreposubdir/foo/subdir. +# See testdata/vcstest/go/gitreposubdir.txt and testdata/vcstest/git/gitreposubdir.txt + +[short] skip 'builds a go program' +[!git] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +# Get the module without having to specify the subdir. +cd a +cp go.mod go.mod.orig +go get vcs-test.golang.org/go/gitreposubdir@v1.2.3 +exists $GOPATH/pkg/mod/vcs-test.golang.org/go/gitreposubdir@v1.2.3 +go get vcs-test.golang.org/go/gitreposubdirv2/v2@v2.0.0 +exists $GOPATH/pkg/mod/vcs-test.golang.org/go/gitreposubdirv2/v2@v2.0.0 + +# Import the module without having to specify the subdir. +cp go.mod.orig go.mod +go mod tidy + +# Run main.go which has the import. +go run main.go +stdout 'hello, world' +stdout 'hello, world v2' + +# Fail if subdir is specified in get. +! go get vcs-test.golang.org/go/gitreposubdir/foo/subdir +stderr 'module vcs-test.golang.org/go/gitreposubdir@upgrade found \(v1.2.3\), but does not contain package vcs-test.golang.org/go/gitreposubdir/foo/subdir' +! go get vcs-test.golang.org/go/gitreposubdirv2/v2/foo/subdir +stderr 'module vcs-test.golang.org/go/gitreposubdirv2/v2@upgrade found \(v2.0.0\), but does not contain package vcs-test.golang.org/go/gitreposubdirv2/v2/foo/subdir' + +# Fail if subdir is specified in the import. +cd ../b +! go mod tidy +stderr 'module vcs-test.golang.org/go/gitreposubdir@latest found \(v1.2.3\), but does not contain package vcs-test.golang.org/go/gitreposubdir/foo/subdir' +stderr 'module vcs-test.golang.org/go/gitreposubdirv2/v2@latest found \(v2.0.0\), but does not contain package vcs-test.golang.org/go/gitreposubdirv2/v2/foo/subdir' + +-- a/main.go -- +package main + +import ( + "fmt" + "vcs-test.golang.org/go/gitreposubdir" + "vcs-test.golang.org/go/gitreposubdirv2/v2" +) + +func main() { + fmt.Println(greeter.Hello()) + fmt.Println(greeterv2.Hello()) +} +-- a/go.mod -- +module example + +go 1.24 +-- b/main.go -- +package main + +import ( + "fmt" + "vcs-test.golang.org/go/gitreposubdir/foo/subdir" + "vcs-test.golang.org/go/gitreposubdirv2/v2/foo/subdir" +) + +func main() { + fmt.Println(greeter.Hello()) + fmt.Println(greeterv2.Hello()) +} +-- b/go.mod -- +module example + +go 1.24 diff --git a/go/src/cmd/go/testdata/script/mod_get_sum_noroot.txt b/go/src/cmd/go/testdata/script/mod_get_sum_noroot.txt new file mode 100644 index 0000000000000000000000000000000000000000..0d9a840e779cc4334544df743213f67ea58b5cc7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_sum_noroot.txt @@ -0,0 +1,11 @@ +# When 'go get' is invoked on a module without a package in the root directory, +# it should add sums for the module's go.mod file and its content to go.sum. +# Verifies golang.org/issue/41103. +go mod init m +go get rsc.io/QUOTE +grep '^rsc.io/QUOTE v1.5.2/go.mod ' go.sum +grep '^rsc.io/QUOTE v1.5.2 ' go.sum + +# Double-check rsc.io/QUOTE does not have a root package. +! go list -mod=readonly rsc.io/QUOTE +stderr '^cannot find module providing package rsc.io/QUOTE: import lookup disabled by -mod=readonly$' diff --git a/go/src/cmd/go/testdata/script/mod_get_tags.txt b/go/src/cmd/go/testdata/script/mod_get_tags.txt new file mode 100644 index 0000000000000000000000000000000000000000..e4fb6c4326b46f52a14b4d8316896a9e18e0d5ce --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_tags.txt @@ -0,0 +1,34 @@ +env GO111MODULE=on + +# get should add modules needed to build packages, even if those +# dependencies are in sources excluded by build tags. +# All build tags are considered true except "ignore". +go mod init m +go get . +go list -m all +stdout 'example.com/version v1.1.0' +stdout 'rsc.io/quote v1.5.2' + +-- empty.go -- +package m + +-- excluded.go -- +// +build windows,mips + +package m + +import _ "example.com/version" + +-- tools.go -- +// +build tools + +package tools + +import _ "rsc.io/quote" + +-- ignore.go -- +// +build ignore + +package ignore + +import _ "example.com/doesnotexist" diff --git a/go/src/cmd/go/testdata/script/mod_get_test.txt b/go/src/cmd/go/testdata/script/mod_get_test.txt new file mode 100644 index 0000000000000000000000000000000000000000..0fa7cd98b98fb2fd0f38d08d35ce27b0503a6484 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_test.txt @@ -0,0 +1,58 @@ +env GO111MODULE=on + +# By default, 'go get' should ignore tests +cp go.mod.empty go.mod +go get m/a +! grep rsc.io/quote go.mod + +# 'go get -t' should consider test dependencies of the named package. +cp go.mod.empty go.mod +go get -t m/a +grep 'rsc.io/quote v1.5.2$' go.mod + +# 'go get -t' should not consider test dependencies of imported packages, +# including packages imported from tests. +cp go.mod.empty go.mod +go get -t m/b +! grep rsc.io/quote go.mod + +# 'go get -t -u' should update test dependencies of the named package. +cp go.mod.empty go.mod +go mod edit -require=rsc.io/quote@v1.5.1 +go get -t -u m/a +grep 'rsc.io/quote v1.5.2$' go.mod + +# 'go get -t -u' should not add or update test dependencies +# of imported packages, including packages imported from tests. +cp go.mod.empty go.mod +go get -t -u m/b +! grep rsc.io/quote go.mod +go mod edit -require=rsc.io/quote@v1.5.1 +go get -t -u m/b +grep 'rsc.io/quote v1.5.1$' go.mod + +# 'go get all' should consider test dependencies with or without -t. +cp go.mod.empty go.mod +go get all +grep 'rsc.io/quote v1.5.2$' go.mod + +-- go.mod.empty -- +module m + +-- a/a.go -- +package a + +-- a/a_test.go -- +package a_test + +import _ "rsc.io/quote" + +-- b/b.go -- +package b + +import _ "m/a" + +-- b/b_test.go -- +package b_test + +import _ "m/a" diff --git a/go/src/cmd/go/testdata/script/mod_get_tool.txt b/go/src/cmd/go/testdata/script/mod_get_tool.txt new file mode 100644 index 0000000000000000000000000000000000000000..15f4db90968e1c1577dd99fd1f8c71330847f09d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_tool.txt @@ -0,0 +1,81 @@ +# test go get -tool +go get -tool example.com/tools/cmd/hello@v1.0.0 +cmp go.mod go.mod.want + +go get -u tool +cmp go.mod go.mod.upgraded + +# test -tool with @none +go get -tool example.com/tools/cmd/hello@none +cmp go.mod go.mod.gone + +go mod tidy +cmp go.mod go.mod.empty + +# test -tool with wildcards +go get -tool ./cmd/... +cmp go.mod go.mod.wildcard +! go get -tool ./cmd/...@none +stderr 'can''t request explicit version "none" of path "./cmd/..." in main module' + +# test -tool with all +! go get -tool all +stderr 'go get -tool does not work with "all"' + +# test tool@none +! go get tool@none +stderr 'can''t request explicit version of "tool" pattern' + +-- main.go -- +package main + +func main() {} + +-- go.mod -- +module example.com/foo +go 1.24 + +-- go.mod.want -- +module example.com/foo + +go 1.24 + +tool example.com/tools/cmd/hello + +require example.com/tools v1.0.0 // indirect +-- go.mod.upgraded -- +module example.com/foo + +go 1.24 + +tool example.com/tools/cmd/hello + +require example.com/tools v1.1.0 // indirect +-- go.mod.gone -- +module example.com/foo + +go 1.24 + +require example.com/tools v1.1.0 // indirect +-- go.mod.empty -- +module example.com/foo + +go 1.24 +-- go.mod.wildcard -- +module example.com/foo + +go 1.24 + +tool ( + example.com/foo/cmd/a + example.com/foo/cmd/b +) +-- cmd/a/a.go -- +package a + +func main() {} + +-- cmd/b/b.go -- +package b + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_get_tool_issue74035.txt b/go/src/cmd/go/testdata/script/mod_get_tool_issue74035.txt new file mode 100644 index 0000000000000000000000000000000000000000..d6fa592c7b27269af01232b729876ea1dd7fb768 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_tool_issue74035.txt @@ -0,0 +1,25 @@ +# Regression test for https://go.dev/issue/74035. +go get -tool example.com/foo/cmd/a example.com/foo/cmd/b +cmp go.mod go.mod.want + +-- go.mod -- +module example.com/foo +go 1.24 +-- go.mod.want -- +module example.com/foo + +go 1.24 + +tool ( + example.com/foo/cmd/a + example.com/foo/cmd/b +) +-- cmd/a/a.go -- +package a + +func main() {} + +-- cmd/b/b.go -- +package b + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_get_toolchain.txt b/go/src/cmd/go/testdata/script/mod_get_toolchain.txt new file mode 100644 index 0000000000000000000000000000000000000000..83cef4a0fd0c5edd16ac426a3407829cd1413aaf --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_toolchain.txt @@ -0,0 +1,136 @@ +# setup +env TESTGO_VERSION=go1.99rc1 +env TESTGO_VERSION_SWITCH=switch + +# go get go should use the latest Go 1.23 +cp go.mod.orig go.mod +go get go +stderr '^go: upgraded go 1.21 => 1.23.9$' +grep 'go 1.23.9' go.mod +! grep toolchain go.mod + +# go get go@1.23 should use the latest Go 1.23 +cp go.mod.orig go.mod +go get go@1.23 +stderr '^go: upgraded go 1.21 => 1.23.9$' +grep 'go 1.23.9' go.mod +! grep toolchain go.mod + +# go get go@1.22 should use the latest Go 1.22 +cp go.mod.orig go.mod +go get go@1.22 +stderr '^go: upgraded go 1.21 => 1.22.9$' +grep 'go 1.22.9' go.mod +! grep toolchain1 go.mod + +# go get go@patch should use the latest patch release +go get go@1.22.1 +go get go@patch +stderr '^go: upgraded go 1.22.1 => 1.22.9$' +grep 'go 1.22.9' go.mod +! grep toolchain go.mod + +# go get go@1.24 does NOT find the release candidate +cp go.mod.orig go.mod +! go get go@1.24 +stderr '^go: go@1.24: no matching versions for query "1.24"$' + +# go get go@1.24rc1 works +cp go.mod.orig go.mod +go get go@1.24rc1 +stderr '^go: upgraded go 1.21 => 1.24rc1$' +grep 'go 1.24rc1' go.mod +! grep toolchain go.mod + +# go get go@latest finds the latest Go 1.23 +cp go.mod.orig go.mod +go get go@latest +stderr '^go: upgraded go 1.21 => 1.23.9$' +grep 'go 1.23.9' go.mod +! grep toolchain go.mod + +# Again, with toolchains. + +go get toolchain@go1.99rc1 +stderr '^go: added toolchain go1.99rc1$' +grep 'go 1.23.9' go.mod +grep 'toolchain go1.99rc1' go.mod + +# go get toolchain should find go1.999testmod. +go get toolchain +stderr '^go: upgraded toolchain go1.99rc1 => go1.999testmod$' +grep 'go 1.23.9' go.mod +grep 'toolchain go1.999testmod' go.mod + +# go get toolchain@go1.23 should use the latest Go 1.23 +go get toolchain@go1.23 +stderr '^go: removed toolchain go1.999testmod$' +grep 'go 1.23.9' go.mod +! grep 'toolchain go1.23.9' go.mod # implied + +# go get toolchain@go1.22 should use the latest Go 1.22 and downgrade go. +go get toolchain@go1.22 +stderr '^go: downgraded go 1.23.9 => 1.22.9$' +grep 'go 1.22.9' go.mod +! grep 'toolchain go1.22.9' go.mod # implied + +# go get toolchain@patch should use the latest patch release +go get toolchain@go1.22.1 +go get toolchain@patch +stderr '^go: added toolchain go1.22.9$' +grep 'go 1.22.1' go.mod +grep 'toolchain go1.22.9' go.mod +go get go@1.22.9 toolchain@none +grep 'go 1.22.9' go.mod +! grep 'toolchain go1.22.9' go.mod + +# go get toolchain@go1.24 does NOT find the release candidate +! go get toolchain@go1.24 +stderr '^go: toolchain@go1.24: no matching versions for query "go1.24"$' + +# go get toolchain@go1.24rc1 works +go get toolchain@go1.24rc1 +stderr '^go: added toolchain go1.24rc1$' +grep 'go 1.22.9' go.mod # no longer implied +grep 'toolchain go1.24rc1' go.mod + +# go get toolchain@latest finds go1.23.9. +cp go.mod.orig go.mod +go get toolchain@latest +stderr '^go: added toolchain go1.23.9$' +grep 'go 1.21' go.mod +grep 'toolchain go1.23.9' go.mod + + + +# Bug fixes. + +# go get go@garbage should fail but not crash +! go get go@garbage +! stderr panic +stderr '^go: invalid go version garbage$' + +# go get go@go1.21.0 is OK - we silently correct to 1.21.0 +go get go@1.19 +go get go@go1.21.0 +stderr '^go: upgraded go 1.19 => 1.21.0' + +# go get toolchain@1.24rc1 is OK too. +go get toolchain@1.24rc1 +stderr '^go: upgraded toolchain go1.23.9 => go1.24rc1$' + +# go get go@1.21 should work if we are the Go 1.21 language version, +# even though there's no toolchain for it. +# (Older versions resolve to the latest release in that version, so for example +# go get go@1.20 might resolve to 1.20.9, but if we're the devel copy of +# Go 1.21, there's no release yet to resolve to, so we resolve to ourselves.) +env TESTGO_VERSION=go1.21 +go get go@1.19 toolchain@none +go get go@1.21 +grep 'go 1.21$' go.mod +! grep toolchain go.mod + +-- go.mod.orig -- +module m + +go 1.21 diff --git a/go/src/cmd/go/testdata/script/mod_get_trailing_slash.txt b/go/src/cmd/go/testdata/script/mod_get_trailing_slash.txt new file mode 100644 index 0000000000000000000000000000000000000000..7b469008baffd414014094578da7b0ee36618b3b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_trailing_slash.txt @@ -0,0 +1,30 @@ +# go list should succeed to load a package ending with ".go" if the path does +# not correspond to an existing local file. Listing a pattern ending with +# ".go/" should try to list a package regardless of whether a file exists at the +# path without the suffixed "/" or not. +go list example.com/dotgo.go +stdout ^example.com/dotgo.go$ +go list example.com/dotgo.go/ +stdout ^example.com/dotgo.go$ + +# go get should succeed in either case, with or without a version. +# Arguments are interpreted as packages or package patterns with versions, +# not source files. +go get example.com/dotgo.go +go get example.com/dotgo.go/ +go get example.com/dotgo.go@v1.0.0 +go get example.com/dotgo.go/@v1.0.0 + +-- go.mod -- +module m + +go 1.13 + +require example.com/dotgo.go v1.0.0 +-- go.sum -- +example.com/dotgo.go v1.0.0 h1:XKJfs0V8x2PvY2tX8bJBCEbCDLnt15ma2onwhVpew/I= +example.com/dotgo.go v1.0.0/go.mod h1:Qi6z/X3AC5vHiuMt6HF2ICx3KhIBGrMdrA7YoPDKqR0= +-- use.go -- +package use + +import _ "example.com/dotgo.go" diff --git a/go/src/cmd/go/testdata/script/mod_get_update_unrelated_sum.txt b/go/src/cmd/go/testdata/script/mod_get_update_unrelated_sum.txt new file mode 100644 index 0000000000000000000000000000000000000000..a5651e934181a70dc5e302193792fb939bbe4bd9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_update_unrelated_sum.txt @@ -0,0 +1,120 @@ +# Check that 'go get' adds sums for updated modules if we had sums before, +# even if we didn't load packages from them. +# Verifies #44129. + +env fmt='{{.ImportPath}}: {{if .Error}}{{.Error.Err}}{{else}}ok{{end}}' + +# Control case: before upgrading, we have the sums we need. +# go list -deps -e -f $fmt . +# stdout '^rsc.io/quote: ok$' +# ! stdout rsc.io/sampler # not imported by quote in this version +cp go.mod.orig go.mod +cp go.sum.orig go.sum +go mod tidy +cmp go.mod.orig go.mod +cmp go.sum.orig go.sum + + +# Upgrade a module. This also upgrades rsc.io/quote, and though we didn't load +# a package from it, we had the sum for its old version, so we need the +# sum for the new version, too. +go get example.com/upgrade@v0.0.2 +grep '^rsc.io/quote v1.5.2 ' go.sum + +# The upgrade still breaks the build because the new version of quote imports +# rsc.io/sampler, and we don't have its zip sum. +go list -deps -e -f $fmt +stdout 'rsc.io/quote: ok' +stdout 'rsc.io/sampler: missing go.sum entry for module providing package rsc.io/sampler' +cp go.mod.orig go.mod +cp go.sum.orig go.sum + + +# Replace the old version with a directory before upgrading. +# We didn't need a sum for it before (even though we had one), so we won't +# fetch a new sum. +go mod edit -replace rsc.io/quote@v1.0.0=./dummy +go get example.com/upgrade@v0.0.2 +! grep '^rsc.io/quote v1.5.2 ' go.sum +cp go.mod.orig go.mod +cp go.sum.orig go.sum + + +# Replace the new version with a directory before upgrading. +# We can't get a sum for a directory. +go mod edit -replace rsc.io/quote@v1.5.2=./dummy +go get example.com/upgrade@v0.0.2 +! grep '^rsc.io/quote v1.5.2 ' go.sum +cp go.mod.orig go.mod +cp go.sum.orig go.sum + + +# Replace the new version with a different version. +# We should get a sum for that version. +go mod edit -replace rsc.io/quote@v1.5.2=rsc.io/quote@v1.5.1 +go get example.com/upgrade@v0.0.2 +! grep '^rsc.io/quote v1.5.2 ' go.sum +grep '^rsc.io/quote v1.5.1 ' go.sum +cp go.mod.orig go.mod +cp go.sum.orig go.sum + + +# Delete the new version's zip (but not mod) from the cache and go offline. +# 'go get' should fail when fetching the zip. +rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip +env GOPROXY=off +! go get example.com/upgrade@v0.0.2 +stderr '^go: upgraded rsc.io/quote v1.0.0 => v1.5.2: error finding sum for rsc.io/quote@v1.5.2: module lookup disabled by GOPROXY=off$' + +-- go.mod.orig -- +module m + +go 1.16 + +require ( + example.com/upgrade v0.0.1 + rsc.io/quote v1.0.0 +) + +replace ( + example.com/upgrade v0.0.1 => ./upgrade1 + example.com/upgrade v0.0.2 => ./upgrade2 +) +-- go.sum.orig -- +rsc.io/quote v1.0.0 h1:kQ3IZQzPTiDJxSZI98YaWgxFEhlNdYASHvh+MplbViw= +rsc.io/quote v1.0.0/go.mod h1:v83Ri/njykPcgJltBc/gEkJTmjTsNgtO1Y7vyIK1CQA= +-- go.sum.want -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.0.0 h1:kQ3IZQzPTiDJxSZI98YaWgxFEhlNdYASHvh+MplbViw= +rsc.io/quote v1.0.0/go.mod h1:v83Ri/njykPcgJltBc/gEkJTmjTsNgtO1Y7vyIK1CQA= +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +-- use.go -- +package use + +import ( + _ "example.com/upgrade" + _ "rsc.io/quote" +) +-- upgrade1/go.mod -- +module example.com/upgrade + +go 1.16 +-- upgrade1/upgrade.go -- +package upgrade +-- upgrade2/go.mod -- +module example.com/upgrade + +go 1.16 + +require rsc.io/quote v1.5.2 // indirect +-- upgrade2/upgrade.go -- +package upgrade +-- dummy/go.mod -- +module rsc.io/quote + +go 1.16 +-- dummy/quote.go -- +package quote + diff --git a/go/src/cmd/go/testdata/script/mod_get_upgrade.txt b/go/src/cmd/go/testdata/script/mod_get_upgrade.txt new file mode 100644 index 0000000000000000000000000000000000000000..51d5990ee179c73a90bcd42661a29f764313a813 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_upgrade.txt @@ -0,0 +1,46 @@ +env GO111MODULE=on + +go get rsc.io/quote@v1.5.1 +go list -m all +stdout 'rsc.io/quote v1.5.1' +grep 'rsc.io/quote v1.5.1$' go.mod + +# get -u should update dependencies of the package in the current directory +go get -u +grep 'rsc.io/quote v1.5.2$' go.mod +grep 'golang.org/x/text [v0-9a-f\.-]+ // indirect' go.mod + +# get -u rsc.io/sampler should update only sampler's dependencies +cp go.mod-v1.5.1 go.mod +go get -u rsc.io/sampler +grep 'rsc.io/quote v1.5.1$' go.mod +grep 'golang.org/x/text [v0-9a-f\.-]+ // indirect' go.mod + +# move to a pseudo-version after any tags +go get rsc.io/quote@dd9747d +grep 'rsc.io/quote v0.0.0-20180628003336-dd9747d19b04' go.mod + +# get -u should not jump off newer pseudo-version to earlier tag +go get -u +grep 'rsc.io/quote v0.0.0-20180628003336-dd9747d19b04' go.mod + +# move to earlier pseudo-version +go get rsc.io/quote@e7a685a342 +grep 'rsc.io/quote v0.0.0-20180214005133-e7a685a342c0' go.mod + +# get -u should jump off earlier pseudo-version to newer tag +go get -u +grep 'rsc.io/quote v1.5.2' go.mod + +-- go.mod -- +module x +require rsc.io/quote v1.1.0 + +-- go.mod-v1.5.1 -- +module x +require rsc.io/quote v1.5.1 + +-- use.go -- +package use + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_get_upgrade_pseudo.txt b/go/src/cmd/go/testdata/script/mod_get_upgrade_pseudo.txt new file mode 100644 index 0000000000000000000000000000000000000000..deff9358f060f462a74c0ab349a97139d553202e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_upgrade_pseudo.txt @@ -0,0 +1,70 @@ +env GO111MODULE=on + +# For this test module there are three versions: +# * v0.1.1-0.20190429073117-b5426c86b553 +# * v0.1.0 +# * v0.0.0-20190430073000-30950c05d534 +# Only v0.1.0 is tagged. +# +# The v0.1.1 pseudo-version is semantically higher than the latest tag. +# The v0.0.0 pseudo-version is chronologically newer. + +# Start at v0.1.1-0.20190429073117-b5426c86b553 +go get example.com/pseudoupgrade@b5426c8 +go list -m -u all +stdout '^example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553$' + +# 'get -u' should not downgrade to the (lower) tagged version. +go get -u +go list -m -u all +stdout '^example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553$' + +# 'get example.com/pseudoupgrade@upgrade' should not downgrade. +go get example.com/pseudoupgrade@upgrade +go list -m all +stdout '^example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553$' + +# 'get example.com/pseudoupgrade' should not downgrade. +# This is equivalent to 'get example.com/pseudoupgrade@upgrade'. +go get example.com/pseudoupgrade +go list -m all +stdout '^example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553$' + +# 'get example.com/pseudoupgrade@latest' should downgrade. +# @latest should not consider the current version. +go get example.com/pseudoupgrade@latest +go list -m all +stdout '^example.com/pseudoupgrade v0.1.0$' + +# We should observe the same behavior with the newer pseudo-version. +go get example.com/pseudoupgrade@v0.0.0-20190430073000-30950c05d534 + +# 'get -u' should not downgrade to the chronologically older tagged version. +go get -u +go list -m -u all +stdout '^example.com/pseudoupgrade v0.0.0-20190430073000-30950c05d534$' + +# 'get example.com/pseudoupgrade@upgrade should not downgrade. +go get example.com/pseudoupgrade@upgrade +go list -m -u all +stdout '^example.com/pseudoupgrade v0.0.0-20190430073000-30950c05d534$' + +# 'get example.com/pseudoupgrade' should not downgrade. +go get example.com/pseudoupgrade +go list -m -u all +stdout '^example.com/pseudoupgrade v0.0.0-20190430073000-30950c05d534$' + +# 'get example.com/pseudoupgrade@latest' should downgrade. +go get example.com/pseudoupgrade@latest +go list -m -u all +stdout '^example.com/pseudoupgrade v0.1.0$' + +-- go.mod -- +module x + +go 1.12 + +-- main.go -- +package x + +import _ "example.com/pseudoupgrade" diff --git a/go/src/cmd/go/testdata/script/mod_get_wild.txt b/go/src/cmd/go/testdata/script/mod_get_wild.txt new file mode 100644 index 0000000000000000000000000000000000000000..06f9973e431932f35923d937e0e3378247b9ad7a --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_wild.txt @@ -0,0 +1,95 @@ +# This test covers a crazy edge-case involving wildcards and multiple passes of +# patch-upgrades, but if we get it right we probably get many other edge-cases +# right too. + +go list -m all +stdout '^example.net/a v0.1.0 ' +! stdout '^example.net/b ' + + +# Requesting pattern example.../b by itself fails: there is no such module +# already in the build list, and the wildcard in the first element prevents us +# from attempting to resolve a new module whose path is a prefix of the pattern. + +! go get -u=patch example.../b@upgrade +stderr '^go: no modules to query for example\.\.\./b@upgrade because first path element contains a wildcard$' + + +# Patching . causes a patch to example.net/a, which introduces a new match +# for example.net/b/..., which is itself patched and causes another upgrade to +# example.net/a, which is then patched again. + +go get -u=patch . example.../b@upgrade +go list -m all +stdout '^example.net/a v0.2.1 ' # upgraded by dependency of b and -u=patch +stdout '^example.net/b v0.2.0 ' # introduced by patch of a and upgraded by wildcard + + +-- go.mod -- +module example + +go 1.16 + +require example.net/a v0.1.0 + +replace ( + example.net/a v0.1.0 => ./a10 + example.net/a v0.1.1 => ./a11 + example.net/a v0.2.0 => ./a20 + example.net/a v0.2.1 => ./a20 + example.net/b v0.1.0 => ./b1 + example.net/b v0.1.1 => ./b1 + example.net/b v0.2.0 => ./b2 +) +-- example.go -- +package example + +import _ "example.net/a" + +-- a10/go.mod -- +module example.net/a + +go 1.16 +-- a10/a.go -- +package a + +-- a11/go.mod -- +module example.net/a + +go 1.16 + +require example.net/b v0.1.0 +-- a11/a.go -- +package a +-- a11/unimported/unimported.go -- +package unimported + +import _ "example.net/b" + + +-- a20/go.mod -- +module example.net/a + +go 1.16 +-- a20/a.go -- +package a + +-- b1/go.mod -- +module example.net/b + +go 1.16 +-- b1/b.go -- +package b + +-- b2/go.mod -- +module example.net/b + +go 1.16 + +require example.net/a v0.2.0 +-- b2/b.go -- +package b +-- b2/b_test.go -- +package b_test + +import _ "example.net/a" diff --git a/go/src/cmd/go/testdata/script/mod_get_work.txt b/go/src/cmd/go/testdata/script/mod_get_work.txt new file mode 100644 index 0000000000000000000000000000000000000000..39c7ea6beba42afb5530a8ea038c10b5aba75569 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_work.txt @@ -0,0 +1,46 @@ +# Test go get with the work pattern. + +# go get work gets dependencies to satisfy missing imports in the +# main modules' package graph. Before the 'work' pattern existed, users +# would have to run './...' in the root of the work (main) module. +cp go.mod go.mod.orig +go get work +cmp go.mod go.mod.want + +# 'go get work' and 'go get all' behave very differently. Because +# 'all' evaluates to work packages but also to their dependencies, +# 'go get all' will run the 'get' logic on all the dependency module +# packages, bumping all their modules to the latest versions. +cp go.mod.orig go.mod +go get all +cmp go.mod go.mod.all.want +-- go.mod -- +module example.com/a + +go 1.25 +-- go.mod.want -- +module example.com/a + +go 1.25 + +require rsc.io/quote v1.5.2 + +require ( + golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect + rsc.io/sampler v1.3.0 // indirect +) +-- go.mod.all.want -- +module example.com/a + +go 1.25 + +require rsc.io/quote v1.5.2 + +require ( + golang.org/x/text v0.3.0 // indirect + rsc.io/sampler v1.99.99 // indirect +) +-- a.go -- +package a + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_get_workspace_incomplete.txt b/go/src/cmd/go/testdata/script/mod_get_workspace_incomplete.txt new file mode 100644 index 0000000000000000000000000000000000000000..89340ffb5735f1cf7450313ed9b105633627c189 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_get_workspace_incomplete.txt @@ -0,0 +1,385 @@ +# Enter the first set of test cases. In this test case, package +# example.com/m has an import of example.com/n, which is also +# in the workspace, but is not required by example.com/m, and does not exist +# upstream. It also has an import of rsc.io/quote, which +# is also not required by example.com/m but does exist upstream. get should resolve +# rsc.io/quote and not try to resolve example.com/n. +cd m +cp go.mod go.mod.orig + +# Test go get with an incomplete module using a local query. +cp go.mod.orig go.mod +go get +cmp go.mod go.mod.want +cmp go.sum go.sum.want + +# Test go get with an incomplete module using a wildcard query. +cp go.mod.orig go.mod +rm go.sum +go get ./... +cmp go.mod go.mod.want +cmp go.sum go.sum.want + +# Test go get with an incomplete module using a "work" query. +cp go.mod.orig go.mod +rm go.sum +go get work +cmp go.mod go.mod.want +cmp go.sum go.sum.want + +# Test go get with an incomplete module using a path query that can be resolved. +cp go.mod.orig go.mod +rm go.sum +go get rsc.io/quote +cmp go.mod go.mod.want.path_query # query wasn't resolved through import, so don't know if it's direct +cmp go.sum go.sum.want + +# Test go get with a path query that is to a workspace module but that can't be resolved. +# Normally, when we encounter an unresolved import of a workspace module, it's +# ignored, but a path query of the module was asked for explicitly and isn't ignored. +cp go.mod.orig go.mod +rm go.sum +! go get example.com/n +# The following error is returned because module example.com does exist in the proxy we use +# to run these tests, and because its is a prefix of example.com/n, it is a candidate to +# satisfy the import. +stderr 'module example.com@upgrade found \(v1\.0\.0\), but does not contain package example.com/n' + +# Test go get with an incomplete module using an "all" query. +cp go.mod.orig go.mod +rm go.sum +go get all +cmp go.mod go.mod.want.all # all loads a different graph so the requirements get bumped up +cmp go.sum go.sum.want.all + +# Test go get with an incomplete module using a tool query +# The hastool directory has its own go.work file than includes example.com/n and hastool. +cd ../hastool +go get tool +cmp go.mod go.mod.want + +# Test that missing imports from loading the workspace are reported. +# In this example, there is a workspace with the +# example.com/missingworkspaceimport and example.com/withmissing modules. +# missingworkspaceimport imports withmissing, and withmissing in turn +# imports rsc.io/quote, but doesn't have a requirement on it. +# The get operation won't resolve rsc.io/quote because it doesn't +# appear in the missingworkspaceimport's module graph, and the +# workspace will fail to load in checkPackageProblems because of the missing import. +cd ../missingworkspaceimport +! go get ./... +stderr 'cannot find module providing package rsc.io/quote' + +# Test that missing imports are not reported if they're not in the package +# graph. This test case is the same as the above except that there's no +# import from the missingworkspaceimport package to the one that +# imports the unresolved rsc.io/quote dependency. The example.com/missingworkspaceimport +# package imports example.com/withmissing/other so it still depends on the example.com/missing +# module, but not on the withmissing package itself. The example.com/withmissing +# module still has an import on the rsc.io/quote package, but the package +# with the import doesn't appear in the loaded package graph. +cd ../missingworkspaceimport_disconnected +go get ./... + +# Test that deprecations are reported using the workspace. +# First, the control case: without the workspace, the deprecated module +# is an indirect dependency of example.com/withdeprecation/indirect, +# so we shouldn't get a deprecation warning. +cd ../withdeprecation/indirect +cp go.mod go.mod.orig +env GOWORK=off +go get ./... +! stderr 'is deprecated' +cmp go.mod go.mod.want +# Now, in the workspace, we should get a deprecation warning, because +# the deprecated module is a direct dependency of example.com/withdeprecation/direct, which +# is a workspace module. +cp go.mod.orig go.mod +env GOWORK= +go get ./... +stderr 'go: module example.com/deprecated/b is deprecated: in example.com/deprecated/b@v1.9.0' +cmp go.mod go.mod.want + +# Test that retractions are reported using the workspace. +# First, the control case. Even though a workspace module depends on +# a retracted version, because we didn't ask for it on the command line, +# we didn't resolve that retracted module to satisfy an import, +# or need it to build a requested package, we don't produce the warning. +cd ../../withretraction/doesnotrequireretracted +cp go.mod go.mod.orig +go get rsc.io/quote +! stderr 'retracted' +# If we do request a non-retracted version of the module but the workspace +# is off, we also won't see the retraction warning because the retracted +# module isn't selected in the graph. +cp go.mod.orig go.mod +env GOWORK=off +go get example.com/retract@v1.0.0-good +! stderr 'retracted' +# Now, with the workspace on, because example.com/retract@v1.0.0-unused +# is a higher version, it will be selected and the retraction will +# be reported. +cp go.mod.orig go.mod +env GOWORK= +go get example.com/retract@v1.0.0-good +stderr 'retracted' +# Finally, with the workspace on, if the other workspace depends on +# example.com/retract@v1.0.0-bad rather than 'v1.0.0-unused', because +# 'v1.0.0-bad' is considered a lower version than 'v1.0.0-good', 'v1.0.0-good' +# will be selected and the deprecation will not be reported. +cp go.mod.orig go.mod +cd ../requiresretracted +go get example.com/retract@v1.0.0-bad # set the verison to 'v1.0.0-bad' +stderr 'retracted' +cd ../doesnotrequireretracted +go get example.com/retract@v1.0.0-good +! stderr 'retracted' + +-- go.work -- +go 1.25 + +use ( + m + n +) +-- q/go.mod -- +module example.com/q + +go 1.25 +-- q/q.go -- +package q + +import "rsc.io/quote" + +func Q() { + quote.Hello() +} +-- m/go.mod -- +module example.com/m + +go 1.25 +-- m/go.mod.want -- +module example.com/m + +go 1.25 + +require rsc.io/quote v1.5.2 + +require ( + golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect + rsc.io/sampler v1.3.0 // indirect +) +-- m/go.mod.want.path_query -- +module example.com/m + +go 1.25 + +require ( + golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect + rsc.io/quote v1.5.2 // indirect + rsc.io/sampler v1.3.0 // indirect +) +-- m/go.sum.want -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +-- m/go.mod.want.all -- +module example.com/m + +go 1.25 + +require rsc.io/quote v1.5.2 + +require ( + golang.org/x/text v0.3.0 // indirect + rsc.io/sampler v1.99.99 // indirect +) +-- m/go.sum.want.all -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0 h1:ivTorhoiROmZ1mcs15mO2czVF0uy0tnezXpBVNzgrmA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/sampler v1.99.99 h1:iMG9lbEG/8MdeR4lgL+Q8IcwbLNw7ijW7fTiK8Miqts= +rsc.io/sampler v1.99.99/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +-- m/m.go -- +package m + +import ( + "example.com/n" + "rsc.io/quote" +) + +func M() { + n.Hello() + quote.Hello() +} +-- n/go.mod -- +module example.com/n + +go 1.25 +-- n/n.go -- +package n + +func Hello() { +} +-- hastool/go.work -- +go 1.25 + +use ( + . + ../n +) +-- hastool/go.mod -- +module example.com/hastool + +go 1.25 + +tool rsc.io/fortune +-- hastool/go.mod.want -- +module example.com/hastool + +go 1.25 + +tool rsc.io/fortune + +require ( + golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect + rsc.io/fortune v1.0.0 // indirect + rsc.io/quote v1.5.2 // indirect + rsc.io/sampler v1.3.0 // indirect +) +-- hastool/p.go -- +package hastool + +import "example.com/n" + +func T() { + n.Hello() +} +-- missingworkspaceimport/go.work -- +go 1.25 + +use ( + . + withmissing +) +-- missingworkspaceimport/go.mod -- +module example.com/missingworkspaceimport + +go 1.25 +-- missingworkspaceimport/m.go -- +package m + +import _ "example.com/withmissing" +-- missingworkspaceimport/withmissing/go.mod -- +module example.com/withmissing + +go 1.25 +-- missingworkspaceimport/withmissing/w.go -- +package w + +import _ "rsc.io/quote" +-- missingworkspaceimport_disconnected/go.work -- +go 1.25 + +use ( + . + withmissing +) +-- missingworkspaceimport_disconnected/go.mod -- +module example.com/missingworkspaceimport + +go 1.25 +-- missingworkspaceimport_disconnected/m.go -- +package m + +import _ "example.com/withmissing/other" +-- missingworkspaceimport_disconnected/withmissing/go.mod -- +module example.com/withmissing + +go 1.25 +-- missingworkspaceimport_disconnected/withmissing/w.go -- +package w + +import _ "rsc.io/quote" +-- missingworkspaceimport_disconnected/withmissing/other/other.go -- +package other +-- withdeprecation/go.work -- +go 1.25 + +use ( + indirect + direct +) + +replace example.com/requiresdeprecatednotworkspace => ./requiresdeprecatednotworkspace +-- withdeprecation/indirect/go.mod -- +module example.com/withdeprecation/indirect + +go 1.25 + +replace example.com/requiresdeprecatednotworkspace => ../requiresdeprecatednotworkspace +-- withdeprecation/indirect/go.mod.want -- +module example.com/withdeprecation/indirect + +go 1.25 + +replace example.com/requiresdeprecatednotworkspace => ../requiresdeprecatednotworkspace + +require example.com/requiresdeprecatednotworkspace v0.0.0-00010101000000-000000000000 + +require example.com/deprecated/b v1.9.0 // indirect +-- withdeprecation/indirect/go.mod.want.direct -- +module example.com/withdeprecation/indirect + +go 1.25 + +replace example.com/requiresdeprecatednotworkspace => ../requiresdeprecatednotworkspace + +require example.com/requiresdeprecatednotworkspace v0.0.0-00010101000000-000000000000 + +require example.com/deprecated/b v1.9.0 +-- withdeprecation/indirect/a.go -- +package indirect + +import "example.com/requiresdeprecatednotworkspace" +-- withdeprecation/direct/go.mod -- +module example.com/withdeprecation/direct + +go 1.25 + +require "example.com/deprecated/b" v1.9.0 +-- withdeprecation/direct/import.go -- +package direct + +import "example.com/deprecated/b" +-- withdeprecation/requiresdeprecatednotworkspace/go.mod -- +module example.com/requiresdeprecatednotworkspace + +go 1.25 +-- withdeprecation/requiresdeprecatednotworkspace/a.go -- +package a + +import "example.com/deprecated/b" +-- withretraction/go.work -- +go 1.25 + +use ( + doesnotrequireretracted + requiresretracted +) +-- withretraction/doesnotrequireretracted/go.mod -- +module example.com/withretraction/doesnotrequireretracted + +go 1.25 +-- withretraction/requiresretracted/go.mod -- +module example.com/withretraction/requiresretracted + +go 1.25 + +require example.com/retract v1.0.0-unused diff --git a/go/src/cmd/go/testdata/script/mod_getmode_vendor.txt b/go/src/cmd/go/testdata/script/mod_getmode_vendor.txt new file mode 100644 index 0000000000000000000000000000000000000000..aaf526b2ab54beb3245ea4737a313bc54456055f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_getmode_vendor.txt @@ -0,0 +1,31 @@ +env GO111MODULE=on + +go get rsc.io/quote@v1.5.1 +go mod vendor +env GOPATH=$WORK/empty +env GOPROXY=file:///nonexist + +go list -mod=vendor +go list -mod=vendor -f '{{with .Module}}{{.Path}} {{.Version}}{{end}} {{.Dir}}' all +stdout '^rsc.io/quote v1.5.1 .*vendor[\\/]rsc.io[\\/]quote$' +stdout '^golang.org/x/text v0.0.0.* .*vendor[\\/]golang.org[\\/]x[\\/]text[\\/]language$' + +! go list -mod=vendor -m rsc.io/quote@latest +stderr 'go: rsc.io/quote@latest: cannot query module due to -mod=vendor' +! go get -mod=vendor -u +stderr 'flag provided but not defined: -mod' + +# Since we don't have a complete module graph, 'go list -m' queries +# that require the complete graph should fail with a useful error. +! go list -mod=vendor -m all +stderr 'go: can''t compute ''all'' using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)' +! go list -mod=vendor -m ... +stderr 'go: can''t match module patterns using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)' + +-- go.mod -- +module x + +go 1.16 +-- x.go -- +package x +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_getx.txt b/go/src/cmd/go/testdata/script/mod_getx.txt new file mode 100644 index 0000000000000000000000000000000000000000..46bb95bf58fb3a75abfb5ca52263c68d627e1ff3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_getx.txt @@ -0,0 +1,18 @@ +[!net:golang.org] skip +[!git] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +# 'go get -x' should log URLs with an HTTP or HTTPS scheme. +# A bug had caused us to log schemeless URLs instead. +go get -x golang.org/x/text@v0.1.0 +stderr '^# get https://golang.org/x/text\?go-get=1$' +stderr '^# get https://golang.org/x/text\?go-get=1: 200 OK \([0-9.]+s\)$' +! stderr '^# get //.*' + +-- go.mod -- +module m + +go 1.18 diff --git a/go/src/cmd/go/testdata/script/mod_git_export_subst.txt b/go/src/cmd/go/testdata/script/mod_git_export_subst.txt new file mode 100644 index 0000000000000000000000000000000000000000..740ccbdb81e780dae8b6b30ec761e4a335dcdaaf --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_git_export_subst.txt @@ -0,0 +1,21 @@ +env GO111MODULE=on +env GOPROXY=direct + +# Testing that git export-subst is disabled +[!net:github.com] skip +[!git] skip +go build + +-- x.go -- +package x + +import _ "github.com/jasonkeene/export-subst" + +-- go.mod -- +module x + +require github.com/jasonkeene/export-subst v0.0.0-20180927204031-5845945ec626 + +-- go.sum -- +github.com/jasonkeene/export-subst v0.0.0-20180927204031-5845945ec626 h1:AUkXi/xFnm7lH2pgtvVkGb7buRn1ywFHw+xDpZ29Rz0= +github.com/jasonkeene/export-subst v0.0.0-20180927204031-5845945ec626/go.mod h1:DwJXqVtrgrQkv3Giuf2Jh4YyubVe7y41S1eOIaysTJw= diff --git a/go/src/cmd/go/testdata/script/mod_go_version.txt b/go/src/cmd/go/testdata/script/mod_go_version.txt new file mode 100644 index 0000000000000000000000000000000000000000..82b55d8070d8ae21672996affbb812d44687a66e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_go_version.txt @@ -0,0 +1,29 @@ +# Test support for declaring needed Go version in module. + +env GO111MODULE=on +env TESTGO_VERSION=go1.21 + +! go list +stderr -count=1 '^go: sub@v1.0.0: module ./sub requires go >= 1.999 \(running go 1.21\)$' +! go build sub +stderr -count=1 '^go: sub@v1.0.0: module ./sub requires go >= 1.999 \(running go 1.21\)$' + +-- go.mod -- +module m +go 1.1 +require ( + sub v1.0.0 +) +replace ( + sub => ./sub +) + +-- x.go -- +package x + +-- sub/go.mod -- +module sub +go 1.999 + +-- sub/x.go -- +package x diff --git a/go/src/cmd/go/testdata/script/mod_go_version_missing.txt b/go/src/cmd/go/testdata/script/mod_go_version_missing.txt new file mode 100644 index 0000000000000000000000000000000000000000..e9a8e7291df6279261e7bc44bce1ba7e653d5015 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_go_version_missing.txt @@ -0,0 +1,122 @@ +cp go.mod go.mod.orig + +# For modules whose go.mod file does not include a 'go' directive, +# we assume the language and dependency semantics of Go 1.16, +# but do not trigger “automatic vendoring†mode (-mod=vendor), +# which was added in Go 1.14 and was not triggered +# under the same conditions in Go 1.16 (which would instead +# default to -mod=readonly when no 'go' directive is present). + +# For Go 1.16 modules, 'all' should prune out dependencies of tests, +# even if the 'go' directive is missing. + +go list -mod=readonly all +stdout '^example.com/dep$' +! stdout '^example.com/testdep$' +cp stdout list-1.txt +cmp go.mod go.mod.orig + +# We should only default to -mod=vendor if the 'go' directive is explicit in the +# go.mod file. Otherwise, we don't actually know whether the module was written +# against Go 1.11 or 1.16. We would have to update the go.mod file to clarify, +# and as of Go 1.16 we don't update the go.mod file by default. +# +# If we set -mod=vendor explicitly, we shouldn't apply the Go 1.14 +# consistency check, because — again — we don't know whether we're in a 1.11 +# module or a bad-script-edited 1.16 module. + +! go list -mod=vendor all +! stderr '^go: inconsistent vendoring' +stderr 'cannot find module providing package example.com/badedit: import lookup disabled by -mod=vendor' + +# When we set -mod=mod, the go version should be updated immediately, +# to the current version, converting the requirements from eager to lazy. +# +# Since we don't know which requirements are actually relevant to the main +# module, all requirements are added as roots, making the requirements untidy. + +go list -mod=mod all +! stdout '^example.com/testdep$' +cmp stdout list-1.txt +cmpenv go.mod go.mod.untidy + +go mod tidy +cmpenv go.mod go.mod.tidy + +# On the other hand, if we jump straight to 'go mod tidy', +# the requirements remain tidy from the start. + +cp go.mod.orig go.mod +go mod tidy +cmpenv go.mod go.mod.tidy + + +# The updated version should have been written back to go.mod, so now the 'go' +# directive is explicit. -mod=vendor should trigger by default, and the stronger +# Go 1.14 consistency check should apply. +! go list all +stderr '^go: inconsistent vendoring' +! stderr badedit + + +-- go.mod -- +module example.com/m + +require example.com/dep v0.1.0 + +replace ( + example.com/dep v0.1.0 => ./dep + example.com/testdep v0.1.0 => ./testdep +) +-- go.mod.untidy -- +module example.com/m + +go $goversion + +require example.com/dep v0.1.0 + +require example.com/testdep v0.1.0 // indirect + +replace ( + example.com/dep v0.1.0 => ./dep + example.com/testdep v0.1.0 => ./testdep +) +-- go.mod.tidy -- +module example.com/m + +go $goversion + +require example.com/dep v0.1.0 + +replace ( + example.com/dep v0.1.0 => ./dep + example.com/testdep v0.1.0 => ./testdep +) +-- vendor/example.com/dep/dep.go -- +package dep +import _ "example.com/badedit" +-- vendor/modules.txt -- +HAHAHA this is broken. + +-- m.go -- +package m + +import _ "example.com/dep" + +const x = 1_000 + +-- dep/go.mod -- +module example.com/dep + +require example.com/testdep v0.1.0 +-- dep/dep.go -- +package dep +-- dep/dep_test.go -- +package dep_test + +import _ "example.com/testdep" + +-- testdep/go.mod -- +module example.com/testdep +-- testdep/testdep.go -- +package testdep diff --git a/go/src/cmd/go/testdata/script/mod_go_version_mixed.txt b/go/src/cmd/go/testdata/script/mod_go_version_mixed.txt new file mode 100644 index 0000000000000000000000000000000000000000..d6216ae2443a17cc72f77fa294e05b45820db2c2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_go_version_mixed.txt @@ -0,0 +1,43 @@ +# Test that dependencies can use Go language features newer than the +# Go version specified by the main module. + +env GO111MODULE=on + +go build + +-- go.mod -- +module m +go 1.12 +require ( + sub.1 v1.0.0 +) +replace ( + sub.1 => ./sub +) + +-- x.go -- +package x + +import "sub.1" + +func F() { sub.F(0, 0) } + +var A sub.Alias +var D sub.Defined + +-- sub/go.mod -- +module m +go 1.14 + +-- sub/sub.go -- +package sub + +// signed shift counts added in Go 1.13 +func F(l, r int) int { return l << r } + +type m1 interface { M() } +type m2 interface { M() } + +// overlapping interfaces added in Go 1.14 +type Alias = interface { m1; m2; M() } +type Defined interface { m1; m2; M() } diff --git a/go/src/cmd/go/testdata/script/mod_gobuild_import.txt b/go/src/cmd/go/testdata/script/mod_gobuild_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..70af331595058a4f13ffd80b6d09709f3252596f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_gobuild_import.txt @@ -0,0 +1,133 @@ +[short] skip + +# go/build's Import should find modules by invoking the go command + +go build -o $WORK ./testimport ./testfindonly + +# GO111MODULE=off +env GO111MODULE=off +! exec $WORK/testimport$GOEXE gobuild.example.com/x/y/z/w . + +# GO111MODULE=auto in GOPATH/src +env GO111MODULE=auto +exec $WORK/testimport$GOEXE gobuild.example.com/x/y/z/w . + +# GO111MODULE=auto outside GOPATH/src +cd $GOPATH/other +env GO111MODULE=auto +exec $WORK/testimport$GOEXE other/x/y/z/w . +stdout w2.go + +! exec $WORK/testimport$GOEXE gobuild.example.com/x/y/z/w . +stderr 'no required module provides package gobuild.example.com/x/y/z/w; to add it:\n\tgo get gobuild.example.com/x/y/z/w' + +cd z +exec $WORK/testimport$GOEXE other/x/y/z/w . +stdout w2.go + +# GO111MODULE=on outside GOPATH/src +env GO111MODULE= +exec $WORK/testimport$GOEXE other/x/y/z/w . +stdout w2.go +env GO111MODULE=on +exec $WORK/testimport$GOEXE other/x/y/z/w . +stdout w2.go + +# GO111MODULE=on in GOPATH/src +cd $GOPATH/src +env GO111MODULE= +exec $WORK/testimport$GOEXE gobuild.example.com/x/y/z/w . +stdout w1.go +env GO111MODULE=on +exec $WORK/testimport$GOEXE gobuild.example.com/x/y/z/w . +stdout w1.go +cd w +exec $WORK/testimport$GOEXE gobuild.example.com/x/y/z/w .. +stdout w1.go + +# go/build's Import in FindOnly mode should find directories by invoking the go command +# +# Calling build.Import in build.FindOnly mode on an import path of a Go package +# that produces errors when loading (e.g., due to build constraints not matching +# the current build context) should return the package directory and nil error. + +# Issue 31603: Import with non-empty srcDir should work. +env GO111MODULE=on +exec $WORK/testfindonly$GOEXE gobuild.example.com/x/y/z/i $WORK +! stdout 'build constraints' +stdout '^dir='$WORK'.+i err=$' + +# Issue 37153: Import with empty srcDir should work. +env GO111MODULE=on +exec $WORK/testfindonly$GOEXE gobuild.example.com/x/y/z/i '' +! stdout 'build constraints' +stdout '^dir='$WORK'.+i err=$' + +-- go.mod -- +module gobuild.example.com/x/y/z + +-- z.go -- +package z + +-- w/w1.go -- +package w + +-- i/i.go -- +// +build i + +package i + +-- testimport/x.go -- +package main + +import ( + "fmt" + "go/build" + "log" + "os" + "path/filepath" + "strings" +) + +func main() { + // build.Import should support relative and absolute source dir paths. + path := os.Args[1] + srcDir := os.Args[2] + p1, err := build.Import(path, srcDir, 0) + if err != nil { + log.Fatal(err) + } + absSrcDir, err := filepath.Abs(srcDir) + if err != nil { + log.Fatal(err) + } + p2, err := build.Import(path, absSrcDir, 0) + if err != nil { + log.Fatal(err) + } + if p1.Dir != p2.Dir { + log.Fatalf("different packages loaded with relative and absolute paths:\n\t%s\n\t%s", p1.Dir, p2.Dir) + } + + fmt.Printf("%s\n%s\n", p1.Dir, strings.Join(p1.GoFiles, " ")) +} + +-- testfindonly/x.go -- +package main + +import ( + "fmt" + "go/build" + "os" +) + +func main() { + p, err := build.Import(os.Args[1], os.Args[2], build.FindOnly) + fmt.Printf("dir=%s err=%v\n", p.Dir, err) +} + +-- $GOPATH/other/go.mod -- +module other/x/y + +-- $GOPATH/other/z/w/w2.go -- +package w diff --git a/go/src/cmd/go/testdata/script/mod_gofmt_invalid.txt b/go/src/cmd/go/testdata/script/mod_gofmt_invalid.txt new file mode 100644 index 0000000000000000000000000000000000000000..21edc7dc2f4744230f464f66ae2adcb8a4333035 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_gofmt_invalid.txt @@ -0,0 +1,13 @@ +# Test for a crash in go fmt on invalid input when using modules. +# Issue 26792. + +env GO111MODULE=on +! go fmt x.go +! stderr panic + +-- go.mod -- +module x + +-- x.go -- +// Missing package declaration. +var V int diff --git a/go/src/cmd/go/testdata/script/mod_goline.txt b/go/src/cmd/go/testdata/script/mod_goline.txt new file mode 100644 index 0000000000000000000000000000000000000000..6b2eab0f2ed7dd232dfc2116051a511e83b3339a --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_goline.txt @@ -0,0 +1,117 @@ +env TESTGO_VERSION=go1.99 + +! go list -f '{{.Module.GoVersion}}' +stderr 'go: updates to go.mod needed' +stderr 'go mod tidy' + +go mod tidy +cat go.mod +go list -f '{{.Module.GoVersion}}' +stdout 1.22 + +# Adding a@v1.0.01 should upgrade to Go 1.23rc1. +cp go.mod go.mod1 +go get example.com/a@v1.0.1 +stderr '^go: upgraded go 1.22 => 1.23rc1\ngo: upgraded example.com/a v1.0.0 => v1.0.1\ngo: upgraded example.com/b v1.0.0 => v1.0.1$' +go list -f '{{.Module.GoVersion}}' +stdout 1.23rc1 + +# Repeating the update with go@1.24.0 should use that Go version. +cp go.mod1 go.mod +go get example.com/a@v1.0.1 go@1.24.0 +go list -f '{{.Module.GoVersion}}' +stdout 1.24.0 + +# Go version-constrained updates should report the problems. +cp go.mod1 go.mod +! go get example.com/a@v1.0.2 go@1.24.2 +stderr '^go: example.com/a@v1.0.2 requires go@1.25, not go@1.24.2$' +! go get example.com/a@v1.0.2 go@1.26.3 +stderr '^go: example.com/a@v1.0.2 indirectly requires go@1.27, not go@1.26.3$' +go get example.com/a@v1.0.2 go@1.28rc1 +go list -f '{{.Module.GoVersion}}' +stdout 1.28rc1 +go get go@1.24.2 +stderr '^go: downgraded go 1.28rc1 => 1.24.2$' +stderr '^go: downgraded example.com/a v1.0.2 => v1.0.1$' +stderr '^go: downgraded example.com/b v1.0.2 => v1.0.1$' +go list -f '{{.Module.GoVersion}}' +stdout 1.24.2 + +-- go.mod -- +module m +go 1.21 + +require ( + example.com/a v1.0.0 + example.com/b v0.9.0 +) + +replace example.com/a v1.0.0 => ./a100 +replace example.com/a v1.0.1 => ./a101 +replace example.com/a v1.0.2 => ./a102 +replace example.com/b v1.0.1 => ./b101 +replace example.com/b v1.0.2 => ./b102 +replace example.com/b v1.0.0 => ./b100 +replace example.com/b v0.9.0 => ./b100 + +-- x.go -- +package m + +import ( + _ "example.com/a" + _ "example.com/b" +) + +-- a100/go.mod -- +module example.com/a +go 1.22 + +require example.com/b v1.0.0 + +-- a100/a.go -- +package a + +-- a101/go.mod -- +// this module is technically invalid, since the dep example.com/b has a newer go line than this module, +// but we should still be able to handle it. +module example.com/a +go 1.22 + +require example.com/b v1.0.1 + +-- a101/a.go -- +package a + +-- a102/go.mod -- +// this module is technically invalid, since the dep example.com/b has a newer go line than this module, +// but we should still be able to handle it. +module example.com/a +go 1.25 + +require example.com/b v1.0.2 + +-- a102/a.go -- +package a + +-- b100/go.mod -- +module example.com/b +go 1.22 + +-- b100/b.go -- +package b + +-- b101/go.mod -- +module example.com/b +go 1.23rc1 + +-- b101/b.go -- +package b + +-- b102/go.mod -- +module example.com/b +go 1.27 + +-- b102/b.go -- +package b + diff --git a/go/src/cmd/go/testdata/script/mod_goline_old.txt b/go/src/cmd/go/testdata/script/mod_goline_old.txt new file mode 100644 index 0000000000000000000000000000000000000000..bbe611bab782455d762fea65297d48f3c28b55de --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_goline_old.txt @@ -0,0 +1,72 @@ +env TESTGO_VERSION=go1.24 + +go list -f '{{.Module.GoVersion}}' +stdout 1.15 + +go mod tidy +go list -f '{{.Module.GoVersion}}' +stdout 1.15 + +go get example.com/a@v1.0.1 +go list -f '{{.Module.GoVersion}}' +stdout 1.15 + +go get example.com/a@v1.0.1 go@1.16 +go list -f '{{.Module.GoVersion}}' +stdout 1.16 + +-- go.mod -- +module m +go 1.15 + +require ( + example.com/a v1.0.0 + example.com/b v1.0.0 +) + +replace example.com/a v1.0.0 => ./a100 +replace example.com/a v1.0.1 => ./a101 +replace example.com/b v1.0.1 => ./b101 +replace example.com/b v1.0.0 => ./b100 +replace example.com/b v0.9.0 => ./b100 + +-- x.go -- +package m + +import ( + _ "example.com/a" + _ "example.com/b" +) + +-- a100/go.mod -- +module example.com/a +go 1.16 + +require example.com/b v1.0.0 + +-- a100/a.go -- +package a + +-- a101/go.mod -- +module example.com/a +go 1.17 + +require example.com/b v1.0.1 + +-- a101/a.go -- +package a + +-- b100/go.mod -- +module example.com/b +go 1.18 + +-- b100/b.go -- +package b + +-- b101/go.mod -- +module example.com/b +go 1.19 + +-- b101/b.go -- +package b + diff --git a/go/src/cmd/go/testdata/script/mod_goline_too_new.txt b/go/src/cmd/go/testdata/script/mod_goline_too_new.txt new file mode 100644 index 0000000000000000000000000000000000000000..6d2667937af3f77852c1479f3ae19d88680b26aa --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_goline_too_new.txt @@ -0,0 +1,50 @@ +# Go should refuse to build code that is too new according to go.mod. + +# go.mod too new +env GOTOOLCHAIN=local +! go build . +stderr '^go: go.mod requires go >= 1.99999 \(running go 1\..+\)$' + +# go.mod referenced from go.work too new +cp go.work.old go.work +! go build . +stderr '^go: module . listed in go.work file requires go >= 1.99999, but go.work lists go 1.10; to update it:\n\tgo work use$' + +! go work sync +stderr '^go: cannot load module . listed in go.work file: go.mod requires go >= 1.99999 \(running go 1\..+\)$' + +# go.work too new +cp go.work.new go.work +cp go.mod.old go.mod +! go build . +stderr '^go: go.work requires go >= 1.99999 \(running go 1\..+\)$' + +# vendor too new +rm go.work +mv notvendor vendor +! go build -mod=vendor . +stderr '^go: golang.org/x/text in vendor'${/}'modules.txt requires go >= 1.99999 \(running go 1\..+\)$' + +-- go.mod -- +module example +go 1.99999 + +-- p.go -- +package p + +-- go.mod.old -- +module example +go 1.10 + +-- go.work.new -- +go 1.99999 +use . + +-- go.work.old -- +go 1.10 +use . + +-- notvendor/modules.txt -- +# golang.org/x/text v0.9.0 +## explicit; go 1.99999 +golang.org/x/text/internal/language diff --git a/go/src/cmd/go/testdata/script/mod_gomodcache.txt b/go/src/cmd/go/testdata/script/mod_gomodcache.txt new file mode 100644 index 0000000000000000000000000000000000000000..bfc6cb1c797316fa9e15ee154fe2dcfe40fe3620 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_gomodcache.txt @@ -0,0 +1,74 @@ +# Test GOMODCACHE +env GO111MODULE=on + +# Explicitly set GOMODCACHE +env GOMODCACHE=$WORK/modcache +go env GOMODCACHE +stdout $WORK[/\\]modcache +go get rsc.io/quote@v1.0.0 +exists $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info +grep '{"Version":"v1.0.0","Time":"2018-02-14T00:45:20Z"}' $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info + +# Ensure GOMODCACHE doesn't affect location of sumdb, but $GOMODCACHE/cache/download/sumdb is still written +exists $GOPATH/pkg/sumdb +! exists $WORK/modcache/sumdb +exists $WORK/modcache/cache/download/sumdb + +# Test that the default GOMODCACHE is $GOPATH[0]/pkg/mod +env GOMODCACHE= +go env GOMODCACHE +stdout $GOPATH[/\\]pkg[/\\]mod +go get rsc.io/quote@v1.0.0 +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.0.0.info +grep '{"Version":"v1.0.0","Time":"2018-02-14T00:45:20Z"}' $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.0.0.info + +# If neither GOMODCACHE or GOPATH are set, GOPATH defaults to the user's $HOME/go, so GOMODCACHE becomes $HOME/go/pkg/mod +[GOOS:windows] env USERPROFILE=$WORK/home # Ensure USERPROFILE is a valid path (rather than /no-home/ so we don't run into the logic that "uninfers" GOPATH in cmd/go/main.go +[GOOS:plan9] env home=$WORK/home +[!GOOS:windows] [!GOOS:plan9] env HOME=$WORK/home +env GOMODCACHE= +env GOPATH= +go env GOMODCACHE +stdout $HOME[/\\]go[/\\]pkg[/\\]mod + +# If GOMODCACHE isn't set and GOPATH starts with the path list separator, +# GOMODCACHE is empty and any command that needs it errors out. +env GOMODCACHE= +env GOPATH=${:}$WORK/this/is/ignored + +go env GOMODCACHE +stdout '^$' +! stdout . +! stderr . + +! go mod download rsc.io/quote@v1.0.0 +stderr '^go: module cache not found: neither GOMODCACHE nor GOPATH is set$' + +# If GOMODCACHE isn't set and GOPATH has multiple elements only the first is used. +env GOMODCACHE= +env GOPATH=$WORK/first/path${:}$WORK/this/is/ignored +go env GOMODCACHE +stdout $WORK[/\\]first[/\\]path[/\\]pkg[/\\]mod + +env GOMODCACHE=$WORK/modcache +go mod download rsc.io/quote@v1.0.0 +exists $WORK/modcache/cache/download/rsc.io/quote/@v/v1.0.0.info + +# Test error when cannot create GOMODCACHE directory +env GOMODCACHE=$WORK/modcachefile +! go install example.com/cmd/a@v1.0.0 +stderr 'go: could not create module cache' + +# Test that the following work even with GO111MODULE=off +env GO111MODULE=off + +# Cleaning modcache +exists $WORK/modcache +env GOMODCACHE=$WORK/modcache +go clean -modcache +! exists $WORK/modcache + +-- go.mod -- +module m + +-- $WORK/modcachefile -- diff --git a/go/src/cmd/go/testdata/script/mod_gomodcache_vendor.txt b/go/src/cmd/go/testdata/script/mod_gomodcache_vendor.txt new file mode 100644 index 0000000000000000000000000000000000000000..164460be844164a33a991a8560a3e7a13be7c470 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_gomodcache_vendor.txt @@ -0,0 +1,32 @@ +# This test verifies that GOMODCACHE does not affect whether checksums are embedded +# with vendored files. +# See issue #46400 +[short] skip 'builds and links a binary twice' +go mod tidy +go mod vendor + +go build -mod=vendor +go version -m example$GOEXE +cp stdout version-m.txt + +env GOMODCACHE=$WORK${/}modcache +go build -mod=vendor +go version -m example$GOEXE +cmp stdout version-m.txt + +-- go.mod -- +module example +go 1.22 +require rsc.io/sampler v1.3.0 + +-- main.go -- +package main + +import ( + "fmt" + "rsc.io/sampler" +) + +func main() { + fmt.Println(sampler.Hello()) +} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_gonoproxy.txt b/go/src/cmd/go/testdata/script/mod_gonoproxy.txt new file mode 100644 index 0000000000000000000000000000000000000000..94d03f22f266b27fd7b73c954cfbb1e944acd3c4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_gonoproxy.txt @@ -0,0 +1,55 @@ +env GO111MODULE=on +env sumdb=$GOSUMDB +env proxy=$GOPROXY +env GOPRIVATE GOPROXY GONOPROXY GOSUMDB GONOSUMDB +env dbname=localhost.localdev/sumdb + +# disagree with sumdb fails +cp go.mod.orig go.mod +env GOSUMDB=$sumdb' '$proxy/sumdb-wrong +! go get rsc.io/quote +stderr 'SECURITY ERROR' + +# GONOSUMDB bypasses sumdb, for rsc.io/quote, rsc.io/sampler, golang.org/x/text +env GONOSUMDB='*/quote,*/*mple*,golang.org/x' +go get rsc.io/quote +rm go.sum +env GOPRIVATE='*/quote,*/*mple*,golang.org/x' +env GONOPROXY=none # that is, proxy all despite GOPRIVATE +go get rsc.io/quote + +# Download .info files needed for 'go list -m all' later. +# TODO(#42723): either 'go list -m' should not read these files, +# or 'go get' and 'go mod tidy' should download them. +go list -m all +stdout '^golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c$' + +# When GOPROXY is not empty but contains no entries, an error should be reported. +env GOPROXY=',' +! go get golang.org/x/text +stderr '^go: golang.org/x/text: GOPROXY list is not the empty string, but contains no entries$' + +# When GOPROXY=off, fetching modules not matched by GONOPROXY fails. +env GONOPROXY=*/fortune +env GOPROXY=off +! go get golang.org/x/text +stderr '^go: golang.org/x/text: module lookup disabled by GOPROXY=off$' + +# GONOPROXY bypasses proxy +[!net:rsc.io] skip +[!git] skip +env GOPRIVATE=none +env GONOPROXY='*/fortune' +! go get rsc.io/fortune # does not exist in real world, only on test proxy +stderr 'git ls-remote' + +[!net:golang.org] skip +env GOSUMDB= +env GONOPROXY= +env GOPRIVATE='*/x' +go get golang.org/x/text +go list -m all +! stdout 'text.*v0.0.0-2017' # should not have the version from the proxy + +-- go.mod.orig -- +module m diff --git a/go/src/cmd/go/testdata/script/mod_gopkg_unstable.txt b/go/src/cmd/go/testdata/script/mod_gopkg_unstable.txt new file mode 100644 index 0000000000000000000000000000000000000000..856f493f30ce9104b6c91995af19995184bdbac7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_gopkg_unstable.txt @@ -0,0 +1,26 @@ +env GO111MODULE=on + +cp go.mod.empty go.mod +go get gopkg.in/dummy.v2-unstable + +cp x.go.txt x.go +cp go.mod.empty go.mod +go list + +[!net:gopkg.in] skip +[!git] skip + +skip # TODO(#54503): redirect gopkg.in requests to a local server and re-enable. + +env GOPROXY=direct +env GOSUMDB=off +go get gopkg.in/macaroon-bakery.v2-unstable/bakery +go list -m all +stdout 'gopkg.in/macaroon-bakery.v2-unstable v2.0.0-[0-9]+-[0-9a-f]+$' + +-- go.mod.empty -- +module m + +-- x.go.txt -- +package x +import _ "gopkg.in/dummy.v2-unstable" diff --git a/go/src/cmd/go/testdata/script/mod_goroot_errors.txt b/go/src/cmd/go/testdata/script/mod_goroot_errors.txt new file mode 100644 index 0000000000000000000000000000000000000000..110a196a61fb5b58577f4e8efab961be694f64e9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_goroot_errors.txt @@ -0,0 +1,53 @@ +env GO111MODULE=on + +# Regression test for https://golang.org/issue/34769. +# Missing standard-library imports should refer to GOROOT rather than +# complaining about a malformed module path. +# This is especially important when GOROOT is set incorrectly, +# since such an error will occur for every package in std. + +# Building a nonexistent std package directly should fail usefully. + +! go build -mod=readonly nonexist +! stderr 'import lookup disabled' +! stderr 'missing dot' +stderr '^package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$' + +! go build nonexist +! stderr 'import lookup disabled' +! stderr 'missing dot' +stderr '^package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$' + +# Building a nonexistent std package indirectly should also fail usefully. + +! go build -mod=readonly ./importnonexist +! stderr 'import lookup disabled' +! stderr 'missing dot' +stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$' + +! go build ./importnonexist +! stderr 'import lookup disabled' +! stderr 'missing dot' +stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$' + +# Building an *actual* std package should fail if GOROOT is set to something bogus. + +[!short] go build ./importjson # Prove that it works when GOROOT is valid. + +env GOROOT=$WORK/not-a-valid-goroot +! go build ./importjson +! stderr 'import lookup disabled' +! stderr 'missing dot' +stderr 'importjson[/\\]x.go:2:8: package encoding/json is not in std \('$WORK'[/\\]not-a-valid-goroot[/\\]src[/\\]encoding[/\\]json\)$' + +-- go.mod -- +module example.com +go 1.14 +-- importnonexist/x.go -- +package importnonexist +import _ "nonexist" +-- importjson/x.go -- +package importjson +import _ "encoding/json" +-- $WORK/not-a-valid-goroot/README -- +This directory is not a valid GOROOT. diff --git a/go/src/cmd/go/testdata/script/mod_graph.txt b/go/src/cmd/go/testdata/script/mod_graph.txt new file mode 100644 index 0000000000000000000000000000000000000000..8d514392e4c1718f9023d24929a44f2fa9dd5f31 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_graph.txt @@ -0,0 +1,15 @@ +env GO111MODULE=on + +go mod graph +stdout '^m rsc.io/quote@v1.5.2$' +stdout '^rsc.io/quote@v1.5.2 rsc.io/sampler@v1.3.0$' +! stdout '^m rsc.io/sampler@v1.3.0$' +! stderr 'get '$GOPROXY + +rm $GOPATH/pkg/mod/cache/download/rsc.io/quote +go mod graph -x +stderr 'get '$GOPROXY + +-- go.mod -- +module m +require rsc.io/quote v1.5.2 diff --git a/go/src/cmd/go/testdata/script/mod_graph_version.txt b/go/src/cmd/go/testdata/script/mod_graph_version.txt new file mode 100644 index 0000000000000000000000000000000000000000..ed7e399418c86b2cd1c883868e0fb97b4b2e27ad --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_graph_version.txt @@ -0,0 +1,101 @@ +# For this module, Go 1.17 prunes out a (transitive and otherwise-irrelevant) +# requirement on a retracted higher version of a dependency. +# However, when Go 1.16 reads the same requirements from the go.mod file, +# it does not prune out that requirement, and selects the retracted version. +# +# The Go 1.16 module graph looks like: +# +# m ---- lazy v0.1.0 ---- requireincompatible v0.1.0 ---- incompatible v2.0.0+incompatible +# | | +# + -------+------------- incompatible v1.0.0 +# +# The Go 1.17 module graph is the same except that the dependencies of +# requireincompatible are pruned out (because the module that requires +# it — lazy v0.1.0 — specifies 'go 1.17', and it is not otherwise relevant to +# the main module). + +cp go.mod go.mod.orig + +go mod graph +cp stdout graph-1.17.txt +stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$' +stdout '^example\.net/lazy@v0\.1\.0 example\.com/retract/incompatible@v1\.0\.0$' +! stdout 'example\.com/retract/incompatible@v2\.0\.0\+incompatible' + +go mod graph -go=1.17 +cmp stdout graph-1.17.txt + +cmp go.mod go.mod.orig + + +# Setting -go=1.16 should report the graph as viewed by Go 1.16, +# but should not edit the go.mod file. + +go mod graph -go=1.16 +cp stdout graph-1.16.txt +stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$' +stdout '^example\.net/lazy@v0\.1\.0 example.com/retract/incompatible@v1\.0\.0$' +stdout '^example.net/requireincompatible@v0.1.0 example.com/retract/incompatible@v2\.0\.0\+incompatible$' + +cmp go.mod go.mod.orig + + +# If we actually update the go.mod file to the requested go version, +# we should get the same selected versions, but the roots of the graph +# may be updated. +# +# TODO(#45551): The roots should not be updated. + +go mod edit -go=1.16 +go mod graph +! stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$' +stdout '^example\.net/lazy@v0.1.0 example.com/retract/incompatible@v1\.0\.0$' +stdout '^example.net/requireincompatible@v0.1.0 example.com/retract/incompatible@v2\.0\.0\+incompatible$' + # TODO(#45551): cmp stdout graph-1.16.txt + + +# Unsupported go versions should be rejected, since we don't know +# what versions they would report. +! go mod graph -go=1.99999999999 +stderr '^invalid value "1\.99999999999" for flag -go: maximum supported Go version is '$goversion'\nusage: go mod graph \[-go=version\] \[-x\]\nRun ''go help mod graph'' for details.$' + + +-- go.mod -- +// Module m indirectly imports a package from +// example.com/retract/incompatible. Its selected version of +// that module is lower under Go 1.17 semantics than under Go 1.16. +module example.com/m + +go 1.17 + +replace ( + example.net/lazy v0.1.0 => ./lazy + example.net/requireincompatible v0.1.0 => ./requireincompatible +) + +require ( + example.com/retract/incompatible v1.0.0 // indirect + example.net/lazy v0.1.0 +) +-- lazy/go.mod -- +// Module lazy requires example.com/retract/incompatible v1.0.0. +// +// When viewed from the outside it also has a transitive dependency +// on v2.0.0+incompatible, but in lazy mode that transitive dependency +// is pruned out. +module example.net/lazy + +go 1.17 + +exclude example.com/retract/incompatible v2.0.0+incompatible + +require ( + example.com/retract/incompatible v1.0.0 + example.net/requireincompatible v0.1.0 +) +-- requireincompatible/go.mod -- +module example.net/requireincompatible + +go 1.15 + +require example.com/retract/incompatible v2.0.0+incompatible diff --git a/go/src/cmd/go/testdata/script/mod_help.txt b/go/src/cmd/go/testdata/script/mod_help.txt new file mode 100644 index 0000000000000000000000000000000000000000..7cb808ff237500862d916234ed1a249ba1a7cfc3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_help.txt @@ -0,0 +1,6 @@ +env GO111MODULE=on + +# go help get shows usage for get +go help get +stdout 'usage: go get' +stdout 'updates go.mod to require those versions' diff --git a/go/src/cmd/go/testdata/script/mod_import.txt b/go/src/cmd/go/testdata/script/mod_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..07714e92c720d1d498e4fb4000f6bf00a669399d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_import.txt @@ -0,0 +1,18 @@ +env GO111MODULE=on + +# latest rsc.io/quote should be v1.5.2 not v1.5.3-pre1 +go get +go list -m all +stdout 'rsc.io/quote v1.5.2' + +# but v1.5.3-pre1 should be a known version +go list -m -versions rsc.io/quote +stdout '^rsc.io/quote v1.0.0 v1.1.0 v1.2.0 v1.2.1 v1.3.0 v1.4.0 v1.5.0 v1.5.1 v1.5.2 v1.5.3-pre1$' + +-- go.mod -- +module x + +-- x.go -- +package x +import _ "rsc.io/quote" + diff --git a/go/src/cmd/go/testdata/script/mod_import_cycle.txt b/go/src/cmd/go/testdata/script/mod_import_cycle.txt new file mode 100644 index 0000000000000000000000000000000000000000..218efc6e840890adbe8c5b37bb47d68958fb21e0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_import_cycle.txt @@ -0,0 +1,40 @@ +env GO111MODULE=on + +# 'go list all' should fail with a reasonable error message +! go list all +stderr '^package m\n\timports m/a from m.go\n\timports m/b from a.go\n\timports m/a from b.go: import cycle not allowed' + +# 'go list -e' should not print to stderr, but should mark all three +# packages (m, m/a, and m/b) as Incomplete. +go list -e -json all +! stderr . +stdout -count=3 '"Incomplete": true,' + +-- go.mod -- +module m + +require ( + m/a v0.0.0 + m/b v0.0.0 +) + +replace ( + m/a => ./a + m/b => ./b +) +-- m.go -- +package m +import ( + _ "m/a" + _ "m/b" +) +-- a/go.mod -- +module m/a +-- a/a.go -- +package a +import _ "m/b" +-- b/go.mod -- +module m/b +-- b/b.go -- +package b +import _ "m/a" diff --git a/go/src/cmd/go/testdata/script/mod_import_issue41113.txt b/go/src/cmd/go/testdata/script/mod_import_issue41113.txt new file mode 100644 index 0000000000000000000000000000000000000000..fed2510f574e58e58f94f6400b247e437309ed22 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_import_issue41113.txt @@ -0,0 +1,28 @@ +# Regression test for https://golang.org/issue/41113. +# +# When resolving a missing import path, the inability to add the package from +# one module path should not interfere with adding a nested path. + +# Initially, our module depends on split-incompatible v2.1.0-pre+incompatible, +# from which an imported package has been removed (and relocated to the nested +# split-incompatible/subpkg module). modload.QueryPattern will suggest +# split-incompatible v2.0.0+incompatible, which we cannot use (because it would +# be an implicit downgrade), and split-incompatible/subpkg v0.1.0, which we +# *should* use. + +go mod tidy + +go list -m all +stdout '^example.com/split-incompatible/subpkg v0\.1\.0$' +! stdout '^example.com/split-incompatible .*' + +-- go.mod -- +module golang.org/issue/41113 + +go 1.16 + +require example.com/split-incompatible v2.1.0-pre+incompatible +-- x.go -- +package issue41113 + +import _ "example.com/split-incompatible/subpkg" diff --git a/go/src/cmd/go/testdata/script/mod_import_issue42891.txt b/go/src/cmd/go/testdata/script/mod_import_issue42891.txt new file mode 100644 index 0000000000000000000000000000000000000000..a78cab29ba53fcadcfeafa1dc26cafbd1703dfbc --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_import_issue42891.txt @@ -0,0 +1,14 @@ +# If an import declaration is an absolute path, most commands should report +# an error instead of going into an infinite loop. +# Verifies golang.org/issue/42891. +go list . +stdout '^m$' + +-- go.mod -- +module m + +go 1.16 +-- m.go -- +package m + +import "/" diff --git a/go/src/cmd/go/testdata/script/mod_import_meta.txt b/go/src/cmd/go/testdata/script/mod_import_meta.txt new file mode 100644 index 0000000000000000000000000000000000000000..0e469d09d260dc94650b2474df48556b76212cbd --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_import_meta.txt @@ -0,0 +1,45 @@ +# The loader should not attempt to resolve imports of the "all", "std", and "cmd" meta-packages. + +! go list -deps ./importall +! stderr 'internal error' +stderr '^importall[/\\]x.go:3:8: "all" is not an importable package; see ''go help packages''$' + +! go list -deps ./importcmd +! stderr 'internal error' +stderr '^importcmd[/\\]x.go:3:8: "cmd" is not an importable package; see ''go help packages''$' + +! go list -deps ./importstd +! stderr 'internal error' +stderr '^importstd[/\\]x.go:3:8: "std" is not an importable package; see ''go help packages''$' + + +# Not even if such a path is theoretically provided by a (necessarily replaced) module. + +go mod edit -replace std@v0.1.0=./modstd +go mod edit -require std@v0.1.0 + +! go list -deps ./importstd +stderr '^importstd[/\\]x.go:3:8: "std" is not an importable package; see ''go help packages''$' + + +-- go.mod -- +module example.com +go 1.16 +-- importall/x.go -- +package importall + +import _ "all" +-- importcmd/x.go -- +package importcmd + +import _ "cmd" +-- importstd/x.go -- +package importstd + +import _ "std" +-- modstd/go.mod -- +module std +go 1.16 +-- modstd/std.go -- +// Package std is an incredibly confusingly-named package. +package std diff --git a/go/src/cmd/go/testdata/script/mod_import_mod.txt b/go/src/cmd/go/testdata/script/mod_import_mod.txt new file mode 100644 index 0000000000000000000000000000000000000000..b035e3dec22befb36e35d6db6b5c78d5a84c17da --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_import_mod.txt @@ -0,0 +1,7 @@ +# Test that GOPATH/pkg/mod is excluded +env GO111MODULE=off +! go list mod/foo +stderr 'disallowed import path' + +-- mod/foo/foo.go -- +package foo diff --git a/go/src/cmd/go/testdata/script/mod_import_toolchain.txt b/go/src/cmd/go/testdata/script/mod_import_toolchain.txt new file mode 100644 index 0000000000000000000000000000000000000000..d19b93d932c25b3205184ac5cc5a77f9d3851ea3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_import_toolchain.txt @@ -0,0 +1,186 @@ +# This test verifies that 'go get' and 'go mod tidy' switch to a newer toolchain +# if needed to process newly-resolved imports. + +env TESTGO_VERSION=go1.21.0 +env TESTGO_VERSION_SWITCH=switch + +cp go.mod go.mod.orig + +# tidy reports needing 1.22.0 for b1 +env GOTOOLCHAIN=local +! go mod tidy +stderr '^go: example imports\n\texample.net/b: module ./b1 requires go >= 1.22.0 \(running go 1.21.0; GOTOOLCHAIN=local\)$' +env GOTOOLCHAIN=auto +go mod tidy + +cmp stderr tidy-stderr.want +cmp go.mod go.mod.tidy + +cp go.mod.orig go.mod +env GOTOOLCHAIN=local +! go get -v . +stderr '^go: example.net/b@v0.1.0: module ./b1 requires go >= 1.22.0 \(running go 1.21.0; GOTOOLCHAIN=local\)$' +env GOTOOLCHAIN=auto +go get -v . +cmp stderr get-v-stderr.want +cmp go.mod go.mod.tidy + +cp go.mod.orig go.mod +env GOTOOLCHAIN=local +! go get -u -v . +stderr '^go: example.net/a@v0.2.0: module ./a2 requires go >= 1.22.0 \(running go 1.21.0; GOTOOLCHAIN=local\)$' +env GOTOOLCHAIN=auto +go get -u -v . +cmp stderr get-u-v-stderr.want +cmp go.mod go.mod.upgraded + +-- tidy-stderr.want -- +go: found example.net/b in example.net/b v0.1.0 +go: module ./b1 requires go >= 1.22.0; switching to go1.22.9 +go: found example.net/b in example.net/b v0.1.0 +go: found example.net/c in example.net/c v0.1.0 +-- get-v-stderr.want -- +go: trying upgrade to example.net/b@v0.1.0 +go: module ./b1 requires go >= 1.22.0; switching to go1.22.9 +go: trying upgrade to example.net/b@v0.1.0 +go: accepting indirect upgrade from go@1.20 to 1.22.0 +go: trying upgrade to example.net/c@v0.1.0 +go: upgraded go 1.20 => 1.22.0 +go: added example.net/b v0.1.0 +go: added example.net/c v0.1.0 +go: added example.net/d v0.1.0 +-- get-u-v-stderr.want -- +go: trying upgrade to example.net/a@v0.2.0 +go: trying upgrade to example.net/b@v0.1.0 +go: module ./a2 requires go >= 1.22.0; switching to go1.22.9 +go: trying upgrade to example.net/a@v0.2.0 +go: trying upgrade to example.net/b@v0.1.0 +go: accepting indirect upgrade from go@1.20 to 1.22.0 +go: trying upgrade to example.net/c@v0.1.0 +go: trying upgrade to example.net/d@v0.2.0 +go: module ./d2 requires go >= 1.23.0; switching to go1.23.9 +go: trying upgrade to example.net/a@v0.2.0 +go: trying upgrade to example.net/b@v0.1.0 +go: accepting indirect upgrade from go@1.20 to 1.22.0 +go: trying upgrade to example.net/c@v0.1.0 +go: trying upgrade to example.net/d@v0.2.0 +go: accepting indirect upgrade from go@1.22.0 to 1.23.0 +go: upgraded go 1.20 => 1.23.0 +go: upgraded example.net/a v0.1.0 => v0.2.0 +go: added example.net/b v0.1.0 +go: added example.net/c v0.1.0 +go: added example.net/d v0.2.0 +-- go.mod -- +module example + +go 1.20 + +require example.net/a v0.1.0 + +replace ( + example.net/a v0.1.0 => ./a1 + example.net/a v0.2.0 => ./a2 + example.net/b v0.1.0 => ./b1 + example.net/c v0.1.0 => ./c1 + example.net/d v0.1.0 => ./d1 + example.net/d v0.2.0 => ./d2 +) +-- go.mod.tidy -- +module example + +go 1.22.0 + +require ( + example.net/a v0.1.0 + example.net/b v0.1.0 +) + +require ( + example.net/c v0.1.0 // indirect + example.net/d v0.1.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a1 + example.net/a v0.2.0 => ./a2 + example.net/b v0.1.0 => ./b1 + example.net/c v0.1.0 => ./c1 + example.net/d v0.1.0 => ./d1 + example.net/d v0.2.0 => ./d2 +) +-- go.mod.upgraded -- +module example + +go 1.23.0 + +require ( + example.net/a v0.2.0 + example.net/b v0.1.0 +) + +require ( + example.net/c v0.1.0 // indirect + example.net/d v0.2.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a1 + example.net/a v0.2.0 => ./a2 + example.net/b v0.1.0 => ./b1 + example.net/c v0.1.0 => ./c1 + example.net/d v0.1.0 => ./d1 + example.net/d v0.2.0 => ./d2 +) +-- example.go -- +package example + +import ( + _ "example.net/a" + _ "example.net/b" +) +-- a1/go.mod -- +module example.net/a + +go 1.20 +-- a1/a.go -- +package a +-- a2/go.mod -- +module example.net/a + +go 1.22.0 + +toolchain go1.23.0 +-- a2/a.go -- +package a +-- b1/go.mod -- +module example.net/b + +go 1.22.0 + +toolchain go1.23.0 +-- b1/b.go -- +package b + +import _ "example.net/c" // Note: module b is intentionally untidy, as if due to a bad git merge +-- c1/go.mod -- +module example.net/c + +go 1.22.0 + +require example.net/d v0.1.0 +-- c1/c.go -- +package c + +import _ "example.net/d" +-- d1/go.mod -- +module example.net/d + +go 1.22.0 +-- d1/d.go -- +package d +-- d2/go.mod -- +module example.net/d + +go 1.23.0 +-- d2/d.go -- +package d diff --git a/go/src/cmd/go/testdata/script/mod_import_v1suffix.txt b/go/src/cmd/go/testdata/script/mod_import_v1suffix.txt new file mode 100644 index 0000000000000000000000000000000000000000..75b3374bca0016ebdb3160fd0b35720187d7cb79 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_import_v1suffix.txt @@ -0,0 +1,11 @@ +env GO111MODULE=on + +! go get example.com/invalidpath/v1 +! go install . + +-- go.mod -- +module example.com +-- main.go -- +package main +import _ "example.com/invalidpath/v1" +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_import_vendor.txt b/go/src/cmd/go/testdata/script/mod_import_vendor.txt new file mode 100644 index 0000000000000000000000000000000000000000..391ea86bd91fa3334f718030664898052b3f7e35 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_import_vendor.txt @@ -0,0 +1,50 @@ +# For 1.23+, vendored packages that are missing in modules.txt should result in an error. +cp incorrect_modules.txt vendor/modules.txt +# incorrect_modules is missing foo.com/internal/bar/b so the build should fail. +! go build ./vendor/foo.com/internal/bar/a +stderr 'cannot find module providing package foo.com/internal/bar/b: import lookup disabled by -mod=vendor' +stderr 'go: ignoring package foo.com/internal/bar/b which exists in the vendor directory but is missing from vendor/modules.txt. To sync the vendor directory run go mod vendor.' + +cp correct_modules.txt vendor/modules.txt +go build ./vendor/foo.com/internal/bar/a + +# For go versions < 1.23, vendored packages that are missing in modules.txt should not result in an error. +cp 122go.mod go.mod + +cp incorrect_modules.txt vendor/modules.txt + +# go version < 1.23 and incorrect_modules is missing foo.com/internal/bar/b so the build should not fail +go build ./vendor/foo.com/internal/bar/a + +cp correct_modules.txt vendor/modules.txt +go build ./vendor/foo.com/internal/bar/a + +-- 122go.mod -- +module example.com/x +go 1.22 + +require "foo.com/internal/bar" v1.0.0 + +-- go.mod -- +module example.com/x +go 1.23 + +require "foo.com/internal/bar" v1.0.0 + +-- incorrect_modules.txt -- +# foo.com/internal/bar v1.0.0 +## explicit +foo.com/internal/bar/a + +-- correct_modules.txt -- +# foo.com/internal/bar v1.0.0 +## explicit +foo.com/internal/bar/a +foo.com/internal/bar/b + +-- vendor/foo.com/internal/bar/a/a.go -- +package a +import _ "foo.com/internal/bar/b" + +-- vendor/foo.com/internal/bar/b/b.go -- +package b \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_in_testdata_dir.txt b/go/src/cmd/go/testdata/script/mod_in_testdata_dir.txt new file mode 100644 index 0000000000000000000000000000000000000000..866f7841b9fbb1104e45244a630978c16d10d9e0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_in_testdata_dir.txt @@ -0,0 +1,45 @@ +# Regression test for golang.org/issue/28481: +# 'mod tidy' removed dependencies if the module root was +# within a directory named 'testdata' or '_foo'. + +env GO111MODULE=on + +# A module should be allowed in a directory named testdata. +cd $WORK/testdata +go mod init testdata.tld/foo + +# Getting a package within that module should resolve its dependencies. +go get +grep 'rsc.io/quote' go.mod + +# Tidying the module should preserve those dependencies. +go mod tidy +grep 'rsc.io/quote' go.mod + +[short] stop + +# Vendoring the module's dependencies should work too. +go mod vendor +exists vendor/rsc.io/quote + +# The same should work in directories with names starting with underscores. +cd $WORK/_ignored +go mod init testdata.tld/foo + +go get +grep 'rsc.io/quote' go.mod + +go mod tidy +grep 'rsc.io/quote' go.mod + +go mod vendor +exists vendor/rsc.io/quote + +-- $WORK/testdata/main.go -- +package foo + +import _ "rsc.io/quote" +-- $WORK/_ignored/main.go -- +package foo + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_indirect.txt b/go/src/cmd/go/testdata/script/mod_indirect.txt new file mode 100644 index 0000000000000000000000000000000000000000..6ea1cae98bcc8a152735310fbd5a349225671ccc --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_indirect.txt @@ -0,0 +1,81 @@ +env GO111MODULE=on + +# golang.org/issue/31248: required modules imposed by dependency versions +# older than the selected version must still be taken into account. + +env GOFLAGS=-mod=readonly + +# Indirect dependencies required via older-than-selected versions must exist in +# the module graph, but do not need to be listed explicitly in the go.mod file +# (since they are implied). +go mod graph +stdout i@v0.1.0 + +# The modules must also appear in the build list, not just the graph. +go list -m all +stdout '^i v0.1.0' + +# The packages provided by those dependencies must resolve. +go list all +stdout '^i$' + +-- go.mod -- +module main + +go 1.13 + +require ( + a v0.0.0 + b v0.0.0 + c v0.0.0 +) + +// Apply replacements so that the test can be self-contained. +// (It's easier to see all of the modules here than to go +// rooting around in testdata/mod.) +replace ( + a => ./a + b => ./b + c => ./c + x v0.1.0 => ./x1 + x v0.2.0 => ./x2 + i => ./i +) +-- main.go -- +package main + +import ( + _ "a" + _ "b" + _ "c" +) + +func main() {} +-- a/go.mod -- +module a +go 1.13 +require x v0.1.0 +-- a/a.go -- +package a +-- b/go.mod -- +module b +go 1.13 +require x v0.2.0 +-- b/b.go -- +package b +-- c/go.mod -- +module c +go 1.13 +-- c/c.go -- +package c +import _ "i" +-- x1/go.mod -- +module x +go1.13 +require i v0.1.0 +-- x2/go.mod -- +module x +go1.13 +-- i/go.mod -- +-- i/i.go -- +package i diff --git a/go/src/cmd/go/testdata/script/mod_indirect_main.txt b/go/src/cmd/go/testdata/script/mod_indirect_main.txt new file mode 100644 index 0000000000000000000000000000000000000000..e84eb9c5cd3708f35576d26cece3e26b879a00db --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_indirect_main.txt @@ -0,0 +1,66 @@ +env GO111MODULE=on + +# Regression test for golang.org/issue/29773: 'go list -m' was not following +# dependencies through older versions of the main module. + +go list -f '{{with .Module}}{{.Path}}{{with .Version}} {{.}}{{end}}{{end}}' all +cmp stdout pkgmods.txt + +go list -m all +cmp stdout mods.txt + +go mod graph +cmp stdout graph.txt + +-- go.mod -- +module golang.org/issue/root + +go 1.12 + +replace ( + golang.org/issue/mirror v0.1.0 => ./mirror-v0.1.0 + golang.org/issue/pkg v0.1.0 => ./pkg-v0.1.0 + golang.org/issue/root v0.1.0 => ./root-v0.1.0 +) + +require golang.org/issue/mirror v0.1.0 + +-- root.go -- +package root + +import _ "golang.org/issue/mirror" + +-- mirror-v0.1.0/go.mod -- +module golang.org/issue/mirror + +require golang.org/issue/root v0.1.0 + +-- mirror-v0.1.0/mirror.go -- +package mirror + +import _ "golang.org/issue/pkg" + +-- pkg-v0.1.0/go.mod -- +module golang.org/issue/pkg + +-- pkg-v0.1.0/pkg.go -- +package pkg + +-- root-v0.1.0/go.mod -- +module golang.org/issue/root + +require golang.org/issue/pkg v0.1.0 + +-- pkgmods.txt -- +golang.org/issue/mirror v0.1.0 +golang.org/issue/pkg v0.1.0 +golang.org/issue/root +-- mods.txt -- +golang.org/issue/root +golang.org/issue/mirror v0.1.0 => ./mirror-v0.1.0 +golang.org/issue/pkg v0.1.0 => ./pkg-v0.1.0 +-- graph.txt -- +golang.org/issue/root go@1.12 +golang.org/issue/root golang.org/issue/mirror@v0.1.0 +golang.org/issue/mirror@v0.1.0 golang.org/issue/root@v0.1.0 +golang.org/issue/root@v0.1.0 golang.org/issue/pkg@v0.1.0 diff --git a/go/src/cmd/go/testdata/script/mod_indirect_nospace.txt b/go/src/cmd/go/testdata/script/mod_indirect_nospace.txt new file mode 100644 index 0000000000000000000000000000000000000000..f4fb6a8c1b529fd06701073363030a7d3c96732b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_indirect_nospace.txt @@ -0,0 +1,32 @@ +# https://golang.org/issue/45932: "indirect" comments missing spaces +# should not be corrupted when the comment is removed. + +go mod tidy +cmp go.mod go.mod.direct + +-- go.mod -- +module example.net/m + +go 1.16 + +require example.net/x v0.1.0 //indirect + +replace example.net/x v0.1.0 => ./x +-- go.mod.direct -- +module example.net/m + +go 1.16 + +require example.net/x v0.1.0 + +replace example.net/x v0.1.0 => ./x +-- m.go -- +package m +import _ "example.net/x" + +-- x/go.mod -- +module example.net/x + +go 1.16 +-- x/x.go -- +package x diff --git a/go/src/cmd/go/testdata/script/mod_indirect_tidy.txt b/go/src/cmd/go/testdata/script/mod_indirect_tidy.txt new file mode 100644 index 0000000000000000000000000000000000000000..a12b35c72b1824e3a9f8251f71399b04a7d067a8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_indirect_tidy.txt @@ -0,0 +1,60 @@ +env GO111MODULE=on + +# golang.org/issue/31248: loading the build list must not add explicit entries +# for indirect dependencies already implied by older-than-selected versions +# already in the build list. + +cp go.mod.orig go.mod +go mod tidy +cmp go.mod go.mod.orig + +cp go.mod.orig go.mod +go list -m all +cmp go.mod go.mod.orig + +-- go.mod.orig -- +module main + +go 1.13 + +require a v0.0.0 + +replace ( + a v0.0.0 => ./a + b v0.0.0 => ./b + i v0.0.0 => ./i + x v0.1.0 => ./x1 + x v0.2.0 => ./x2 +) +-- main.go -- +package main + +import _ "a" + +func main() {} +-- a/go.mod -- +module a +go 1.13 +require ( + x v0.2.0 + b v0.0.0 +) +-- a/a.go -- +package a +-- b/go.mod -- +module b +go 1.13 +require x v0.1.0 +-- x1/go.mod -- +module x +go 1.13 +require ( + b v0.0.0 + i v0.0.0 +) +-- x2/go.mod -- +module x +go 1.13 +-- i/go.mod -- +module i +go 1.13 diff --git a/go/src/cmd/go/testdata/script/mod_init_empty.txt b/go/src/cmd/go/testdata/script/mod_init_empty.txt new file mode 100644 index 0000000000000000000000000000000000000000..d197a79a67180cd8567b815be7a367539d317259 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_init_empty.txt @@ -0,0 +1,21 @@ +env GO111MODULE=on + +env GOPATH=$WORK${/}invalid-gopath + +go list -m +stdout '^example.com$' + +go list +stdout '^example.com$' + +-- go.mod -- +module example.com + +go 1.13 +-- main.go -- +package main + +func main() {} + +-- $WORK/invalid-gopath +This is a text file, not a directory. diff --git a/go/src/cmd/go/testdata/script/mod_init_invalid_major.txt b/go/src/cmd/go/testdata/script/mod_init_invalid_major.txt new file mode 100644 index 0000000000000000000000000000000000000000..ae93e70d6307ff6e432c193d5db86bb187e24808 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_init_invalid_major.txt @@ -0,0 +1,82 @@ +env GO111MODULE=on +env GOFLAGS=-mod=mod + +! go mod init example.com/user/repo/v0 +stderr '(?s)^go: invalid module path "example.com/user/repo/v0": major version suffixes must be in the form of /vN and are only allowed for v2 or later(.*)go mod init example.com/user/repo/v2$' + +! go mod init example.com/user/repo/v02 +stderr '(?s)^go: invalid module path "example.com/user/repo/v02": major version suffixes must be in the form of /vN and are only allowed for v2 or later(.*)go mod init example.com/user/repo/v2$' + +! go mod init example.com/user/repo/v023 +stderr '(?s)^go: invalid module path "example.com/user/repo/v023": major version suffixes must be in the form of /vN and are only allowed for v2 or later(.*)go mod init example.com/user/repo/v23$' + +! go mod init example.com/user/repo/v1 +stderr '(?s)^go: invalid module path "example.com/user/repo/v1": major version suffixes must be in the form of /vN and are only allowed for v2 or later(.*)go mod init example.com/user/repo/v2$' + +! go mod init example.com/user/repo/v2.0 +stderr '(?s)^go: invalid module path "example.com/user/repo/v2.0": major version suffixes must be in the form of /vN and are only allowed for v2 or later(.*)go mod init example.com/user/repo/v2$' + +! go mod init example.com/user/repo/v2.1.4 +stderr '(?s)^go: invalid module path "example.com/user/repo/v2.1.4": major version suffixes must be in the form of /vN and are only allowed for v2 or later(.*)go mod init example.com/user/repo/v2$' + +! go mod init example.com/user/repo/v3.5 +stderr '(?s)^go: invalid module path "example.com/user/repo/v3.5": major version suffixes must be in the form of /vN and are only allowed for v2 or later(.*)go mod init example.com/user/repo/v3$' + +! go mod init example.com/user/repo/v4.1.4 +stderr '(?s)^go: invalid module path "example.com/user/repo/v4.1.4": major version suffixes must be in the form of /vN and are only allowed for v2 or later(.*)go mod init example.com/user/repo/v4$' + +! go mod init example.com/user/repo/v.2.3 +stderr '(?s)^go: invalid module path "example.com/user/repo/v.2.3": major version suffixes must be in the form of /vN and are only allowed for v2 or later(.*)go mod init example.com/user/repo/v2$' + +! go mod init example.com/user/repo/v.5.3 +stderr '(?s)^go: invalid module path "example.com/user/repo/v.5.3": major version suffixes must be in the form of /vN and are only allowed for v2 or later(.*)go mod init example.com/user/repo/v5$' + +! go mod init gopkg.in/pkg +stderr '(?s)^go: invalid module path "gopkg.in/pkg": module paths beginning with gopkg.in/ must always have a major version suffix in the form of .vN(.*)go mod init gopkg.in/pkg.v1$' + +! go mod init gopkg.in/user/pkg +stderr '(?s)^go: invalid module path "gopkg.in/user/pkg": module paths beginning with gopkg.in/ must always have a major version suffix in the form of .vN(.*)go mod init gopkg.in/user/pkg.v1$' + +! go mod init gopkg.in/user/pkg/v0 +stderr '(?s)^go: invalid module path "gopkg.in/user/pkg/v0": module paths beginning with gopkg.in/ must always have a major version suffix in the form of .vN(.*)go mod init gopkg.in/user/pkg.v1$' + +! go mod init gopkg.in/user/pkg/v1 +stderr '(?s)^go: invalid module path "gopkg.in/user/pkg/v1": module paths beginning with gopkg.in/ must always have a major version suffix in the form of .vN(.*)go mod init gopkg.in/user/pkg.v1$' + +! go mod init gopkg.in/user/pkg/v2 +stderr '(?s)^go: invalid module path "gopkg.in/user/pkg/v2": module paths beginning with gopkg.in/ must always have a major version suffix in the form of .vN(.*)go mod init gopkg.in/user/pkg.v2$' + +! go mod init gopkg.in/user/pkg.v +stderr '(?s)^go: invalid module path "gopkg.in/user/pkg.v": module paths beginning with gopkg.in/ must always have a major version suffix in the form of .vN(.*)go mod init gopkg.in/user/pkg.v1$' + +! go mod init gopkg.in/user/pkg.v0.1 +stderr '(?s)^go: invalid module path "gopkg.in/user/pkg.v0.1": module paths beginning with gopkg.in/ must always have a major version suffix in the form of .vN(.*)go mod init gopkg.in/user/pkg.v1$' + +! go mod init gopkg.in/user/pkg.v.1 +stderr '(?s)^go: invalid module path "gopkg.in/user/pkg.v.1": module paths beginning with gopkg.in/ must always have a major version suffix in the form of .vN(.*)go mod init gopkg.in/user/pkg.v1$' + +! go mod init gopkg.in/user/pkg.v01 +stderr '(?s)^go: invalid module path "gopkg.in/user/pkg.v01": module paths beginning with gopkg.in/ must always have a major version suffix in the form of .vN(.*)go mod init gopkg.in/user/pkg.v1$' + +! go mod init gopkg.in/user/pkg.v.2.3 +stderr '(?s)^go: invalid module path "gopkg.in/user/pkg.v.2.3": module paths beginning with gopkg.in/ must always have a major version suffix in the form of .vN(.*)go mod init gopkg.in/user/pkg.v2$' + +# module paths with a trailing dot are rejected as invalid import paths +! go mod init example.com/user/repo/v2. +stderr '(?s)^go: malformed module path "example.com/user/repo/v2.": trailing dot in path element$' + +! go mod init example.com/user/repo/v2.. +stderr '(?s)^go: malformed module path "example.com/user/repo/v2..": trailing dot in path element$' + +! go mod init gopkg.in/user/pkg.v.2. +stderr '(?s)^go: malformed module path "gopkg.in/user/pkg.v.2.": trailing dot in path element$' + +! go mod init gopkg.in/user/pkg.v.2.. +stderr '(?s)^go: malformed module path "gopkg.in/user/pkg.v.2..": trailing dot in path element$' + +# module paths with spaces are also rejected +! go mod init 'foo bar' +stderr '(?s)^go: malformed module path "foo bar": invalid char '' ''$' + +! go mod init 'foo bar baz' +stderr '(?s)^go: malformed module path "foo bar baz": invalid char '' ''$' diff --git a/go/src/cmd/go/testdata/script/mod_init_issue74784.txt b/go/src/cmd/go/testdata/script/mod_init_issue74784.txt new file mode 100644 index 0000000000000000000000000000000000000000..f7863636e51255fb15cffb1dddd1b8de29fd1e64 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_init_issue74784.txt @@ -0,0 +1,26 @@ +# Don't allow the creation of modules with special "go" or "toolchain" paths. +! go mod init go +! stderr 'panic' +stderr 'invalid module path' + +! go mod init toolchain +! stderr 'panic' +stderr 'invalid module path' + +# A module that contains the path element "go" is okay. +go mod init example.com/go +stderr 'creating new go.mod' + +# go mod edit won't allow a reserved module path either +! go mod edit -module=go +stderr 'invalid -module' + +# The go command should check for work modules for bad +# names to return a proper error and avoid a panic. +cp badmod.txt go.mod +! go list +! stderr panic +stderr 'invalid module path' + +-- badmod.txt -- +module go diff --git a/go/src/cmd/go/testdata/script/mod_init_path.txt b/go/src/cmd/go/testdata/script/mod_init_path.txt new file mode 100644 index 0000000000000000000000000000000000000000..e5fd4ddbcb92c7d585b1e5b239a6dfc5cfe8089d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_init_path.txt @@ -0,0 +1,20 @@ +env GO111MODULE=on + +! go mod init . +stderr '^go: malformed module path ".": is a local import path$' + +cd x +go mod init example.com/x + +cd ../y +go mod init m + +-- x/main.go -- +package main + +func main() {} + +-- y/main.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_init_tidy.txt b/go/src/cmd/go/testdata/script/mod_init_tidy.txt new file mode 100644 index 0000000000000000000000000000000000000000..4a525903b23f11fc0f6cfb2c40af5042f818f41e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_init_tidy.txt @@ -0,0 +1,30 @@ +# 'go mod init' should not recommend 'go mod tidy' in an empty directory +# (one that contains no non-hidden .go files or subdirectories). +cd empty +go mod init m +! stderr tidy +cd .. + +# 'go mod init' should recommend 'go mod tidy' if the directory has a .go file. +cd pkginroot +go mod init m +stderr '^go: to add module requirements and sums:\n\tgo mod tidy$' +cd .. + +# 'go mod init' should recommend 'go mod tidy' if the directory has a +# subdirectory. We don't walk the tree to see if it has .go files. +cd subdir +go mod init m +stderr '^go: to add module requirements and sums:\n\tgo mod tidy$' +cd .. + +-- empty/empty.txt -- +Not a .go file. Still counts as an empty project. +-- empty/.hidden/empty.go -- +File in hidden directory. Still as an empty project. +-- empty/_hidden/empty.go -- +File in hidden directory. Still as an empty project. +-- pkginroot/hello.go -- +package vendorimport +-- subdir/sub/empty.txt -- +Subdirectory doesn't need to contain a package. diff --git a/go/src/cmd/go/testdata/script/mod_insecure_issue63845.txt b/go/src/cmd/go/testdata/script/mod_insecure_issue63845.txt new file mode 100644 index 0000000000000000000000000000000000000000..c051c05f53931b7a7ef3c60ad60186536dfa8f8c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_insecure_issue63845.txt @@ -0,0 +1,28 @@ +# Regression test for https://go.dev/issue/63845: +# If 'git ls-remote' fails for all secure protocols, +# we should fail instead of falling back to an arbitrary protocol. +# +# Note that this test does not use the local vcweb test server +# (vcs-test.golang.org), because the hook for redirecting to that +# server bypasses the "ping to determine protocol" logic +# in cmd/go/internal/vcs. + +[!net:golang.org] skip +[!git] skip +[short] skip 'tries to access a nonexistent external Git repo' + +env GOPRIVATE=golang.org +env CURLOPT_TIMEOUT_MS=100 +env GIT_SSH_COMMAND=false + +! go get -x golang.org/nonexist.git@latest +stderr '^git ls-remote https://golang.org/nonexist$' +stderr '^git ls-remote git\+ssh://golang.org/nonexist' +stderr '^git ls-remote ssh://golang.org/nonexist$' +! stderr 'git://' +stderr '^go: golang.org/nonexist.git@latest: no secure protocol found for repository$' + +-- go.mod -- +module example + +go 1.19 diff --git a/go/src/cmd/go/testdata/script/mod_install_hint.txt b/go/src/cmd/go/testdata/script/mod_install_hint.txt new file mode 100644 index 0000000000000000000000000000000000000000..ab02840eb8befb1f5579d7704e0fc8f5000f4232 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_install_hint.txt @@ -0,0 +1,5 @@ +# Module is replaced but not required. No hint appears as no module is suggested. +go mod init m +go mod edit -replace=github.com/notrequired@v0.5.0=github.com/doesnotexist@v0.5.0 +! go install github.com/notrequired +! stderr 'to add it:' \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_install_pkg_version.txt b/go/src/cmd/go/testdata/script/mod_install_pkg_version.txt new file mode 100644 index 0000000000000000000000000000000000000000..98cf4e408786e3f953c3508eec8db64b2cede212 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_install_pkg_version.txt @@ -0,0 +1,217 @@ +# 'go install pkg@version' works outside a module. +env GO111MODULE=auto +go install example.com/cmd/a@v1.0.0 +exists $GOPATH/bin/a$GOEXE +rm $GOPATH/bin + + +# 'go install pkg@version' reports an error if modules are disabled. +env GO111MODULE=off +! go install example.com/cmd/a@v1.0.0 +stderr '^go: modules disabled by GO111MODULE=off; see ''go help modules''$' +env GO111MODULE=auto + + +# 'go install pkg@version' ignores go.mod in current directory. +cd m +cp go.mod go.mod.orig +! go list -m all +stderr '^go: example.com/cmd@v1.1.0-doesnotexist: reading http.*/mod/example.com/cmd/@v/v1.1.0-doesnotexist.info: 404 Not Found\n\tserver response: 404 page not found$' +stderr '^go: example.com/cmd@v1.1.0-doesnotexist: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/cmd$' +go install example.com/cmd/a@latest +cmp go.mod go.mod.orig +exists $GOPATH/bin/a$GOEXE +go version -m $GOPATH/bin/a$GOEXE +stdout '^\tmod\texample.com/cmd\tv1.0.0\t' # "latest", not from go.mod +rm $GOPATH/bin/a +cd .. + + +# 'go install -modfile=x.mod pkg@version' reports an error, but only if +# -modfile is specified explicitly on the command line. +cd m +env GOFLAGS=-modfile=go.mod +go install example.com/cmd/a@latest # same as above +env GOFLAGS= +! go install -modfile=go.mod example.com/cmd/a@latest +stderr '^go: -modfile cannot be used with commands that ignore the current module$' +cd .. + + +# Every test case requires linking, so we only cover the most important cases +# when -short is set. +[short] stop + + +# 'go install pkg@version' works on a module that doesn't have a go.mod file +# and with a module whose go.mod file has missing requirements. +# With a proxy, the two cases are indistinguishable. +go install rsc.io/fortune@v1.0.0 +stderr '^go: found rsc.io/quote in rsc.io/quote v1.5.2$' +exists $GOPATH/bin/fortune$GOEXE +! exists $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0/go.mod # no go.mod file +go version -m $GOPATH/bin/fortune$GOEXE +stdout '^\tdep\trsc.io/quote\tv1.5.2\t' # latest version of fortune's dependency +rm $GOPATH/bin + + +# 'go install dir@version' works like a normal 'go install' command if +# dir is a relative or absolute path. +env GO111MODULE=on +go mod download rsc.io/fortune@v1.0.0 +! go install $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0 +stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$' +! go install ../pkg/mod/rsc.io/fortune@v1.0.0 +stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$' +mkdir tmp +cd tmp +go mod init tmp +go mod edit -require=rsc.io/fortune@v1.0.0 +! go install -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0 +stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$' +! go install -mod=readonly ../../pkg/mod/rsc.io/fortune@v1.0.0 +stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$' +go get rsc.io/fortune@v1.0.0 +go install -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0 +exists $GOPATH/bin/fortune$GOEXE +cd .. +rm tmp +rm $GOPATH/bin +env GO111MODULE=auto + +# 'go install pkg@version' reports errors for meta packages, std packages, +# and directories. +! go install std@v1.0.0 +stderr '^go: std@v1.0.0: argument must be a package path, not a meta-package$' +! go install fmt@v1.0.0 +stderr '^go: fmt@v1.0.0: argument must not be a package in the standard library$' +! go install example.com//cmd/a@v1.0.0 +stderr '^go: example.com//cmd/a@v1.0.0: argument must be a clean package path$' +! go install example.com/cmd/a@v1.0.0 ./x@v1.0.0 +stderr '^go: ./x@v1.0.0: argument must be a package path, not a relative path$' +! go install example.com/cmd/a@v1.0.0 $GOPATH/src/x@v1.0.0 +stderr '^go: '$WORK'[/\\]gopath/src/x@v1.0.0: argument must be a package path, not an absolute path$' +! go install example.com/cmd/a@v1.0.0 cmd/...@v1.0.0 +stderr '^package cmd/go not provided by module example.com/cmd@v1.0.0$' + +# 'go install pkg@version' should accept multiple arguments but report an error +# if the version suffixes are different, even if they refer to the same version. +go install example.com/cmd/a@v1.0.0 example.com/cmd/b@v1.0.0 +exists $GOPATH/bin/a$GOEXE +exists $GOPATH/bin/b$GOEXE +rm $GOPATH/bin + +env GO111MODULE=on +go list -m example.com/cmd@latest +stdout '^example.com/cmd v1.0.0$' +env GO111MODULE=auto + +! go install example.com/cmd/a@v1.0.0 example.com/cmd/b@latest +stderr '^go: example.com/cmd/b@latest: all arguments must refer to packages in the same module at the same version \(@v1.0.0\)$' + + +# 'go install pkg@version' should report an error if the arguments are in +# different modules. +! go install example.com/cmd/a@v1.0.0 rsc.io/fortune@v1.0.0 +stderr '^package rsc.io/fortune provided by module rsc.io/fortune@v1.0.0\n\tAll packages must be provided by the same module \(example.com/cmd@v1.0.0\).$' + + +# 'go install pkg@version' should report an error if an argument is not +# a main package. +! go install example.com/cmd/a@v1.0.0 example.com/cmd/err@v1.0.0 +stderr '^package example.com/cmd/err is not a main package$' + +# Wildcards should match only main packages. This module has a non-main package +# with an error, so we'll know if that gets built. +mkdir tmp +cd tmp +go mod init m +go get example.com/cmd@v1.0.0 +! go build example.com/cmd/... +stderr 'err[/\\]err.go:3:9: undefined: DoesNotCompile( .*)?$' +cd .. + +go install example.com/cmd/...@v1.0.0 +exists $GOPATH/bin/a$GOEXE +exists $GOPATH/bin/b$GOEXE +rm $GOPATH/bin + +# If a wildcard matches no packages, we should see a warning. +! go install example.com/cmd/nomatch...@v1.0.0 +stderr '^go: example.com/cmd/nomatch\.\.\.@v1.0.0: module example.com/cmd@v1.0.0 found, but does not contain packages matching example.com/cmd/nomatch\.\.\.$' +go install example.com/cmd/a@v1.0.0 example.com/cmd/nomatch...@v1.0.0 +stderr '^go: warning: "example.com/cmd/nomatch\.\.\." matched no packages$' + +# If a wildcard matches only non-main packages, we should see a different warning. +go install example.com/cmd/err...@v1.0.0 +stderr '^go: warning: "example.com/cmd/err\.\.\." matched only non-main packages$' + + +# 'go install pkg@version' should report errors if the module contains +# replace or exclude directives. +go mod download example.com/cmd@v1.0.0-replace +! go install example.com/cmd/a@v1.0.0-replace +cmp stderr replace-err + +go mod download example.com/cmd@v1.0.0-exclude +! go install example.com/cmd/a@v1.0.0-exclude +cmp stderr exclude-err + +# 'go install pkg@version' should report an error if the module requires a +# higher version of itself. +! go install example.com/cmd/a@v1.0.0-newerself +stderr '^go: example.com/cmd/a@v1.0.0-newerself: version constraints conflict:\n\texample.com/cmd@v1.0.0-newerself requires example.com/cmd@v1.0.0, but v1.0.0-newerself is requested$' + + +# 'go install pkg@version' will only match a retracted version if it's +# explicitly requested. +env GO111MODULE=on +go list -m -versions example.com/cmd +! stdout v1.9.0 +go list -m -versions -retracted example.com/cmd +stdout v1.9.0 +go install example.com/cmd/a@latest +go version -m $GOPATH/bin/a$GOEXE +stdout '^\tmod\texample.com/cmd\tv1.0.0\t' +go install example.com/cmd/a@v1.9.0 +go version -m $GOPATH/bin/a$GOEXE +stdout '^\tmod\texample.com/cmd\tv1.9.0\t' +env GO111MODULE= + +# 'go install pkg@version' succeeds when -mod=readonly is set explicitly. +# Verifies #43278. +go install -mod=readonly example.com/cmd/a@v1.0.0 + + +# 'go install pkg@version' should show a deprecation message if the module is deprecated. +env GO111MODULE=on +go install example.com/deprecated/a/cmd/a@latest +stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$' +go install example.com/deprecated/a/cmd/a@v1.0.0 +stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$' + +# 'go install pkg@version' does not show a deprecation message if the module is no longer +# deprecated in its latest version, even if the module is deprecated in its current version. +go install example.com/undeprecated/cmd/a@v1.0.0 +! stderr 'module.*is deprecated' + +-- m/go.mod -- +module m + +go 1.16 + +require example.com/cmd v1.1.0-doesnotexist +-- x/x.go -- +package main + +func main() {} +-- replace-err -- +go: example.com/cmd/a@v1.0.0-replace (in example.com/cmd@v1.0.0-replace): + The go.mod file for the module providing named packages contains one or + more replace directives. It must not contain directives that would cause + it to be interpreted differently than if it were the main module. +-- exclude-err -- +go: example.com/cmd/a@v1.0.0-exclude (in example.com/cmd@v1.0.0-exclude): + The go.mod file for the module providing named packages contains one or + more exclude directives. It must not contain directives that would cause + it to be interpreted differently than if it were the main module. diff --git a/go/src/cmd/go/testdata/script/mod_install_versioned.txt b/go/src/cmd/go/testdata/script/mod_install_versioned.txt new file mode 100644 index 0000000000000000000000000000000000000000..51b78968e98399ca1a1a0f40500c8b86e65fd5fa --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_install_versioned.txt @@ -0,0 +1,14 @@ +env GO111MODULE=on + +go get rsc.io/fortune +go list -f '{{.Target}}' rsc.io/fortune +! stdout fortune@v1 +stdout 'fortune(\.exe)?$' + +go get rsc.io/fortune/v2 +go list -f '{{.Target}}' rsc.io/fortune/v2 +! stdout 'v2(\.exe)?$' +stdout 'fortune(\.exe)?$' + +-- go.mod -- +module m diff --git a/go/src/cmd/go/testdata/script/mod_internal.txt b/go/src/cmd/go/testdata/script/mod_internal.txt new file mode 100644 index 0000000000000000000000000000000000000000..787b21f379c793f0428d90eb2ecdfc690a493cac --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_internal.txt @@ -0,0 +1,96 @@ +env GO111MODULE=on +[short] skip + +# golang.org/x/internal should be importable from other golang.org/x modules. +go mod edit -module=golang.org/x/anything +go get . + +# ...and their tests... +go test +stdout PASS + +# ...but that should not leak into other modules. +go get ./baddep +! go build ./baddep +stderr golang.org[/\\]notx[/\\]useinternal +stderr 'use of internal package golang.org/x/.* not allowed' + +# Internal packages in the standard library should not leak into modules. +go get ./fromstd +! go build ./fromstd +stderr 'use of internal package internal/testenv not allowed' + +# Dependencies should be able to use their own internal modules... +go mod edit -module=golang.org/notx +go get ./throughdep + +# ... but other modules should not, even if they have transitive dependencies. +go get . +! go build . +stderr 'use of internal package golang.org/x/.* not allowed' + +# And transitive dependencies still should not leak. +go get ./baddep +! go build ./baddep +stderr golang.org[/\\]notx[/\\]useinternal +stderr 'use of internal package golang.org/x/.* not allowed' + +# Replacing an internal module should keep it internal to the same paths. +go mod edit -module=golang.org/notx +go mod edit -replace golang.org/x/internal=./replace/golang.org/notx/internal +go get ./throughdep + +go get ./baddep +! go build ./baddep +stderr golang.org[/\\]notx[/\\]useinternal +stderr 'use of internal package golang.org/x/.* not allowed' + +go mod edit -replace golang.org/x/internal=./vendor/golang.org/x/internal +go get ./throughdep + +go get ./baddep +! go build ./baddep +stderr golang.org[/\\]notx[/\\]useinternal +stderr 'use of internal package golang.org/x/.* not allowed' + +-- go.mod -- +module TBD +go 1.12 +-- useinternal.go -- +package useinternal +import _ "golang.org/x/internal/subtle" + +-- useinternal_test.go -- +package useinternal_test +import ( + "testing" + _ "golang.org/x/internal/subtle" +) + +func Test(*testing.T) {} + +-- throughdep/useinternal.go -- +package throughdep +import _ "golang.org/x/useinternal" + +-- baddep/useinternal.go -- +package baddep +import _ "golang.org/notx/useinternal" + +-- fromstd/useinternal.go -- +package fromstd +import _ "internal/testenv" + +-- replace/golang.org/notx/internal/go.mod -- +module golang.org/x/internal + +-- replace/golang.org/notx/internal/subtle/subtle.go -- +package subtle +// Ha ha! Nothing here! + +-- vendor/golang.org/x/internal/go.mod -- +module golang.org/x/internal + +-- vendor/golang.org/x/internal/subtle/subtle.go -- +package subtle +// Ha ha! Nothing here! diff --git a/go/src/cmd/go/testdata/script/mod_invalid_path.txt b/go/src/cmd/go/testdata/script/mod_invalid_path.txt new file mode 100644 index 0000000000000000000000000000000000000000..975de5ebcabfcb79dd71c547e28fe84026898ed1 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_invalid_path.txt @@ -0,0 +1,61 @@ +# Test that mod files with invalid or missing paths produce an error. + +# Test that go list fails on a go.mod with no module declaration. +cd $WORK/gopath/src/mod +! go list . +stderr '^go: error reading go.mod: missing module declaration. To specify the module path:\n\tgo mod edit -module=example.com/mod$' + +# Test that go mod init in GOPATH doesn't add a module declaration +# with a path that can't possibly be a module path, because +# it isn't even a valid import path. +# The single quote and backtick are the only characters which are not allowed +# but are a valid Windows file name. +cd $WORK/'gopath/src/m''d' +! go mod init +stderr 'cannot determine module path' + +# Test that a go.mod file is rejected when its module declaration has a path that can't +# possibly be a module path, because it isn't even a valid import path +cd $WORK/gopath/src/badname +! go list . +stderr 'malformed module path' + +# Test that an import path containing an element with a leading dot is valid, +# but such a module path is not. +# Verifies #43985. +cd $WORK/gopath/src/dotname +go list ./.dot +stdout '^example.com/dotname/.dot$' +go list ./use +stdout '^example.com/dotname/use$' +! go list -m example.com/dotname/.dot@latest +stderr '^go: example.com/dotname/.dot@latest: malformed module path "example.com/dotname/.dot": leading dot in path element$' +go get example.com/dotname/.dot +go get example.com/dotname/use +go mod tidy + +-- mod/go.mod -- + +-- mod/foo.go -- +package foo + +-- m'd/foo.go -- +package mad + +-- badname/go.mod -- + +module .\. + +-- badname/foo.go -- +package badname + +-- dotname/go.mod -- +module example.com/dotname + +go 1.16 +-- dotname/.dot/dot.go -- +package dot +-- dotname/use/use.go -- +package use + +import _ "example.com/dotname/.dot" diff --git a/go/src/cmd/go/testdata/script/mod_invalid_path_dotname.txt b/go/src/cmd/go/testdata/script/mod_invalid_path_dotname.txt new file mode 100644 index 0000000000000000000000000000000000000000..484c208f0f7567196b39d19dc00683d787efdc15 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_invalid_path_dotname.txt @@ -0,0 +1,46 @@ +# Test that an import path containing an element with a leading dot +# in another module is valid. + +# 'go get' works with no version query. +cp go.mod.empty go.mod +go get example.com/dotname/.dot +go list -m example.com/dotname +stdout '^example.com/dotname v1.0.0$' + +# 'go get' works with a version query. +cp go.mod.empty go.mod +go get example.com/dotname/.dot@latest +go list -m example.com/dotname +stdout '^example.com/dotname v1.0.0$' + +# 'go get' works on an importing package. +cp go.mod.empty go.mod +go get . +go list -m example.com/dotname +stdout '^example.com/dotname v1.0.0$' + +# 'go list' works on the dotted package. +go list example.com/dotname/.dot +stdout '^example.com/dotname/.dot$' + +# 'go list' works on an importing package. +go list . +stdout '^m$' + +# 'go mod tidy' works. +cp go.mod.empty go.mod +go mod tidy +go list -m example.com/dotname +stdout '^example.com/dotname v1.0.0$' + +-- go.mod.empty -- +module m + +go 1.16 +-- go.sum -- +example.com/dotname v1.0.0 h1:Q0JMAn464CnwFVCshs1n4+f5EFiW/eRhnx/fTWjw2Ag= +example.com/dotname v1.0.0/go.mod h1:7K4VLT7QylRI8H7yZwUkeDH2s19wQnyfp/3oBlItWJ0= +-- use.go -- +package use + +import _ "example.com/dotname/.dot" diff --git a/go/src/cmd/go/testdata/script/mod_invalid_path_plus.txt b/go/src/cmd/go/testdata/script/mod_invalid_path_plus.txt new file mode 100644 index 0000000000000000000000000000000000000000..dd59eb1fedac6870c1696869959f63a5a945d638 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_invalid_path_plus.txt @@ -0,0 +1,36 @@ +# https://golang.org/issue/44776 +# The '+' character should be disallowed in module paths, but allowed in package +# paths within valid modules. + +# 'go list' accepts package paths with pluses. +cp go.mod.orig go.mod +go get example.net/cmd +go list example.net/cmd/x++ + +# 'go list -m' rejects module paths with pluses. +! go list -versions -m 'example.net/bad++' +stderr '^go: malformed module path "example.net/bad\+\+": invalid char ''\+''$' + +# 'go get' accepts package paths with pluses. +cp go.mod.orig go.mod +go get example.net/cmd/x++ +go list -m example.net/cmd +stdout '^example.net/cmd v0.0.0-00010101000000-000000000000 => ./cmd$' + +-- go.mod.orig -- +module example.com/m + +go 1.16 + +replace ( + example.net/cmd => ./cmd +) + +-- cmd/go.mod -- +module example.net/cmd + +go 1.16 +-- cmd/x++/main.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_invalid_version.txt b/go/src/cmd/go/testdata/script/mod_invalid_version.txt new file mode 100644 index 0000000000000000000000000000000000000000..a0427b39a089e6696f6f45bb565d14082ce73974 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_invalid_version.txt @@ -0,0 +1,253 @@ +[!net:golang.org] skip +[!git] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off +env GOFLAGS=-mod=mod + +# Regression test for golang.org/issue/27173: if the user (or go.mod file) +# requests a pseudo-version that does not match both the module path and commit +# metadata, reject it with a helpful error message. +# +# TODO(bcmills): Replace the github.com/pierrec/lz4 examples with something +# equivalent on vcs-test.golang.org. + +# An incomplete commit hash is not a valid semantic version, +# but can appear in the main go.mod file anyway and should be resolved. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@14c0d48ead0c +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 \(replaced by \./\.\.\): parsing ..[/\\]go.mod: '$WORK'[/\\]gopath[/\\]src[/\\]go.mod:5: require golang.org/x/text: version "14c0d48ead0c" invalid: must be of the form v1.2.3' +cd .. +go list -m golang.org/x/text +stdout 'golang.org/x/text v0.1.1-0.20170915032832-14c0d48ead0c' +grep 'golang.org/x/text v0.1.1-0.20170915032832-14c0d48ead0c' go.mod + +# A module path below the repo root that does not contain a go.mod file is invalid. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c: invalid version: missing golang.org/x/text/unicode/go.mod at revision 14c0d48ead0c' +cd .. +! go list -m golang.org/x/text +stderr 'golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c: invalid version: missing golang.org/x/text/unicode/go.mod at revision 14c0d48ead0c' + +# However, arguments to 'go get' can name packages above the root. +cp go.mod.orig go.mod +go get golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c +go list -m golang.org/x/text/... +stdout 'golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c' +! stdout 'golang.org/x/text/unicode' + +# A major version that does not match the module path is invalid. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@v2.1.1-0.20170915032832-14c0d48ead0c +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 \(replaced by \./\.\.\): parsing ..[/\\]go.mod: '$WORK'[/\\]gopath[/\\]src[/\\]go.mod:5: require golang.org/x/text: version "v2.1.1-0.20170915032832-14c0d48ead0c" invalid: should be v0 or v1, not v2' +cd .. +! go list -m golang.org/x/text +stderr '^go.mod:5: require golang.org/x/text: version "v2.1.1-0.20170915032832-14c0d48ead0c" invalid: should be v0 or v1, not v2' + +# A pseudo-version with fewer than 12 digits of SHA-1 prefix is invalid. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0 +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0: invalid pseudo-version: revision is shorter than canonical \(expected 14c0d48ead0c\)' +cd .. +! go list -m golang.org/x/text +stderr 'golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0: invalid pseudo-version: revision is shorter than canonical \(expected 14c0d48ead0c\)' + +# A pseudo-version with more than 12 digits of SHA-1 prefix is invalid. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0cd47e3104ada247d91be04afc7a5a +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0cd47e3104ada247d91be04afc7a5a: invalid pseudo-version: revision is longer than canonical \(expected 14c0d48ead0c\)' +cd .. +! go list -m golang.org/x/text +stderr 'golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0cd47e3104ada247d91be04afc7a5a: invalid pseudo-version: revision is longer than canonical \(expected 14c0d48ead0c\)' + +# A pseudo-version that does not match the commit timestamp is invalid. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)' +cd .. +! go list -m golang.org/x/text +stderr 'golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)' + +# A 'replace' directive in the main module can replace an invalid timestamp +# with a valid one. +go mod edit -replace golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c=golang.org/x/text@14c0d48ead0c +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)' +cd .. +go list -m golang.org/x/text +stdout 'golang.org/x/text v0.1.1-0.20190915032832-14c0d48ead0c => golang.org/x/text v0.1.1-0.20170915032832-14c0d48ead0c' + +# A pseudo-version that is not derived from a tag is invalid. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@v1.999.999-0.20170915032832-14c0d48ead0c +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v1.999.999-0.20170915032832-14c0d48ead0c: invalid pseudo-version: preceding tag \(v1.999.998\) not found' +cd .. +! go list -m golang.org/x/text +stderr 'golang.org/x/text@v1.999.999-0.20170915032832-14c0d48ead0c: invalid pseudo-version: preceding tag \(v1.999.998\) not found' + +# A v1.0.0- pseudo-version that is not derived from a tag is invalid: +# v1.0.0- implies no tag, but the correct no-tag prefix for a module path +# without a major-version suffix is v0.0.0-. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@v1.0.0-20170915032832-14c0d48ead0c +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v1.0.0-20170915032832-14c0d48ead0c: invalid pseudo-version: major version without preceding tag must be v0, not v1' +cd .. +! go list -m golang.org/x/text +stderr 'golang.org/x/text@v1.0.0-20170915032832-14c0d48ead0c: invalid pseudo-version: major version without preceding tag must be v0, not v1' + +# A pseudo-version vX.Y.Z+1 cannot have Z+1 == 0, since that would +# imply a base tag with a negative patch field. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c: invalid pseudo-version: version before v0.0.0 would have negative patch number' +cd .. +! go list -m golang.org/x/text +stderr 'golang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c: invalid pseudo-version: version before v0.0.0 would have negative patch number' + +# A 'replace' directive in the main module can replace an +# invalid pseudo-version base with a valid one. +go mod edit -replace golang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c=golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.0.0-0.20170915032832-14c0d48ead0c: invalid pseudo-version: version before v0.0.0 would have negative patch number' +cd .. +go list -m golang.org/x/text +stdout 'golang.org/x/text v0.0.0-0.20170915032832-14c0d48ead0c => golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c' + +# A 'replace' directive can replace an invalid 'latest' version, and +# should suppress errors for that version in 'go get -u' +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@v1.999999.0 +go mod edit -replace golang.org/x/text@v1.999999.0=golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c +cd outside +! go get golang.org/x/text@upgrade +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v1.999999.0: reading golang.org/x/text/go.mod at revision v1.999999.0: unknown revision v1.999999.0' +cd .. +go get golang.org/x/text@upgrade +go list -m golang.org/x/text +stdout 'golang.org/x/text v1.999999.0 => golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c' + +# A pseudo-version derived from a non-ancestor tag is invalid. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@v0.2.1-0.20170915032832-14c0d48ead0c +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.2.1-0.20170915032832-14c0d48ead0c: invalid pseudo-version: revision 14c0d48ead0c is not a descendent of preceding tag \(v0.2.0\)' +cd .. +! go list -m golang.org/x/text +stderr 'golang.org/x/text@v0.2.1-0.20170915032832-14c0d48ead0c: invalid pseudo-version: revision 14c0d48ead0c is not a descendent of preceding tag \(v0.2.0\)' + +# A pseudo-version derived from a canonical tag on the same revision is invalid. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@v0.2.1-0.20171213102548-c4d099d611ac +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.2.1-0.20171213102548-c4d099d611ac: invalid pseudo-version: tag \(v0.2.0\) found on revision c4d099d611ac is already canonical, so should not be replaced with a pseudo-version derived from that tag' +cd .. +! go list -m golang.org/x/text +stderr 'golang.org/x/text@v0.2.1-0.20171213102548-c4d099d611ac: invalid pseudo-version: tag \(v0.2.0\) found on revision c4d099d611ac is already canonical, so should not be replaced with a pseudo-version derived from that tag' + +# A +incompatible suffix is not allowed on a version that is actually compatible. +cp go.mod.orig go.mod +go mod edit -require golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0c+incompatible +cd outside +! go list -m golang.org/x/text +stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0c\+incompatible: invalid version: \+incompatible suffix not allowed: major version v0 is compatible' +cd .. +! go list -m golang.org/x/text +stderr 'golang.org/x/text@v0.1.1-0.20170915032832-14c0d48ead0c\+incompatible: invalid version: \+incompatible suffix not allowed: major version v0 is compatible' + +[!net:github.com] stop + +# The pseudo-version for a commit after a tag with a non-matching major version +# should instead be based on the last matching tag. +cp go.mod.orig go.mod +go mod edit -require github.com/pierrec/lz4@473cd7ce01a1 +go list -m github.com/pierrec/lz4 +stdout 'github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1' +cd outside +go list -m github.com/pierrec/lz4 +stdout 'github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1' +cd .. + +# A +incompatible pseudo-version for a module that has an explicit go.mod file is invalid. +cp go.mod.orig go.mod +go mod edit -require github.com/pierrec/lz4@v2.0.9-0.20190209155647-9a39efadad3d+incompatible +cd outside +! go list -m github.com/pierrec/lz4 +stderr '^go: example.com@v0.0.0 requires\n\tgithub.com/pierrec/lz4@v2.0.9-0.20190209155647-9a39efadad3d\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$' +cd .. +! go list -m github.com/pierrec/lz4 +stderr '^go: github.com/pierrec/lz4@v2.0.9-0.20190209155647-9a39efadad3d\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$' + +# A +incompatible pseudo-version is valid for a revision of the module +# that lacks a go.mod file. +cp go.mod.orig go.mod +go mod edit -require github.com/pierrec/lz4@v2.0.4-0.20180826165652-dbe9298ce099+incompatible +cd outside +go list -m github.com/pierrec/lz4 +stdout 'github.com/pierrec/lz4 v2.0.4-0.20180826165652-dbe9298ce099\+incompatible' +cd .. +go list -m github.com/pierrec/lz4 +stdout 'github.com/pierrec/lz4 v2.0.4-0.20180826165652-dbe9298ce099\+incompatible' + +# 'go get' for a mismatched major version without a go.mod file should resolve +# to the equivalent +incompatible version, not a pseudo-version with a different +# major version. +cp go.mod.orig go.mod +go get github.com/pierrec/lz4@v2.0.5 +go list -m github.com/pierrec/lz4 +stdout 'github.com/pierrec/lz4 v2.0.5\+incompatible' + +# 'go get' for a mismatched major version with a go.mod file should error out, +# not resolve to a pseudo-version with a different major version. +cp go.mod.orig go.mod +! go get github.com/pierrec/lz4@v2.0.8 +stderr 'go: github.com/pierrec/lz4@v2.0.8: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$' + +# An invalid +incompatible suffix for a canonical version should error out, +# not resolve to a pseudo-version. +# +# TODO(bcmills): The "outside" view for this failure mode is missing its import stack. +# Figure out why and fix it. +cp go.mod.orig go.mod +go mod edit -require github.com/pierrec/lz4@v2.0.8+incompatible +cd outside +! go list -m github.com/pierrec/lz4 +stderr '^go: github.com/pierrec/lz4@v2.0.8\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$' +cd .. +! go list -m github.com/pierrec/lz4 +stderr '^go: github.com/pierrec/lz4@v2.0.8\+incompatible: invalid version: module contains a go.mod file, so module path must match major version \("github.com/pierrec/lz4/v2"\)$' + +-- go.mod.orig -- +module example.com + +go 1.13 +-- outside/go.mod -- +module example.com/outside + +go 1.13 + +require example.com v0.0.0 +replace example.com v0.0.0 => ./.. diff --git a/go/src/cmd/go/testdata/script/mod_issue35270.txt b/go/src/cmd/go/testdata/script/mod_issue35270.txt new file mode 100644 index 0000000000000000000000000000000000000000..27b922636cd09dde1c8217bb71d7cf9cd3185ca5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_issue35270.txt @@ -0,0 +1,57 @@ + +cd a +! go build +stderr '^ambiguous import: found package image in multiple modules:\s+image\s+.+\s.+image.+\s$' + + +cd ../b +! go build -mod=vendor +stderr '^main.go:4:5: ambiguous import: found package image in multiple directories:\s+.+image\s+.+image\s+$' + +cd ../c +! go build -mod=vendor +stderr 'main.go:4:5: package p is not in std' + +-- a/go.mod -- +module image + +-- a/main.go -- +package main + +func main() { + println("hello world!") +} + +-- b/go.mod -- +module test + +-- b/vendor/image/b.go -- +package image +func Add(a, b int) int { + return a + b +} + +-- b/main.go -- +package main + +import ( + "image" +) + +func main() { + println(image.Add(1,1)) +} + +-- c/go.mod -- +module test + +-- c/main.go -- +package main + +import ( + "p" +) + +func main() { + println(p.Add(1,1)) +} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_issue35317.txt b/go/src/cmd/go/testdata/script/mod_issue35317.txt new file mode 100644 index 0000000000000000000000000000000000000000..92416a54e474e0a8bb22c6422e1dd2a2fca01154 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_issue35317.txt @@ -0,0 +1,8 @@ +# Regression test for golang.org/issue/35317: +# 'go get' with multiple module-only arguments was racy. + +env GO111MODULE=on +[short] skip + +go mod init example.com +go get golang.org/x/text@v0.3.0 golang.org/x/internal@v0.1.0 golang.org/x/exp@none diff --git a/go/src/cmd/go/testdata/script/mod_lazy_consistency.txt b/go/src/cmd/go/testdata/script/mod_lazy_consistency.txt new file mode 100644 index 0000000000000000000000000000000000000000..1bf3e31bfe0799b6f51159332febe315893957a6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_lazy_consistency.txt @@ -0,0 +1,95 @@ +# If the root requirements in a lazy module are inconsistent +# (for example, due to a bad hand-edit or git merge), +# they can go unnoticed as long as the module with the violated +# requirement is not used. +# When we load a package from that module, we should spot-check its +# requirements and either emit an error or update the go.mod file. + +cp go.mod go.mod.orig + + +# If we load package x from x.1, we only check the requirements of x, +# which are fine: loading succeeds. + +go list -deps ./usex +stdout '^example.net/x$' +cmp go.mod go.mod.orig + + +# However, if we load needx2, we should load the requirements of needx2. +# Those requirements indicate x.2, not x.1, so the module graph is +# inconsistent and needs to be fixed. + +! go list -deps ./useneedx2 +stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$' + +! go list -deps example.net/needx2 +stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$' + + +# The command printed in the error message should fix the problem. + +go mod tidy +go list -deps ./useneedx2 +stdout '^example.net/m/useneedx2$' +stdout '^example.net/needx2$' +stdout '^example.net/x$' + +go list -m all +stdout '^example.net/needx2 v0\.1\.0 ' +stdout '^example.net/x v0\.2\.0 ' + + +-- go.mod -- +module example.net/m + +go 1.17 + +require ( + example.net/needx2 v0.1.0 + example.net/x v0.1.0 +) + +replace ( + example.net/needx2 v0.1.0 => ./needx2.1 + example.net/x v0.1.0 => ./x.1 + example.net/x v0.2.0 => ./x.2 +) +-- useneedx2/useneedx2.go -- +package useneedx2 + +import _ "example.net/needx2" +-- usex/usex.go -- +package usex + +import _ "example.net/x" + +-- x.1/go.mod -- +module example.com/x + +go 1.17 +-- x.1/x.go -- +package x + +-- x.2/go.mod -- +module example.com/x + +go 1.17 +-- x.2/x.go -- +package x + +const AddedInV2 = true + +-- needx2.1/go.mod -- +module example.com/x + +go 1.17 + +require example.net/x v0.2.0 +-- needx2.1/needx2.go -- +// Package needx2 needs x v0.2.0 or higher. +package needx2 + +import "example.net/x" + +var _ = x.AddedInV2 diff --git a/go/src/cmd/go/testdata/script/mod_lazy_downgrade.txt b/go/src/cmd/go/testdata/script/mod_lazy_downgrade.txt new file mode 100644 index 0000000000000000000000000000000000000000..eb69d2eb8f81e12bb2ee762c290cb25529c4e040 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_lazy_downgrade.txt @@ -0,0 +1,183 @@ +# This test illustrates the interaction between lazy loading and downgrading in +# 'go get'. + +# The package import graph used in this test looks like: +# +# lazy ---- a +# | +# a_test ---- b +# b_test ---- c +# +# The module dependency graph initially looks like: +# +# lazy ---- a.1 ---- b.1 ---- c.1 +# \ / +# b.3 ---- c.2 b.2 +# +# (Note that lazy loading will prune out the dependency from b.1 on c.1.) + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod.orig go.mod + +go list -m all +stdout '^example.com/a v0.1.0 ' +stdout '^example.com/b v0.3.0 ' +stdout '^example.com/c v0.2.0 ' + +# Downgrading c should also downgrade the b that requires it. + +go get example.com/c@v0.1.0 +go list -m all +stdout '^example.com/a v0.1.0 ' +stdout '^example.com/b v0.2.0 ' +stdout '^example.com/c v0.1.0 ' + +# Removing c entirely should also remove the a and b that require it. + +go get example.com/c@none +go list -m all +! stdout '^example.com/a ' +! stdout '^example.com/b ' +! stdout '^example.com/c ' + + +# With lazy loading, downgrading c should work the same way, but dependencies +# outside of the deepening scan should not affect the downgrade. + +cp go.mod.orig go.mod +go mod edit -go=1.17 + +go list -m all +stdout '^example.com/a v0.1.0 ' +stdout '^example.com/b v0.3.0 ' +stdout '^example.com/c v0.2.0 ' + +go get example.com/c@v0.1.0 +go list -m all +stdout '^example.com/a v0.1.0 ' +stdout '^example.com/b v0.2.0 ' +stdout '^example.com/c v0.1.0 ' + +# At this point, b.2 is still an explicit root, so its dependency on c +# is still tracked, and it will still be downgraded away if we remove c. +# ('go get' never makes a root into a non-root. Only 'go mod tidy' does that.) + +go get example.com/c@none +go list -m all +! stdout '^example.com/a ' +! stdout '^example.com/b ' +! stdout '^example.com/c ' + + +# This time, we drop the explicit 'b' root by downgrading it to v0.1.0 +# (the version required by a.1) and running 'go mod tidy'. +# It is still selected at v0.1.0 (as a dependency of a), +# but its dependency on c is now pruned from the module graph, so it doesn't +# result in any downgrades to b or a if we run 'go get c@none'. + +cp go.mod.orig go.mod +go mod edit -go=1.17 + +go list -m all +stdout '^example.com/a v0.1.0 ' +stdout '^example.com/b v0.3.0 ' +stdout '^example.com/c v0.2.0 ' + +go get example.com/c@v0.1.0 example.com/b@v0.1.0 +go list -m all +stdout '^example.com/a v0.1.0 ' +stdout '^example.com/b v0.1.0 ' +stdout '^example.com/c v0.1.0 ' + +go mod tidy +go list -m all +stdout '^example.com/a v0.1.0 ' +stdout '^example.com/b v0.1.0 ' +! stdout '^example.com/c ' + +go get example.com/c@none +go list -m all +stdout '^example.com/a v0.1.0' +stdout '^example.com/b v0.1.0' +! stdout '^example.com/c ' + + +-- go.mod -- +module example.com/lazy + +go 1.15 + +require ( + example.com/a v0.1.0 + example.com/b v0.3.0 // indirect +) + +replace ( + example.com/a v0.1.0 => ./a + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0 => ./b2 + example.com/b v0.3.0 => ./b3 + example.com/c v0.1.0 => ./c + example.com/c v0.2.0 => ./c +) +-- lazy.go -- +package lazy + +import _ "example.com/a" + +-- a/go.mod -- +module example.com/a + +go 1.17 + +require example.com/b v0.1.0 +-- a/a.go -- +package a +-- a/a_test.go -- +package a_test + +import _ "example.com/b" + +-- b1/go.mod -- +module example.com/b + +go 1.17 + +require example.com/c v0.1.0 +-- b1/b.go -- +package b +-- b1/b_test.go -- +package b_test +import _ "example.com/c" + +-- b2/go.mod -- +module example.com/b + +go 1.17 + +require example.com/c v0.1.0 +-- b2/b.go -- +package b +-- b2/b_test.go -- +package b_test +import _ "example.com/c" + +-- b3/go.mod -- +module example.com/b + +go 1.17 + +require example.com/c v0.2.0 +-- b3/b.go -- +package b +-- b3/b_test.go -- +package b_test +import _ "example.com/c" + +-- c/go.mod -- +module example.com/c + +go 1.17 +-- c/c.go -- +package c diff --git a/go/src/cmd/go/testdata/script/mod_lazy_import_allmod.txt b/go/src/cmd/go/testdata/script/mod_lazy_import_allmod.txt new file mode 100644 index 0000000000000000000000000000000000000000..60d4187b1178aec7deb1a5e554fe55d936899d76 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_lazy_import_allmod.txt @@ -0,0 +1,191 @@ +# This test demonstrates dependency resolution when the main module imports a +# new package from a previously-test-only dependency. +# +# When lazy loading is active, the loader will not load dependencies of any +# module whose packages are *only* imported by tests outside the main module. If +# the main module is changed to import a package from such a module, the +# dependencies of that module will need to be reloaded. + +# The import graph used in this test looks like: +# +# m ---- a +# \ | +# \ a_test ---- b/x +# \ +# --------------b/y (new) ---- c +# +# Where b/x and b/y are disjoint packages, but both contained in module b. +# +# The module dependency graph initially looks like: +# +# m ---- a.1 ---- b.1 ---- c.1 +# +# This configuration is similar to that used in mod_lazy_new_import, +# but the new import is from what is initially a test-only dependency. + +# Control case: in Go 1.14, the original go.mod is tidy, +# and the dependency on c is eagerly loaded. + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod.orig go.mod + +go list -m all +stdout '^a v0.1.0 ' +stdout '^b v0.1.0 ' +stdout '^c v0.1.0 ' + +# After adding a new import of b/y, +# the import of c from b/y should resolve to the version required by b. + +cp m.go m.go.orig +cp m.go.new m.go +go mod tidy +cmp go.mod.new go.mod + +go list -m all +stdout '^a v0.1.0 ' +stdout '^b v0.1.0 ' +stdout '^c v0.1.0 ' + +# With lazy loading, the go.mod requirements are the same, +# but the dependency on c is initially pruned out. + +cp m.go.orig m.go +cp go.mod.orig go.mod +go mod edit -go=1.17 +go mod edit -go=1.17 go.mod.new + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod.orig go.mod + +go list -m all +stdout '^a v0.1.0 ' +stdout '^b v0.1.0 ' +! stdout '^c ' + +# After adding a new direct import of b/y, +# the existing version of b should be promoted to a root, +# bringing the version of c required by b into the build list. + +cp m.go.new m.go +go mod tidy +cmp go.mod.lazy go.mod + +go list -m all +stdout '^a v0.1.0 ' +stdout '^b v0.1.0 ' +stdout '^c v0.1.0 ' + +-- m.go -- +package main + +import ( + "fmt" + + _ "a" // a_test imports b/x. +) + +func main() { +} +-- m.go.new -- +package main + +import ( + "fmt" + + _ "a" // a_test imports b/x. + "b/y" // This is a new import, not yet reflected in the go.mod file. +) + +func main() { + fmt.Println(b.CVersion()) +} +-- go.mod -- +module m + +go 1.14 + +require a v0.1.0 + +replace ( + a v0.1.0 => ./a1 + b v0.1.0 => ./b1 + c v0.1.0 => ./c1 + c v0.2.0 => ./c2 +) +-- go.mod.new -- +module m + +go 1.14 + +require ( + a v0.1.0 + b v0.1.0 +) + +replace ( + a v0.1.0 => ./a1 + b v0.1.0 => ./b1 + c v0.1.0 => ./c1 + c v0.2.0 => ./c2 +) +-- go.mod.lazy -- +module m + +go 1.17 + +require ( + a v0.1.0 + b v0.1.0 +) + +require c v0.1.0 // indirect + +replace ( + a v0.1.0 => ./a1 + b v0.1.0 => ./b1 + c v0.1.0 => ./c1 + c v0.2.0 => ./c2 +) +-- a1/go.mod -- +module a + +go 1.17 + +require b v0.1.0 +-- a1/a.go -- +package a +-- a1/a_test.go -- +package a_test + +import _ "b/x" +-- b1/go.mod -- +module b + +go 1.17 + +require c v0.1.0 +-- b1/x/x.go -- +package x +-- b1/y/y.go -- +package y + +import "c" + +func CVersion() string { + return c.Version +} +-- c1/go.mod -- +module c + +go 1.17 +-- c1/c.go -- +package c + +const Version = "v0.1.0" +-- c2/go.mod -- +This file should be unused. +-- c2/c.go -- +This file should be unused. diff --git a/go/src/cmd/go/testdata/script/mod_lazy_new_import.txt b/go/src/cmd/go/testdata/script/mod_lazy_new_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..520d8459cc11d4909ea381c2ed5df476b61af7fe --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_lazy_new_import.txt @@ -0,0 +1,155 @@ +# This test illustrates the use of a deepening scan to resolve transitive +# imports of imports of new packages from within existing dependencies. + +# The package import graph used in this test looks like: +# +# lazy ---- a/x ---- b +# \ +# ---- a/y (new) ---- c +# +# Where a/x and a/y are disjoint packages, but both contained in module a. +# +# The module dependency graph initially looks like: +# +# lazy ---- a.1 ---- b.1 +# \ +# c.1 + + +cp go.mod go.mod.old +cp lazy.go lazy.go.old +go mod tidy +cmp go.mod go.mod.old + +# Before adding a new import, the go.mod file should +# enumerate modules for all packages already imported. +go list all +cmp go.mod go.mod.old + +# When we add a new import of a package in an existing dependency, +# and that dependency is already tidy, its transitive dependencies +# should already be present. +cp lazy.go.new lazy.go +go list all +go list -m all +stdout '^example.com/c v0.1.0' # not v0.2.0 as would be resolved by 'latest' +cmp go.mod go.mod.old + +# Now, we repeat the test with a lazy main module. +cp lazy.go.old lazy.go +cp go.mod.117 go.mod + +# Before adding a new import, the go.mod file should +# enumerate modules for all packages already imported. +go list all +cmp go.mod go.mod.117 + +# When a new import is found, we should perform a deepening scan of the existing +# dependencies and add a requirement on the version required by those +# dependencies — not re-resolve 'latest'. +cp lazy.go.new lazy.go + +! go list all +stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$' + +go mod tidy +go list all +go list -m all +stdout '^example.com/c v0.1.0' # not v0.2.0 as would be resolved by 'latest' + +cmp go.mod go.mod.new + + +-- go.mod -- +module example.com/lazy + +go 1.15 + +require example.com/a v0.1.0 + +replace ( + example.com/a v0.1.0 => ./a + example.com/b v0.1.0 => ./b + example.com/c v0.1.0 => ./c1 + example.com/c v0.2.0 => ./c2 +) +-- go.mod.117 -- +module example.com/lazy + +go 1.17 + +require example.com/a v0.1.0 + +require example.com/b v0.1.0 // indirect + +replace ( + example.com/a v0.1.0 => ./a + example.com/b v0.1.0 => ./b + example.com/c v0.1.0 => ./c1 + example.com/c v0.2.0 => ./c2 +) +-- go.mod.new -- +module example.com/lazy + +go 1.17 + +require example.com/a v0.1.0 + +require ( + example.com/b v0.1.0 // indirect + example.com/c v0.1.0 // indirect +) + +replace ( + example.com/a v0.1.0 => ./a + example.com/b v0.1.0 => ./b + example.com/c v0.1.0 => ./c1 + example.com/c v0.2.0 => ./c2 +) +-- lazy.go -- +package lazy + +import ( + _ "example.com/a/x" +) +-- lazy.go.new -- +package lazy + +import ( + _ "example.com/a/x" + _ "example.com/a/y" +) +-- a/go.mod -- +module example.com/a + +go 1.15 + +require ( + example.com/b v0.1.0 + example.com/c v0.1.0 +) +-- a/x/x.go -- +package x +import _ "example.com/b" +-- a/y/y.go -- +package y +import _ "example.com/c" +-- b/go.mod -- +module example.com/b + +go 1.15 +-- b/b.go -- +package b +-- c1/go.mod -- +module example.com/c + +go 1.15 +-- c1/c.go -- +package c +-- c2/go.mod -- +module example.com/c + +go 1.15 +-- c2/c.go -- +package c +This file should not be used, so this syntax error should be ignored. diff --git a/go/src/cmd/go/testdata/script/mod_lazy_test_horizon.txt b/go/src/cmd/go/testdata/script/mod_lazy_test_horizon.txt new file mode 100644 index 0000000000000000000000000000000000000000..7d07eb60aa66baade8024253d584e44e5ad8b524 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_lazy_test_horizon.txt @@ -0,0 +1,131 @@ +# This file demonstrates the effect of lazy loading on the selected +# versions of test dependencies. + +# The package import graph used in this test looks like: +# +# m ---- a +# \ | +# \ a_test ---- b +# \ | +# x b_test +# | \ +# x_test -------------- c +# +# And the module dependency graph looks like: +# +# m -- a.1 -- b.1 -- c.2 +# \ +# x.1 ------------ c.1 + +# Control case: in Go 1.15, the version of c imported by 'go test x' is the +# version required by module b, even though b_test is not relevant to the main +# module. (The main module imports a, and a_test imports b, but all of the +# packages and tests in the main module can be built without b.) + +go list -m c +stdout '^c v0.2.0 ' + +[!short] go test -v x +[!short] stdout ' c v0.2.0$' + +# With lazy loading, the go.mod requirements are the same, +# but the irrelevant dependency on c v0.2.0 should be pruned out, +# leaving only the relevant dependency on c v0.1.0. + +go mod edit -go=1.17 +go list -m c +stdout '^c v0.1.0' + +[!short] go test -v x +[!short] stdout ' c v0.1.0$' + +-- m.go -- +package m + +import ( + _ "a" + _ "x" +) +-- go.mod -- +module m + +go 1.15 + +require ( + a v0.1.0 + x v0.1.0 +) + +replace ( + a v0.1.0 => ./a1 + b v0.1.0 => ./b1 + c v0.1.0 => ./c1 + c v0.2.0 => ./c2 + x v0.1.0 => ./x1 +) +-- a1/go.mod -- +module a + +go 1.17 + +require b v0.1.0 +-- a1/a.go -- +package a +-- a1/a_test.go -- +package a_test + +import _ "b" +-- b1/go.mod -- +module b + +go 1.17 + +require c v0.2.0 +-- b1/b.go -- +package b +-- b1/b_test.go -- +package b_test + +import ( + "c" + "testing" +) + +func TestCVersion(t *testing.T) { + t.Log(c.Version) +} +-- c1/go.mod -- +module c + +go 1.17 +-- c1/c.go -- +package c + +const Version = "v0.1.0" +-- c2/go.mod -- +module c + +go 1.17 +-- c2/c.go -- +package c + +const Version = "v0.2.0" +-- x1/go.mod -- +module x + +go 1.17 + +require c v0.1.0 +-- x1/x.go -- +package x +-- x1/x_test.go -- +package x_test + +import ( + "c" + "testing" +) + +func TestCVersion(t *testing.T) { + t.Log("c", c.Version) +} diff --git a/go/src/cmd/go/testdata/script/mod_lazy_test_of_test_dep.txt b/go/src/cmd/go/testdata/script/mod_lazy_test_of_test_dep.txt new file mode 100644 index 0000000000000000000000000000000000000000..68a5b6dca2ad6091068df7795873d764096a9903 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_lazy_test_of_test_dep.txt @@ -0,0 +1,224 @@ +# This file demonstrates the effect of lazy loading on the reproducibility of +# tests (and tests of test dependencies) outside the main module. +# +# It is similar to the cases in mod_all.txt and mod_lazy_test_horizon.txt, but +# focuses on the effect of "go test" on specific packages instead of the "all" +# pattern. + +# The package import graph used in this test looks like: +# +# lazy ---- a +# | +# a_test ---- b +# | +# b_test ---- c +# +# And the non-lazy module dependency graph looks like: +# +# lazy ---- a.1 ---- b.1 ---- c.1 + +cp go.mod go.mod.old +go mod tidy +cmp go.mod go.mod.old + + +# In Go 1.15 mode, 'go list -m all' includes modules needed by the +# transitive closure of tests of dependencies of tests of dependencies of …. + +go list -m all +stdout '^example.com/b v0.1.0 ' +stdout '^example.com/c v0.1.0 ' +cmp go.mod go.mod.old + +# 'go test' (or equivalent) of any such dependency, no matter how remote, does +# not update the go.mod file. + +go list -test -deps example.com/a +stdout example.com/b +! stdout example.com/c + +[!short] go test -c -o $devnull example.com/a +[!short] cmp go.mod go.mod.old + +go list -test -deps example.com/b +stdout example.com/c + +[!short] go test -c -o $devnull example.com/b +[!short] cmp go.mod go.mod.old + +go mod edit -go=1.17 a/go.mod +go mod edit -go=1.17 b1/go.mod +go mod edit -go=1.17 b2/go.mod +go mod edit -go=1.17 c1/go.mod +go mod edit -go=1.17 c2/go.mod +go mod edit -go=1.17 + + +# After changing to 'go 1.17` uniformly, 'go list -m all' should prune out +# example.com/c, because it is not imported by any package (or test of a package) +# transitively imported by the main module. +# +# example.com/a is imported, +# and example.com/b is needed in order to run 'go test example.com/a', +# but example.com/c is not needed because we don't expect the user to need to run +# 'go test example.com/b'. + +# If we skip directly to adding a new import of c, the dependency is too far +# away for a deepening scan to find, which is fine because the package whose +# test imported it wasn't even it "all". It should resolve from the latest +# version of its module. + +# However, if we reach c by running successive tests starting from the main +# module, we should end up with exactly the version required by b, with an update +# to the go.mod file as soon as we test a test dependency that is not itself in +# "all". + +cp go.mod go.mod.117 +go mod tidy +cmp go.mod go.mod.117 + +go list -m all +stdout '^example.com/b v0.1.0 ' +! stdout '^example.com/c ' + +# 'go test' of a package (transitively) imported by the main module +# should work without changes to the go.mod file. + +go list -test -deps example.com/a +stdout example.com/b +! stdout example.com/c + +[!short] go test -c -o $devnull example.com/a + +# However, 'go test' of a package that is itself a dependency should require an +# update to the go.mod file. +! go list -test -deps example.com/b + + # TODO(#36460): The hint here is wrong. We should suggest + # 'go get -t example.com/b@v0.1.0' instead of 'go mod tidy'. +stderr '^go: updates to go\.mod needed; to update it:\n\tgo mod tidy$' + +[!short] ! go test -c -o $devnull example.com/b +[!short] stderr '^go: updates to go\.mod needed; to update it:\n\tgo mod tidy$' + +go get -t example.com/b@v0.1.0 +go list -test -deps example.com/b +stdout example.com/c + +[!short] go test -c -o $devnull example.com/b + +# The update should bring the version required by b, not the latest version of c. + +go list -m example.com/c +stdout '^example.com/c v0.1.0 ' + +cmp go.mod go.mod.b + + +# We should reach the same state if we arrive at it via `go test -mod=mod`. + +cp go.mod.117 go.mod + +[short] go list -mod=mod -test -deps example.com/a +[!short] go test -mod=mod -c -o $devnull example.com/a + +[short] go list -mod=mod -test -deps example.com/b +[!short] go test -mod=mod -c -o $devnull example.com/b + +cmp go.mod go.mod.b + + + +-- go.mod -- +module example.com/lazy + +go 1.15 + +require example.com/a v0.1.0 + +replace ( + example.com/a v0.1.0 => ./a + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0 => ./b2 + example.com/c v0.1.0 => ./c1 + example.com/c v0.2.0 => ./c2 +) +-- go.mod.b -- +module example.com/lazy + +go 1.17 + +require example.com/a v0.1.0 + +require example.com/b v0.1.0 // indirect + +replace ( + example.com/a v0.1.0 => ./a + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0 => ./b2 + example.com/c v0.1.0 => ./c1 + example.com/c v0.2.0 => ./c2 +) +-- lazy.go -- +package lazy + +import ( + _ "example.com/a" +) +-- a/go.mod -- +module example.com/a + +go 1.15 + +require example.com/b v0.1.0 +-- a/a.go -- +package a +-- a/a_test.go -- +package a + +import ( + "testing" + + _ "example.com/b" +) + +func TestUsingB(t *testing.T) { + // … +} +-- b1/go.mod -- +module example.com/b + +go 1.15 + +require example.com/c v0.1.0 +-- b1/b.go -- +package b +-- b1/b_test.go -- +package b + +import _ "example.com/c" +-- b2/go.mod -- +module example.com/b + +go 1.15 + +require example.com/c v0.1.0 +-- b2/b.go -- +package b +This file should not be used, so this syntax error should be ignored. +-- b2/b_test.go -- +package b +This file should not be used, so this syntax error should be ignored. +-- c1/go.mod -- +module example.com/c + +go 1.15 +-- c1/c.go -- +package c +-- c2/go.mod -- +module example.com/c + +go 1.15 +-- c2/c.go -- +package c +This file should not be used, so this syntax error should be ignored. diff --git a/go/src/cmd/go/testdata/script/mod_list.txt b/go/src/cmd/go/testdata/script/mod_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..40820b3bb5aed5c8e182febda4f2492543b85f2c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list.txt @@ -0,0 +1,62 @@ +env GO111MODULE=on +[short] skip + +# list {{.Dir}} shows main module and go.mod but not not-yet-downloaded dependency dir. +go list -mod=mod -m -f '{{.Path}} {{.Main}} {{.GoMod}} {{.Dir}}' all +stdout '^x true .*[\\/]src[\\/]go.mod .*[\\/]src$' +stdout '^rsc.io/quote false .*[\\/]v1.5.2.mod $' + +# list {{.Dir}} shows dependency after download (and go list without -m downloads it) +go list -mod=mod -f '{{.Dir}}' rsc.io/quote +stdout '.*mod[\\/]rsc.io[\\/]quote@v1.5.2$' + +# downloaded dependencies are read-only +exists -readonly $GOPATH/pkg/mod/rsc.io/quote@v1.5.2 +exists -readonly $GOPATH/pkg/mod/rsc.io/quote@v1.5.2/buggy + +# go clean -modcache can delete read-only dependencies +go clean -modcache +! exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.2 + +# list {{.Dir}} shows replaced directories +cp go.mod2 go.mod +go list -mod=mod -f {{.Dir}} rsc.io/quote +go list -m -f '{{.Path}} {{.Version}} {{.Dir}}{{with .Replace}} {{.GoMod}} => {{.Version}} {{.Dir}} {{.GoMod}}{{end}}' all +stdout 'mod[\\/]rsc.io[\\/]quote@v1.5.1' +stdout 'v1.3.0.*mod[\\/]rsc.io[\\/]sampler@v1.3.1 .*[\\/]v1.3.1.mod => v1.3.1.*sampler@v1.3.1 .*[\\/]v1.3.1.mod' + +# list std should work +go list std +stdout ^math/big + +# rsc.io/quote/buggy should be listable as a package, +# even though it is only a test. +go list -mod=mod rsc.io/quote/buggy + +# rsc.io/quote/buggy should not be listable as a module +go list -m -e -f '{{.Error.Err}}' nonexist rsc.io/quote/buggy +stdout '^module nonexist: not a known dependency$' +stdout '^module rsc.io/quote/buggy: not a known dependency$' + +! go list -m nonexist rsc.io/quote/buggy +stderr '^go: module nonexist: not a known dependency' +stderr '^go: module rsc.io/quote/buggy: not a known dependency' + +# Module loader does not interfere with list -e (golang.org/issue/24149). +go list -e -f '{{.Error.Err}}' database +stdout 'package database is not in std' +! go list database +stderr 'package database is not in std' + +-- go.mod -- +module x +require rsc.io/quote v1.5.2 + +-- go.mod2 -- +module x +require rsc.io/quote v1.5.1 +replace rsc.io/sampler v1.3.0 => rsc.io/sampler v1.3.1 + +-- x.go -- +package x +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_list_bad_import.txt b/go/src/cmd/go/testdata/script/mod_list_bad_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..b128408a612a4163ed58d9470e1f63a929b28063 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_bad_import.txt @@ -0,0 +1,75 @@ +# This test matches list_bad_import, but in module mode. +# Please keep them in sync. + +env GO111MODULE=on +cd example.com + +# Without -e, listing an otherwise-valid package with an unsatisfied direct import should fail. +# BUG: Today it succeeds. +go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}} {{range .DepsErrors}}bad dep: {{.Err}}{{end}}' example.com/direct +! stdout ^error +stdout 'incomplete' +stdout 'bad dep: .*example.com/notfound' + +# Listing with -deps should also fail. +! go list -deps example.com/direct +stderr example.com/notfound + +# But -e -deps should succeed. +go list -e -deps example.com/direct +stdout example.com/notfound + + +# Listing an otherwise-valid package that imports some *other* package with an +# unsatisfied import should also fail. +# BUG: Today, it succeeds. +go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}} {{range .DepsErrors}}bad dep: {{.Err}}{{end}}' example.com/indirect +! stdout ^error +stdout incomplete +stdout 'bad dep: .*example.com/notfound' + +# Again, -deps should fail. +! go list -deps example.com/indirect +stderr example.com/notfound + +# But -e -deps should succeed. +go list -e -deps example.com/indirect +stdout example.com/notfound + + +# Listing the missing dependency directly should fail outright... +! go list -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}}' example.com/notfound +stderr 'no required module provides package example.com/notfound; to add it:\n\tgo get example.com/notfound' +! stdout error +! stdout incomplete + +# ...but listing with -e should succeed. +go list -e -f '{{if .Error}}error{{end}} {{if .Incomplete}}incomplete{{end}}' example.com/notfound +stdout error +stdout incomplete + + +# The pattern "all" should match only packages that actually exist, +# ignoring those whose existence is merely implied by imports. +go list -e -f '{{.ImportPath}} {{.Error}}' all +stdout example.com/direct +stdout example.com/indirect +# TODO: go list creates a dummy package with the import-not-found +# but really the Error belongs on example.com/direct, and this package +# should not be printed. +# ! stdout example.com/notfound + + +-- example.com/go.mod -- +module example.com + +-- example.com/direct/direct.go -- +package direct +import _ "example.com/notfound" + +-- example.com/indirect/indirect.go -- +package indirect +import _ "example.com/direct" + +-- example.com/notfound/README -- +This directory intentionally left blank. diff --git a/go/src/cmd/go/testdata/script/mod_list_command_line_arguments.txt b/go/src/cmd/go/testdata/script/mod_list_command_line_arguments.txt new file mode 100644 index 0000000000000000000000000000000000000000..25c68c5a8265d5efe46f9fce60b305ce06acde22 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_command_line_arguments.txt @@ -0,0 +1,35 @@ +# The command-line-arguments package does not belong to a module... +cd a +go list -f '{{.Module}}' ../b/b.go +stdout '^$' + +# ... even if the arguments are sources from that module +go list -f '{{.Module}}' a.go +stdout '^$' + +[short] skip + +# check that the version of command-line-arguments doesn't include a module +go build -o a.exe a.go +go version -m a.exe +stdout '^\tpath\tcommand-line-arguments$' +stdout '^\tdep\ta\t\(devel\)\t$' +! stdout mod[^e] + +-- a/go.mod -- +module a +go 1.17 +-- a/a.go -- +package main + +import "a/dep" + +func main() { + dep.D() +} +-- a/dep/dep.go -- +package dep + +func D() {} +-- b/b.go -- +package b \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_list_compiled_concurrent.txt b/go/src/cmd/go/testdata/script/mod_list_compiled_concurrent.txt new file mode 100644 index 0000000000000000000000000000000000000000..195f7b1527969cbf663f80571d569780dae53add --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_compiled_concurrent.txt @@ -0,0 +1,21 @@ +env GO111MODULE=on + +[short] skip +[!cgo] skip + +# Regression test for golang.org/issue/29667: +# spurious 'failed to cache compiled Go files' errors. + +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +go list -json -compiled -test=false -export=false -deps=true -- . & +go list -json -compiled -test=false -export=false -deps=true -- . & +wait + +-- go.mod -- +module sandbox/bar +-- bar.go -- +package bar + +import "C" diff --git a/go/src/cmd/go/testdata/script/mod_list_deprecated.txt b/go/src/cmd/go/testdata/script/mod_list_deprecated.txt new file mode 100644 index 0000000000000000000000000000000000000000..4c1625cff045ab9f1c9e8869be2e2a9954be75f1 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_deprecated.txt @@ -0,0 +1,52 @@ +# 'go list pkg' does not show deprecation. +go list example.com/deprecated/a +stdout '^example.com/deprecated/a$' + +# 'go list -m' does not show deprecation. +go list -m example.com/deprecated/a +stdout '^example.com/deprecated/a v1.9.0$' + +# 'go list -m -versions' does not show deprecation. +go list -m -versions example.com/deprecated/a +stdout '^example.com/deprecated/a v1.0.0 v1.9.0$' + +# 'go list -m -u' shows deprecation. +go list -m -u example.com/deprecated/a +stdout '^example.com/deprecated/a v1.9.0 \(deprecated\)$' + +# 'go list -m -u -f' exposes the deprecation message. +go list -m -u -f {{.Deprecated}} example.com/deprecated/a +stdout '^in example.com/deprecated/a@v1.9.0$' + +# This works even if we use an old version that does not have the deprecation +# message in its go.mod file. +go get example.com/deprecated/a@v1.0.0 +! grep Deprecated: $WORK/gopath/pkg/mod/cache/download/example.com/deprecated/a/@v/v1.0.0.mod +go list -m -u -f {{.Deprecated}} example.com/deprecated/a +stdout '^in example.com/deprecated/a@v1.9.0$' + +# 'go list -m -u' does not show deprecation for the main module. +go list -m -u +! stdout deprecated +go list -m -u -f '{{if not .Deprecated}}ok{{end}}' +stdout ok + +# 'go list -m -u' does not show a deprecation message for a module that is not +# deprecated at the latest version, even if it is deprecated at the current +# version. +go list -m -u example.com/undeprecated +stdout '^example.com/undeprecated v1.0.0 \[v1.0.1\]$' +-- go.mod -- +// Deprecated: main module is deprecated, too! +module example.com/use + +go 1.17 + +require ( + example.com/deprecated/a v1.9.0 + example.com/undeprecated v1.0.0 +) +-- go.sum -- +example.com/deprecated/a v1.9.0 h1:HeC7d0lb7umZa0vCCW+0W3WtBTulO+1Mr32m/Hwzeg8= +example.com/deprecated/a v1.9.0/go.mod h1:Z1uUVshSY9kh6l/2hZ8oA9SBviX2yfaeEpcLDz6AZwY= +example.com/undeprecated v1.0.0/go.mod h1:1qiRbdA9VzJXDqlG26Y41O5Z7YyO+jAD9do8XCZQ+Gg= diff --git a/go/src/cmd/go/testdata/script/mod_list_deprecated_replace.txt b/go/src/cmd/go/testdata/script/mod_list_deprecated_replace.txt new file mode 100644 index 0000000000000000000000000000000000000000..48b991fc473f60aed647705d4fcc99b216d702f9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_deprecated_replace.txt @@ -0,0 +1,68 @@ +# When all versions are replaced, we should not look up a deprecation message. +# We will still look up a deprecation message for the replacement. +cp go.mod.allreplaced go.mod +go list -m -u -f '{{.Path}}@{{.Version}} <{{.Deprecated}}>{{with .Replace}} => {{.Path}}@{{.Version}} <{{.Deprecated}}>{{end}}' all +stdout '^example.com/deprecated/a@v1.0.0 <> => example.com/deprecated/b@v1.0.0 $' + +# When one version is replaced, we should see a deprecation message. +cp go.mod.onereplaced go.mod +go list -m -u -f '{{.Path}}@{{.Version}} <{{.Deprecated}}>{{with .Replace}} => {{.Path}}@{{.Version}} <{{.Deprecated}}>{{end}}' all +stdout '^example.com/deprecated/a@v1.0.0 => example.com/deprecated/b@v1.0.0 $' + +# If the replacement is a directory, we won't look that up. +cp go.mod.dirreplacement go.mod +go list -m -u -f '{{.Path}}@{{.Version}} <{{.Deprecated}}>{{with .Replace}} => {{.Path}}@{{.Version}} <{{.Deprecated}}>{{end}}' all +stdout '^example.com/deprecated/a@v1.0.0 <> => ./a@ <>$' + +# If the latest version of the replacement is replaced, we'll use the content +# from that replacement. +cp go.mod.latestreplaced go.mod +go list -m -u -f '{{.Path}}@{{.Version}} <{{.Deprecated}}>{{with .Replace}} => {{.Path}}@{{.Version}} <{{.Deprecated}}>{{end}}' all +stdout '^example.com/deprecated/a@v1.0.0 <> => example.com/deprecated/b@v1.0.0 $' + +-- go.mod.allreplaced -- +module m + +go 1.17 + +require example.com/deprecated/a v1.0.0 + +replace example.com/deprecated/a => example.com/deprecated/b v1.0.0 +-- go.mod.onereplaced -- +module m + +go 1.17 + +require example.com/deprecated/a v1.0.0 + +replace example.com/deprecated/a v1.0.0 => example.com/deprecated/b v1.0.0 +-- go.mod.dirreplacement -- +module m + +go 1.17 + +require example.com/deprecated/a v1.0.0 + +replace example.com/deprecated/a => ./a +-- go.mod.latestreplaced -- +module m + +go 1.17 + +require example.com/deprecated/a v1.0.0 + +replace ( + example.com/deprecated/a => example.com/deprecated/b v1.0.0 + example.com/deprecated/b v1.9.0 => ./b +) +-- go.sum -- +example.com/deprecated/b v1.0.0/go.mod h1:b19J9ywRGviY7Nq4aJ1WBJ+A7qUlEY9ihp22yI4/F6M= +-- a/go.mod -- +module example.com/deprecated/a + +go 1.17 +-- b/go.mod -- +// Deprecated: in ./b +module example.com/deprecated/b + +go 1.17 diff --git a/go/src/cmd/go/testdata/script/mod_list_dir.txt b/go/src/cmd/go/testdata/script/mod_list_dir.txt new file mode 100644 index 0000000000000000000000000000000000000000..157d3b6a8a66721d1db65b4329b3ae64a9c6d935 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_dir.txt @@ -0,0 +1,36 @@ +[short] skip + +# go list with path to directory should work + +# populate go.sum +go get + +env GO111MODULE=off +go list -f '{{.ImportPath}}' $GOROOT/src/math +stdout ^math$ + +env GO111MODULE=on +go list -f '{{.ImportPath}}' $GOROOT/src/math +stdout ^math$ +go list -f '{{.ImportPath}}' . +stdout ^x$ + +go mod download rsc.io/quote@v1.5.2 +go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/quote@v1.5.2 +stdout '^rsc.io/quote$' +go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sampler@v1.3.0 +stdout '^rsc.io/sampler$' +go get rsc.io/sampler@v1.3.1 +go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sampler@v1.3.1 +stdout '^rsc.io/sampler$' +! go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sampler@v1.3.0 +stderr 'outside main module or its selected dependencies' + +-- go.mod -- +module x +require rsc.io/quote v1.5.2 + +-- x.go -- +package x + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_list_direct.txt b/go/src/cmd/go/testdata/script/mod_list_direct.txt new file mode 100644 index 0000000000000000000000000000000000000000..8bab330ac82c913a9c5f612f722652e611dadb59 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_direct.txt @@ -0,0 +1,24 @@ +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +[short] skip +[!git] skip + +# golang.org/issue/33099: if an import path ends in a major-version suffix, +# ensure that 'direct' mode can resolve the package to the module. +# For a while, (*modfetch.codeRepo).Stat was not checking for a go.mod file, +# which would produce a hard error at the subsequent call to GoMod. + +go get -v + +-- go.mod -- +module example.com +go 1.13 + +-- main.go -- +package main + +import _ "vcs-test.golang.org/git/v3pkg.git/v3" + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_list_direct_work.txt b/go/src/cmd/go/testdata/script/mod_list_direct_work.txt new file mode 100644 index 0000000000000000000000000000000000000000..517d43548671857d3a45e7f9d3dd81ebf5948e3f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_direct_work.txt @@ -0,0 +1,76 @@ +# Test that ModuleDirect.Public is correctly set on go list output. +# This is a regression test for issue #66789. + +# In this test, the workspace contains modules example.com/a and +# example.com/b. Module example.com/a has a direct requirement +# on rsc.io/sampler, and an indirect requirement on golang.org/x/text +# through rsc.io/isampler. Module example.com/b has a direct +# requirement on example.com/c which is incorrectly marked as indirect +# in module example.com/b's go.mod file. + +# Check that go list -m processes the indirect annotations in the +# go.mod file. +go list -f '{{.Path}} {{.Indirect}}' -m all +stdout 'example.com/a false' +stdout 'example.com/b false' +stdout 'rsc.io/sampler false' +stdout 'golang.org/x/text true' +stdout 'example.com/c true' # Uses the information in go.mod without checking imports. + +# Check that 'go list all' correctly populates "indirect" module annotation. +go list -f '{{.ImportPath}} {{with .Module}}{{.Indirect}}{{end}}' all +stdout 'example.com/a false' +stdout 'example.com/b false' +stdout 'rsc.io/sampler false' +stdout 'golang.org/x/text/language true' +stdout 'example.com/c false' + +-- go.work -- +go 1.23 + +use ./a +use ./b +-- a/go.mod -- +module example.com/a + +go 1.23 + +require rsc.io/sampler v1.2.1 + +require golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect +-- a/a.go -- +package a + +import "rsc.io/sampler" + +func A() string { + return sampler.Hello() +} +-- b/go.mod -- +module example.com/b + +go 1.23 + +// The indirect comment below is inaccurate. Its purpose +// is to test that it is corrected when enough packages +// are loaded to correct it. + +require example.com/c v1.0.0 // indirect + +replace example.com/c => ../c +-- b/b.go -- +package b + +import "example.com/c" + +func B() { + c.C() +} +-- c/go.mod -- +module example.com/c + +go 1.23 +-- c/c.go -- +package c + +func C() {} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_list_e_readonly.txt b/go/src/cmd/go/testdata/script/mod_list_e_readonly.txt new file mode 100644 index 0000000000000000000000000000000000000000..4969434e52b731ab3f12de70ae9dcfeefb3ac3c7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_e_readonly.txt @@ -0,0 +1,15 @@ +# 'go list -mod=readonly -e should attribute errors +# to individual missing packages. +# Verifies golang.org/issue/34829. +go list -mod=readonly -e -deps -f '{{if .Error}}{{.ImportPath}}: {{.Error}}{{end}}' . +stdout 'example.com/missing: use.go:3:8: cannot find module providing package example.com/missing: import lookup disabled by -mod=readonly' + +-- go.mod -- +module example.com/m + +go 1.14 + +-- use.go -- +package use + +import _ "example.com/missing" diff --git a/go/src/cmd/go/testdata/script/mod_list_issue61415.txt b/go/src/cmd/go/testdata/script/mod_list_issue61415.txt new file mode 100644 index 0000000000000000000000000000000000000000..e763fae8953f110425190375ed64c0d8756781ca --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_issue61415.txt @@ -0,0 +1,76 @@ +[short] skip 'generates a vcstest git repo' +[!git] skip + +env GOPROXY=direct + +# Control case: fetching a nested module at a tag that exists should +# emit Origin metadata for that tag and commit, and the origin should +# be reusable for that tag. + +go list -json -m --versions -e vcs-test.golang.org/git/issue61415.git/nested@has-nested +cp stdout has-nested.json +stdout '"Origin":' +stdout '"VCS": "git"' +stdout '"URL":' # randomly-chosen vcweb localhost URL +stdout '"Subdir": "nested"' +stdout '"TagPrefix": "nested/"' +stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Ref": "refs/tags/has-nested"' +stdout '"Hash": "08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a"' + +go list -reuse=has-nested.json -json -m --versions -e vcs-test.golang.org/git/issue61415.git/nested@has-nested +stdout '"Origin":' +stdout '"VCS": "git"' +stdout '"URL":' # randomly-chosen vcweb localhost URL +stdout '"Subdir": "nested"' +stdout '"TagPrefix": "nested/"' +stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Ref": "refs/tags/has-nested"' +stdout '"Hash": "08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a"' +stdout '"Reuse": true' + + +# Experiment case: if the nested module doesn't exist at "latest", +# the Origin metadata should include the ref that we tried to resolve +# (HEAD for a repo without version tags) and the hash to which it refers, +# so that changing the HEAD ref will invalidate the result. + +go list -json -m --versions -e vcs-test.golang.org/git/issue61415.git/nested@latest +cp stdout no-nested.json +stdout '"Err": "module vcs-test.golang.org/git/issue61415.git/nested: no matching versions for query \\"latest\\""' +stdout '"URL":' # randomly-chosen vcweb localhost URL +stdout '"Subdir": "nested"' +stdout '"TagPrefix": "nested/"' +stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' + +stdout '"Ref": "HEAD"' +stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' + +# The error result should be reusable. + +go list -reuse=no-nested.json -json -m --versions -e vcs-test.golang.org/git/issue61415.git/nested@latest + +stdout '"Err": "module vcs-test.golang.org/git/issue61415.git/nested: no matching versions for query \\"latest\\""' +stdout '"URL":' # randomly-chosen vcweb localhost URL +stdout '"Subdir": "nested"' +stdout '"TagPrefix": "nested/"' +stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Ref": "HEAD"' +stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' +stdout '"Reuse": true' + + +# If the hash refers to some other commit instead, the +# result should not be reused. + +replace f213069baa68ec26412fb373c7cf6669db1f8e69 08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a no-nested.json + +go list -reuse=no-nested.json -json -m --versions -e vcs-test.golang.org/git/issue61415.git/nested@latest +stdout '"Err": "module vcs-test.golang.org/git/issue61415.git/nested: no matching versions for query \\"latest\\""' +stdout '"URL":' # randomly-chosen vcweb localhost URL +stdout '"Subdir": "nested"' +stdout '"TagPrefix": "nested/"' +stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Ref": "HEAD"' +stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' +! stdout '"Reuse"' diff --git a/go/src/cmd/go/testdata/script/mod_list_issue61423.txt b/go/src/cmd/go/testdata/script/mod_list_issue61423.txt new file mode 100644 index 0000000000000000000000000000000000000000..2888391f6d63025aedca5c4ac3e570c16e3bdf46 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_issue61423.txt @@ -0,0 +1,100 @@ +[short] skip 'generates a vcstest git repo' +[!git] skip + +mkdir $WORK/mod1 +mkdir $WORK/mod2 +env GONOSUMDB=vcs-test.golang.org + +env GOPROXY=direct +env GOMODCACHE=$WORK/mod1 + + +# If we query a module version from a git repo, we expect its +# Origin data to be reusable. + +go list -m -json vcs-test.golang.org/git/issue61415.git@latest +cp stdout git-latest.json +stdout '"Version": "v0.0.0-20231114180001-f213069baa68"' +stdout '"Origin":' +stdout '"VCS": "git"' +stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' +stdout '"Ref": "HEAD"' +stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' + +go list -reuse=git-latest.json -m -json vcs-test.golang.org/git/issue61415.git@latest +stdout '"Version": "v0.0.0-20231114180001-f213069baa68"' +stdout '"Origin":' +stdout '"VCS": "git"' +stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' +stdout '"Ref": "HEAD"' +stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Reuse": true' + + +# Now we construct a filesystem-based module proxy that +# contains only an older commit. + +go clean -modcache + +go mod download -json vcs-test.golang.org/git/issue61415.git@08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a +stdout '"Version": "v0.0.0-20231114180000-08a4fa6bb9c0"' +stdout '"Origin":' +stdout '"VCS": "git"' +stdout '"Hash": "08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a"' + +[GOOS:windows] env GOPROXY=file:///$WORK/mod1/cache/download +[!GOOS:windows] env GOPROXY=file://$WORK/mod1/cache/download +env GOMODCACHE=$WORK/modcache2 + + +# If we resolve the "latest" version query using a proxy, +# it is only going to have Git origin information about the one +# commit — not the other tags that would go into resolving +# the underlying version list. +# 'go list' should not emit the partial information, +# since it isn't enough to reconstruct the result. + +go list -m -json vcs-test.golang.org/git/issue61415.git@latest +cp stdout proxy-latest.json +stdout '"Version": "v0.0.0-20231114180000-08a4fa6bb9c0"' +! stdout '"Origin":' + +# However, if we list a specific, stable version, we should get +# whatever origin metadata the proxy has for the version. + +go list -m -json vcs-test.golang.org/git/issue61415.git@v0.0.0-20231114180000-08a4fa6bb9c0 +cp stdout proxy-version.json +stdout '"Version": "v0.0.0-20231114180000-08a4fa6bb9c0"' +stdout '"Origin":' +stdout '"VCS": "git"' +stdout '"Hash": "08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a"' +! stdout '"Ref":' +! stdout '"TagSum":' + +# The -reuse flag has no effect with a proxy, since the proxy can serve +# metadata about a given module version cheaply anyway. + +go list -reuse=proxy-version.json -m -json vcs-test.golang.org/git/issue61415.git@v0.0.0-20231114180000-08a4fa6bb9c0 +stdout '"Version": "v0.0.0-20231114180000-08a4fa6bb9c0"' +stdout '"Origin":' +stdout '"VCS": "git"' +stdout '"Hash": "08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a"' +! stdout '"Ref":' +! stdout '"TagSum":' +! stdout '"Reuse":' + + +# With GOPROXY=direct, the -reuse flag has an effect, but +# the Origin data from the proxy should not be sufficient +# for the proxy response to be reused. + +env GOPROXY=direct + +go list -reuse=proxy-latest.json -m -json vcs-test.golang.org/git/issue61415.git@latest +stdout '"Version": "v0.0.0-20231114180001-f213069baa68"' +stdout '"Origin":' +stdout '"VCS": "git"' +stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' +stdout '"Ref": "HEAD"' +stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' +! stdout '"Reuse":' diff --git a/go/src/cmd/go/testdata/script/mod_list_m.txt b/go/src/cmd/go/testdata/script/mod_list_m.txt new file mode 100644 index 0000000000000000000000000000000000000000..d579153966292da1d5e86d0d8cb49903d39da7c6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_m.txt @@ -0,0 +1,16 @@ +go mod tidy + +go list -m -json all +stdout '"GoModSum":\s+"h1:.+"' +stdout '"Sum":\s+"h1:.+"' + +-- go.mod -- +module example + +go 1.21 + +require rsc.io/quote v1.5.1 +-- example.go -- +package example + +import _ "rsc.io/quote" \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_list_odd_tags.txt b/go/src/cmd/go/testdata/script/mod_list_odd_tags.txt new file mode 100644 index 0000000000000000000000000000000000000000..232754eacaba5f845836927159169b1ef80141e7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_odd_tags.txt @@ -0,0 +1,12 @@ +[short] skip +[!git] skip + +env GOPROXY=direct + +go list -m vcs-test.golang.org/git/odd-tags.git@latest +stdout -count=1 '^.' +stdout '^vcs-test.golang.org/git/odd-tags.git v0.1.1-0.20220223184835-9d863d525bbf$' + +go list -m -versions vcs-test.golang.org/git/odd-tags.git +stdout -count=1 '^.' +stdout '^vcs-test.golang.org/git/odd-tags.git$' # No versions listed — the odd tags are filtered out. diff --git a/go/src/cmd/go/testdata/script/mod_list_pseudo.txt b/go/src/cmd/go/testdata/script/mod_list_pseudo.txt new file mode 100644 index 0000000000000000000000000000000000000000..056c0931285685eccf00e874bff370084e81ea34 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_pseudo.txt @@ -0,0 +1,39 @@ +env GO111MODULE=on + +# Regression test for golang.org/issue/32715. + +# When using $GOPATH/pkg/mod/cache/download as a proxy, +# 'latest' queries should prefer tagged versions over pseudo-versions. + +go mod download github.com/dmitshur-test/modtest5@v0.0.0-20190619020302-197a620e0c9a +go mod download github.com/dmitshur-test/modtest5@v0.5.0-alpha +go mod download github.com/dmitshur-test/modtest5@v0.5.0-alpha.0.20190619023908-3da23a9deb9e +cmp $GOPATH/pkg/mod/cache/download/github.com/dmitshur-test/modtest5/@v/list $WORK/modtest5.list + +env GOSUMDB=off # don't verify go.mod files when loading retractions +env GOPROXY=file:///$GOPATH/pkg/mod/cache/download +env GOPATH=$WORK/gopath2 +mkdir $GOPATH + +go list -m -f '{{.Path}} {{.Version}} {{.Time.Format "2006-01-02"}}' github.com/dmitshur-test/modtest5@latest +stdout '^github.com/dmitshur-test/modtest5 v0.5.0-alpha 2019-06-18$' + +# If the module proxy contains only pseudo-versions, 'latest' should stat +# the version with the most recent timestamp — not the highest semantic +# version — and return its metadata. +env GOPROXY=file:///$WORK/tinyproxy +go list -m -f '{{.Path}} {{.Version}} {{.Time.Format "2006-01-02"}}' dmitri.shuralyov.com/test/modtest3@latest +stdout '^dmitri.shuralyov.com/test/modtest3 v0.0.0-20181023043359-a85b471d5412 2018-10-22$' + +-- $WORK/modtest5.list -- +v0.0.0-20190619020302-197a620e0c9a +v0.5.0-alpha +v0.5.0-alpha.0.20190619023908-3da23a9deb9e +-- $WORK/tinyproxy/dmitri.shuralyov.com/test/modtest3/@v/list -- +v0.1.0-0.20161023043300-000000000000 +v0.0.0-20181023043359-a85b471d5412 +-- $WORK/tinyproxy/dmitri.shuralyov.com/test/modtest3/@v/v0.0.0-20181023043359-a85b471d5412.info -- +{ + "Version": "v0.0.0-20181023043359-a85b471d5412", + "Time": "2018-10-22T21:33:59-07:00" +} diff --git a/go/src/cmd/go/testdata/script/mod_list_replace_dir.txt b/go/src/cmd/go/testdata/script/mod_list_replace_dir.txt new file mode 100644 index 0000000000000000000000000000000000000000..b446543916f53bd04dc8bd4704059a62fb7a3bdc --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_replace_dir.txt @@ -0,0 +1,27 @@ +# Test that "go list" succeeds when given a directory in a replacement +# module within the module cache. +# Verifies golang.org/issue/29548 + +# Populate go.sum and download dependencies. +go get + +# Ensure v1.5.2 is also in the cache so we can list it. +go mod download rsc.io/quote@v1.5.2 + +! go list $GOPATH/pkg/mod/rsc.io/quote@v1.5.2 +stderr '^directory ..[/\\]pkg[/\\]mod[/\\]rsc.io[/\\]quote@v1.5.2 outside main module or its selected dependencies$' + +go list $GOPATH/pkg/mod/rsc.io/quote@v1.5.1 +stdout 'rsc.io/quote' + +-- go.mod -- +module example.com/quoter + +require rsc.io/quote v1.5.2 + +replace rsc.io/quote => rsc.io/quote v1.5.1 + +-- use.go -- +package use + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_list_retract.txt b/go/src/cmd/go/testdata/script/mod_list_retract.txt new file mode 100644 index 0000000000000000000000000000000000000000..b7147aa18241fda4c406fc9d5bb0f2d19ff928d6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_list_retract.txt @@ -0,0 +1,110 @@ +# 'go list -mod=vendor -retracted' reports an error. +go mod vendor +! go list -m -retracted -mod=vendor +stderr '^go list -retracted cannot be used when vendoring is enabled$' +rm vendor + +# 'go list -retracted' reports an error in GOPATH mode. +env GO111MODULE=off +! go list -retracted +stderr '^go list -retracted can only be used in module-aware mode$' +env GO111MODULE= + +# 'go list pkg' does not show retraction. +go list -f '{{with .Module}}{{with .Retracted}}retracted{{end}}{{end}}' example.com/retract +! stdout . + +# 'go list -retracted pkg' shows retraction. +go list -retracted -f '{{with .Module}}{{with .Retracted}}retracted{{end}}{{end}}' example.com/retract +stdout retracted + +# 'go list -m' does not show retraction. +go list -m -f '{{with .Retracted}}retracted{{end}}' example.com/retract +! stdout . + +# 'go list -m -retracted' shows retraction. +go list -m -retracted -f '{{with .Retracted}}retracted{{end}}' example.com/retract + +# 'go list -m mod@version' does not show retraction. +go list -m -f '{{with .Retracted}}retracted{{end}}' example.com/retract@v1.0.0-unused +! stdout . + +# 'go list -m -retracted mod@version' does not show an error if the module +# that would contain the retraction is unavailable. See #45305. +go list -m -retracted -f '{{.Path}} {{.Version}} {{.Error}}' example.com/retract/missingmod@v1.0.0 +stdout '^example.com/retract/missingmod v1.0.0 $' +exists $GOPATH/pkg/mod/cache/download/example.com/retract/missingmod/@v/v1.9.0.info +! exists $GOPATH/pkg/mod/cache/download/example.com/retract/missingmod/@v/v1.9.0.mod + +# 'go list -m -retracted mod@version' shows retractions. +go list -m -retracted example.com/retract@v1.0.0-unused +stdout '^example.com/retract v1.0.0-unused \(retracted\)$' +go list -m -retracted -f '{{with .Retracted}}retracted{{end}}' example.com/retract@v1.0.0-unused +stdout retracted + +# 'go list -m mod@latest' selects a previous release version, not self-retracted latest. +go list -m -f '{{.Version}}{{with .Retracted}} retracted{{end}}' example.com/retract/self/prev@latest +stdout '^v1.1.0$' + +# 'go list -m -retracted mod@latest' selects the self-retracted latest version. +go list -m -retracted -f '{{.Version}}{{with .Retracted}} retracted{{end}}' example.com/retract/self/prev@latest +stdout '^v1.9.0 retracted$' + +# 'go list -m mod@latest' selects a pre-release version if all release versions are retracted. +go list -m -f '{{.Version}}{{with .Retracted}} retracted{{end}}' example.com/retract/self/prerelease@latest +stdout '^v1.9.1-pre$' + +# 'go list -m -retracted mod@latest' selects the self-retracted latest version. +go list -m -retracted -f '{{.Version}}{{with .Retracted}} retracted{{end}}' example.com/retract/self/prerelease@latest +stdout '^v1.9.0 retracted$' + +# 'go list -m mod@latest' selects a pseudo-version if all versions are retracted. +# TODO(golang.org/issue/24031): the proxy does not expose the pseudo-version, +# even if all release versions are retracted. +go list -m -e -f '{{.Error.Err}}' example.com/retract/self/pseudo@latest +stdout '^module example.com/retract/self/pseudo: no matching versions for query "latest"$' + +# 'go list -m mod@latest' reports an error if all versions are retracted. +go list -m -e -f '{{.Error.Err}}' example.com/retract/self/all@latest +stdout '^module example.com/retract/self/all: no matching versions for query "latest"$' + +# 'go list -m mod@ ./sub +-- sub/go.mod -- +module sub +hello world diff --git a/go/src/cmd/go/testdata/script/mod_load_badzip.txt b/go/src/cmd/go/testdata/script/mod_load_badzip.txt new file mode 100644 index 0000000000000000000000000000000000000000..58160b4d442252f5903845158950bcd635ac5708 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_load_badzip.txt @@ -0,0 +1,13 @@ +# Zip files with unexpected file names inside should be rejected. +env GO111MODULE=on + +! go get rsc.io/badzip +stderr 'zip for rsc.io/badzip@v1.0.0 has unexpected file rsc.io/badzip@v1.0.0.txt' +! grep rsc.io/badzip go.mod + +go mod edit -require rsc.io/badzip@v1.0.0 +! go build -mod=mod rsc.io/badzip +stderr 'zip for rsc.io/badzip@v1.0.0 has unexpected file rsc.io/badzip@v1.0.0.txt' + +-- go.mod -- +module m diff --git a/go/src/cmd/go/testdata/script/mod_load_replace_mismatch.txt b/go/src/cmd/go/testdata/script/mod_load_replace_mismatch.txt new file mode 100644 index 0000000000000000000000000000000000000000..2ca8b3cace22ced2b2dac9ca4e7dc8e47a244ff8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_load_replace_mismatch.txt @@ -0,0 +1,23 @@ +# If a replacement module declares a module path different from both +# the original module and its location, report an error with all three paths. +# In particular, the "required as" path should be the original. +# Verifies golang.org/issue/38220. +! go mod download +cmp stderr want + +-- go.mod -- +module m + +require rsc.io/quote v1.5.2 + +replace rsc.io/quote v1.5.2 => example.com/quote v1.5.2 + +-- use.go -- +package use + +import _ "rsc.io/quote" + +-- want -- +go: rsc.io/quote@v1.5.2 (replaced by example.com/quote@v1.5.2): parsing go.mod: + module declares its path as: rsc.io/Quote + but was required as: rsc.io/quote diff --git a/go/src/cmd/go/testdata/script/mod_local_replace.txt b/go/src/cmd/go/testdata/script/mod_local_replace.txt new file mode 100644 index 0000000000000000000000000000000000000000..19bc8f39045f11c25775ed8fc44410b45af2bbef --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_local_replace.txt @@ -0,0 +1,23 @@ +# Test that local replacements work even with dummy module names. +# golang.org/issue/24100. + +env GO111MODULE=on + +cd x/y +go list -f '{{.Dir}}' zz +stdout x[/\\]z$ + +-- x/y/go.mod -- +module x/y +require zz v1.0.0 +replace zz v1.0.0 => ../z + +-- x/y/y.go -- +package y +import _ "zz" + +-- x/z/go.mod -- +module x/z + +-- x/z/z.go -- +package z diff --git a/go/src/cmd/go/testdata/script/mod_missing_repo.txt b/go/src/cmd/go/testdata/script/mod_missing_repo.txt new file mode 100644 index 0000000000000000000000000000000000000000..d0076f7b3bdfdcda93dc5f66080b2f7f77e2f7af --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_missing_repo.txt @@ -0,0 +1,15 @@ +# Regression test for golang.org/issue/34094: modules hosted within gitlab.com +# subgroups could not be fetched because the server returned bogus go-import +# tags for prefixes of the module path. + +[short] skip +[!git] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +! go mod download vcs-test.golang.org/go/missingrepo/missingrepo-git@latest +stderr 'vcs-test.golang.org/go/missingrepo/missingrepo-git: git ls-remote .*: exit status .*' + +go mod download vcs-test.golang.org/go/missingrepo/missingrepo-git/notmissing@latest diff --git a/go/src/cmd/go/testdata/script/mod_missingpkg_prerelease.txt b/go/src/cmd/go/testdata/script/mod_missingpkg_prerelease.txt new file mode 100644 index 0000000000000000000000000000000000000000..9c250e7d1c451bbc4c5ccf6935e1938377809da5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_missingpkg_prerelease.txt @@ -0,0 +1,17 @@ +env GO111MODULE=on + +! go list -mod=mod -deps use.go +stderr '^use.go:4:2: package example.com/missingpkg/deprecated provided by example.com/missingpkg at latest version v1.0.0 but not at required version v1.0.1-beta$' + +-- go.mod -- +module m + +go 1.14 + +-- use.go -- +package use + +import ( + _ "example.com/missingpkg/deprecated" + _ "example.com/usemissingpre" +) diff --git a/go/src/cmd/go/testdata/script/mod_modinfo.txt b/go/src/cmd/go/testdata/script/mod_modinfo.txt new file mode 100644 index 0000000000000000000000000000000000000000..8d77e224a5a227c9f863f3721965a648fb775950 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_modinfo.txt @@ -0,0 +1,89 @@ +# Test to ensure runtime/debug.ReadBuildInfo parses +# the modinfo embedded in a binary by the go tool +# when module is enabled. +env GO111MODULE=on + +cd x +go mod edit -require=rsc.io/quote@v1.5.2 +go mod edit -replace=rsc.io/quote@v1.5.2=rsc.io/quote@v1.0.0 +go mod tidy # populate go.sum + +# Build a binary and ensure that it can output its own debug info. +# The debug info should be accessible before main starts (golang.org/issue/29628). +go build +exec ./x$GOEXE +stderr 'mod\s+x\s+\(devel\)' +stderr 'dep\s+rsc.io/quote\s+v1.5.2\s+' +stderr '=>\s+rsc.io/quote\s+v1.0.0\s+h1:' +stderr 'Hello, world.' + +[short] skip + +# Build a binary that accesses its debug info by reading the binary directly +# (rather than through debug.ReadBuildInfo). +# The debug info should still be present (golang.org/issue/28753). +cd unused +go build +exec ./unused$GOEXE + +-- x/go.mod -- +module x + +-- x/lib/lib.go -- +// Package lib accesses runtime/debug.modinfo before package main's init +// functions have run. +package lib + +import "runtime/debug" + +func init() { + m, ok := debug.ReadBuildInfo() + if !ok { + panic("failed debug.ReadBuildInfo") + } + println("mod", m.Main.Path, m.Main.Version) + for _, d := range m.Deps { + println("dep", d.Path, d.Version, d.Sum) + if r := d.Replace; r != nil { + println("=>", r.Path, r.Version, r.Sum) + } + } +} + +-- x/main.go -- +package main + +import ( + "rsc.io/quote" + _ "x/lib" +) + +func main() { + println(quote.Hello()) +} + +-- x/unused/main.go -- +// The unused binary does not access runtime/debug.modinfo. +package main + +import ( + "bytes" + "encoding/hex" + "log" + "os" + + _ "rsc.io/quote" +) + +func main() { + b, err := os.ReadFile(os.Args[0]) + if err != nil { + log.Fatal(err) + } + + infoStart, _ := hex.DecodeString("3077af0c9274080241e1c107e6d618e6") + if !bytes.Contains(b, infoStart) { + log.Fatal("infoStart not found in binary") + } + log.Println("ok") +} diff --git a/go/src/cmd/go/testdata/script/mod_multirepo.txt b/go/src/cmd/go/testdata/script/mod_multirepo.txt new file mode 100644 index 0000000000000000000000000000000000000000..bbefb78d90a48ee9b25874fb1853e33478126e5c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_multirepo.txt @@ -0,0 +1,41 @@ +env GO111MODULE=on + +# initial standalone module should use no downloaded modules +go list -deps -f {{.Dir}} +! stdout 'pkg[\\/]mod' + +# v2 import should use a downloaded module +# both without an explicit go.mod entry ... +cp tmp/use_v2.go x.go +go get . +go list -deps -f {{.Dir}} +stdout 'pkg[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$' + +# ... and with one ... +cp tmp/use_v2.mod go.mod +go list -deps -f {{.Dir}} +stdout 'pkg[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$' + +# ... and even if there is a v2 module in a subdirectory. +mkdir v2 +cp x.go v2/x.go +cp tmp/v2.mod v2/go.mod +go list -deps -f {{.Dir}} +stdout 'pkg[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$' + +-- go.mod -- +module rsc.io/quote + +-- x.go -- +package quote + +-- tmp/use_v2.go -- +package quote +import _ "rsc.io/quote/v2" + +-- tmp/use_v2.mod -- +module rsc.io/quote +require rsc.io/quote/v2 v2.0.1 + +-- tmp/v2.mod -- +package rsc.io/quote/v2 diff --git a/go/src/cmd/go/testdata/script/mod_no_gopath.txt b/go/src/cmd/go/testdata/script/mod_no_gopath.txt new file mode 100644 index 0000000000000000000000000000000000000000..ed91f5d42e5c8a8b1f1f84bf856c55764ce0b376 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_no_gopath.txt @@ -0,0 +1,15 @@ +# https://golang.org/issue/43938: 'go build' should succeed +# if GOPATH and the variables needed for its default value +# are all unset but not relevant to the specific command. + +env HOME='' +env home='' +env GOPATH='' + +go list -deps main.go +stdout '^io$' + +-- main.go -- +package main + +import _ "io" diff --git a/go/src/cmd/go/testdata/script/mod_nomod.txt b/go/src/cmd/go/testdata/script/mod_nomod.txt new file mode 100644 index 0000000000000000000000000000000000000000..7e0f55a602fd66fddd7430c00adfc7ec188c59fe --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_nomod.txt @@ -0,0 +1,43 @@ +# Test go commands with no module. +env GO111MODULE=on + +# go mod edit fails unless given explicit mod file argument +! go mod edit -json +go mod edit -json x.mod + +# bug succeeds +[exec:echo] env BROWSER=echo +[exec:echo] go bug + +# commands that load the package in the current directory fail +! go build +! go fmt +! go generate +! go get +! go install +! go list +! go run +! go test +! go vet + +# clean succeeds, even with -modcache +go clean -modcache + +# doc succeeds for standard library +go doc unsafe + +# env succeeds +go env + +# tool succeeds +go tool -n test2json + +# version succeeds +go version + +-- x.mod -- +module m + +-- x.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_notall.txt b/go/src/cmd/go/testdata/script/mod_notall.txt new file mode 100644 index 0000000000000000000000000000000000000000..1657c8d2d0003ff3dac632b078dd0c160334931d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_notall.txt @@ -0,0 +1,99 @@ +# This test demonstrates go commands that combine the 'all' pattern +# with packages outside of 'all'. + +# With -deps, 'all' should include test dependencies of packages in the main +# module, but not should not include test dependencies of packages imported only +# by other root patterns. + +env GOFLAGS=-mod=mod +cp go.mod go.mod.orig + +go list -deps all x/otherroot + +stdout '^x/inall$' +stdout '^x/inall/fromtest$' +stdout '^x/inall/fromtestinall$' +stdout '^x/otherroot$' +stdout '^x/otherdep$' + +! stdout '^x/fromotherroottest$' +! stdout '^y/fromotherdeptest$' + +cmp go.mod go.mod.orig + +# With -deps -test, test dependencies of other roots should be included, +# but test dependencies of non-roots should not. + +go list -deps -test all x/otherroot +stdout '^x/inall$' +stdout '^x/inall/fromtest$' +stdout '^x/inall/fromtestinall$' +stdout '^x/otherroot$' +stdout '^x/otherdep$' + +stdout '^x/fromotherroottest$' +! stdout '^y/fromotherdeptest$' + +cmp go.mod go.mod.orig + +-- m.go -- +package m + +import _ "x/inall" +-- m_test.go -- +package m_test + +import _ "x/inall/fromtest" +-- go.mod -- +module m + +go 1.15 + +require x v0.1.0 + +replace ( + x v0.1.0 => ./x + y v0.1.0 => ./y +) +-- x/go.mod -- +module x + +go 1.15 +-- x/inall/inall.go -- +package inall +-- x/inall/inall_test.go -- +package inall_test + +import _ "x/inall/fromtestinall" +-- x/inall/fromtest/fromtest.go -- +package fromtest +-- x/inall/fromtestinall/fromtestinall.go -- +package fromtestinall +-- x/otherroot/otherroot.go -- +package otherroot + +import _ "x/otherdep" +-- x/otherroot/otherroot_test.go -- +package otherroot_test + +import _ "x/fromotherroottest" +-- x/fromotherroottest/fromotherroottest.go -- +package fromotherroottest +-- x/otherdep/otherdep.go -- +package otherdep +-- x/otherdep/otherdep_test.go -- +package otherdep_test + +import _ "y/fromotherdeptest" +-- x/otherroot/testonly/testonly.go -- +package testonly +-- y/go.mod -- +module y + +go 1.15 +-- y/fromotherdeptest/fromotherdeptest.go -- +// Package fromotherdeptest is a test dependency of x/otherdep that is +// not declared in x/go.mod. If the loader resolves this package, +// it will add this module to the main module's go.mod file, +// and we can detect the mistake. +package fromotherdeptest diff --git a/go/src/cmd/go/testdata/script/mod_off.txt b/go/src/cmd/go/testdata/script/mod_off.txt new file mode 100644 index 0000000000000000000000000000000000000000..a73a58d4d0c0e7ea2298cce8da02bf02a0ead96a --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_off.txt @@ -0,0 +1,35 @@ +env GO111MODULE=off + +# This script tests that running go mod with +# GO111MODULE=off when outside of GOPATH will fatal +# with an error message, even with some source code in the directory and a go.mod. +! go mod init +stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' +! go mod graph +stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' +! go mod verify +stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' +! go mod download +stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' + +# Same result in an empty directory +mkdir z +cd z +! go mod init +stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' +! go mod graph +stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' +! go mod verify +stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' +! go mod download +stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' + +-- sample.go -- +package sample + +func main() {} + +-- go.mod -- +module sample + +go 1.12 diff --git a/go/src/cmd/go/testdata/script/mod_off_init.txt b/go/src/cmd/go/testdata/script/mod_off_init.txt new file mode 100644 index 0000000000000000000000000000000000000000..2aec0b3ed5443d65c4980f76857d4d2870430875 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_off_init.txt @@ -0,0 +1,5 @@ +# 'go mod init' should refuse to initialize a module if it will be +# ignored anyway due to GO111MODULE=off. +env GO111MODULE=off +! go mod init +stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' diff --git a/go/src/cmd/go/testdata/script/mod_outside.txt b/go/src/cmd/go/testdata/script/mod_outside.txt new file mode 100644 index 0000000000000000000000000000000000000000..7a0dc9f22f675ec3e5bab3f88d1ab5ceb09fd4f5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_outside.txt @@ -0,0 +1,315 @@ +env GO111MODULE=on +[short] skip + +# This script tests commands in module mode outside of any module. +# +# First, ensure that we really are in module mode, and that we really don't have +# a go.mod file. +go env GOMOD +stdout 'NUL|/dev/null' + + +# 'go list' without arguments implicitly operates on the current directory, +# which is not in a module. +! go list +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' +go list -m +stdout '^command-line-arguments$' +# 'go list' in the working directory should fail even if there is a a 'package +# main' present: without a main module, we do not know its package path. +! go list ./needmod +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + +# 'go list all' lists the transitive import graph of the main module, +# which is empty if there is no main module. +go list all +! stdout . +stderr 'warning: "all" matched no packages' + +# 'go list' on standard-library packages should work, since they do not depend +# on the contents of any module. +go list -deps cmd +stdout '^fmt$' +stdout '^cmd/go$' + +go list $GOROOT/src/fmt +stdout '^fmt$' + +# 'go list' should work with file arguments. +go list ./needmod/needmod.go +stdout 'command-line-arguments' + +# 'go list' on a package from a module should fail. +! go list example.com/printversion +stderr '^no required module provides package example.com/printversion: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + + +# 'go list -m' with an explicit version should resolve that version. +go list -m example.com/version@latest +stdout 'example.com/version v1.1.0' + +# 'go list -m -versions' should succeed even without an explicit version. +go list -m -versions example.com/version +stdout 'v1.0.0\s+v1.0.1\s+v1.1.0' + +# 'go list -m all' should fail. "all" is not meaningful outside of a module. +! go list -m all +stderr 'go: cannot match "all": go.mod file not found in current directory or any parent directory; see ''go help modules''$' + +# 'go list -m all' should also fail. +! go list -m example.com/printversion@v1.0.0 all +stderr 'go: cannot match "all": go.mod file not found in current directory or any parent directory; see ''go help modules''$' +! stdout 'example.com/version' + +# 'go list -m ' should fail if any of the mods lacks an explicit version. +! go list -m example.com/printversion +stderr 'go: cannot match "example.com/printversion" without -versions or an explicit version: go.mod file not found in current directory or any parent directory; see ''go help modules''$' +! stdout 'example.com/version' + +# 'go list -m' with wildcards should fail. Wildcards match modules in the +# build list, so they aren't meaningful outside a module. +! go list -m ... +stderr 'go: cannot match "...": go.mod file not found in current directory or any parent directory; see ''go help modules''$' +! go list -m rsc.io/quote/... +stderr 'go: cannot match "rsc.io/quote/...": go.mod file not found in current directory or any parent directory; see ''go help modules''$' + + +# 'go clean' should skip the current directory if it isn't in a module. +go clean -n +! stdout . +! stderr . + +# 'go mod graph' should fail, since there's no module graph. +! go mod graph +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + +# 'go mod why' should fail, since there is no main module to depend on anything. +! go mod why -m example.com/version +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + +# 'go mod edit', 'go mod tidy', and 'go mod fmt' should fail: +# there is no go.mod file to edit. +! go mod tidy +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' +! go mod edit -fmt +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' +! go mod edit -require example.com/version@v1.0.0 +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + + +# 'go mod download' without arguments should report an error. +! go mod download +stderr 'no modules specified' + +# 'go mod download' should download exactly the requested module without dependencies. +rm -r $GOPATH/pkg/mod/cache/download/example.com +go mod download example.com/printversion@v1.0.0 +exists $GOPATH/pkg/mod/cache/download/example.com/printversion/@v/v1.0.0.zip +! exists $GOPATH/pkg/mod/cache/download/example.com/version/@v/v1.0.0.zip + +# 'go mod download all' should fail. "all" is not meaningful outside of a module. +! go mod download all +stderr 'go: cannot match "all": go.mod file not found in current directory or any parent directory; see ''go help modules''$' + + +# 'go mod vendor' should fail: it starts by clearing the existing vendor +# directory, and we don't know where that is. +! go mod vendor +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + + +# 'go mod verify' should fail: we have no modules to verify. +! go mod verify +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + + +# 'go get' has no go.mod file to update outside a module and should fail. +! go get +stderr '^go: go.mod file not found in current directory or any parent directory.$' +stderr '^\t''go get'' is no longer supported outside a module.$' +! go get -u +stderr '^go: go.mod file not found in current directory or any parent directory.$' +stderr '^\t''go get'' is no longer supported outside a module.$' +! go get -u ./needmod +stderr '^go: go.mod file not found in current directory or any parent directory.$' +stderr '^\t''go get'' is no longer supported outside a module.$' +! go get -u all +stderr '^go: go.mod file not found in current directory or any parent directory.$' +stderr '^\t''go get'' is no longer supported outside a module.$' +! go get example.com/printversion@v1.0.0 example.com/version@none +stderr '^go: go.mod file not found in current directory or any parent directory.$' +stderr '^\t''go get'' is no longer supported outside a module.$' + +# 'go get' should not download anything. +go clean -modcache +! go get example.com/printversion@v1.0.0 +stderr '^go: go.mod file not found in current directory or any parent directory.$' +stderr '^\t''go get'' is no longer supported outside a module.$' +! exists $GOPATH/pkg/mod/example.com/printversion@v1.0.0 +! exists $GOPATH/pkg/mod/example.com/version@v1.0.0 + + +# 'go build' without arguments implicitly operates on the current directory, and should fail. +cd needmod +! go build +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' +cd .. + +# 'go build' of a non-module directory should fail too. +! go build ./needmod +stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + +# 'go build' of source files should fail if they import anything outside std. +! go build -n ./needmod/needmod.go +stderr '^needmod[/\\]needmod.go:10:2: no required module provides package example.com/version: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + +# 'go build' of source files should succeed if they do not import anything outside std. +go build -n -o ignore ./stdonly/stdonly.go + +# 'go build' should succeed for standard-library packages. +go build -n fmt + +# 'go build' should use the latest version of the Go language. +go build ./newgo/newgo.go + +# 'go doc' without arguments implicitly operates on the current directory, and should fail. +# TODO(golang.org/issue/32027): currently, it succeeds. +cd needmod +go doc +cd .. + +# 'go doc' of a non-module directory should also succeed. +go doc ./needmod + +# 'go doc' should succeed for standard-library packages. +go doc fmt + +# 'go doc' should fail for a package path outside a module. +! go doc example.com/version +stderr 'doc: no required module provides package example.com/version: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + +# 'go install' with a version should succeed if all constraints are met. +# See mod_install_pkg_version. +rm $GOPATH/bin +go install example.com/printversion@v0.1.0 +exists $GOPATH/bin/printversion$GOEXE + +# 'go install' should fail if a package argument must be resolved to a module. +! go install example.com/printversion +stderr '^go: ''go install'' requires a version when current directory is not in a module\n\tTry ''go install example.com/printversion@latest'' to install the latest version$' + +# 'go install' should fail if a source file imports a package that must be +# resolved to a module. +! go install ./needmod/needmod.go +stderr 'needmod[/\\]needmod.go:10:2: no required module provides package example.com/version: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + +# 'go run' should fail if a package argument must be resolved to a module. +! go run example.com/printversion +stderr '^no required module provides package example.com/printversion: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + +# 'go run' should fail if a source file imports a package that must be +# resolved to a module. +! go run ./needmod/needmod.go +stderr '^needmod[/\\]needmod.go:10:2: no required module provides package example.com/version: go.mod file not found in current directory or any parent directory; see ''go help modules''$' + + +# 'go fmt' should be able to format files outside of a module. +go fmt needmod/needmod.go + + +# The remainder of the test checks dependencies by linking and running binaries. + +# 'go run' should work with file arguments if they don't import anything +# outside std. +go run ./stdonly/stdonly.go +stdout 'path is command-line-arguments$' +stdout 'main is $' + +# 'go generate' should work with file arguments. +[exec:touch] go generate ./needmod/needmod.go +[exec:touch] exists ./needmod/gen.txt + +# 'go install' should work with file arguments. +go install ./stdonly/stdonly.go + +# 'go test' should work with file arguments. +go test -v ./stdonly/stdonly_test.go +stdout 'stdonly was tested' + +# 'go vet' should work with file arguments. +go vet ./stdonly/stdonly.go + + +-- README.txt -- +There is no go.mod file in the working directory. + +-- needmod/needmod.go -- +//go:generate touch gen.txt + +package main + +import ( + "fmt" + "os" + "runtime/debug" + + _ "example.com/version" +) + +func main() { + info, ok := debug.ReadBuildInfo() + if !ok { + panic("missing build info") + } + fmt.Fprintf(os.Stdout, "path is %s\n", info.Path) + fmt.Fprintf(os.Stdout, "main is %s %s\n", info.Main.Path, info.Main.Version) + for _, m := range info.Deps { + fmt.Fprintf(os.Stdout, "using %s %s\n", m.Path, m.Version) + } +} + +-- stdonly/stdonly.go -- +package main + +import ( + "fmt" + "os" + "runtime/debug" +) + +func main() { + info, ok := debug.ReadBuildInfo() + if !ok { + panic("missing build info") + } + fmt.Fprintf(os.Stdout, "path is %s\n", info.Path) + fmt.Fprintf(os.Stdout, "main is %s %s\n", info.Main.Path, info.Main.Version) + for _, m := range info.Deps { + fmt.Fprintf(os.Stdout, "using %s %s\n", m.Path, m.Version) + } +} + +-- stdonly/stdonly_test.go -- +package main + +import ( + "fmt" + "testing" +) + +func Test(t *testing.T) { + fmt.Println("stdonly was tested") +} + +-- newgo/newgo.go -- +// Package newgo requires Go 1.14 or newer. +package newgo + +import "io" + +const C = 299_792_458 + +type ReadWriteCloser interface { + io.ReadCloser + io.WriteCloser +} diff --git a/go/src/cmd/go/testdata/script/mod_overlay.txt b/go/src/cmd/go/testdata/script/mod_overlay.txt new file mode 100644 index 0000000000000000000000000000000000000000..da35be6a196ed619d54d6f00668550b16c7c4b29 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_overlay.txt @@ -0,0 +1,254 @@ +# Test overlays that affect go.mod files + +# The go.mod file can exist only in the overlay. +cd $WORK/gopath/src/no-go-mod +go list -overlay overlay.json . +stdout example.com/simple + +# Check content of overlaid go.mod is used. +cd $WORK/gopath/src/overlay-go-mod +go list -overlay overlay.json . +stdout use.this/module/name + +# Check content of overlaid go.mod in a replacement module is used. +# The go.mod in the replacement module is missing a requirement +# that the overlay has, so it will fail to list without the overlay. +cd $WORK/gopath/src/overlay-replaced-go-mod +! go list -deps . +go list -deps -overlay overlay.json . + +# Overlaid go.mod is not rewritten by 'go get'. +cd $WORK/gopath/src/get-doesnt-add-dep +cp $WORK/overlay/get_doesnt_add_dep_go_mod $WORK/want_go_mod +! go get -overlay overlay.json . +stderr '^go: updates to go.mod needed, but go.mod is part of the overlay specified with -overlay$' +cmp $WORK/overlay/get_doesnt_add_dep_go_mod $WORK/want_go_mod + +# Content of overlaid go.sum is used. +# The go.sum in the module directory has garbage values for its +# hashes, but the overlaid file has the correct values. If +# the correct go.sum is used with the overlay, 'go get .' should +# not report a security error. +cd $WORK/gopath/src/overlay-sum-used +! go get . +stderr 'SECURITY ERROR' +! go mod verify +stderr 'SECURITY ERROR' +go get -overlay overlay.json . +go mod verify -overlay overlay.json +# Overlaid go.sum is not rewritten. +# Copy an incomplete file to the overlay file, and expect an error +# attempting to update the file +cp incomplete-sum-file $WORK/overlay/overlay-sum-used-correct-sums +! go get -overlay overlay.json . +stderr '^go: updates to go.sum needed, but go.sum is part of the overlay specified with -overlay$' +cmp incomplete-sum-file $WORK/overlay/overlay-sum-used-correct-sums +! go mod tidy -overlay overlay.json +stderr '^go: updates to go.sum needed, but go.sum is part of the overlay specified with -overlay$' +cmp incomplete-sum-file $WORK/overlay/overlay-sum-used-correct-sums + +# -overlay works with -modfile. +# There's an empty go.mod file in the directory, and the file alternate.mod is +# overlaid to the true go.mod file, so the -modfile flag and the overlay +# mechanism need to work together to determine the name of the module. +cd $WORK/gopath/src/overlay-and-dash-modfile +go list -modfile=alternate.mod -overlay overlay.json . +stdout 'found.the/module' +# Even with -modfile, overlaid files can't be opened for write. +! go get -modfile=alternate.mod -overlay overlay.json rsc.io/quote +stderr '^go: updates to go.mod needed, but go.mod is part of the overlay specified with -overlay$' + +# Carving out a module by adding an overlaid go.mod file +cd $WORK/gopath/src/carve +go list ./... # without an overlay, hasmod is carved out and nomod isn't +stdout carve/nomod +! stdout carve/hasmod +go list -overlay overlay_carve_module.json ./... # The overlay carves out nomod, leaving nothing +! stdout . +stderr 'matched no packages' +go list -overlay overlay_uncarve_module.json ./... # The overlay uncarves out hasmod +stdout carve/nomod +stdout carve/hasmod + +# Carving out a module by adding an overlaid go.mod file and using +# -modfile to write to that file. +cd $WORK/gopath/src/carve2/nomod +go list -overlay overlay.json all +! stdout ^carve2$ +stdout ^carve2/nomod$ +# Editing go.mod file fails because overlay is read only +! go get -overlay overlay.json rsc.io/quote +stderr '^go: updates to go.mod needed, but go.mod is part of the overlay specified with -overlay$' +! grep rsc.io/quote $WORK/overlay/carve2-nomod-go.mod +# Editing go.mod file succeeds because we use -modfile to redirect to same file +go get -overlay overlay.json -modfile $WORK/overlay/carve2-nomod-go.mod rsc.io/quote +grep rsc.io/quote $WORK/overlay/carve2-nomod-go.mod + +-- no-go-mod/file.go -- +package simple +-- no-go-mod/overlay.json -- +{ + "Replace": { + "go.mod": "../../../overlay/simple_go_mod" + } +} +-- $WORK/overlay/simple_go_mod -- +module example.com/simple +-- overlay-go-mod/file.go -- +package name +-- overlay-go-mod/go.mod -- +module dont.use/this/module/name +-- overlay-go-mod/overlay.json -- +{ + "Replace": { + "go.mod": "../../../overlay/use_this_go_mod" + } +} +-- $WORK/overlay/use_this_go_mod -- +module use.this/module/name +-- overlay-replaced-go-mod/go.mod -- +module m + +go 1.15 + +require replaced/mod v1.0.0 +replace replaced/mod v1.0.0 => ../replaced-mod +replace dep/mod v1.0.0 => ../dep-mod +-- overlay-replaced-go-mod/source.go -- +package m + +import "replaced/mod/foo" + +func main() { + foo.f() +} +-- overlay-replaced-go-mod/overlay.json -- +{ + "Replace": { + "../replaced-mod/go.mod": "../../../overlay/replacement_module_go_mod" + } +} +-- replaced-mod/go.mod -- +module replaced/mod +-- replaced-mod/foo/foo.go -- +package foo + +import "dep/mod/foo" + +func f() { foo.g() } +-- dep-mod/go.mod -- +invalid +-- dep-mod/foo/foo.go -- +package foo + +func g() { fmt.Println("hello") } +-- $WORK/overlay/replacement_module_go_mod -- +module replaced/mod + +require dep/mod v1.0.0 + +-- get-doesnt-add-dep/overlay.json -- +{ + "Replace": { + "go.mod": "../../../overlay/get_doesnt_add_dep_go_mod" + } +} +-- get-doesnt-add-dep/p.go -- +package p + +import "dependency/mod" + +func f() { mod.G() } +-- get-doesnt-add-dep-dependency/go.mod -- +module dependency/mod +-- get-doesnt-add-dep-dependency/mod.go -- +package mod + +func G() {} +-- $WORK/overlay/get_doesnt_add_dep_go_mod -- +module get.doesnt/add/dep + +replace dependency/mod v1.0.0 => ../get-doesnt-add-dep-dependency +-- overlay-sum-used/go.mod -- +module overlay.sum/used + +require rsc.io/quote v1.5.0 +-- overlay-sum-used/p.go -- +package p + +import "rsc.io/quote" + +func f() string { + return quote.Hello() +} +-- overlay-sum-used/incomplete-sum-file -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +rsc.io/quote v1.5.0 h1:6fJa6E+wGadANKkUMlZ0DhXFpoKlslOQDCo259XtdIE= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +-- overlay-sum-used/overlay.json -- +{ + "Replace": { + "go.sum": "../../../overlay/overlay-sum-used-correct-sums" + } +} +-- overlay-sum-used/go.sum -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:garbage+hash +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:garbage+hash +rsc.io/quote v1.5.0 h1:garbage+hash +rsc.io/quote v1.5.0/go.mod h1:garbage+hash +rsc.io/sampler v1.3.0 h1:garbage+hash +rsc.io/sampler v1.3.0/go.mod h1:garbage+hash +-- $WORK/overlay/overlay-sum-used-correct-sums -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.0 h1:6fJa6E+wGadANKkUMlZ0DhXFpoKlslOQDCo259XtdIE= +rsc.io/quote v1.5.0/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +-- overlay-and-dash-modfile/p.go -- +package module +-- overlay-and-dash-modfile/go.mod -- +-- overlay-and-dash-modfile/overlay.json -- +{ + "Replace": { + "alternate.mod": "../../../overlay/overlay-and-dash-modfile-alternate-mod" + } +} +-- $WORK/overlay/overlay-and-dash-modfile-alternate-mod -- +module found.the/module +-- carve/go.mod -- +module carve +-- carve/overlay_carve_module.json -- +{ + "Replace": { + "nomod/go.mod": "../../../overlay/carve-nomod-go-mod" + } +} +-- carve/overlay_uncarve_module.json -- +{ + "Replace": { + "hasmod/go.mod": "" + } +} +-- carve/hasmod/a.go -- +package hasmod +-- carve/hasmod/go.mod -- +module carve/hasmod +-- carve/nomod/b.go -- +package nomod +-- $WORK/overlay/carve-nomod-go-mod -- +module carve/nomod +-- carve2/go.mod -- +module carve2 +-- carve2/p.go -- +package p +-- carve2/nomod/overlay.json -- +{ + "Replace": { + "go.mod": "../../../../overlay/carve2-nomod-go.mod" + } +} +-- carve2/nomod/b.go -- +package nomod +-- $WORK/overlay/carve2-nomod-go.mod -- +module carve2/nomod diff --git a/go/src/cmd/go/testdata/script/mod_patterns.txt b/go/src/cmd/go/testdata/script/mod_patterns.txt new file mode 100644 index 0000000000000000000000000000000000000000..1b4b4380b44af68ab7034bb427dbb2f7ee734680 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_patterns.txt @@ -0,0 +1,78 @@ +env GO111MODULE=on +[short] skip + +cd m + +# 'go list all' should list all of the packages used (directly or indirectly) by +# the packages in the main module, but no other packages from the standard +# library or active modules. +# +# 'go list ...' should list packages in all active modules and the standard library. +# +# 'go list example.com/m/...' should list packages in all modules that begin with 'example.com/m/'. +# +# 'go list ./...' should list only packages in the current module, not other active modules. +# +# Warnings about unmatched patterns should only be printed once. +# +# And the go command should be able to keep track of all this! +go list -f '{{.ImportPath}}: {{.Match}}' all ... example.com/m/... ./... ./xyz... +stdout 'example.com/m/useunicode: \[all \.\.\. example.com/m/... ./...\]' +stdout 'example.com/m/useunsafe: \[all \.\.\. example.com/m/... ./...\]' +[cgo] stdout 'example.com/m/useC: \[all \.\.\. example.com/m/... ./...\]' +[!cgo] ! stdout example.com/m/useC +stdout 'example.com/unused/useerrors: \[\.\.\.\]' # but not "all" +stdout 'example.com/m/nested/useencoding: \[\.\.\. example.com/m/...\]' # but NOT "all" or "./..." +stdout '^unicode: \[all \.\.\.\]' +stdout '^unsafe: \[all \.\.\.\]' +stdout 'index/suffixarray: \[\.\.\.\]' +stdout 'cmd/pprof: \[\.\.\.\]' + +stderr -count=1 '^go: warning: "./xyz..." matched no packages$' + +# 'go list ./...' should not try to resolve the main module. +cd ../empty +go list -deps ./... +! stdout . +! stderr 'finding' +stderr -count=1 '^go: warning: "./..." matched no packages' + +# disabling cgo should drop useC +[short] skip +env CGO_ENABLED=0 +go list -f '{{.ImportPath}}: {{.Match}}' all ... example.com/m/... ./... ./xyz... +! stdout example.com/m/useC + +-- m/go.mod -- +module example.com/m + +require example.com/unused v0.0.0 // indirect +replace example.com/unused => ../unused + +require example.com/m/nested v0.0.0 // indirect +replace example.com/m/nested => ../nested + +-- m/useC/useC.go -- +package useC +import _ "C" // "C" is a pseudo-package, not an actual one +-- m/useunicode/useunicode.go -- +package useunicode +import _ "unicode" +-- m/useunsafe/useunsafe.go -- +package useunsafe +import _ "unsafe" + +-- unused/go.mod -- +module example.com/unused +-- unused/useerrors/useerrors.go -- +package useerrors +import _ "errors" + +-- nested/go.mod -- +module example.com/m/nested +-- nested/useencoding/useencoding.go -- +package useencoding +import _ "encoding" + +-- empty/go.mod -- +module example.com/empty diff --git a/go/src/cmd/go/testdata/script/mod_patterns_vendor.txt b/go/src/cmd/go/testdata/script/mod_patterns_vendor.txt new file mode 100644 index 0000000000000000000000000000000000000000..b4dc401117dfef4b51f19d04f4694ae9236911b7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_patterns_vendor.txt @@ -0,0 +1,28 @@ +env GO111MODULE=on + +go list -mod=vendor example.com/... +stdout ^example.com/x$ +stdout ^example.com/x/y$ +! stdout ^example.com/x/vendor + +-- go.mod -- +module example.com/m + +-- vendor/modules.txt -- +# example.com/x v0.0.0 +example.com/x +# example.com/x/y v0.1.0 +example.com/x/y + +-- vendor/example.com/x/go.mod -- +module example.com/x +-- vendor/example.com/x/x.go -- +package x + +-- vendor/example.com/x/y/go.mod -- +module example.com/x/y +-- vendor/example.com/x/y/y.go -- +package y + +-- vendor/example.com/x/vendor/z/z.go -- +package z diff --git a/go/src/cmd/go/testdata/script/mod_perm.txt b/go/src/cmd/go/testdata/script/mod_perm.txt new file mode 100644 index 0000000000000000000000000000000000000000..2972f46601c0ebedb164866b33851daccd75af04 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_perm.txt @@ -0,0 +1,23 @@ +# go list should work in ordinary conditions. +go list ./... +! stdout _data + +# skip in conditions where chmod 0 may not work. +# plan9 should be fine, but copied from list_perm.txt unchanged. +[root] skip +[GOOS:windows] skip +[GOOS:plan9] skip + +# go list should work with unreadable _data directory. +chmod 0 _data +go list ./... +! stdout _data + +-- go.mod -- +module m + +-- x.go -- +package m + +-- _data/x.go -- +package p diff --git a/go/src/cmd/go/testdata/script/mod_permissions.txt b/go/src/cmd/go/testdata/script/mod_permissions.txt new file mode 100644 index 0000000000000000000000000000000000000000..b523e6ac778204140046fef0da8db2046ddeb580 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_permissions.txt @@ -0,0 +1,57 @@ +# Regression test for golang.org/issue/34634: permissions for the go.sum and +# go.mod files should be preserved when overwriting them. + +env GO111MODULE=on +[short] skip + +# Skip platforms that do not have Unix-style file permissions. +[GOOS:windows] skip +[GOOS:plan9] skip + +chmod 0640 go.mod +chmod 0604 go.sum +go mod edit -module=golang.org/issue/34634 + +go get +cmp go.mod go.mod.want +cmp go.sum go.sum.want + +go run . +stdout 'go.mod: 0640' +stdout 'go.sum: 0604' + +-- read_perm.go -- +package main + +import ( + "fmt" + "os" + _ "rsc.io/sampler" +) + +func main() { + for _, name := range []string{"go.mod", "go.sum"} { + fi, err := os.Stat(name) + if err != nil { + fmt.Fprintf(os.Stderr, "%s: %v\n", err) + continue + } + fmt.Printf("%s: 0%o\n", name, fi.Mode().Perm()) + } +} +-- go.mod -- +module TODO + +go 1.14 +-- go.sum -- +-- go.mod.want -- +module golang.org/issue/34634 + +go 1.14 + +require rsc.io/sampler v1.99.99 +-- go.sum.want -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/sampler v1.99.99 h1:iMG9lbEG/8MdeR4lgL+Q8IcwbLNw7ijW7fTiK8Miqts= +rsc.io/sampler v1.99.99/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/go/src/cmd/go/testdata/script/mod_prefer_compatible.txt b/go/src/cmd/go/testdata/script/mod_prefer_compatible.txt new file mode 100644 index 0000000000000000000000000000000000000000..4d583ff5f7e5a0a43b6570077c84ebd7708aa6be --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_prefer_compatible.txt @@ -0,0 +1,80 @@ +# Regression test for golang.org/issue/34189 and golang.org/issue/34165: +# @latest, @upgrade, and @patch should prefer compatible versions over +# +incompatible ones, even if offered by a proxy. + +[!net:github.com] skip +[!net:proxy.golang.org] skip + +env GO111MODULE=on +env GOPROXY= +env GOSUMDB= + +# github.com/russross/blackfriday v2.0.0+incompatible exists, +# and should be resolved if we ask for it explicitly. + +go list -m github.com/russross/blackfriday@v2.0.0+incompatible +stdout '^github.com/russross/blackfriday v2\.0\.0\+incompatible$' + +# blackfriday v1.5.2 has a go.mod file, so v1.5.2 should be preferred over +# v2.0.0+incompatible when resolving latest, upgrade, and patch. + +go list -m github.com/russross/blackfriday@latest +stdout '^github.com/russross/blackfriday v1\.' + +go list -m github.com/russross/blackfriday@upgrade +stdout '^github.com/russross/blackfriday v1\.' + +! go list -m github.com/russross/blackfriday@patch +stderr '^go: github.com/russross/blackfriday@patch: can''t query version "patch" of module github.com/russross/blackfriday: no existing version is required$' + + +# If we're fetching directly from version control, ignored +incompatible +# versions should also be omitted by 'go list'. + +# (Note that they may still be included in results from a proxy: in proxy mode, +# we would need to fetch the whole zipfile for the latest compatible version in +# order to determine whether it contains a go.mod file, and part of the point of +# the proxy is to avoid fetching unnecessary data.) + +[!git] stop +env GOPROXY=direct + +go list -versions -m github.com/russross/blackfriday +stdout '^github.com/russross/blackfriday v1\.5\.1 v1\.5\.2' # and possibly others +! stdout ' v2\.' + +# For this module, v2.1.0 exists and has a go.mod file. +# 'go list -m github.com/russross/blackfriday@v2.0' will check +# the latest v2.0 tag, discover that it isn't the right module, and stop there +# (instead of spending the time to check O(N) previous tags). + +! go list -m github.com/russross/blackfriday@v2.0 +stderr '^go: module github.com/russross/blackfriday: no matching versions for query "v2\.0\"' + +# (But asking for exactly v2.0.0+incompatible should still succeed.) +go list -m github.com/russross/blackfriday@v2.0.0+incompatible +stdout '^github.com/russross/blackfriday v2\.0\.0\+incompatible$' + + +# However, if the latest compatible version does not include a go.mod file, +# +incompatible versions should still be listed, as they may still reflect the +# intent of the module author. + +go list -versions -m github.com/rsc/legacytest +stdout '^github.com/rsc/legacytest v1\.0\.0 v1\.1\.0-pre v1\.2\.0 v2\.0\.0\+incompatible' + +# If we're fetching directly from version control, asking for a commit hash +# corresponding to a +incompatible version should continue to produce the +# +incompatible version tagged for that commit, even if it is no longer listed. + +go list -m github.com/russross/blackfriday@cadec560ec52 +stdout '^github.com/russross/blackfriday v2\.0\.0\+incompatible$' + +# Similarly, requesting an untagged commit should continue to produce a +incompatible +# pseudo-version. + +go list -m github.com/rsc/legacytest@7303f7796364 +stdout '^github.com/rsc/legacytest v2\.0\.1-0\.20180717164253-7303f7796364\+incompatible$' + +-- go.mod -- +module github.com/golang.org/issue/34165 diff --git a/go/src/cmd/go/testdata/script/mod_proxy_errors.txt b/go/src/cmd/go/testdata/script/mod_proxy_errors.txt new file mode 100644 index 0000000000000000000000000000000000000000..99a4ef1c5dd988f3866c0cfb1731d639f35671f4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_proxy_errors.txt @@ -0,0 +1,19 @@ +[short] skip + +env GO111MODULE=on +env GOSUMDB=off +env GOPROXY=direct + +# Server responses should be truncated to some reasonable number of lines. +# (For now, exactly eight.) +! go list -m vcs-test.golang.org/auth/ormanylines@latest +stderr '\tserver response:\n(.|\n)*\tline 8\n\t\[Truncated: too many lines.\]$' + +# Server responses should be truncated to some reasonable number of characters. +! go list -m vcs-test.golang.org/auth/oronelongline@latest +! stderr 'blah{40}' +stderr '\tserver response: \[Truncated: too long\.\]$' + +# Responses from servers using the 'mod' protocol should be propagated. +! go list -m vcs-test.golang.org/go/modauth404@latest +stderr '\tserver response: File\? What file\?' diff --git a/go/src/cmd/go/testdata/script/mod_proxy_https.txt b/go/src/cmd/go/testdata/script/mod_proxy_https.txt new file mode 100644 index 0000000000000000000000000000000000000000..c87a0d9450616f93be03246b7499be7e4d58ee6e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_proxy_https.txt @@ -0,0 +1,20 @@ +env GO111MODULE=on + +# GOPROXY file paths must provide the "file://" prefix explicitly. +env GOPROXY=$WORK/proxydir +! go list -versions -m golang.org/x/text +stderr 'invalid proxy URL.*proxydir' + +[!net:proxy.golang.org] stop + +# GOPROXY HTTPS paths may elide the "https://" prefix. +# (See golang.org/issue/32191.) +env GOPROXY=proxy.golang.org +env GOSUMDB= +go list -versions -m golang.org/x/text + +-- go.mod -- +module example.com +go 1.13 +-- $WORK/proxydir/README.md -- +This proxy contains no data. diff --git a/go/src/cmd/go/testdata/script/mod_proxy_invalid.txt b/go/src/cmd/go/testdata/script/mod_proxy_invalid.txt new file mode 100644 index 0000000000000000000000000000000000000000..63980b839e7743780d6959b26e6dbd6e542e38a2 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_proxy_invalid.txt @@ -0,0 +1,8 @@ +env GO111MODULE=on +env GOPROXY=$GOPROXY/invalid + +! go list -m rsc.io/quote@latest +stderr '^go: module rsc.io/quote: invalid response from proxy "'$GOPROXY'": invalid character ''i'' looking for beginning of value$' + +! go list -m rsc.io/quote@1.5.2 +stderr '^go: rsc.io/quote@1.5.2: invalid version: invalid response from proxy "'$GOPROXY'": invalid character ''i'' looking for beginning of value$' diff --git a/go/src/cmd/go/testdata/script/mod_proxy_list.txt b/go/src/cmd/go/testdata/script/mod_proxy_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..849cf2c476406554244339100d1699327f5857aa --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_proxy_list.txt @@ -0,0 +1,37 @@ +env GO111MODULE=on +env proxy=$GOPROXY + +# Proxy that can't serve should fail. +env GOPROXY=$proxy/404 +! go get rsc.io/quote@v1.0.0 +stderr '404 Not Found' + +# get should walk down the proxy list past 404 and 410 responses. +env GOPROXY=$proxy/404,$proxy/410,$proxy +go get rsc.io/quote@v1.1.0 + +# get should not walk past other 4xx errors if proxies are separated with ','. +env GOPROXY=$proxy/403,$proxy +! go get rsc.io/quote@v1.2.0 +stderr 'reading.*/403/rsc.io/.*: 403 Forbidden' + +# get should not walk past non-4xx errors if proxies are separated with ','. +env GOPROXY=$proxy/500,$proxy +! go get rsc.io/quote@v1.3.0 +stderr 'reading.*/500/rsc.io/.*: 500 Internal Server Error' + +# get should walk past other 4xx errors if proxies are separated with '|'. +env GOPROXY=$proxy/403|https://0.0.0.0|$proxy +go get rsc.io/quote@v1.2.0 + +# get should walk past non-4xx errors if proxies are separated with '|'. +env GOPROXY=$proxy/500|https://0.0.0.0|$proxy +go get rsc.io/quote@v1.3.0 + +# get should return the final error if that's all we have. +env GOPROXY=$proxy/404,$proxy/410 +! go get rsc.io/quote@v1.4.0 +stderr 'reading.*/410/rsc.io/.*: 410 Gone' + +-- go.mod -- +module x diff --git a/go/src/cmd/go/testdata/script/mod_pseudo_cache.txt b/go/src/cmd/go/testdata/script/mod_pseudo_cache.txt new file mode 100644 index 0000000000000000000000000000000000000000..bcaefa2f79f5c7f3a64aeec7c2e822dac7a68b09 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_pseudo_cache.txt @@ -0,0 +1,29 @@ +[!net:golang.org] skip +[!git] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +# Regression test for golang.org/issue/27171: after resolving an older +# pseudo-version of a commit, future resolution of that commit by hash should +# choose the highest appropriate pseudo-version instead of the cached one. + +go mod download -json golang.org/x/text@v0.0.0-20171215141712-a1b916ed6726 +stdout '"Version": "v0.0.0-20171215141712-a1b916ed6726",' + +# If GOPROXY is 'off', lookups should use whatever pseudo-version is available. +env GOPROXY=off +go mod download -json golang.org/x/text@a1b916ed6726 +stdout '"Version": "v0.0.0-20171215141712-a1b916ed6726",' + +# If we can re-resolve the commit to a pseudo-version, fetching the commit by +# hash should use the highest such pseudo-version appropriate to the commit. +env GOPROXY=direct +go mod download -json golang.org/x/text@a1b916ed6726 +stdout '"Version": "v0.3.1-0.20171215141712-a1b916ed6726",' + +# If GOPROXY is 'off', lookups should use the highest pseudo-version in the cache. +env GOPROXY=off +go mod download -json golang.org/x/text@a1b916ed6726 +stdout '"Version": "v0.3.1-0.20171215141712-a1b916ed6726",' diff --git a/go/src/cmd/go/testdata/script/mod_query.txt b/go/src/cmd/go/testdata/script/mod_query.txt new file mode 100644 index 0000000000000000000000000000000000000000..3758732504d0ca3f056acf169d1d96cf1171af40 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_query.txt @@ -0,0 +1,43 @@ +env GO111MODULE=on + +# TODO(golang.org/issue/41297): we shouldn't need go.sum. None of the commands +# below depend on the build list. + +go list -m -versions rsc.io/quote +stdout '^rsc.io/quote v1.0.0 v1.1.0 v1.2.0 v1.2.1 v1.3.0 v1.4.0 v1.5.0 v1.5.1 v1.5.2 v1.5.3-pre1$' + +# Latest rsc.io/quote should be v1.5.2, not v1.5.3-pre1. +go list -m rsc.io/quote@latest +stdout 'rsc.io/quote v1.5.2$' + +# Same for rsc.io/quote@v1 and rsc.io/quote@v1.5 (with no patch version). +go list -m rsc.io/quote@v1 +stdout 'rsc.io/quote v1.5.2$' +go list -m rsc.io/quote@v1.5 +stdout 'rsc.io/quote v1.5.2$' + +# We should fall back to prereleases if no release tags match... +go list -m rsc.io/quote@>v1.5.2 +stdout 'rsc.io/quote v1.5.3-pre1$' + +# ...but prefer release versions when given the option. +go list -m rsc.io/quote@v1.5.3 +stderr 'go: module rsc.io/quote: no matching versions for query ">v1.5.3"' + +go list -m -e -f '{{.Error.Err}}' rsc.io/quote@>v1.5.3 +stdout 'no matching versions for query ">v1.5.3"' + +-- go.mod -- +module x +require rsc.io/quote v1.0.0 + +-- go.sum -- +rsc.io/quote v1.0.0 h1:kQ3IZQzPTiDJxSZI98YaWgxFEhlNdYASHvh+MplbViw= +rsc.io/quote v1.0.0/go.mod h1:v83Ri/njykPcgJltBc/gEkJTmjTsNgtO1Y7vyIK1CQA= +-- use.go -- +package use + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_query_empty.txt b/go/src/cmd/go/testdata/script/mod_query_empty.txt new file mode 100644 index 0000000000000000000000000000000000000000..1c39eae5744c31d0b12a483eddd3a59a6d75ce1e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_query_empty.txt @@ -0,0 +1,73 @@ +env GO111MODULE=on +env GOSUMDB=off + +go mod download example.com/join@v1.1.0 + +# If the proxy serves a bogus result for the @latest version, +# reading that version should cause 'go get' to fail. +env GOPROXY=file:///$WORK/badproxy +cp go.mod.orig go.mod +! go get example.com/join/subpkg +stderr 'go: example.com/join/subpkg@v0.0.0-20190624000000-123456abcdef: .*' + +# If @v/list is empty, the 'go' command should still try to resolve +# other module paths. +env GOPROXY=file:///$WORK/emptysub +cp go.mod.orig go.mod +go get example.com/join/subpkg +go list -m example.com/join/... +! stdout 'example.com/join/subpkg' +stdout 'example.com/join v1.1.0' + +# If @v/list includes a version that the proxy does not actually serve, +# that version is treated as nonexistent. +env GOPROXY=file:///$WORK/notfound +cp go.mod.orig go.mod +go get example.com/join/subpkg +go list -m example.com/join/... +! stdout 'example.com/join/subpkg' +stdout 'example.com/join v1.1.0' + +# If the proxy provides an empty @v/list but rejects @latest with +# some other explicit error (for example, a "permission denied" error), +# that error should be reported to the user (and override a successful +# result for other possible module paths). +# +# Depending on how the specific platform enforces permissions, the 'go get' may +# fail either due to the intended permission error or due to a parse error. +# We accept either failure message. +env GOPROXY=file:///$WORK/gatekeeper +chmod 0000 $WORK/gatekeeper/example.com/join/subpkg/@latest +cp go.mod.orig go.mod +! go get example.com/join/subpkg +stderr 'go: module example.com/join/subpkg: (invalid response from proxy ".+": invalid character .+|reading file://.*/gatekeeper/example.com/join/subpkg/@latest: .+)' + +-- go.mod.orig -- +module example.com/othermodule +go 1.13 +-- $WORK/badproxy/example.com/join/subpkg/@v/list -- +v0.0.0-20190624000000-123456abcdef +-- $WORK/badproxy/example.com/join/subpkg/@v/v0.0.0-20190624000000-123456abcdef.info -- +This file is not valid JSON. +-- $WORK/badproxy/example.com/join/@v/list -- +v1.1.0 +-- $WORK/badproxy/example.com/join/@v/v1.1.0.info -- +{"Version": "v1.1.0"} +-- $WORK/emptysub/example.com/join/subpkg/@v/list -- +-- $WORK/emptysub/example.com/join/@v/list -- +v1.1.0 +-- $WORK/emptysub/example.com/join/@v/v1.1.0.info -- +{"Version": "v1.1.0"} +-- $WORK/notfound/example.com/join/subpkg/@v/list -- +v1.0.0-does-not-exist +-- $WORK/notfound/example.com/join/@v/list -- +v1.1.0 +-- $WORK/notfound/example.com/join/@v/v1.1.0.info -- +{"Version": "v1.1.0"} +-- $WORK/gatekeeper/example.com/join/subpkg/@v/list -- +-- $WORK/gatekeeper/example.com/join/subpkg/@latest -- +ERROR: Latest version is forbidden. +-- $WORK/gatekeeper/example.com/join/@v/list -- +v1.1.0 +-- $WORK/gatekeeper/example.com/join/@v/v1.1.0.info -- +{"Version": "v1.1.0"} diff --git a/go/src/cmd/go/testdata/script/mod_query_exclude.txt b/go/src/cmd/go/testdata/script/mod_query_exclude.txt new file mode 100644 index 0000000000000000000000000000000000000000..f76b20c6d8830693856d8f59420cb7bb07aa9cb8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_query_exclude.txt @@ -0,0 +1,46 @@ +env GO111MODULE=on + +# list excluded version +go list -modfile=go.exclude.mod -m rsc.io/quote@v1.5.0 +stdout '^rsc.io/quote v1.5.0$' + +# list versions should not print excluded versions +go list -m -versions rsc.io/quote +stdout '\bv1.5.0\b' +go list -modfile=go.exclude.mod -m -versions rsc.io/quote +! stdout '\bv1.5.0\b' + +# list query with excluded version +go list -m rsc.io/quote@>=v1.5 +stdout '^rsc.io/quote v1.5.0$' +go list -modfile=go.exclude.mod -m rsc.io/quote@>=v1.5 +stdout '^rsc.io/quote v1.5.1$' + +# get excluded version +cp go.exclude.mod go.exclude.mod.orig +! go get -modfile=go.exclude.mod rsc.io/quote@v1.5.0 +stderr '^go: rsc.io/quote@v1.5.0: excluded by go.mod$' + +# get non-excluded version +cp go.exclude.mod.orig go.exclude.mod +go get -modfile=go.exclude.mod rsc.io/quote@v1.5.1 +stderr 'rsc.io/quote v1.5.1' + +# get query with excluded version +cp go.exclude.mod.orig go.exclude.mod +go get -modfile=go.exclude.mod rsc.io/quote@>=v1.5 +go list -modfile=go.exclude.mod -m ...quote +stdout 'rsc.io/quote v1.5.[1-9]' + +-- go.mod -- +module x + +-- go.exclude.mod -- +module x + +exclude rsc.io/quote v1.5.0 + +-- x.go -- +package x +import _ "rsc.io/quote" + diff --git a/go/src/cmd/go/testdata/script/mod_query_main.txt b/go/src/cmd/go/testdata/script/mod_query_main.txt new file mode 100644 index 0000000000000000000000000000000000000000..2a2fa42318aa1d10ceaef2d8725b868bd6013de6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_query_main.txt @@ -0,0 +1,43 @@ +# 'go mod download' can download specific versions of the main module. +go mod download rsc.io/quote@5d9f230b +go mod download rsc.io/quote@v1.5.2 +go mod download rsc.io/quote@latest + +# 'go mod download' will not download @upgrade or @patch, since they always +# resolve to the main module. +go mod download rsc.io/quote@upgrade +stderr '^go: skipping download of rsc.io/quote@upgrade that resolves to the main module$' +go mod download rsc.io/quote@patch +stderr '^go: skipping download of rsc.io/quote@patch that resolves to the main module$' + +# 'go list -m' can show a version of the main module. +go list -m rsc.io/quote@5d9f230b +stdout '^rsc.io/quote v0.0.0-20180710144737-5d9f230bcfba$' +go list -m rsc.io/quote@v1.5.2 +stdout '^rsc.io/quote v1.5.2$' +go list -m rsc.io/quote@latest +stdout '^rsc.io/quote v1.5.2$' + +# 'go list -m -versions' shows available versions. +go list -m -versions rsc.io/quote +stdout '^rsc.io/quote.*v1.5.2' + +# 'go list -m' resolves @upgrade and @patch to the main module. +go list -m rsc.io/quote@upgrade +stdout '^rsc.io/quote$' +go list -m rsc.io/quote@patch +stdout '^rsc.io/quote$' + +# 'go get' will not attempt to upgrade the main module to any specific version. +# See also: mod_get_main.txt. +! go get rsc.io/quote@5d9f230b +stderr '^go: can''t request version "5d9f230b" of the main module \(rsc.io/quote\)$' +! go get rsc.io/quote@v1.5.2 +stderr '^go: can''t request version "v1.5.2" of the main module \(rsc.io/quote\)$' +! go get rsc.io/quote@latest +stderr '^go: can''t request version "latest" of the main module \(rsc.io/quote\)$' + +-- go.mod -- +module rsc.io/quote + +go 1.16 diff --git a/go/src/cmd/go/testdata/script/mod_readonly.txt b/go/src/cmd/go/testdata/script/mod_readonly.txt new file mode 100644 index 0000000000000000000000000000000000000000..9e950c389821208b1f4fd9e75459555261ebb8b0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_readonly.txt @@ -0,0 +1,131 @@ +env GO111MODULE=on +[short] skip + +# -mod=readonly must not resolve missing modules nor update go.mod +env GOFLAGS=-mod=readonly +go mod edit -fmt +cp go.mod go.mod.empty +! go list all +stderr '^x.go:2:8: cannot find module providing package rsc\.io/quote: import lookup disabled by -mod=readonly' +! stderr '\(\)' # If we don't have a reason for -mod=readonly, don't log an empty one. +cmp go.mod go.mod.empty + +# -mod=readonly should be set by default. +env GOFLAGS= +! go list all +stderr '^x.go:2:8: no required module provides package rsc\.io/quote; to add it:\n\tgo get rsc\.io/quote$' +cmp go.mod go.mod.empty + +env GOFLAGS=-mod=readonly + +# update go.mod - go get allowed +go get rsc.io/quote +grep rsc.io/quote go.mod + +# update go.mod - go mod tidy allowed +cp go.mod.empty go.mod +go mod tidy +cp go.mod go.mod.tidy + +# -mod=readonly must succeed once go.mod is up-to-date... +go list all + +# ... even if it needs downloads +go clean -modcache +go list all + +# -mod=readonly must not cause 'go list -m' to fail. +# (golang.org/issue/36478) +go list -m all +! stderr 'cannot query module' + +# -mod=readonly should reject inconsistent go.mod files +# (ones that would be rewritten). +go get rsc.io/sampler@v1.2.0 +go mod edit -require rsc.io/quote@v1.5.2 +cp go.mod go.mod.inconsistent +! go list +stderr 'go: updates to go.mod needed, disabled by -mod=readonly' +cmp go.mod go.mod.inconsistent + +# We get a different message when -mod=readonly is used by default. +env GOFLAGS= +! go list +stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy' + +# However, it should not reject files missing a 'go' directive, +# since that was not always required. +cp go.mod.nogo go.mod +go list all +cmp go.mod go.mod.nogo + +# Nor should it reject files with redundant (not incorrect) +# requirements. +cp go.mod.redundant go.mod +go list all +cmp go.mod go.mod.redundant + +cp go.mod.indirect go.mod +go list all +cmp go.mod go.mod.indirect + + +# If we identify a missing package as a dependency of some other package in the +# main module, we should suggest 'go mod tidy' instead of resolving it. + +cp go.mod.untidy go.mod +! go list all +stderr '^x.go:2:8: no required module provides package rsc.io/quote; to add it:\n\tgo get rsc.io/quote$' + +! go list -deps . +stderr '^x.go:2:8: no required module provides package rsc.io/quote; to add it:\n\tgo get rsc.io/quote$' + +# However, if we didn't see an import from the main module, we should suggest +# 'go get' instead, because we don't know whether 'go mod tidy' would add it. +! go list rsc.io/quote +stderr '^no required module provides package rsc.io/quote; to add it:\n\tgo get rsc.io/quote$' + + +-- go.mod -- +module m + +go 1.16 + +-- x.go -- +package x +import _ "rsc.io/quote" +-- go.mod.nogo -- +module m + +require ( + rsc.io/quote v1.5.2 + rsc.io/testonly v1.0.0 // indirect +) +-- go.mod.redundant -- +module m + +go 1.16 + +require ( + rsc.io/quote v1.5.2 + rsc.io/sampler v1.3.0 // indirect + rsc.io/testonly v1.0.0 // indirect +) +-- go.mod.indirect -- +module m + +go 1.16 + +require ( + rsc.io/quote v1.5.2 // indirect + rsc.io/sampler v1.3.0 // indirect + rsc.io/testonly v1.0.0 // indirect +) +-- go.mod.untidy -- +module m + +go 1.16 + +require ( + rsc.io/sampler v1.3.0 // indirect +) diff --git a/go/src/cmd/go/testdata/script/mod_removed_godebug.txt b/go/src/cmd/go/testdata/script/mod_removed_godebug.txt new file mode 100644 index 0000000000000000000000000000000000000000..bd1f61c9d26cc9933d25ada2b68c6a4047a1c5f7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_removed_godebug.txt @@ -0,0 +1,11 @@ +# Test case that makes sure we print a nice error message +# instead of the generic "unknown godebug" error message +# for removed GODEBUGs. + +! go list +stderr '^go.mod:3: use of removed godebug "x509sha1", see https://go.dev/doc/godebug#go-124$' + +-- go.mod -- +module example.com/bar + +godebug x509sha1=1 diff --git a/go/src/cmd/go/testdata/script/mod_replace.txt b/go/src/cmd/go/testdata/script/mod_replace.txt new file mode 100644 index 0000000000000000000000000000000000000000..26b15518d94fa3bcf7e762abdd1f4d0667a0c50b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_replace.txt @@ -0,0 +1,129 @@ +env GO111MODULE=on +[short] skip + +cp go.mod go.mod.orig + +# Make sure the test builds without replacement. +go build -mod=mod -o a1.exe . +exec ./a1.exe +stdout 'Don''t communicate by sharing memory' + +# Modules can be replaced by local packages. +cp go.mod.orig go.mod +go mod edit -replace=rsc.io/quote/v3=./local/rsc.io/quote/v3 +go build -o a2.exe . +exec ./a2.exe +stdout 'Concurrency is not parallelism.' + +# The module path of the replacement doesn't need to match. +# (For example, it could be a long-running fork with its own import path.) +cp go.mod.orig go.mod +go mod edit -replace=rsc.io/quote/v3=./local/not-rsc.io/quote/v3 +go build -o a3.exe . +exec ./a3.exe +stdout 'Clear is better than clever.' + +# However, the same module can't be used as two different paths. +cp go.mod.orig go.mod +go mod edit -replace=not-rsc.io/quote/v3@v3.0.0=rsc.io/quote/v3@v3.0.0 -require=not-rsc.io/quote/v3@v3.0.0 +! go build -o a4.exe . +stderr 'rsc.io/quote/v3@v3.0.0 used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)' + +# Modules that do not (yet) exist upstream can be replaced too. +cp go.mod.orig go.mod +go mod edit -replace=not-rsc.io/quote/v3@v3.1.0=./local/rsc.io/quote/v3 +go build -mod=mod -o a5.exe ./usenewmodule +! stderr 'finding not-rsc.io/quote/v3' +grep 'not-rsc.io/quote/v3 v3.1.0' go.mod +exec ./a5.exe +stdout 'Concurrency is not parallelism.' + +# Error messages for modules not found in replacements should +# indicate the replacement module. +cp go.mod.orig go.mod +go mod edit -replace=rsc.io/quote/v3=./local/rsc.io/quote/v3 +! go get rsc.io/quote/v3/missing-package +stderr 'module rsc.io/quote/v3@upgrade found \(v3.0.0, replaced by ./local/rsc.io/quote/v3\), but does not contain package' + +# The reported Dir and GoMod for a replaced module should be accurate. +cp go.mod.orig go.mod +go mod edit -replace=rsc.io/quote/v3=not-rsc.io/quote@v0.1.0-nomod +go mod download rsc.io/quote/v3 +go list -m -f '{{.Path}} {{.Version}} {{.Dir}} {{.GoMod}}{{with .Replace}} => {{.Path}} {{.Version}} {{.Dir}} {{.GoMod}}{{end}}' rsc.io/quote/v3 +stdout '^rsc.io/quote/v3 v3.0.0 '$GOPATH'[/\\]pkg[/\\]mod[/\\]not-rsc.io[/\\]quote@v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]cache[/\\]download[/\\]not-rsc.io[/\\]quote[/\\]@v[/\\]v0.1.0-nomod.mod => not-rsc.io/quote v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]not-rsc.io[/\\]quote@v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]cache[/\\]download[/\\]not-rsc.io[/\\]quote[/\\]@v[/\\]v0.1.0-nomod.mod$' + +-- go.mod -- +module quoter + +require rsc.io/quote/v3 v3.0.0 + +-- main.go -- +package main + +import ( + "fmt" + "rsc.io/quote/v3" +) + +func main() { + fmt.Println(quote.GoV3()) +} + +-- usenewmodule/main.go -- +package main + +import ( + "fmt" + "not-rsc.io/quote/v3" +) + +func main() { + fmt.Println(quote.GoV3()) +} + +-- local/rsc.io/quote/v3/go.mod -- +module rsc.io/quote/v3 + +require rsc.io/sampler v1.3.0 + +-- local/rsc.io/quote/v3/quote.go -- +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quote collects pithy sayings. +package quote + +import "rsc.io/sampler" + +// Hello returns a greeting. +func HelloV3() string { + return sampler.Hello() +} + +// Glass returns a useful phrase for world travelers. +func GlassV3() string { + // See http://www.oocities.org/nodotus/hbglass.html. + return "I can eat glass and it doesn't hurt me." +} + +// Go returns a REPLACED Go proverb. +func GoV3() string { + return "Concurrency is not parallelism." +} + +// Opt returns a optimization truth. +func OptV3() string { + // Wisdom from ken. + return "If a program is too slow, it must have a loop." +} + +-- local/not-rsc.io/quote/v3/go.mod -- +module not-rsc.io/quote/v3 + +-- local/not-rsc.io/quote/v3/quote.go -- +package quote + +func GoV3() string { + return "Clear is better than clever." +} diff --git a/go/src/cmd/go/testdata/script/mod_replace_gopkgin.txt b/go/src/cmd/go/testdata/script/mod_replace_gopkgin.txt new file mode 100644 index 0000000000000000000000000000000000000000..91008f920f31b44dad165c237dd586415db21f43 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_replace_gopkgin.txt @@ -0,0 +1,82 @@ +# Regression test for golang.org/issue/34254: +# a clone of gopkg.in/[…].vN should be replaceable by +# a fork hosted at corp.example.com/[…]/vN, +# even if there is an explicit go.mod file containing the +# gopkg.in path. + +skip 'skipping test that depends on an unreliable third-party server; see https://go.dev/issue/54503' + # TODO(#54043): Make this test hermetic and re-enable it. + +[!net:gopkg.in] skip +[!git] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off +env GOFLAGS=-mod=mod + +# Replacing gopkg.in/[…].vN with a repository with a root go.mod file +# specifying […].vN and a compatible version should succeed, even if +# the replacement path is not a gopkg.in path. +cd 4-to-4 +go list -m gopkg.in/src-d/go-git.v4 + +# Previous versions of the "go" command accepted v0 and v1 pseudo-versions +# as replacements for gopkg.in/[…].v4. +# As a special case, we continue to accept those. + +cd ../4-to-0 +go list -m gopkg.in/src-d/go-git.v4 + +cd ../4-to-1 +go list -m gopkg.in/src-d/go-git.v4 + +cd ../4-to-incompatible +go list -m gopkg.in/src-d/go-git.v4 + +# A mismatched gopkg.in path should not be able to replace a different major version. +cd ../3-to-gomod-4 +! go list -m gopkg.in/src-d/go-git.v3 +stderr '^go: gopkg\.in/src-d/go-git\.v3@v3\.2\.0 \(replaced by gopkg\.in/src-d/go-git\.v3@v3\.0\.0-20190801152248-0d1a009cbb60\): version "v3\.0\.0-20190801152248-0d1a009cbb60" invalid: go\.mod has non-\.\.\.\.v3 module path "gopkg\.in/src-d/go-git\.v4" at revision 0d1a009cbb60$' + +-- 4-to-4/go.mod -- +module golang.org/issue/34254 + +go 1.13 + +require gopkg.in/src-d/go-git.v4 v4.13.1 + +replace gopkg.in/src-d/go-git.v4 v4.13.1 => github.com/src-d/go-git/v4 v4.13.1 +-- 4-to-1/go.mod -- +module golang.org/issue/34254 + +go 1.13 + +require gopkg.in/src-d/go-git.v4 v4.13.1 + +replace gopkg.in/src-d/go-git.v4 v4.13.1 => github.com/src-d/go-git v1.0.1-0.20190801152248-0d1a009cbb60 +-- 4-to-0/go.mod -- +module golang.org/issue/34254 + +go 1.13 + +require gopkg.in/src-d/go-git.v4 v4.13.1 + +replace gopkg.in/src-d/go-git.v4 v4.13.1 => github.com/src-d/go-git v0.0.0-20190801152248-0d1a009cbb60 +-- 4-to-incompatible/go.mod -- +module golang.org/issue/34254 + +go 1.13 + +require gopkg.in/src-d/go-git.v4 v4.13.1 + +replace gopkg.in/src-d/go-git.v4 v4.13.1 => github.com/src-d/go-git v4.6.0+incompatible +-- 3-to-gomod-4/go.mod -- +module golang.org/issue/34254 +go 1.13 + +require gopkg.in/src-d/go-git.v3 v3.2.0 + +// This replacement has a go.mod file declaring its path to be +// gopkg.in/src-d/go-git.v4, so it cannot be used as a replacement for v3. +replace gopkg.in/src-d/go-git.v3 v3.2.0 => gopkg.in/src-d/go-git.v3 v3.0.0-20190801152248-0d1a009cbb60 diff --git a/go/src/cmd/go/testdata/script/mod_replace_import.txt b/go/src/cmd/go/testdata/script/mod_replace_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..753071f4baae96eb1c52f449cc998d6d2425d71f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_replace_import.txt @@ -0,0 +1,144 @@ +env GO111MODULE=on + +# 'go list' should not add requirements even if they can be resolved locally. +cp go.mod go.mod.orig +! go list all +cmp go.mod go.mod.orig + +# 'go list' should resolve imports using replacements. +go get +go list all +stdout 'example.com/a/b$' +stdout 'example.com/x/v3$' +stdout 'example.com/y/z/w$' +stdout 'example.com/v' + +# The selected modules should prefer longer paths, +# but should try shorter paths if needed. +# Modules with a major-version suffix should have a corresponding pseudo-version. +# Replacements that specify a version should use the latest such version. +go list -m all +stdout 'example.com/a/b v0.0.0-00010101000000-000000000000 => ./b' +stdout 'example.com/y v0.0.0-00010101000000-000000000000 => ./y' +stdout 'example.com/x/v3 v3.0.0-00010101000000-000000000000 => ./v3' +stdout 'example.com/v v1.12.0 => ./v12' + +# The go command should print an informative error when the matched +# module does not contain a package. +# TODO(#26909): Ideally these errors should include line numbers for the imports within the main module. +cd fail +! go mod tidy +stderr '^go: localhost.fail imports\n\tw: module w@latest found \(v0.0.0-00010101000000-000000000000, replaced by ../w\), but does not contain package w$' +stderr '^go: localhost.fail imports\n\tnonexist: nonexist@v0.1.0: replacement directory ../nonexist does not exist$' + +-- go.mod -- +module example.com/m + +replace ( + example.com/a => ./a + example.com/a/b => ./b +) + +replace ( + example.com/x => ./x + example.com/x/v3 => ./v3 +) + +replace ( + example.com/y/z/w => ./w + example.com/y => ./y +) + +replace ( + example.com/v v1.11.0 => ./v11 + example.com/v v1.12.0 => ./v12 + example.com/v => ./v +) + +replace ( + example.com/i v2.0.0+incompatible => ./i2 +) + +-- m.go -- +package main +import ( + _ "example.com/a/b" + _ "example.com/x/v3" + _ "example.com/y/z/w" + _ "example.com/v" + _ "example.com/i" +) +func main() {} + +-- a/go.mod -- +module a.localhost +-- a/a.go -- +package a +-- a/b/b.go-- +package b + +-- b/go.mod -- +module a.localhost/b +-- b/b.go -- +package b + +-- x/go.mod -- +module x.localhost +-- x/x.go -- +package x +-- x/v3.go -- +package v3 +import _ "x.localhost/v3" + +-- v3/go.mod -- +module x.localhost/v3 +-- v3/x.go -- +package x + +-- w/go.mod -- +module w.localhost +-- w/skip/skip.go -- +// Package skip is nested below nonexistent package w. +package skip + +-- y/go.mod -- +module y.localhost +-- y/z/w/w.go -- +package w + +-- v12/go.mod -- +module v.localhost +-- v12/v.go -- +package v + +-- v11/go.mod -- +module v.localhost +-- v11/v.go -- +package v + +-- v/go.mod -- +module v.localhost +-- v/v.go -- +package v + +-- i2/go.mod -- +module example.com/i +-- i2/i.go -- +package i + +-- fail/m.go -- +package main + +import ( + _ "w" + _ "nonexist" +) + +func main() {} + +-- fail/go.mod -- +module localhost.fail + +replace w => ../w + +replace nonexist v0.1.0 => ../nonexist diff --git a/go/src/cmd/go/testdata/script/mod_replace_readonly.txt b/go/src/cmd/go/testdata/script/mod_replace_readonly.txt new file mode 100644 index 0000000000000000000000000000000000000000..5c1226b15efd46e06af85ed7277b83123bf0e83f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_replace_readonly.txt @@ -0,0 +1,62 @@ +# Check that with -mod=readonly, when we load a package in a module that is +# replaced but not required, we emit an error with the command to add the +# requirement. +# Verifies golang.org/issue/41416, golang.org/issue/41577. +cp go.mod go.mod.orig + +# Replace all versions of a module without requiring it. +# With -mod=mod, we'd add a requirement for a "zero" pseudo-version, but we +# can't in readonly mode, since its go.mod may alter the build list. +go mod edit -replace rsc.io/quote=./quote +! go list rsc.io/quote +stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote$' +go get rsc.io/quote +cmp go.mod go.mod.latest +go list rsc.io/quote +cp go.mod.orig go.mod + +# Same test with a specific version. +go mod edit -replace rsc.io/quote@v1.0.0-doesnotexist=./quote +! go list rsc.io/quote +stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote@v1.0.0-doesnotexist$' +go get rsc.io/quote@v1.0.0-doesnotexist +cmp go.mod go.mod.specific +go list rsc.io/quote +cp go.mod.orig go.mod + +# If there are multiple versions, the highest is suggested. +go mod edit -replace rsc.io/quote@v1.0.0-doesnotexist=./quote +go mod edit -replace rsc.io/quote@v1.1.0-doesnotexist=./quote +! go list rsc.io/quote +stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote@v1.1.0-doesnotexist$' + +-- go.mod -- +module m + +go 1.16 +-- go.mod.latest -- +module m + +go 1.16 + +replace rsc.io/quote => ./quote + +require rsc.io/quote v1.5.2 // indirect +-- go.mod.specific -- +module m + +go 1.16 + +replace rsc.io/quote v1.0.0-doesnotexist => ./quote + +require rsc.io/quote v1.0.0-doesnotexist // indirect +-- use.go -- +package use + +import _ "rsc.io/quote" +-- quote/go.mod -- +module rsc.io/quote + +go 1.16 +-- quote/quote.go -- +package quote diff --git a/go/src/cmd/go/testdata/script/mod_require_exclude.txt b/go/src/cmd/go/testdata/script/mod_require_exclude.txt new file mode 100644 index 0000000000000000000000000000000000000000..0946dbf0bb39d0796b3f66c8d593c037c5ef51b9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_require_exclude.txt @@ -0,0 +1,96 @@ +# build with no newer version to satisfy exclude +env GO111MODULE=on +cp go.mod go.mod.orig + +# With the selected version excluded, commands that query that version without +# updating go.mod should fail. + +! go list -mod=readonly -m all +stderr '^go: ignoring requirement on excluded version rsc.io/sampler v1\.99\.99$' +stderr '^go: updates to go.mod needed, disabled by -mod=readonly; to update it:\n\tgo mod tidy$' +! stdout '^rsc.io/sampler v1.99.99' +cmp go.mod go.mod.orig + +! go list -mod=vendor -m rsc.io/sampler +stderr '^go: ignoring requirement on excluded version rsc.io/sampler v1\.99\.99$' +stderr '^go: updates to go.mod needed, disabled by -mod=vendor; to update it:\n\tgo mod tidy$' +! stdout '^rsc.io/sampler v1.99.99' +cmp go.mod go.mod.orig + +# The failure message should be clear when -mod=vendor is implicit. + +go mod edit -go=1.14 +! go list -m rsc.io/sampler +stderr '^go: ignoring requirement on excluded version rsc.io/sampler v1\.99\.99$' +stderr '^go: updates to go.mod needed, disabled by -mod=vendor\n\t\(Go version in go.mod is at least 1.14 and vendor directory exists\.\)\n\tto update it:\n\tgo mod tidy$' +! stdout '^rsc.io/sampler v1.99.99' +go mod edit -go=1.13 +cmp go.mod go.mod.orig + + +# With the selected version excluded, commands that load only modules should +# drop the excluded module. + +go list -m -mod=mod all +stderr '^go: dropping requirement on excluded version rsc.io/sampler v1\.99\.99$' +stdout '^x$' +! stdout '^rsc.io/sampler' +cmp go.mod go.moddrop + +# With the latest version excluded, 'go list' should resolve needed packages +# from the next-highest version. + +cp go.mod.orig go.mod +go list -mod=mod -f '{{with .Module}}{{.Path}} {{.Version}}{{end}}' all +stderr '^go: dropping requirement on excluded version rsc.io/sampler v1\.99\.99$' +stdout '^x $' +! stdout '^rsc.io/sampler v1.99.99' +stdout '^rsc.io/sampler v1.3.0' + +# build with newer version available +cp go.mod2 go.mod +go list -mod=mod -f '{{with .Module}}{{.Path}} {{.Version}}{{end}}' all +stderr '^go: dropping requirement on excluded version rsc.io/quote v1\.5\.1$' +stdout 'rsc.io/quote v1.5.2' + +# build with excluded newer version +cp go.mod3 go.mod +go list -mod=mod -f '{{with .Module}}{{.Path}} {{.Version}}{{end}}' all +! stderr '^go: dropping requirement' +stdout 'rsc.io/quote v1.5.1' + +-- x.go -- +package x +import _ "rsc.io/quote" + +-- go.mod -- +module x + +go 1.13 + +exclude rsc.io/sampler v1.99.99 + +require rsc.io/sampler v1.99.99 +-- vendor/modules.txt -- +# rsc.io/sampler v1.99.99 +## explicit +-- go.moddrop -- +module x + +go 1.13 + +exclude rsc.io/sampler v1.99.99 +-- go.mod2 -- +module x + +go 1.13 + +exclude rsc.io/quote v1.5.1 +require rsc.io/quote v1.5.1 +-- go.mod3 -- +module x + +go 1.13 + +exclude rsc.io/quote v1.5.2 +require rsc.io/quote v1.5.1 diff --git a/go/src/cmd/go/testdata/script/mod_retention.txt b/go/src/cmd/go/testdata/script/mod_retention.txt new file mode 100644 index 0000000000000000000000000000000000000000..9d30026459a8af6440f0eb8bbce61eb0f4d9a179 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_retention.txt @@ -0,0 +1,150 @@ +# Regression test for golang.org/issue/34822: the 'go' command should prefer not +# to update the go.mod file if the changes only affect formatting, and should only +# remove redundant requirements in 'go mod tidy'. + +env GO111MODULE=on +[short] skip + +# Control case: verify that go.mod.tidy is actually tidy. +cp go.mod.tidy go.mod +go list -mod=mod all +cmp go.mod go.mod.tidy + + +# If the only difference in the go.mod file is the line endings, +# it should not be overwritten automatically. +cp go.mod.crlf go.mod +go list all +cmp go.mod go.mod.crlf + +# However, 'go mod tidy' should fix whitespace even if there are no other changes. +go mod tidy +cmp go.mod go.mod.tidy + + +# Out-of-order requirements should not be overwritten automatically... +cp go.mod.unsorted go.mod +go list all +cmp go.mod go.mod.unsorted + +# ...but 'go mod edit -fmt' should sort them. +go mod edit -fmt +cmp go.mod go.mod.tidy + + +# "// indirect" comments should be removed if direct dependencies are seen. +# changes. +cp go.mod.indirect go.mod +go list -mod=mod all +cmp go.mod go.mod.tidy + +# "// indirect" comments should be added if appropriate. +# TODO(#42504): add case for 'go list -mod=mod -tags=any all' when -tags=any +# is supported. Only a command that loads "all" without build constraints +# (except "ignore") has enough information to add "// indirect" comments. +# 'go mod tidy' and 'go mod vendor' are the only commands that do that, +# but 'go mod vendor' cannot write go.mod. +cp go.mod.toodirect go.mod +go list all +cmp go.mod go.mod.toodirect + + +# Redundant requirements should be preserved... +cp go.mod.redundant go.mod +go list all +cmp go.mod go.mod.redundant +go mod vendor +cmp go.mod go.mod.redundant +rm -r vendor + +# ...except by 'go mod tidy'. +go mod tidy +cmp go.mod go.mod.tidy + + +# A missing "go" version directive should be added. +# However, that should not remove other redundant requirements. +# In fact, it may *add* redundant requirements due to activating lazy loading. +cp go.mod.nogo go.mod +go list -mod=mod all +cmpenv go.mod go.mod.addedgo + + +-- go.mod.tidy -- +module m + +go 1.14 + +require ( + rsc.io/quote v1.5.2 + rsc.io/testonly v1.0.0 // indirect +) +-- x.go -- +package x +import _ "rsc.io/quote" +-- go.mod.crlf -- +module m + +go 1.14 + +require ( + rsc.io/quote v1.5.2 + rsc.io/testonly v1.0.0 // indirect +) +-- go.mod.unsorted -- +module m + +go 1.14 + +require ( + rsc.io/testonly v1.0.0 // indirect + rsc.io/quote v1.5.2 +) +-- go.mod.indirect -- +module m + +go 1.14 + +require ( + rsc.io/quote v1.5.2 // indirect + rsc.io/testonly v1.0.0 // indirect +) +-- go.mod.toodirect -- +module m + +go 1.14 + +require ( + rsc.io/quote v1.5.2 + rsc.io/testonly v1.0.0 +) +-- go.mod.redundant -- +module m + +go 1.14 + +require ( + rsc.io/quote v1.5.2 + rsc.io/sampler v1.3.0 // indirect + rsc.io/testonly v1.0.0 // indirect +) +-- go.mod.nogo -- +module m + +require ( + rsc.io/quote v1.5.2 + rsc.io/sampler v1.3.0 // indirect + rsc.io/testonly v1.0.0 // indirect +) +-- go.mod.addedgo -- +module m + +go $goversion + +require rsc.io/quote v1.5.2 + +require ( + golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect + rsc.io/sampler v1.3.0 // indirect + rsc.io/testonly v1.0.0 // indirect +) diff --git a/go/src/cmd/go/testdata/script/mod_retract.txt b/go/src/cmd/go/testdata/script/mod_retract.txt new file mode 100644 index 0000000000000000000000000000000000000000..37aae4896d0c718b983f2a6f15375c2e38f0159c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_retract.txt @@ -0,0 +1,45 @@ +cp go.mod go.mod.orig + +# 'go list pkg' does not report an error when a retracted version is used. +go list -e -f '{{if .Error}}{{.Error}}{{end}}' ./use +! stdout . +cmp go.mod go.mod.orig + +# Nor does 'go build'. +[!short] go build ./use +[!short] ! stderr . +[!short] cmp go.mod go.mod.orig + +# Neither 'go list' nor 'go build' should download go.mod from the version +# that would list retractions. +exists $GOPATH/pkg/mod/cache/download/example.com/retract/@v/v1.0.0-bad.mod +! exists $GOPATH/pkg/mod/cache/download/example.com/retract/@v/v1.1.0.mod + +# Importing a package from a module with a retracted latest version will +# select the latest non-retracted version. +go get ./use_self_prev +go list -m example.com/retract/self/prev +stdout '^example.com/retract/self/prev v1.1.0$' +exists $GOPATH/pkg/mod/cache/download/example.com/retract/self/prev/@v/v1.9.0.mod + +-- go.mod -- +module example.com/use + +go 1.15 + +require example.com/retract v1.0.0-bad + +-- go.sum -- +example.com/retract v1.0.0-bad h1:liAW69rbtjY67x2CcNzat668L/w+YGgNX3lhJsWIJis= +example.com/retract v1.0.0-bad/go.mod h1:0DvGGofJ9hr1q63cBrOY/jSY52OwhRGA0K47NE80I5Y= +example.com/retract/self/prev v1.1.0 h1:0/8I/GTG+1eJTFeDQ/fUbgrMsVHHyKhh3Z8DSZp1fuA= +example.com/retract/self/prev v1.1.0/go.mod h1:xl2EcklWuZZHVtHWcpzfSJQmnzAGpKZYpA/Wto7SZN4= +-- use/use.go -- +package use + +import _ "example.com/retract" + +-- use_self_prev/use.go -- +package use_self_prev + +import _ "example.com/retract/self/prev" diff --git a/go/src/cmd/go/testdata/script/mod_retract_fix_version.txt b/go/src/cmd/go/testdata/script/mod_retract_fix_version.txt new file mode 100644 index 0000000000000000000000000000000000000000..9ae49f53ab3797cbcd86b0e5dd899bef5fbd5fb0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_retract_fix_version.txt @@ -0,0 +1,48 @@ +# retract must not be used without a module directive. +! go list -m all +stderr 'go.mod:3: no module directive found, so retract cannot be used$' + +# Commands that update go.mod should fix non-canonical versions in +# retract directives. +# Verifies #44494. +go mod edit -module=rsc.io/quote/v2 +! go list -m all +stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$' +go mod tidy +go list -m all +cmp go.mod go.mod.want + +# If a retracted version doesn't match the module's major version suffx, +# an error should be reported. +! go mod edit -retract=v3.0.1 +stderr '^go: -retract=v3.0.1: version "v3.0.1" invalid: should be v2, not v3$' +cp go.mod.mismatch-v2 go.mod +! go list -m all +stderr 'go.mod:3: retract rsc.io/quote/v2: version "v3.0.1" invalid: should be v2, not v3$' + +cp go.mod.mismatch-v1 go.mod +! go list -m all +stderr 'go.mod:3: retract rsc.io/quote: version "v3.0.1" invalid: should be v0 or v1, not v3$' + +-- go.mod -- +go 1.16 + +retract latest +-- go.mod.want -- +go 1.16 + +retract v2.0.1 + +module rsc.io/quote/v2 +-- go.mod.mismatch-v2 -- +go 1.16 + +retract v3.0.1 + +module rsc.io/quote/v2 +-- go.mod.mismatch-v1 -- +go 1.16 + +retract v3.0.1 + +module rsc.io/quote diff --git a/go/src/cmd/go/testdata/script/mod_retract_incompatible.txt b/go/src/cmd/go/testdata/script/mod_retract_incompatible.txt new file mode 100644 index 0000000000000000000000000000000000000000..5d09532529239b9201d14b38a6a22a1112eae8c8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_retract_incompatible.txt @@ -0,0 +1,15 @@ +# The current version of a module should not be considered when loading +# retractions. If the current version is +incompatible, we should not prefer +# +incompatible versions when looking for retractions. +# Verifies #42601. + +go mod init m + +# Request a +incompatible version retracted in v1.0.0. +go get example.com/retract/incompatible@v2.0.0+incompatible +stderr '^go: warning: example.com/retract/incompatible@v2.0.0\+incompatible: retracted by module author$' + +# We should still see a warning if the +incompatible was previously in the +# build list. +go get example.com/retract/incompatible@v2.0.0+incompatible +stderr '^go: warning: example.com/retract/incompatible@v2.0.0\+incompatible: retracted by module author$' diff --git a/go/src/cmd/go/testdata/script/mod_retract_noupgrade.txt b/go/src/cmd/go/testdata/script/mod_retract_noupgrade.txt new file mode 100644 index 0000000000000000000000000000000000000000..67de79f42d51a215faa51a74e279e5322e644b9a --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_retract_noupgrade.txt @@ -0,0 +1,11 @@ +go list -m -u example.com/retract/noupgrade +stdout '^example.com/retract/noupgrade v1.0.0 \(retracted\)$' + +-- go.mod -- +module use + +go 1.19 + +require example.com/retract/noupgrade v1.0.0 +-- go.sum -- +example.com/retract/noupgrade v1.0.0/go.mod h1:q2/HnBejUQ83RcUo4stf2U++/Zr9R/Ky3BsodjKBkQ4= diff --git a/go/src/cmd/go/testdata/script/mod_retract_pseudo_base.txt b/go/src/cmd/go/testdata/script/mod_retract_pseudo_base.txt new file mode 100644 index 0000000000000000000000000000000000000000..87b440dc7ea793d601cf76ea47eef967ec1633ba --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_retract_pseudo_base.txt @@ -0,0 +1,62 @@ +# When converting a commit to a pseudo-version, don't use a retracted version +# as the base. +# Verifies golang.org/issue/41700. + +[short] skip +[!git] skip +env GOPROXY=direct +env GOSUMDB=off +go mod init m + +# Control: check that v1.0.0 is the only version and is retracted. +go list -m -versions vcs-test.golang.org/git/retract-pseudo.git +stdout '^vcs-test.golang.org/git/retract-pseudo.git$' +go list -m -versions -retracted vcs-test.golang.org/git/retract-pseudo.git +stdout '^vcs-test.golang.org/git/retract-pseudo.git v1.0.0$' + +# 713affd19d7b is a commit after v1.0.0. Don't use v1.0.0 as the base. +go list -m vcs-test.golang.org/git/retract-pseudo.git@713affd19d7b +stdout '^vcs-test.golang.org/git/retract-pseudo.git v0.0.0-20201009173747-713affd19d7b$' + +# 64c061ed4371 is the commit v1.0.0 refers to. Don't convert to v1.0.0. +go list -m vcs-test.golang.org/git/retract-pseudo.git@64c061ed4371 +stdout '^vcs-test.golang.org/git/retract-pseudo.git v0.0.0-20201009173747-64c061ed4371' + +# A retracted version is a valid base. Retraction should not validate existing +# pseudo-versions, nor should it turn invalid pseudo-versions valid. +go get vcs-test.golang.org/git/retract-pseudo.git@v1.0.1-0.20201009173747-713affd19d7b +go list -m vcs-test.golang.org/git/retract-pseudo.git +stdout '^vcs-test.golang.org/git/retract-pseudo.git v1.0.1-0.20201009173747-713affd19d7b$' + +! go get vcs-test.golang.org/git/retract-pseudo.git@v1.0.1-0.20201009173747-64c061ed4371 +stderr '^go: vcs-test.golang.org/git/retract-pseudo.git@v1.0.1-0.20201009173747-64c061ed4371: invalid pseudo-version: tag \(v1.0.0\) found on revision 64c061ed4371 is already canonical, so should not be replaced with a pseudo-version derived from that tag$' + +-- retract-pseudo.sh -- +#!/bin/bash + +# This is not part of the test. +# Run this to generate and update the repository on vcs-test.golang.org. + +set -euo pipefail + +rm -rf retract-pseudo +mkdir retract-pseudo +cd retract-pseudo +git init + +# Create the module. +# Retract v1.0.0 and tag v1.0.0 at the same commit. +# The module has no unretracted release versions. +go mod init vcs-test.golang.org/git/retract-pseudo.git +go mod edit -retract v1.0.0 +echo 'package p' >p.go +git add -A +git commit -m 'create module retract-pseudo' +git tag v1.0.0 + +# Commit a trivial change so the default branch does not point to v1.0.0. +git mv p.go q.go +git commit -m 'trivial change' + +zip -r ../retract-pseudo.zip . +gsutil cp ../retract-pseudo.zip gs://vcs-test/git/retract-pseudo.zip diff --git a/go/src/cmd/go/testdata/script/mod_retract_rationale.txt b/go/src/cmd/go/testdata/script/mod_retract_rationale.txt new file mode 100644 index 0000000000000000000000000000000000000000..92e9b7d6ea573c28e3b55471f5f6fd97a2a3ea1b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_retract_rationale.txt @@ -0,0 +1,79 @@ +# When there is no rationale, 'go get' should print a hard-coded message. +go get example.com/retract/rationale@v1.0.0-empty +stderr '^go: warning: example.com/retract/rationale@v1.0.0-empty: retracted by module author$' + +# 'go list' should print the same hard-coded message. +go list -m -retracted -f '{{.Retracted}}' example.com/retract/rationale +stdout '^\[retracted by module author\]$' + + +# When there is a multi-line message, 'go get' should print the first line. +go get example.com/retract/rationale@v1.0.0-multiline1 +stderr '^go: warning: example.com/retract/rationale@v1.0.0-multiline1: retracted by module author: short description$' +! stderr 'detail' + +# 'go list' should show the full message. +go list -m -retracted -f '{{.Retracted}}' example.com/retract/rationale +cmp stdout multiline + +# 'go get' output should be the same whether the retraction appears at top-level +# or in a block. +go get example.com/retract/rationale@v1.0.0-multiline2 +stderr '^go: warning: example.com/retract/rationale@v1.0.0-multiline2: retracted by module author: short description$' +! stderr 'detail' + +# Same for 'go list'. +go list -m -retracted -f '{{.Retracted}}' example.com/retract/rationale +cmp stdout multiline + + +# 'go get' should omit long messages. +go get example.com/retract/rationale@v1.0.0-long +stderr '^go: warning: example.com/retract/rationale@v1.0.0-long: retracted by module author: \(message omitted: too long\)' + +# 'go list' should show the full message. +go list -m -retracted -f '{{.Retracted}}' example.com/retract/rationale +stdout '^\[lo{500}ng\]$' + + +# 'go get' should omit messages with unprintable characters. +go get example.com/retract/rationale@v1.0.0-unprintable +stderr '^go: warning: example.com/retract/rationale@v1.0.0-unprintable: retracted by module author: \(message omitted: contains non-printable characters\)' + +# 'go list' should show the full message. +go list -m -retracted -f '{{.Retracted}}' example.com/retract/rationale +stdout '^\[Ends with a BEL character. Beep!\x07\]$' + + +# When there is a comment on a block, but not on individual retractions within +# the block, the rationale should come from the block comment. +go list -m -retracted -f '{{.Retracted}}' example.com/retract/rationale@v1.0.0-block +stdout '^\[block comment\]$' +go list -m -retracted -f '{{.Retracted}}' example.com/retract/rationale@v1.0.0-blockwithcomment +stdout '^\[inner comment\]$' + + +# When a version is covered by multiple retractions, all retractions should +# be reported in the order they appear in the file. +go list -m -retracted -f '{{range .Retracted}}{{.}},{{end}}' example.com/retract/rationale@v1.0.0-order +stdout '^degenerate range,single version,$' +go list -m -retracted -f '{{range .Retracted}}{{.}},{{end}}' example.com/retract/rationale@v1.0.1-order +stdout '^single version,degenerate range,$' + +# 'go get' will only report the first retraction to avoid being too verbose. +go get example.com/retract/rationale@v1.0.0-order +stderr '^go: warning: example.com/retract/rationale@v1.0.0-order: retracted by module author: degenerate range$' +go get example.com/retract/rationale@v1.0.1-order +stderr '^go: warning: example.com/retract/rationale@v1.0.1-order: retracted by module author: single version$' + +-- go.mod -- +module m + +go 1.14 + +-- multiline -- +[short description +more + +detail +suffix] diff --git a/go/src/cmd/go/testdata/script/mod_retract_rename.txt b/go/src/cmd/go/testdata/script/mod_retract_rename.txt new file mode 100644 index 0000000000000000000000000000000000000000..38986f333f6474e4ac456162b693224c11f1255d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_retract_rename.txt @@ -0,0 +1,28 @@ +# Populate go.sum. +go get + +# 'go list -m -retracted' should load retractions, even if the version +# containing retractions has a different module path. +go list -m -retracted -f '{{with .Retracted}}retracted{{end}}' example.com/retract/rename + +# 'go list -m -u' should load retractions, too. +go list -m -u -f '{{with .Retracted}}retracted{{end}}' example.com/retract/rename + +# 'go get' should warn about the retracted version. +go get +stderr '^go: warning: example.com/retract/rename@v1.0.0-bad: retracted by module author: bad$' + +# We can't upgrade, since this latest version has a different module path. +! go get example.com/retract/rename +stderr 'module declares its path as: example.com/retract/newname' + +-- go.mod -- +module example.com/use + +go 1.16 + +require example.com/retract/rename v1.0.0-bad +-- use.go -- +package use + +import _ "example.com/retract/rename" diff --git a/go/src/cmd/go/testdata/script/mod_retract_replace.txt b/go/src/cmd/go/testdata/script/mod_retract_replace.txt new file mode 100644 index 0000000000000000000000000000000000000000..788968f420ec54a10cfc302bca1d9938cb7c4169 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_retract_replace.txt @@ -0,0 +1,63 @@ +# If the latest unretracted version of a module is replaced, 'go list' should +# obtain retractions from the replacement. + +# Populate go.sum. +go get + +# The latest version, v1.9.0, is not available on the proxy. +go list -m -retracted example.com/retract/missingmod +stdout '^example.com/retract/missingmod v1.0.0$' +exists $GOPATH/pkg/mod/cache/download/example.com/retract/missingmod/@v/v1.9.0.info +! exists $GOPATH/pkg/mod/cache/download/example.com/retract/missingmod/@v/v1.9.0.mod + +# If we replace that version, we should see retractions. +go mod edit -replace=example.com/retract/missingmod@v1.9.0=./missingmod-v1.9.0 +go list -m -retracted -f '{{range .Retracted}}{{.}}{{end}}' example.com/retract/missingmod +stdout '^bad version$' + +# If we replace the retracted version, we should not see a retraction. +go mod edit -replace=example.com/retract/missingmod=./missingmod-v1.9.0 +go list -m -retracted -f '{{if not .Retracted}}good version{{end}}' example.com/retract/missingmod +stdout '^good version$' + + +# If a replacement version is retracted, we should see a retraction. +# It should appear in both the replaced module and the replacement, as other +# fields like GoMod do. +go list -m -retracted -f '{{range .Retracted}}{{.}}{{end}}' example.com/retract +! stdout . +go list -m -retracted -f '{{if .Replace}}replaced{{end}}' example.com/retract +! stdout . +go mod edit -replace example.com/retract@v1.0.0-good=example.com/retract@v1.0.0-bad +go list -m -mod=mod -retracted -f '{{range .Retracted}}{{.}}{{end}}' example.com/retract +stdout '^bad$' +go list -m -mod=mod -retracted -f '{{with .Replace}}{{range .Retracted}}{{.}}{{end}}{{end}}' example.com/retract +stdout '^bad$' + +-- go.mod -- +module m + +go 1.14 + +require ( + example.com/retract v1.0.0-good + example.com/retract/missingmod v1.0.0 +) +-- use.go -- +package use + +import ( + _ "example.com/retract" + _ "example.com/retract/missingmod" +) +-- missingmod-v1.0.0/go.mod -- +module example.com/retract/missingmod + +go 1.14 +-- missingmod-v1.9.0/go.mod -- +module example.com/retract/missingmod + +go 1.14 + +// bad version +retract v1.0.0 diff --git a/go/src/cmd/go/testdata/script/mod_retract_versions.txt b/go/src/cmd/go/testdata/script/mod_retract_versions.txt new file mode 100644 index 0000000000000000000000000000000000000000..012fa15f420c8678e74448e6ffa1919c8dcce8d9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_retract_versions.txt @@ -0,0 +1,22 @@ +# https://golang.org/issue/44296: the --versions flag should not affect +# the version reported by 'go list' in case of retractions. + +env FMT='{{.Path}}{{with .Error}}: {{printf "%q" .Err}}{{end}} {{printf "%q" .Version}}{{with .Versions}} {{.}}{{end}}' + +go list -m -e -f $FMT example.com/retract/self/pseudo +stdout '^example.com/retract/self/pseudo: "module example.com/retract/self/pseudo: not a known dependency" ""$' + +go list -m -e -f $FMT example.com/retract/self/pseudo@latest +stdout '^example.com/retract/self/pseudo: "module example.com/retract/self/pseudo: no matching versions for query \\"latest\\"" "latest"$' + + +go list -m -e -f $FMT --versions example.com/retract/self/pseudo +stdout '^example.com/retract/self/pseudo ""$' + +go list -m -e -f $FMT --versions example.com/retract/self/pseudo@latest +stdout '^example.com/retract/self/pseudo: "module example.com/retract/self/pseudo: no matching versions for query \\"latest\\"" "latest"$' + +-- go.mod -- +module test + +go 1.17 diff --git a/go/src/cmd/go/testdata/script/mod_run_flags_issue64738.txt b/go/src/cmd/go/testdata/script/mod_run_flags_issue64738.txt new file mode 100644 index 0000000000000000000000000000000000000000..f143b026fe7f7cbe746621f05cefc7827ac1371f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_run_flags_issue64738.txt @@ -0,0 +1,4 @@ +# Regression test for https://go.dev/issue/64738: +# a bug in 'go run' caused flags arguments after the requested package to +# also be parsed as cmd/go flags. +go run -n example.com/printversion@v0.1.0 -p ignored diff --git a/go/src/cmd/go/testdata/script/mod_run_issue52331.txt b/go/src/cmd/go/testdata/script/mod_run_issue52331.txt new file mode 100644 index 0000000000000000000000000000000000000000..917e8902118a6714d179540b524e02cfb544fff4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_run_issue52331.txt @@ -0,0 +1,35 @@ +# Regression test for https://go.dev/issue/52331: 'go run -mod=mod' +# failed to write go.mod and go.sum with the resolved dependencies. + +[short] skip + +! go run main.go +# stderr '^main\.go:6:2: no required module provides package example\.com/version; to add it:\n\tgo get example\.com/version\n\z' + +go run -mod=mod main.go +cmp go.mod go.mod.want +grep -count=1 '^example\.com/version v1.1.0 h1:' go.sum +grep -count=1 '^example\.com/version v1.1.0/go.mod h1:' go.sum + +-- go.mod -- +module example + +go 1.17 +-- go.mod.want -- +module example + +go 1.17 + +require example.com/version v1.1.0 // indirect +-- main.go -- +package main + +import ( + "fmt" + + "example.com/version" +) + +func main() { + fmt.Println(version.V) +} diff --git a/go/src/cmd/go/testdata/script/mod_run_nonmain.txt b/go/src/cmd/go/testdata/script/mod_run_nonmain.txt new file mode 100644 index 0000000000000000000000000000000000000000..8435fc05b496365dcc1b6ebbd97bed7b11c57ac5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_run_nonmain.txt @@ -0,0 +1,18 @@ +! go run $PWD +! stderr 'no packages loaded' +stderr '^package example.net/nonmain is not a main package$' + +! go run . +stderr '^package example.net/nonmain is not a main package$' + +! go run ./... +stderr '^go: warning: "\./\.\.\." matched only non-main packages$' +stderr '^go: no packages loaded from \./\.\.\.$' + +-- go.mod -- +module example.net/nonmain + +go 1.17 +-- nonmain.go -- +// Package nonmain is not a main package. +package nonmain diff --git a/go/src/cmd/go/testdata/script/mod_run_path.txt b/go/src/cmd/go/testdata/script/mod_run_path.txt new file mode 100644 index 0000000000000000000000000000000000000000..4369ee413130dca001b25abe1f86774189688a03 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_run_path.txt @@ -0,0 +1,15 @@ +# Test that go run does not get confused by conflict +# between go.mod's module path and what you'd +# expect from GOPATH. golang.org/issue/26046. + +env GO111MODULE=on + +cd $GOPATH/src/example.com/hello +go run main.go + +-- $GOPATH/src/example.com/hello/go.mod -- +module example.com/hello/v2 + +-- $GOPATH/src/example.com/hello/main.go -- +package main +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_run_pkg_version.txt b/go/src/cmd/go/testdata/script/mod_run_pkg_version.txt new file mode 100644 index 0000000000000000000000000000000000000000..5846b9d3f7158177b407f8b29975f9d567749b06 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_run_pkg_version.txt @@ -0,0 +1,118 @@ +# This test checks the behavior of 'go run' with a 'cmd@version' argument. +# Most of 'go run' is covered in other tests. +# mod_install_pkg_version covers most of the package loading functionality. +# This test focuses on 'go run' behavior specific to this mode. +[short] skip + +# 'go run pkg@version' works outside a module. +env GO111MODULE=auto +go run example.com/cmd/a@v1.0.0 +stdout '^a@v1.0.0$' + + +# 'go run pkg@version' reports an error if modules are disabled. +env GO111MODULE=off +! go run example.com/cmd/a@v1.0.0 +stderr '^go: modules disabled by GO111MODULE=off; see ''go help modules''$' +env GO111MODULE=on + + +# 'go run pkg@version' ignores go.mod in the current directory. +cd m +cp go.mod go.mod.orig +! go list -m all +stderr '^go: example.com/cmd@v1.1.0-doesnotexist: reading http.*/mod/example\.com/cmd/@v/v1.1.0-doesnotexist.info: 404 Not Found\n\tserver response: 404 page not found$' +stderr '^go: example.com/cmd@v1.1.0-doesnotexist: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/cmd$' +go run example.com/cmd/a@v1.0.0 +stdout '^a@v1.0.0$' +cmp go.mod go.mod.orig +cd .. + + +# 'go install pkg@version' works on a module that doesn't have a go.mod file +# and with a module whose go.mod file has missing requirements. +# With a proxy, the two cases are indistinguishable. +go run rsc.io/fortune@v1.0.0 +stderr '^go: found rsc.io/quote in rsc.io/quote v1.5.2$' +stderr '^Hello, world.$' + + +# 'go run pkg@version' should report an error if pkg is not a main package. +! go run example.com/cmd/err@v1.0.0 +stderr '^package example.com/cmd/err is not a main package$' + + +# 'go run pkg@version' should report errors if the module contains +# replace or exclude directives. +go mod download example.com/cmd@v1.0.0-replace +! go run example.com/cmd/a@v1.0.0-replace +cmp stderr replace-err + +go mod download example.com/cmd@v1.0.0-exclude +! go run example.com/cmd/a@v1.0.0-exclude +cmp stderr exclude-err + + +# 'go run dir@version' works like a normal 'go run' command if +# dir is a relative or absolute path. +go mod download rsc.io/fortune@v1.0.0 +! go run $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0 +stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$' +! go run ../pkg/mod/rsc.io/fortune@v1.0.0 +stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$' +mkdir tmp +cd tmp +go mod init tmp +go mod edit -require=rsc.io/fortune@v1.0.0 +! go run -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0 +stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$' +! go run -mod=readonly ../../pkg/mod/rsc.io/fortune@v1.0.0 +stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$' +cd .. +rm tmp + + +# 'go run' does not interpret @version arguments after the first. +go run example.com/cmd/a@v1.0.0 example.com/doesnotexist@v1.0.0 +stdout '^a@v1.0.0$' + + +# 'go run pkg@version' succeeds when -mod=readonly is set explicitly. +# Verifies #43278. +go run -mod=readonly example.com/cmd/a@v1.0.0 +stdout '^a@v1.0.0$' + + +# 'go run pkg@version' should show a deprecation message if the module is deprecated. +go run example.com/deprecated/a/cmd/a@latest +stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$' +stdout '^a@v1.9.0$' +go run example.com/deprecated/a/cmd/a@v1.0.0 +stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$' +stdout '^a@v1.0.0$' + +# 'go run pkg@version' does not show a deprecation message if the module is no longer +# deprecated in its latest version, even if the module is deprecated in its current version. +go run example.com/undeprecated/cmd/a@v1.0.0 +! stderr 'module.*is deprecated' + +-- m/go.mod -- +module m + +go 1.16 + +require example.com/cmd v1.1.0-doesnotexist +-- x/x.go -- +package main + +func main() {} +-- replace-err -- +go: example.com/cmd/a@v1.0.0-replace (in example.com/cmd@v1.0.0-replace): + The go.mod file for the module providing named packages contains one or + more replace directives. It must not contain directives that would cause + it to be interpreted differently than if it were the main module. +-- exclude-err -- +go: example.com/cmd/a@v1.0.0-exclude (in example.com/cmd@v1.0.0-exclude): + The go.mod file for the module providing named packages contains one or + more exclude directives. It must not contain directives that would cause + it to be interpreted differently than if it were the main module. diff --git a/go/src/cmd/go/testdata/script/mod_run_pkgerror.txt b/go/src/cmd/go/testdata/script/mod_run_pkgerror.txt new file mode 100644 index 0000000000000000000000000000000000000000..48f900dd3466af59d632e5a713c129ca407051d4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_run_pkgerror.txt @@ -0,0 +1,32 @@ +# https://golang.org/issue/39986: files reported as invalid by go/build should +# be listed in InvalidGoFiles. + +go list -e -f '{{.Incomplete}}{{"\n"}}{{.Error}}{{"\n"}}{{.InvalidGoFiles}}{{"\n"}}' . +stdout '^true\nfound packages m \(m\.go\) and main \(main\.go\) in '$PWD'\n\[main.go\]\n' + + +# https://golang.org/issue/45827: 'go run .' should report the same package +# errors as 'go build' and 'go list'. + +! go build +stderr '^found packages m \(m\.go\) and main \(main\.go\) in '$PWD'$' + +! go list . +stderr '^found packages m \(m\.go\) and main \(main\.go\) in '$PWD'$' + +! go run . +! stderr 'no packages loaded' +stderr '^found packages m \(m\.go\) and main \(main\.go\) in '$PWD'$' + +! go run ./... +! stderr 'no packages loaded' +stderr '^found packages m \(m\.go\) and main \(main\.go\) in '$PWD'$' + +-- go.mod -- +module m + +go 1.17 +-- m.go -- +package m +-- main.go -- +package main diff --git a/go/src/cmd/go/testdata/script/mod_skip_write.txt b/go/src/cmd/go/testdata/script/mod_skip_write.txt new file mode 100644 index 0000000000000000000000000000000000000000..db47b9c424cfa652811d1ca4c71abaa35dd2f6f4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_skip_write.txt @@ -0,0 +1,93 @@ +# Commands used to debug the module graph should not write go.mod or go.sum +# or report errors when those files need to be updated. + +# Everything's okay initially. +go list -m all + +# Downgrading sampler makes go.mod inconsistent, but 'go mod graph', +# 'go mod verify', and 'go mod why' still work. +cp go.mod go.mod.orig +go mod edit -require=rsc.io/sampler@v1.2.0 +cp go.mod go.mod.edit +! go list -m all +stderr 'updates to go.mod needed' + +go mod graph +cmp stdout graph.want +cmp go.mod go.mod.edit + +go mod verify +stdout '^all modules verified$' +cmp go.mod go.mod.edit + +go mod why rsc.io/sampler +cmp stdout why.want +cmp go.mod go.mod.edit + +go mod why -m rsc.io/sampler +cmp stdout why.want +cmp go.mod go.mod.edit + +cp go.mod.orig go.mod + +# Removing go.sum breaks other commands, but 'go mod graph' and +# 'go mod why' still work. +rm go.sum +! go list -m all +stderr 'missing go.sum entry' + +go mod graph +cmp stdout graph.want +! exists go.sum + +go mod verify +stdout '^all modules verified$' +! exists go.sum + +go mod why rsc.io/sampler +cmp stdout why.want +! exists go.sum + +go mod why -m rsc.io/sampler +cmp stdout why.want +! exists go.sum + +-- go.mod -- +module m + +go 1.18 + +require rsc.io/quote v1.5.2 + +require ( + golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect + rsc.io/sampler v1.3.0 // indirect + rsc.io/testonly v1.0.0 // indirect +) +-- go.sum -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.2.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/testonly v1.0.0 h1:K/VWHdO+Jv7woUXG0GzVNx1czBXUt3Ib1deaMn+xk64= +rsc.io/testonly v1.0.0/go.mod h1:OqmGbIFOcF+XrFReLOGZ6BhMM7uMBiQwZsyNmh74SzY= +-- use.go -- +package use + +import _ "rsc.io/quote" +-- graph.want -- +m go@1.18 +m golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c +m rsc.io/quote@v1.5.2 +m rsc.io/sampler@v1.3.0 +m rsc.io/testonly@v1.0.0 +rsc.io/quote@v1.5.2 rsc.io/sampler@v1.3.0 +rsc.io/sampler@v1.3.0 golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c +-- why.want -- +# rsc.io/sampler +m +rsc.io/quote +rsc.io/sampler diff --git a/go/src/cmd/go/testdata/script/mod_stale.txt b/go/src/cmd/go/testdata/script/mod_stale.txt new file mode 100644 index 0000000000000000000000000000000000000000..c6ab27dd7c49e20b5aca01d76fadd24efebc0d7f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_stale.txt @@ -0,0 +1,15 @@ +[short] skip + +env GOCACHE=$WORK/cache +go list -f '{{.Stale}}' . +stdout true +go install . +go list -f '{{.Stale}}' . +stdout false + +-- go.mod -- +module example.com/mod + +go 1.20 +-- m.go -- +package m diff --git a/go/src/cmd/go/testdata/script/mod_std_vendor.txt b/go/src/cmd/go/testdata/script/mod_std_vendor.txt new file mode 100644 index 0000000000000000000000000000000000000000..ed47542a4e9df51df00feeb08d3d87615817a701 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_std_vendor.txt @@ -0,0 +1,77 @@ +env GO111MODULE=on +env GOPROXY=off + +[!compiler:gc] skip + +# 'go list' should report imports from _test.go in the TestImports field. +go list -f '{{.TestImports}}' +stdout net/http # from .TestImports + +# 'go list' should find standard-vendored packages. +go list -f '{{.Dir}}' vendor/golang.org/x/net/http2/hpack +stdout $GOROOT[/\\]src[/\\]vendor + +# 'go list -test' should report vendored transitive dependencies of _test.go +# imports in the Deps field. +go list -test -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}' +stdout ^vendor/golang.org/x/crypto # dep of .TestImports + + +# Modules outside the standard library should not use the packages vendored there... +cd broken +! go build -mod=readonly +stderr 'disabled by -mod=readonly' +! go build -mod=vendor +stderr 'http.go:5:2: cannot find module providing package golang.org/x/net/http2/hpack: import lookup disabled by -mod=vendor' + +# ...even if they explicitly use the "cmd/vendor/" or "vendor/" prefix. +cd ../importcmd +! go build . +stderr 'use of vendored package' + +cd ../importstd +! go build . +stderr 'use of vendored package' + + +# When run within the 'std' module, 'go list -test' should report vendored +# transitive dependencies at their vendored paths. +cd $GOROOT/src +go list -test -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}' net/http +! stdout ^golang.org/x/net/http2/hpack +stdout ^vendor/golang.org/x/net/http2/hpack + +-- go.mod -- +module m + +-- x.go -- +package x + +-- x_test.go -- +package x +import "testing" +import _ "net/http" +func Test(t *testing.T) {} + +-- broken/go.mod -- +module broken +-- broken/http.go -- +package broken + +import ( + _ "net/http" + _ "golang.org/x/net/http2/hpack" +) + +-- importcmd/go.mod -- +module importcmd +-- importcmd/x.go -- +package importcmd + +import _ "cmd/vendor/golang.org/x/tools/go/analysis" +-- importstd/go.mod -- +module importvendor +-- importstd/x.go -- +package importstd + +import _ "vendor/golang.org/x/net/http2/hpack" diff --git a/go/src/cmd/go/testdata/script/mod_string_alias.txt b/go/src/cmd/go/testdata/script/mod_string_alias.txt new file mode 100644 index 0000000000000000000000000000000000000000..5c3d4287cc876667ad80fa259ea852396ee4a42b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_string_alias.txt @@ -0,0 +1,14 @@ +[short] skip + +env GO111MODULE=on + +go mod init golang.org/issue/27584 + +go build . + +-- main.go -- +package main + +type string = []int + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_sum_absent.txt b/go/src/cmd/go/testdata/script/mod_sum_absent.txt new file mode 100644 index 0000000000000000000000000000000000000000..c2dd814542d671ffeff9326ad5841a73eea5ff79 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_sum_absent.txt @@ -0,0 +1,17 @@ +# When the sumdb returns a response which does not +# include a sum for the requested module, +# we should report an error. +# Verifies CVE-2026-42501. +env sumdb=$GOSUMDB +env proxy=$GOPROXY +env GOPROXY GONOPROXY GOSUMDB GONOSUMDB + +# /sumdb-redirect/ causes the sumdb to return /lookup/ responses +# for rsc.io/quote@v1.0.0, not for the requested module. +env GOSUMDB=$sumdb' '$proxy/sumdb-redirect/rsc.io/quote@v1.0.0: + +! go get rsc.io/fortune@v1.0.0 +stderr 'SECURITY ERROR' +! grep rsc.io go.sum +-- go.mod -- +module m diff --git a/go/src/cmd/go/testdata/script/mod_sum_ambiguous.txt b/go/src/cmd/go/testdata/script/mod_sum_ambiguous.txt new file mode 100644 index 0000000000000000000000000000000000000000..07c66591770342f262b64c83980184dc3fd0ee62 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_sum_ambiguous.txt @@ -0,0 +1,62 @@ +# Confirm our build list. +cp go.sum.buildlist-only go.sum +go list -m all +stdout '^example.com/ambiguous/a v1.0.0$' +stdout '^example.com/ambiguous/a/b v0.0.0-empty$' + +# If two modules could provide a package, but only one does, +# 'go mod tidy' should retain sums for both zips. +go mod tidy +grep '^example.com/ambiguous/a v1.0.0 h1:' go.sum +grep '^example.com/ambiguous/a/b v0.0.0-empty h1:' go.sum + +# 'go mod download' should also add sums. +cp go.sum.buildlist-only go.sum +go mod download example.com/ambiguous/a +grep '^example.com/ambiguous/a v1.0.0 h1:' go.sum +! grep '^example.com/ambiguous/a/b v0.0.0-empty h1:' go.sum +go mod download example.com/ambiguous/a/b +grep '^example.com/ambiguous/a/b v0.0.0-empty h1:' go.sum + +# If two modules could provide a package, and we're missing a sum for one, +# we should see a missing sum error, even if we have a sum for a module that +# provides the package. +cp go.sum.a-only go.sum +! go list example.com/ambiguous/a/b +stderr '^missing go.sum entry needed to verify package example.com/ambiguous/a/b is provided by exactly one module; to add:\n\tgo mod download example.com/ambiguous/a/b$' +! go list -deps . +stderr '^use.go:3:8: missing go.sum entry needed to verify package example.com/ambiguous/a/b \(imported by m\) is provided by exactly one module; to add:\n\tgo get m$' + +cp go.sum.b-only go.sum +! go list example.com/ambiguous/a/b +stderr '^missing go.sum entry for module providing package example.com/ambiguous/a/b; to add:\n\tgo mod download example.com/ambiguous/a$' +! go list -deps . +stderr '^use.go:3:8: missing go.sum entry for module providing package example.com/ambiguous/a/b \(imported by m\); to add:\n\tgo get m$' + +cp go.sum.buildlist-only go.sum +! go list example.com/ambiguous/a/b +stderr '^missing go.sum entry for module providing package example.com/ambiguous/a/b; to add:\n\tgo mod download example.com/ambiguous/a example.com/ambiguous/a/b$' +! go list -deps . +stderr '^use.go:3:8: missing go.sum entry for module providing package example.com/ambiguous/a/b \(imported by m\); to add:\n\tgo get m$' + +-- go.mod -- +module m + +go 1.15 + +require example.com/ambiguous/a v1.0.0 +-- go.sum.buildlist-only -- +example.com/ambiguous/a v1.0.0/go.mod h1:TrBl/3xTPFJ2gmMIYz53h2gkNtg0dokszEMuyS1QEb0= +example.com/ambiguous/a/b v0.0.0-empty/go.mod h1:MajJq5jPEBnnXP+NTWIeXX7kwaPS1sbVEJdooTmsePQ= +-- go.sum.a-only -- +example.com/ambiguous/a v1.0.0 h1:pGZhTXy6+titE2rNfwHwJykSjXDR4plO52PfZrBM0T8= +example.com/ambiguous/a v1.0.0/go.mod h1:TrBl/3xTPFJ2gmMIYz53h2gkNtg0dokszEMuyS1QEb0= +example.com/ambiguous/a/b v0.0.0-empty/go.mod h1:MajJq5jPEBnnXP+NTWIeXX7kwaPS1sbVEJdooTmsePQ= +-- go.sum.b-only -- +example.com/ambiguous/a v1.0.0/go.mod h1:TrBl/3xTPFJ2gmMIYz53h2gkNtg0dokszEMuyS1QEb0= +example.com/ambiguous/a/b v0.0.0-empty h1:xS29ReXXuhjT7jc79mo91h/PevaZ2oS9PciF1DucXtg= +example.com/ambiguous/a/b v0.0.0-empty/go.mod h1:MajJq5jPEBnnXP+NTWIeXX7kwaPS1sbVEJdooTmsePQ= +-- use.go -- +package use + +import _ "example.com/ambiguous/a/b" diff --git a/go/src/cmd/go/testdata/script/mod_sum_issue56222.txt b/go/src/cmd/go/testdata/script/mod_sum_issue56222.txt new file mode 100644 index 0000000000000000000000000000000000000000..12848c91100fd56faa01986cc6e5a6387e1d02bb --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_sum_issue56222.txt @@ -0,0 +1,91 @@ +# Regression test for #56222: 'go get -t' and 'go mod tidy' +# should save enough checksums to run 'go test' on the named +# packages or any package in "all" respectively. + +# 'go mod tidy' in a module at go 1.21 or higher should preserve +# checksums needed to run 'go test all'. +cd m1 +go mod tidy + +go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q +stdout 1.18 +[!short] go test -o $devnull -c all + +cat go.sum +replace 'example.com/generics v1.0.0/go.mod' 'example.com/notgenerics v1.0.0/go.mod' go.sum + +! go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q +stderr '^go: can''t load test package: \.\.'${/}m2${/}q${/}'q_test.go:3:8: example\.com/generics@v1\.0\.0: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example\.com/generics$' + +go mod download -json example.com/generics +stdout '"GoModSum":' +go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q +stdout 1.18 + + +# At go 1.20 or earlier, 'go mod tidy' should preserve the historical go.sum +# contents, but 'go test' should flag the missing checksums (instead of trying +# to build the test dependency with the wrong language version). + +go mod tidy -go=1.20 +! go test -o $devnull -c all +stderr '^# example.com/m2/q\n'..${/}m2${/}q${/}'q_test.go:3:8: example.com/generics@v1.0.0: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/generics$' + +go mod download -json example.com/generics +go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q +stdout 1.18 + + +# Even at go 1.20 or earlier, 'go mod tidy' shouldn't need go.mod files or +# checksums that it won't record. + +go mod tidy -go=1.20 +go clean -modcache # Remove checksums from the module cache, so that only go.sum is used. + +# Issue 60667: 'go list' without -mod=mod shouldn't report the checksums as +# dirty either. +go list -m -u all + +env OLDSUMDB=$GOSUMDB +env GOSUMDB=bad +go mod tidy + +env GOSUMDB=$OLDSUMDB + + +# Regardless of the go version in go.mod, 'go get -t' should fetch +# enough checksums to run 'go test' on the named package. + +rm p +go mod tidy -go=1.20 +go list -m all +! stdout example.com/generics +go get -t example.com/m2/q@v1.0.0 +go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q +stdout 1.18 +[!short] go test -o $devnull -c example.com/m2/q + + +-- m1/go.mod -- +module example.com/m1 + +go 1.21 + +require example.com/m2 v1.0.0 +replace example.com/m2 => ../m2 +-- m1/p/p.go -- +package p + +import _ "example.com/m2/q" +-- m2/go.mod -- +module example.com/m2 + +go 1.19 + +require example.com/generics v1.0.0 +-- m2/q/q.go -- +package q +-- m2/q/q_test.go -- +package q + +import _ "example.com/generics" diff --git a/go/src/cmd/go/testdata/script/mod_sum_lookup.txt b/go/src/cmd/go/testdata/script/mod_sum_lookup.txt new file mode 100644 index 0000000000000000000000000000000000000000..7513f7f49f352ee9e7af699d358db364999404da --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_sum_lookup.txt @@ -0,0 +1,34 @@ +# When we attempt to resolve an import that doesn't exist, we should not save +# hashes for downloaded modules. +# Verifies golang.org/issue/36260. +# TODO(golang.org/issue/26603): use 'go mod tidy -e' when implemented. +go list -e -mod=mod -tags=ignore ./noexist +! exists go.sum + +# When an import is resolved successfully, we should only save hashes for +# the module that provides the package, not for other modules looked up. +# Verifies golang.org/issue/31580. +go get ./exist +grep '^example.com/join v1.1.0 h1:' go.sum +! grep '^example.com/join/subpkg' go.sum +cp go.sum go.list.sum +go mod tidy +cmp go.sum go.list.sum + +-- go.mod -- +module m + +go 1.15 + +-- noexist/use.go -- +// ignore tags prevents errors in 'go mod tidy' +// +build ignore + +package use + +import _ "example.com/join/subpkg/noexist" + +-- exist/use.go -- +package use + +import _ "example.com/join/subpkg" diff --git a/go/src/cmd/go/testdata/script/mod_sum_readonly.txt b/go/src/cmd/go/testdata/script/mod_sum_readonly.txt new file mode 100644 index 0000000000000000000000000000000000000000..c4260739e278de0017bacaece25650eeabed397b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_sum_readonly.txt @@ -0,0 +1,87 @@ +# Test that go.sum does not get updated when -mod=readonly flag is set +env GO111MODULE=on + +# When a sum is needed to load the build list, we get an error for the +# specific module. The .mod file is not downloaded, and go.sum is not written. +! go list -m all +stderr '^go: rsc.io/quote@v1.5.2: missing go.sum entry for go.mod file; to add it:\n\tgo mod download rsc.io/quote$' +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod +! exists go.sum + +# If go.sum exists but contains hashes from an algorithm we don't know about, +# we should see the same error. +cp go.sum.h2only go.sum +! go list -m all +stderr '^go: rsc.io/quote@v1.5.2: missing go.sum entry for go.mod file; to add it:\n\tgo mod download rsc.io/quote$' +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod +cmp go.sum go.sum.h2only +rm go.sum + +# If we replace a module, we should see a missing sum error for the replacement. +cp go.mod go.mod.orig +go mod edit -replace rsc.io/quote@v1.5.2=rsc.io/quote@v1.5.1 +! go list -m all +stderr '^go: rsc.io/quote@v1.5.2 \(replaced by rsc.io/quote@v1.5.1\): missing go.sum entry for go.mod file; to add it:\n\tgo mod download rsc.io/quote$' +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.1.mod +! exists go.sum +cp go.mod.orig go.mod + +# Control: when sums are present, loading the build list downloads .mod files. +cp go.sum.buildlistonly go.sum +go list -m all +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod + + +# When a sum is needed to load a .mod file for a package outside the build list, +# we get a generic missing import error. +! go list example.com/doesnotexist +stderr '^no required module provides package example.com/doesnotexist; to add it:\n\tgo get example.com/doesnotexist$' + +# When a sum is needed to load a .zip file, we get a more specific error. +# The .zip file is not downloaded. +! go list rsc.io/quote +stderr '^missing go.sum entry for module providing package rsc.io/quote; to add:\n\tgo mod download rsc.io/quote$' +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip + +# The error is attached to the package from the missing module. We can load +# a package that imports it without that error. +go list -e -deps -f '{{.ImportPath}}{{with .Error}} {{.Err}}{{end}}' . +stdout '^m$' +stdout '^rsc.io/quote missing go.sum entry for module providing package rsc.io/quote \(imported by m\); to add:\n\tgo get m$' +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip + +# go.sum should not have been written. +cmp go.sum go.sum.buildlistonly + +# Control: when sums are present, 'go list' downloads .zip files. +cp go.sum.tidy go.sum +go list . +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip + +-- go.mod -- +module m + +go 1.15 + +require rsc.io/quote v1.5.2 +-- use.go -- +package use + +import _ "rsc.io/quote" +-- go.sum.h2only -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h2:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2/go.mod h2:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0/go.mod h2:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +-- go.sum.buildlistonly -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +-- go.sum.tidy -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/testonly v1.0.0 h1:K/VWHdO+Jv7woUXG0GzVNx1czBXUt3Ib1deaMn+xk64= +rsc.io/testonly v1.0.0/go.mod h1:OqmGbIFOcF+XrFReLOGZ6BhMM7uMBiQwZsyNmh74SzY= diff --git a/go/src/cmd/go/testdata/script/mod_sum_replaced.txt b/go/src/cmd/go/testdata/script/mod_sum_replaced.txt new file mode 100644 index 0000000000000000000000000000000000000000..6c322a00d607a95a0ea04c8972cd5beb4a3f590c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_sum_replaced.txt @@ -0,0 +1,28 @@ +env GO111MODULE=on + +# After 'go get', the go.sum file should contain the sum for the module. +go get rsc.io/quote@v1.5.0 +grep 'rsc.io/quote v1.5.0' go.sum + +# If we replace the module and run 'go mod tidy', we should get a sum for the replacement. +go mod edit -replace rsc.io/quote@v1.5.0=rsc.io/quote@v1.5.1 +go mod tidy +grep 'rsc.io/quote v1.5.1' go.sum +cp go.sum go.sum.tidy + +# 'go mod vendor' should preserve that sum, and should not need to add any new entries. +go mod vendor +grep 'rsc.io/quote v1.5.1' go.sum +cmp go.sum go.sum.tidy + +-- go.mod -- +module golang.org/issue/27868 + +require rsc.io/quote v1.5.0 + +-- main.go -- +package main + +import _ "rsc.io/quote" + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_sumdb.txt b/go/src/cmd/go/testdata/script/mod_sumdb.txt new file mode 100644 index 0000000000000000000000000000000000000000..d06db4ae69271a53849b8a0cbfbe1a205a7f02f1 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_sumdb.txt @@ -0,0 +1,45 @@ +env GO111MODULE=on +env sumdb=$GOSUMDB +env proxy=$GOPROXY +env GOPROXY GONOPROXY GOSUMDB GONOSUMDB +env dbname=localhost.localdev/sumdb + +# disagreeing with the sumdb produces security errors +# (this also populates tiles on the sumdb server). +cp go.mod.orig go.mod +env GOSUMDB=$sumdb' '$proxy/sumdb-wrong +! go get rsc.io/quote +stderr 'go: rsc.io/quote@v1.5.2: verifying module: checksum mismatch' +stderr 'downloaded: h1:3fEy' +stderr 'localhost.localdev/sumdb: h1:wrong' +stderr 'SECURITY ERROR\nThis download does NOT match the one reported by the checksum server.' +! go get rsc.io/sampler +! go get golang.org/x/text + +go mod edit -require rsc.io/quote@v1.5.2 +! go mod tidy +stderr 'go: rsc.io/quote@v1.5.2: verifying go.mod: checksum mismatch' +stderr 'SECURITY ERROR\n' + +rm go.sum + +# switching to truthful sumdb detects timeline inconsistency +cp go.mod.orig go.mod +env GOSUMDB=$sumdb +! go get rsc.io/fortune +stderr 'SECURITY ERROR\ngo.sum database server misbehavior detected!' +stderr 'proof of misbehavior:' + +# removing the cached wrong tree head and cached tiles clears the bad data +rm $GOPATH/pkg/sumdb/$dbname/latest +go clean -modcache +go get rsc.io/fortune + +-- go.mod.orig -- +module m + +go 1.16 +-- m.go -- +package m + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_sumdb_cache.txt b/go/src/cmd/go/testdata/script/mod_sumdb_cache.txt new file mode 100644 index 0000000000000000000000000000000000000000..063fd20964fde230070699433e4d8ae577f7d65f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_sumdb_cache.txt @@ -0,0 +1,47 @@ +env GO111MODULE=on +env sumdb=$GOSUMDB +env proxy=$GOPROXY +env GOPROXY GONOPROXY GOSUMDB GONOSUMDB + +# rejected proxy fails verification +cp go.mod.orig go.mod +rm go.sum +env GOPROXY=$proxy/sumdb-503 +! go get rsc.io/quote +stderr 503 + +# fetch through working proxy is OK +cp go.mod.orig go.mod +rm go.sum +env GOPROXY=$proxy +go get rsc.io/quote + +# repeated fetch works entirely from cache, does not consult sumdb +cp go.mod.orig go.mod +rm go.sum +env GOPROXY=$proxy/sumdb-503 +go get rsc.io/quote +rm go.sum + +# fetch specific module can work without proxy, using cache or go.sum +cp go.mod.orig go.mod +rm go.sum +env GOPROXY=off +go get rsc.io/quote@v1.5.2 # using cache +rm $GOPATH/pkg/mod/cache/download/sumdb/localhost.localdev/sumdb/lookup/rsc.io/quote@v1.5.2 +go get rsc.io/quote@v1.5.2 # using go.sum + +# fetch fails once we lose access to both cache and go.sum +rm go.sum +env GOPROXY=$proxy/sumdb-504 +! go get rsc.io/quote@v1.5.2 +stderr 504 + +# GOINSECURE does not bypass checksum lookup +env GOINSECURE=rsc.io +env GOPROXY=$proxy/sumdb-504 +! go get rsc.io/quote@v1.5.2 +stderr 504 + +-- go.mod.orig -- +module m diff --git a/go/src/cmd/go/testdata/script/mod_sumdb_file_path.txt b/go/src/cmd/go/testdata/script/mod_sumdb_file_path.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f42cb54f5a3d1eb4814eb033390e758d1e40a31 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_sumdb_file_path.txt @@ -0,0 +1,58 @@ +[!net:proxy.golang.org] skip +[!net:sum.golang.org] skip + +env GO111MODULE=on +[go-builder] env GOSUMDB= +[!go-builder] env GOSUMDB=sum.golang.org # Set explicitly in case GOROOT/go.env is modified. +env GOPATH=$WORK/gopath1 + +# With a file-based proxy with an empty checksum directory, +# downloading a new module should fail, even if a subsequent +# proxy contains a more complete mirror of the sum database. +# +# TODO(bcmills): The error message here is a bit redundant. +# It comes from the sumweb package, which isn't yet producing structured errors. +[GOOS:windows] env GOPROXY=file:///$WORK/sumproxy,https://proxy.golang.org +[!GOOS:windows] env GOPROXY=file://$WORK/sumproxy,https://proxy.golang.org +! go get golang.org/x/text@v0.3.2 +stderr '^go: golang.org/x/text@v0.3.2: verifying module: golang.org/x/text@v0.3.2: reading file://.*/sumdb/sum.golang.org/lookup/golang.org/x/text@v0.3.2: (no such file or directory|.*cannot find the path specified.*)' + +# If the proxy does not claim to support the database, +# checksum verification should fall through to the next proxy, +# and downloading should succeed. +[GOOS:windows] env GOPROXY=file:///$WORK/emptyproxy,https://proxy.golang.org +[!GOOS:windows] env GOPROXY=file://$WORK/emptyproxy,https://proxy.golang.org +go get golang.org/x/text@v0.3.2 + +# After a successful sumdb lookup, the lookup can be repeated +# using the download cache as a proxy. +cp supported $GOPATH/pkg/mod/cache/download/sumdb/sum.golang.org/supported +[GOOS:windows] env GOPROXY=file:///$WORK/gopath1/pkg/mod/cache/download,file:///$WORK/sumproxy +[!GOOS:windows] env GOPROXY=file://$WORK/gopath1/pkg/mod/cache/download,file://$WORK/sumproxy +env GOPATH=$WORK/gopath2 +rm go.sum +go get -x -v golang.org/x/text@v0.3.2 + +# Once the checksum is present in the go.sum file, +# an empty file-based sumdb can be used in conjunction with +# a fallback module mirror. +grep golang.org/x/text go.sum +env GOPATH=$WORK/gopath3 +[GOOS:windows] env GOPROXY=file:///$WORK/sumproxy +[!GOOS:windows] env GOPROXY=file://$WORK/sumproxy +! go get golang.org/x/text@v0.3.2 +[GOOS:windows] env GOPROXY=file:///$WORK/sumproxy,https://proxy.golang.org +[!GOOS:windows] env GOPROXY=file://$WORK/sumproxy,https://proxy.golang.org +go get golang.org/x/text@v0.3.2 + +-- supported -- + +-- go.mod -- +module example.com +go 1.13 +-- $WORK/emptyproxy/README.md -- +This proxy contains no modules. +-- $WORK/sumproxy/README.md -- +This proxy contains no modules. +-- $WORK/sumproxy/sumdb/sum.golang.org/supported -- +This proxy blocks checksum downloads from sum.golang.org. diff --git a/go/src/cmd/go/testdata/script/mod_sumdb_golang.txt b/go/src/cmd/go/testdata/script/mod_sumdb_golang.txt new file mode 100644 index 0000000000000000000000000000000000000000..067e2e3b318350a24d7b14aac0b5107b8267b7be --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_sumdb_golang.txt @@ -0,0 +1,83 @@ +# Test default GOPROXY and GOSUMDB +[go-builder] env GOPROXY= +[go-builder] env GOSUMDB= +[go-builder] go env GOPROXY +[go-builder] stdout '^https://proxy.golang.org,direct$' +[go-builder] go env GOSUMDB +[go-builder] stdout '^sum.golang.org$' +[go-builder] env GOPROXY=https://proxy.golang.org +[go-builder] go env GOSUMDB +[go-builder] stdout '^sum.golang.org$' + +# Download direct from github. + +[!net:proxy.golang.org] skip +[!net:sum.golang.org] skip +[!git] skip +env GOSUMDB=sum.golang.org +env GOPROXY=direct + +go get rsc.io/quote@v1.5.2 +cp go.sum saved.sum + + +# Download from proxy.golang.org with go.sum entry already. +# Use 'go list' instead of 'go get' since the latter may download extra go.mod +# files not listed in go.sum. + +go clean -modcache +env GOSUMDB=sum.golang.org +env GOPROXY=https://proxy.golang.org,direct + +go list -x -m all # Download go.mod files. +! stderr github +stderr proxy.golang.org/rsc.io/quote +! stderr sum.golang.org/tile +! stderr sum.golang.org/lookup/rsc.io/quote + +go list -x -deps rsc.io/quote # Download module source. +! stderr github +stderr proxy.golang.org/rsc.io/quote +! stderr sum.golang.org/tile +! stderr sum.golang.org/lookup/rsc.io/quote + +cmp go.sum saved.sum + + +# Download again. +# Should use the checksum database to validate new go.sum lines, +# but not need to fetch any new data from the proxy. + +rm go.sum + +go list -mod=mod -x -m all # Add checksums for go.mod files. +stderr sum.golang.org/tile +! stderr github +! stderr proxy.golang.org/rsc.io/quote +stderr sum.golang.org/lookup/rsc.io/quote + +go list -mod=mod -x rsc.io/quote # Add checksums for module source. +! stderr . # Adds checksums, but for entities already in the module cache. + +cmp go.sum saved.sum + + +# test fallback to direct + +env TESTGOPROXY404=1 +go clean -modcache +rm go.sum + +go list -mod=mod -x -m all # Download go.mod files +stderr 'proxy.golang.org.*404 testing' +stderr github.com/rsc + +go list -mod=mod -x rsc.io/quote # Download module source. +stderr 'proxy.golang.org.*404 testing' +stderr github.com/rsc + +cmp go.sum saved.sum + + +-- go.mod -- +module m diff --git a/go/src/cmd/go/testdata/script/mod_sumdb_proxy.txt b/go/src/cmd/go/testdata/script/mod_sumdb_proxy.txt new file mode 100644 index 0000000000000000000000000000000000000000..194c0c92e5705179f7658fd4e1f6f79f9de40c62 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_sumdb_proxy.txt @@ -0,0 +1,65 @@ +env GO111MODULE=on +env sumdb=$GOSUMDB +env proxy=$GOPROXY +env GOPROXY GONOPROXY GOSUMDB GONOSUMDB + +# basic fetch (through proxy) works +cp go.mod.orig go.mod +go get rsc.io/fortune@v1.0.0 # note: must use test proxy, does not exist in real world +rm $GOPATH/pkg/mod/cache/download/sumdb # rm sumdb cache but NOT package download cache +rm go.sum + +# can fetch by explicit URL +cp go.mod.orig go.mod +env GOSUMDB=$sumdb' '$proxy/sumdb-direct +go get rsc.io/fortune@v1.0.0 +rm $GOPATH/pkg/mod/cache/download/sumdb +rm go.sum + +# direct access fails (because localhost.localdev does not exist) +# web.get is providing the error message - there's no actual network access. +cp go.mod.orig go.mod +env GOSUMDB=$sumdb +env GOPROXY=direct +! go get rsc.io/fortune@v1.0.0 +stderr 'verifying module: rsc.io/fortune@v1.0.0: .*: no such host localhost.localdev' +rm $GOPATH/pkg/mod/cache/download/sumdb +rm go.sum + +# proxy 404 falls back to direct access (which fails) +cp go.mod.orig go.mod +env GOSUMDB=$sumdb +env GOPROXY=$proxy/sumdb-404 +! go get rsc.io/fortune@v1.0.0 +stderr 'verifying.*localhost.localdev' +rm $GOPATH/pkg/mod/cache/download/sumdb +rm go.sum + +# proxy non-200/404/410 stops direct access +cp go.mod.orig go.mod +env GOSUMDB=$sumdb +env GOPROXY=$proxy/sumdb-503 +! go get rsc.io/fortune@v1.0.0 +stderr '503 Service Unavailable' +rm $GOPATH/pkg/mod/cache/download/sumdb +rm go.sum + +# the error from the last attempted proxy should be returned. +cp go.mod.orig go.mod +env GOSUMDB=$sumdb +env GOPROXY=$proxy/sumdb-404,$proxy/sumdb-503 +! go get rsc.io/fortune@v1.0.0 +stderr '503 Service Unavailable' +rm $GOPATH/pkg/mod/cache/download/sumdb +rm go.sum + +# if proxies are separated with '|', fallback is allowed on any error. +cp go.mod.orig go.mod +env GOSUMDB=$sumdb +env GOPROXY=$proxy/sumdb-503|https://0.0.0.0|$proxy +go get rsc.io/fortune@v1.0.0 +rm $GOPATH/pkg/mod/cache/download/sumdb +rm go.sum + +-- go.mod.orig -- +module m diff --git a/go/src/cmd/go/testdata/script/mod_symlink.txt b/go/src/cmd/go/testdata/script/mod_symlink.txt new file mode 100644 index 0000000000000000000000000000000000000000..0604e1a4c4f1c28493c378d707783506282496f9 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_symlink.txt @@ -0,0 +1,45 @@ +env GO111MODULE=on +[!symlink] skip + +# 'go get' should resolve modules of imported packages. +go get +go list -deps -f '{{.Module}}' . +stdout golang.org/x/text + +go get ./subpkg +go list -deps -f '{{.Module}}' ./subpkg +stdout golang.org/x/text + +# Create a copy of the module using symlinks in src/links. +mkdir links +symlink links/go.mod -> $GOPATH/src/go.mod +symlink links/go.sum -> $GOPATH/src/go.sum +symlink links/issue.go -> $GOPATH/src/issue.go +mkdir links/subpkg +symlink links/subpkg/issue.go -> $GOPATH/src/subpkg/issue.go + +# We should see the copy as a valid module root. +cd links +go env GOMOD +stdout links[/\\]go.mod +go list -m +stdout golang.org/issue/28107 + +# The symlink-based copy should contain the same packages +# and have the same dependencies as the original. +go list -deps -f '{{.Module}}' . +stdout golang.org/x/text +go list -deps -f '{{.Module}}' ./subpkg +stdout golang.org/x/text + +-- go.mod -- +module golang.org/issue/28107 + +-- issue.go -- +package issue + +import _ "golang.org/x/text/language" +-- subpkg/issue.go -- +package issue + +import _ "golang.org/x/text/language" diff --git a/go/src/cmd/go/testdata/script/mod_symlink_dotgo.txt b/go/src/cmd/go/testdata/script/mod_symlink_dotgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..d4cc143a361ce28286e521505e4380037db9f183 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_symlink_dotgo.txt @@ -0,0 +1,17 @@ +env GO111MODULE=on +[!symlink] skip + +symlink dir.go -> dir + +# Issue #39841: symlinks to directories should be ignored, not treated as source files. +go list -f '{{range .GoFiles}}{{.}}{{"\n"}}{{end}}' . +stdout 'p\.go$' +! stdout 'dir\.go$' + +-- go.mod -- +module example.com +go 1.15 +-- p.go -- +package p +-- dir/README.txt -- +This file exists to ensure that dir is a directory. diff --git a/go/src/cmd/go/testdata/script/mod_tagged_import_cycle.txt b/go/src/cmd/go/testdata/script/mod_tagged_import_cycle.txt new file mode 100644 index 0000000000000000000000000000000000000000..0491acb8723a55093a3c84b8f23c16e806d4445a --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tagged_import_cycle.txt @@ -0,0 +1,106 @@ +# Because 'go mod' subcommands ignore build constraints, they can encounter +# package-import cycles that are not possible in an ordinary build. This test +# verifies that such cycles are handled even when they cross module boundaries. + +# First, verify that the import graph depends on build tags as expected. +go list -deps example.com/left +stdout '^example.com/right$' +go list -deps example.com/right +! stdout left + +env GOFLAGS=-tags=mirror +go list -deps example.com/left +! stdout right +go list -deps example.com/right +stdout '^example.com/left$' +env GOFLAGS='' + +# 'go mod why' should be agnostic to build tags. +go mod why example.com/left +stdout '^example.com/chiral$\n^example.com/left$' +go mod why example.com/right +stdout '^example.com/chiral$\n^example.com/right$' + +env GOFLAGS='-tags=mirror' +go mod why example.com/left +stdout '^example.com/chiral$\n^example.com/left$' +go mod why example.com/right +stdout '^example.com/chiral$\n^example.com/right$' +env GOFLAGS='' + +# 'go mod tidy' should successfully handle the cycle. +env GOFLAGS=-mod=readonly +go mod tidy + +# 'go mod vendor' should copy in both packages without crashing. +go mod vendor +exists vendor/example.com/left/default.go +exists vendor/example.com/left/mirror.go +exists vendor/example.com/right/default.go +exists vendor/example.com/right/mirror.go + +-- go.mod -- +module example.com/chiral + +go 1.14 + +require ( + example.com/left v0.1.0 + example.com/right v0.1.0 +) + +replace ( + example.com/left => ./left + example.com/right => ./right +) +-- chiral.go -- +// Package chiral imports packages in an order that depends on build tags. +package chiral +-- default.go -- +// +build !mirror + +package chiral + +import _ "example.com/left" +-- mirror.go -- +// +build mirror + +package chiral + +import _ "example.com/right" +-- left/go.mod -- +module example.com/left + +go 1.14 + +require example.com/right v0.1.0 + +replace example.com/right v0.1.0 => ../right +-- left/default.go -- +// +build !mirror + +package left + +import _ "example.com/right" +-- left/mirror.go -- +// +build mirror + +package left +-- right/go.mod -- +module example.com/right + +go 1.14 + +require example.com/left v0.1.0 + +replace example.com/left v0.1.0 => ../left +-- right/default.go -- +// +build !mirror + +package right +-- right/mirror.go -- +// +build mirror + +package right + +import _ "example.com/left" diff --git a/go/src/cmd/go/testdata/script/mod_test.txt b/go/src/cmd/go/testdata/script/mod_test.txt new file mode 100644 index 0000000000000000000000000000000000000000..76f1d7a9a4d994c20634de26305d0df2aa0ef1cb --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_test.txt @@ -0,0 +1,130 @@ +env GO111MODULE=on +env GOFLAGS=-mod=mod +[short] skip + +# TODO(bcmills): Convert the 'go test' calls below to 'go list -test' once 'go +# list' is more sensitive to package loading errors. + +# A test in the module's root package should work. +cd a/ +cp go.mod.empty go.mod +go list -test +! stderr error + +cp go.mod.empty go.mod +go list -deps +! stdout ^testing$ + +# list all should include test dependencies, like testing +cp go.mod.empty go.mod +go list all +stdout ^testing$ +stdout ^rsc.io/quote$ +stdout ^rsc.io/testonly$ + +# list -deps -tests should also include testing +# but not deps of tests of deps (rsc.io/testonly). +go list -deps -test +stdout ^testing$ +stdout ^rsc.io/quote$ +! stdout ^rsc.io/testonly$ + +# list -test all should succeed +cp go.mod.empty go.mod +go list -test all +stdout '^testing' + +cp go.mod.empty go.mod +go list -test +! stderr error + +# A test with the "_test" suffix in the module root should also work. +cd ../b/ +go list -test +! stderr error + +# A test with the "_test" suffix of a *package* with a "_test" suffix should +# even work (not that you should ever do that). +cd ../c_test +go list -test +! stderr error + +cd ../d_test +go list -test +! stderr error + +cd ../e +go list -test +! stderr error + +-- a/go.mod.empty -- +module example.com/user/a + +go 1.11 + +-- a/a.go -- +package a + +-- a/a_test.go -- +package a + +import "testing" +import _ "rsc.io/quote" + +func Test(t *testing.T) {} + +-- b/go.mod -- +module example.com/user/b + +-- b/b.go -- +package b + +-- b/b_test.go -- +package b_test + +import "testing" + +func Test(t *testing.T) {} + +-- c_test/go.mod -- +module example.com/c_test + +-- c_test/umm.go -- +// Package c_test is the non-test package for its import path! +package c_test + +-- c_test/c_test_test.go -- +package c_test_test + +import "testing" + +func Test(t *testing.T) {} + +-- d_test/go.mod -- +// Package d is an ordinary package in a deceptively-named directory. +module example.com/d + +-- d_test/d.go -- +package d + +-- d_test/d_test.go -- +package d_test + +import "testing" + +func Test(t *testing.T) {} + +-- e/go.mod -- +module example.com/e_test + +-- e/wat.go -- +// Package e_test is the non-test package for its import path, +// in a deceptively-named directory! +package e_test + +-- e/e_test.go -- +package e_test_test + +import "testing" + +func Test(t *testing.T) {} diff --git a/go/src/cmd/go/testdata/script/mod_test_cached.txt b/go/src/cmd/go/testdata/script/mod_test_cached.txt new file mode 100644 index 0000000000000000000000000000000000000000..3da4358fa1435ddb38ee4d5b57e7116935bda861 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_test_cached.txt @@ -0,0 +1,76 @@ +[short] skip + +env GO111MODULE=on +env GOCACHE=$WORK/gocache +env GODEBUG=gocachetest=1 + +# The first run of a test should not be cached. +# The second run should be. +go test -run=WriteTmp . +! stdout '(cached)' +go test -run=WriteTmp . +stdout '(cached)' + +# 'go test' without arguments should never be cached. +go test -run=WriteTmp +! stdout '(cached)' +go test -run=WriteTmp +! stdout '(cached)' + +# We should never cache a test run from command-line files. +go test -run=WriteTmp ./foo_test.go +! stdout '(cached)' +go test -run=WriteTmp ./foo_test.go +! stdout '(cached)' + +[!exec:sleep] stop +# The go command refuses to cache access to files younger than 2s, so sleep that long. +exec sleep 2 + +# Touching a file that the test reads from within its testdata should invalidate the cache. +go test -run=ReadTestdata . +! stdout '(cached)' +go test -run=ReadTestdata . +stdout '(cached)' +cp testdata/bar.txt testdata/foo.txt +go test -run=ReadTestdata . +! stdout '(cached)' + +-- go.mod -- +module golang.org/issue/29111/foo + +-- foo.go -- +package foo + +-- testdata/foo.txt -- +foo +-- testdata/bar.txt -- +bar + +-- foo_test.go -- +package foo_test + +import ( + "os" + "path/filepath" + "testing" +) + +func TestWriteTmp(t *testing.T) { + dir, err := os.MkdirTemp("", "") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(dir) + err = os.WriteFile(filepath.Join(dir, "x"), nil, 0666) + if err != nil { + t.Fatal(err) + } +} + +func TestReadTestdata(t *testing.T) { + _, err := os.ReadFile("testdata/foo.txt") + if err != nil { + t.Fatal(err) + } +} diff --git a/go/src/cmd/go/testdata/script/mod_test_files.txt b/go/src/cmd/go/testdata/script/mod_test_files.txt new file mode 100644 index 0000000000000000000000000000000000000000..6f520c7720d2fee618d1eeb5dcef0d2b4c000503 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_test_files.txt @@ -0,0 +1,50 @@ +env GO111MODULE=on + +cd foo + +# Testing an explicit source file should use the same import visibility as the +# package in the same directory. +go list -test -deps +go list -test -deps foo_test.go + +# If the file is inside the main module's vendor directory, it should have +# visibility based on the vendor-relative import path. +mkdir vendor/example.com/foo +cp foo_test.go vendor/example.com/foo +go list -test -deps vendor/example.com/foo/foo_test.go + +# If the file is outside the main module entirely, it should be treated as outside. +cp foo_test.go ../foo_test.go +! go list -test -deps ../foo_test.go +stderr 'use of internal package' + +-- foo/go.mod -- +module example.com/foo +go 1.12 +require example.com/internal v0.0.0 +replace example.com/internal => ../internal + +-- foo/internal.go -- +package foo +import _ "example.com/internal" + +-- foo/foo_test.go -- +package foo_test + +import ( + "testing" + "example.com/internal" +) + +func TestHacksEnabled(t *testing.T) { + if !internal.Hacks { + t.Fatal("hacks not enabled") + } +} + +-- internal/go.mod -- +module example.com/internal + +-- internal/internal.go -- +package internal +const Hacks = true diff --git a/go/src/cmd/go/testdata/script/mod_tidy.txt b/go/src/cmd/go/testdata/script/mod_tidy.txt new file mode 100644 index 0000000000000000000000000000000000000000..b1d9371217c4bf4b5e7f2289505d576bf2ad4d5d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy.txt @@ -0,0 +1,72 @@ +env GO111MODULE=on + +# tidy removes unused y, but everything else is used +go mod tidy -v +stderr '^unused y.1' +! stderr '^unused [^y]' + +grep 'go 1.10' go.mod + +go list -m all +! stdout '^y' +stdout '^w.1 v1.2.0' +stdout '^z.1 v1.2.0' + +# empty tidy should not crash +cd triv +! grep 'go ' go.mod +go mod tidy + +# tidy should add missing go line +grep 'go ' go.mod + +-- go.mod -- +module m + +go 1.10 + +require ( + x.1 v1.0.0 + y.1 v1.0.0 + w.1 v1.2.0 +) + +replace x.1 v1.0.0 => ./x +replace y.1 v1.0.0 => ./y +replace z.1 v1.1.0 => ./z +replace z.1 v1.2.0 => ./z +replace w.1 => ./w + +-- m.go -- +package m + +import _ "x.1" +import _ "z.1/sub" + +-- w/go.mod -- +module w + +-- w/w.go -- +package w + +-- x/go.mod -- +module x +require w.1 v1.1.0 +require z.1 v1.1.0 + +-- x/x.go -- +package x +import _ "w.1" + +-- y/go.mod -- +module y +require z.1 v1.2.0 + +-- z/go.mod -- +module z + +-- z/sub/sub.go -- +package sub + +-- triv/go.mod -- +module triv diff --git a/go/src/cmd/go/testdata/script/mod_tidy_compat.txt b/go/src/cmd/go/testdata/script/mod_tidy_compat.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a9d2ff8436b7cb8d2cb0350257870245d2bddb8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_compat.txt @@ -0,0 +1,117 @@ +# https://golang.org/issue/46141: 'go mod tidy' for a Go 1.17 module should by +# default preserve enough checksums for the module to be used by Go 1.16. +# +# We don't have a copy of Go 1.16 handy, but we can simulate it by editing the +# 'go' version in the go.mod file to 1.16, without actually updating the +# requirements to match. + +[short] skip + +env MODFMT='{{with .Module}}{{.Path}} {{.Version}}{{end}}' + + +# This module has the same module dependency graph in Go 1.16 as in Go 1.17, +# but in 1.16 requires (checksums for) additional (irrelevant) go.mod files. +# +# The module graph under both versions looks like: +# +# m ---- example.com/version v1.1.0 +# | +# + ---- example.net/lazy v0.1.0 ---- example.com/version v1.0.1 +# +# Go 1.17 avoids loading the go.mod file for example.com/version v1.0.1 +# (because it is lower than the version explicitly required by m, +# and the module that requires it — m — specifies 'go 1.17'). +# +# That go.mod file happens not to affect the final 1.16 module graph anyway, +# so the pruned graph is equivalent to the unpruned one. + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod go.mod.orig + +# Make sure that -diff behaves the same as tidy. +[exec:patch] mv go.mod go.mod.tidyResult +[exec:patch] mv go.sum go.sum.tidyResult +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! go mod tidy -diff +[exec:patch] cp stdout diff.patch +[exec:patch] exec patch -p1 -i diff.patch +[exec:patch] go mod tidy -diff +[exec:patch] cmp go.mod go.mod.tidyResult +[exec:patch] cmp go.sum go.sum.tidyResult + +go list -m all +cmp stdout m_all.txt + +go mod edit -go=1.16 +go list -m all +cmp stdout m_all.txt + + +# If we explicitly drop compatibility with 1.16, we retain fewer checksums, +# which gives a cleaner go.sum file but causes 1.16 to fail in readonly mode. + +cp go.mod.orig go.mod +go mod tidy -compat=1.17 +cmp go.mod go.mod.orig + +# Make sure that -diff behaves the same as tidy. +[exec:patch] mv go.mod go.mod.tidyResult +[exec:patch] mv go.sum go.sum.tidyResult +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! go mod tidy -compat=1.17 -diff +[exec:patch] cp stdout diff.patch +[exec:patch] exec patch -p1 -i diff.patch +[exec:patch] go mod tidy -compat=1.17 -diff +[exec:patch] cmp go.mod go.mod.tidyResult +[exec:patch] cmp go.sum go.sum.tidyResult + +go list -m all +cmp stdout m_all.txt + +go mod edit -go=1.16 +! go list -m all +stderr '^go: example.net/lazy@v0.1.0 requires\n\texample.com/version@v1.0.1: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/version$' + + +-- go.mod -- +// Module m happens to have the exact same build list as what would be +// selected under Go 1.16, but computes that build list without looking at +// as many go.mod files. +module example.com/m + +go 1.17 + +replace example.net/lazy v0.1.0 => ./lazy + +require ( + example.com/version v1.1.0 + example.net/lazy v0.1.0 +) +-- m_all.txt -- +example.com/m +example.com/version v1.1.0 +example.net/lazy v0.1.0 => ./lazy +-- compatible.go -- +package compatible + +import ( + _ "example.com/version" + _ "example.net/lazy" +) +-- lazy/go.mod -- +// Module lazy requires example.com/version v1.0.1. +// +// However, since this module is lazy, its dependents +// should not need checksums for that version of the module +// unless they actually import packages from it. +module example.net/lazy + +go 1.17 + +require example.com/version v1.0.1 +-- lazy/lazy.go -- +package lazy + +import _ "example.com/version" diff --git a/go/src/cmd/go/testdata/script/mod_tidy_compat_added.txt b/go/src/cmd/go/testdata/script/mod_tidy_compat_added.txt new file mode 100644 index 0000000000000000000000000000000000000000..0831d0f0854326b63b40d8f0288d7008a9f03b5c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_compat_added.txt @@ -0,0 +1,125 @@ +# https://golang.org/issue/46141: 'go mod tidy' for a Go 1.17 module should by +# default preserve enough checksums for the module to be used by Go 1.16. +# +# We don't have a copy of Go 1.16 handy, but we can simulate it by editing the +# 'go' version in the go.mod file to 1.16, without actually updating the +# requirements to match. + +[short] skip + +env MODFMT='{{with .Module}}{{.Path}} {{.Version}}{{end}}' + + +# For this module, Go 1.17 produces an error for one module, and Go 1.16 +# produces a different error for a different module. + +cp go.mod go.mod.orig + +! go mod tidy + +stderr '^go: example\.com/m imports\n\texample\.net/added: module example\.net/added@latest found \(v0\.3\.0, replaced by \./a1\), but does not contain package example\.net/added$' + +cmp go.mod go.mod.orig + +# Make sure that -diff behaves the same as tidy. +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! exists go.sum +[exec:patch] ! go mod tidy -diff +[exec:patch] ! stdout . +[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/added: module example\.net/added@latest found \(v0\.3\.0, replaced by \./a1\), but does not contain package example\.net/added$' + +# When we run 'go mod tidy -e', we should proceed past the first error and follow +# it with a second error describing the version discrepancy. +# +# We should not provide advice on how to push past the version discrepancy, +# because the '-e' flag should already do that, writing out an otherwise-tidied +# go.mod file. + +go mod tidy -e + +stderr '^go: example\.com/m imports\n\texample\.net/added: module example\.net/added@latest found \(v0\.3\.0, replaced by \./a1\), but does not contain package example\.net/added\ngo: example\.net/added failed to load from any module,\n\tbut go 1\.16 would load it from example\.net/added@v0\.2\.0$' + +! stderr '\n\tgo mod tidy' + +cmp go.mod go.mod.tidy + +# Make sure that -diff behaves the same as tidy. +[exec:patch] cp go.mod go.mod.tidyResult +[exec:patch] ! exists go.sum +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! go mod tidy -e -diff +[exec:patch] stdout 'diff current/go.mod tidy/go.mod' +[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/added: module example\.net/added@latest found \(v0\.3\.0, replaced by \./a1\), but does not contain package example\.net/added\ngo: example\.net/added failed to load from any module,\n\tbut go 1\.16 would load it from example\.net/added@v0\.2\.0$' +[exec:patch] ! stderr '\n\tgo mod tidy' +[exec:patch] cp stdout diff.patch +[exec:patch] exec patch -p1 -i diff.patch +[exec:patch] go mod tidy -e -diff +[exec:patch] ! stdout . +[exec:patch] cmp go.mod go.mod.tidyResult +[exec:patch] ! exists go.sum + +-- go.mod -- +module example.com/m + +go 1.17 + +replace ( + example.net/added v0.1.0 => ./a1 + example.net/added v0.2.0 => ./a2 + example.net/added v0.3.0 => ./a1 + example.net/lazy v0.1.0 => ./lazy + example.net/pruned v0.1.0 => ./pruned +) + +require ( + example.net/added v0.1.0 + example.net/lazy v0.1.0 +) +-- go.mod.tidy -- +module example.com/m + +go 1.17 + +replace ( + example.net/added v0.1.0 => ./a1 + example.net/added v0.2.0 => ./a2 + example.net/added v0.3.0 => ./a1 + example.net/lazy v0.1.0 => ./lazy + example.net/pruned v0.1.0 => ./pruned +) + +require example.net/lazy v0.1.0 +-- m.go -- +package m + +import ( + _ "example.net/added" + _ "example.net/lazy" +) + +-- a1/go.mod -- +module example.net/added + +go 1.17 +-- a2/go.mod -- +module example.net/added + +go 1.17 +-- a2/added.go -- +package added + +-- lazy/go.mod -- +module example.net/lazy + +go 1.17 + +require example.net/pruned v0.1.0 +-- lazy/lazy.go -- +package lazy + +-- pruned/go.mod -- +module example.net/pruned + +go 1.17 + +require example.net/added v0.2.0 diff --git a/go/src/cmd/go/testdata/script/mod_tidy_compat_ambiguous.txt b/go/src/cmd/go/testdata/script/mod_tidy_compat_ambiguous.txt new file mode 100644 index 0000000000000000000000000000000000000000..5b1f5116fdec0c23c830a20e2e24ec6c36dbde46 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_compat_ambiguous.txt @@ -0,0 +1,131 @@ +# https://golang.org/issue/46141: 'go mod tidy' for a Go 1.17 module should by +# default preserve enough checksums for the module to be used by Go 1.16. +# +# We don't have a copy of Go 1.16 handy, but we can simulate it by editing the +# 'go' version in the go.mod file to 1.16, without actually updating the +# requirements to match. + +[short] skip + +env MODFMT='{{with .Module}}{{.Path}} {{.Version}}{{end}}' + +# For this module, the dependency providing package +# example.net/ambiguous/nested/pkg is unambiguous in Go 1.17 (because only one +# root of the module graph contains the package), whereas it is ambiguous in +# Go 1.16 (because two different modules contain plausible packages and Go 1.16 +# does not privilege roots above other dependencies). +# +# However, the overall build list is identical for both versions. + +cp go.mod go.mod.orig + +! go mod tidy + +stderr '^go: example\.com/m imports\n\texample\.net/indirect imports\n\texample\.net/ambiguous/nested/pkg loaded from example\.net/ambiguous/nested@v0\.1\.0,\n\tbut go 1.16 would fail to locate it:\n\tambiguous import: found package example\.net/ambiguous/nested/pkg in multiple modules:\n\texample\.net/ambiguous v0.1.0 \(.*\)\n\texample\.net/ambiguous/nested v0.1.0 \(.*\)\n\n' + +stderr '\n\nTo proceed despite packages unresolved in go 1\.16:\n\tgo mod tidy -e\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1\.17\nFor information about ''go mod tidy'' compatibility, see:\n\thttps://go\.dev/ref/mod#graph-pruning\n' + +cmp go.mod go.mod.orig + +# Make sure that -diff behaves the same as tidy. +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! exists go.sum +[exec:patch] ! go mod tidy -diff +[exec:patch] ! stdout . +[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/indirect imports\n\texample\.net/ambiguous/nested/pkg loaded from example\.net/ambiguous/nested@v0\.1\.0,\n\tbut go 1.16 would fail to locate it:\n\tambiguous import: found package example\.net/ambiguous/nested/pkg in multiple modules:\n\texample\.net/ambiguous v0.1.0 \(.*\)\n\texample\.net/ambiguous/nested v0.1.0 \(.*\)\n\n' +[exec:patch] stderr '\n\nTo proceed despite packages unresolved in go 1\.16:\n\tgo mod tidy -e\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1\.17\nFor information about ''go mod tidy'' compatibility, see:\n\thttps://go\.dev/ref/mod#graph-pruning\n' + + +# If we run 'go mod tidy -e', we should still save enough checksums to run +# 'go list -m all' reproducibly with go 1.16, even though we can't list +# the specific package. + +go mod tidy -e +! stderr '\n\tgo mod tidy' +cmp go.mod go.mod.orig + +# Make sure that -diff behaves the same as tidy. +[exec:patch] mv go.mod go.mod.tidyResult +[exec:patch] mv go.sum go.sum.tidyResult +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! go mod tidy -e -diff +[exec:patch] ! stderr '\n\tgo mod tidy' +[exec:patch] cp stdout diff.patch +[exec:patch] exec patch -p1 -i diff.patch +[exec:patch] go mod tidy -e -diff +[exec:patch] ! stdout . +[exec:patch] cmp go.mod go.mod.tidyResult +[exec:patch] cmp go.sum go.sum.tidyResult + +go list -m all +cmp stdout all-m.txt + +go list -f $MODFMT example.net/ambiguous/nested/pkg +stdout '^example.net/ambiguous/nested v0\.1\.0$' +! stderr . + +go mod edit -go=1.16 +go list -m all +cmp stdout all-m.txt + +! go list -f $MODFMT example.net/ambiguous/nested/pkg +stderr '^ambiguous import: found package example\.net/ambiguous/nested/pkg in multiple modules:\n\texample\.net/ambiguous v0\.1\.0 \(.*\)\n\texample\.net/ambiguous/nested v0\.1\.0 \(.*\)\n' + + +# On the other hand, if we use -compat=1.17, 1.16 can't even load +# the build list (due to missing checksums). + +cp go.mod.orig go.mod +go mod tidy -compat=1.17 +! stderr . +go list -m all +cmp stdout all-m.txt + +# Make sure that -diff behaves the same as tidy. +[exec:patch] mv go.mod go.mod.tidyResult +[exec:patch] mv go.sum go.sum.tidyResult +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! go mod tidy -compat=1.17 -diff +[exec:patch] ! stderr . +[exec:patch] cp stdout diff.patch +[exec:patch] exec patch -p1 -i diff.patch +[exec:patch] go mod tidy -compat=1.17 -diff +[exec:patch] ! stdout . +[exec:patch] cmp go.mod go.mod.tidyResult +[exec:patch] cmp go.sum go.sum.tidyResult + +go mod edit -go=1.16 +! go list -m all +stderr '^go: example\.net/indirect@v0\.1\.0 requires\n\texample\.net/ambiguous@v0\.1\.0: missing go\.sum entry for go\.mod file; to add it:\n\tgo mod download example\.net/ambiguous\n' + + +-- go.mod -- +module example.com/m + +go 1.17 + +replace example.net/indirect v0.1.0 => ./indirect + +require example.net/indirect v0.1.0 + +require example.net/ambiguous/nested v0.1.0 // indirect +-- all-m.txt -- +example.com/m +example.net/ambiguous v0.1.0 +example.net/ambiguous/nested v0.1.0 +example.net/indirect v0.1.0 => ./indirect +-- m.go -- +package m + +import _ "example.net/indirect" + +-- indirect/go.mod -- +module example.net/indirect + +go 1.17 + +require example.net/ambiguous v0.1.0 +-- indirect/indirect.go -- +package indirect + +import _ "example.net/ambiguous/nested/pkg" diff --git a/go/src/cmd/go/testdata/script/mod_tidy_compat_deleted.txt b/go/src/cmd/go/testdata/script/mod_tidy_compat_deleted.txt new file mode 100644 index 0000000000000000000000000000000000000000..775bba48dd305b157921e87f0575364b3a98bdee --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_compat_deleted.txt @@ -0,0 +1,153 @@ +# https://golang.org/issue/46141: 'go mod tidy' for a Go 1.17 module should by +# default preserve enough checksums for the module to be used by Go 1.16. +# +# We don't have a copy of Go 1.16 handy, but we can simulate it by editing the +# 'go' version in the go.mod file to 1.16, without actually updating the +# requirements to match. + +[short] skip + +env MODFMT='{{with .Module}}{{.Path}} {{.Version}}{{end}}' + + +# For this module, the "deleted" dependency contains an imported package, but +# Go 1.16 selects a higher version (in which that package has been deleted). + +cp go.mod go.mod.orig + +! go mod tidy + +stderr '^go: example\.com/m imports\n\texample\.net/deleted loaded from example\.net/deleted@v0\.1\.0,\n\tbut go 1\.16 would fail to locate it in example\.net/deleted@v0\.2\.0\n\n' + +stderr '\n\nTo upgrade to the versions selected by go 1.16, leaving some packages unresolved:\n\tgo mod tidy -e -go=1\.16 && go mod tidy -e -go=1\.17\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1\.17\nFor information about ''go mod tidy'' compatibility, see:\n\thttps://go\.dev/ref/mod#graph-pruning\n' + +# Make sure that -diff behaves the same as tidy. +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! exists go.sum +[exec:patch] ! go mod tidy -diff +[exec:patch] ! stdout . +[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/deleted loaded from example\.net/deleted@v0\.1\.0,\n\tbut go 1\.16 would fail to locate it in example\.net/deleted@v0\.2\.0\n\n' +[exec:patch] stderr '\n\nTo upgrade to the versions selected by go 1.16, leaving some packages unresolved:\n\tgo mod tidy -e -go=1\.16 && go mod tidy -e -go=1\.17\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1\.17\nFor information about ''go mod tidy'' compatibility, see:\n\thttps://go\.dev/ref/mod#graph-pruning\n' + +# The suggested 'go mod tidy -e' command should proceed anyway. + +go mod tidy -e +cmp go.mod go.mod.tidy + +# Make sure that -diff behaves the same as tidy. +[exec:patch] cp go.mod go.mod.tidyResult +[exec:patch] ! exists go.sum +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! go mod tidy -e -diff +[exec:patch] cp stdout diff.patch +[exec:patch] exec patch -p1 -i diff.patch +[exec:patch] go mod tidy -e -diff +[exec:patch] ! stdout . +[exec:patch] cmp go.mod go.mod.tidyResult +[exec:patch] ! exists go.sum + +# In 'go 1.16' mode we should error out in the way we claimed. + +cd 116-outside +! go list -deps -f $MODFMT example.com/m +stderr '^\.\.[/\\]m\.go:4:2: no required module provides package example\.net/deleted; to add it:\n\tgo get example\.net/deleted$' +cd .. + +go mod edit -go=1.16 +! go list -deps -f $MODFMT example.com/m +stderr '^go: updates to go\.mod needed; to update it:\n\tgo mod tidy$' + +[exec:patch] cp go.mod go.mod.orig +! go mod tidy +stderr '^go: example\.com/m imports\n\texample\.net/deleted: module example\.net/deleted@latest found \(v0\.2\.0, replaced by \./d2\), but does not contain package example\.net/deleted$' + +# Make sure that -diff behaves the same as tidy. +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! exists go.sum +[exec:patch] ! go mod tidy -diff +[exec:patch] ! stdout . +[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/deleted: module example\.net/deleted@latest found \(v0\.2\.0, replaced by \./d2\), but does not contain package example\.net/deleted$' + +-- go.mod -- +module example.com/m + +go 1.17 + +replace ( + example.net/deleted v0.1.0 => ./d1 + example.net/deleted v0.2.0 => ./d2 + example.net/lazy v0.1.0 => ./lazy + example.net/pruned v0.1.0 => ./pruned +) + +require ( + example.net/deleted v0.1.0 + example.net/deleted v0.1.0 // redundant + example.net/lazy v0.1.0 +) +-- go.mod.tidy -- +module example.com/m + +go 1.17 + +replace ( + example.net/deleted v0.1.0 => ./d1 + example.net/deleted v0.2.0 => ./d2 + example.net/lazy v0.1.0 => ./lazy + example.net/pruned v0.1.0 => ./pruned +) + +require ( + example.net/deleted v0.1.0 + example.net/lazy v0.1.0 +) +-- 116-outside/go.mod -- +module outside + +go 1.16 + +replace ( + example.com/m => ../ + example.net/deleted v0.1.0 => ../d1 + example.net/deleted v0.2.0 => ../d2 + example.net/lazy v0.1.0 => ../lazy + example.net/pruned v0.1.0 => ../pruned +) + +require example.com/m v0.1.0 +-- m.go -- +package m + +import ( + _ "example.net/deleted" + _ "example.net/lazy" +) + +-- d1/go.mod -- +module example.net/deleted + +go 1.17 +-- d1/deleted.go -- +package deleted +-- d2/go.mod -- +module example.net/deleted + +go 1.17 +-- d2/README -- +There is no longer a Go package here. + +-- lazy/go.mod -- +module example.net/lazy + +go 1.17 + +require example.net/pruned v0.1.0 +-- lazy/lazy.go -- +package lazy + +-- pruned/go.mod -- +module example.net/pruned + +go 1.17 + +require example.net/deleted v0.2.0 diff --git a/go/src/cmd/go/testdata/script/mod_tidy_compat_implicit.txt b/go/src/cmd/go/testdata/script/mod_tidy_compat_implicit.txt new file mode 100644 index 0000000000000000000000000000000000000000..03ce8dd5e9cd7a080e16534cbc430d451dd780bd --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_compat_implicit.txt @@ -0,0 +1,148 @@ +# https://golang.org/issue/46141: 'go mod tidy' for a Go 1.17 module should by +# default preserve enough checksums for the module to be used by Go 1.16. +# +# We don't have a copy of Go 1.16 handy, but we can simulate it by editing the +# 'go' version in the go.mod file to 1.16, without actually updating the +# requirements to match. + +[short] skip + +env MODFMT='{{with .Module}}{{.Path}} {{.Version}}{{end}}' + + +# For this module, Go 1.16 selects the same versions of all explicit dependencies +# as Go 1.17 does. However, Go 1.16 selects a higher version of an *implicit* +# dependency, imported by a test of one of the (external) imported packages. +# As a result, Go 1.16 also needs checksums for the module sources for that higher +# version. +# +# The Go 1.16 module graph looks like: +# +# m ---- lazy v0.1.0 ---- incompatible v1.0.0 +# | +# + ------------- requireincompatible v0.1.0 ---- incompatible v2.0.0+incompatible +# +# The Go 1.17 module graph is the same except that the dependencies of +# requireincompatible are pruned out (because the module that requires +# it — lazy v0.1.0 — specifies 'go 1.17', and it is not otherwise relevant to +# the main module). + +# 'go mod tidy' should by default diagnose the difference in dependencies as an +# error, with useful suggestions about how to resolve it. + +cp go.mod go.mod.orig +! go mod tidy +stderr '^go: example\.com/m imports\n\texample\.net/lazy tested by\n\texample\.net/lazy.test imports\n\texample\.com/retract/incompatible loaded from example\.com/retract/incompatible@v1\.0\.0,\n\tbut go 1\.16 would select v2\.0\.0\+incompatible\n\n' +stderr '\n\nTo upgrade to the versions selected by go 1\.16:\n\tgo mod tidy -go=1\.16 && go mod tidy -go=1\.17\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1.17\nFor information about ''go mod tidy'' compatibility, see:\n\thttps://go\.dev/ref/mod#graph-pruning\n' + +cmp go.mod go.mod.orig + +# Make sure that -diff behaves the same as tidy. +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! exists go.sum +[exec:patch] ! go mod tidy -diff +[exec:patch] ! stdout . +[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/lazy tested by\n\texample\.net/lazy.test imports\n\texample\.com/retract/incompatible loaded from example\.com/retract/incompatible@v1\.0\.0,\n\tbut go 1\.16 would select v2\.0\.0\+incompatible\n\n' +[exec:patch] stderr '\n\nTo upgrade to the versions selected by go 1\.16:\n\tgo mod tidy -go=1\.16 && go mod tidy -go=1\.17\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1.17\nFor information about ''go mod tidy'' compatibility, see:\n\thttps://go\.dev/ref/mod#graph-pruning\n' + +# The suggested '-compat' flag to ignore differences should silence the error +# and leave go.mod unchanged, resulting in checksum errors when Go 1.16 tries +# to load a module pruned out by Go 1.17. + +go mod tidy -compat=1.17 +! stderr . +cmp go.mod go.mod.orig + +# Make sure that -diff behaves the same as tidy. +[exec:patch] mv go.mod go.mod.tidyResult +[exec:patch] mv go.sum go.sum.tidyResult +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! go mod tidy -compat=1.17 -diff +[exec:patch] cp stdout diff.patch +[exec:patch] exec patch -p1 -i diff.patch +[exec:patch] go mod tidy -compat=1.17 -diff +[exec:patch] ! stdout . +[exec:patch] cmp go.mod go.mod.tidyResult +[exec:patch] cmp go.sum go.sum.tidyResult + +go list -deps -test -f $MODFMT ./... +stdout '^example.net/lazy v0.1.0$' + +go mod edit -go=1.16 +! go list -deps -test -f $MODFMT ./... + +stderr -count=1 '^go: example\.net/lazy@v0\.1\.0 requires\n\texample\.com/retract/incompatible@v1\.0\.0: missing go\.sum entry for go\.mod file; to add it:\n\tgo mod download example\.com/retract/incompatible$' + + +# If we combine a Go 1.16 go.sum file... +go mod tidy -go=1.16 + +# ...with a Go 1.17 go.mod file... +cp go.mod.orig go.mod + +# ...then Go 1.17 no longer works. 😞 +! go list -deps -test -f $MODFMT all +stderr -count=1 '^go: can''t load test package: lazy[/\\]lazy_test.go:3:8: missing go\.sum entry for module providing package example\.com/retract/incompatible \(imported by example\.net/lazy\); to add:\n\tgo get -t example.net/lazy@v0\.1\.0$' + + +# However, if we take the union of the go.sum files... +go list -mod=mod -deps -test all +cmp go.mod go.mod.orig + +# ...then Go 1.17 continues to work... +go list -deps -test -f $MODFMT all +stdout '^example\.com/retract/incompatible v1\.0\.0$' + +# ...and 1.16 also works(‽), but selects a different version for the +# external-test dependency. +go mod edit -go=1.16 +go list -deps -test -f $MODFMT all +stdout '^example\.com/retract/incompatible v2\.0\.0\+incompatible$' + + +-- go.mod -- +// Module m imports packages from the same versions under Go 1.17 +// as under Go 1.16, but under 1.16 its (implicit) external test dependencies +// are higher. +module example.com/m + +go 1.17 + +replace ( + example.net/lazy v0.1.0 => ./lazy + example.net/requireincompatible v0.1.0 => ./requireincompatible +) + +require example.net/lazy v0.1.0 +-- implicit.go -- +package implicit + +import _ "example.net/lazy" +-- lazy/go.mod -- +// Module lazy requires example.com/retract/incompatible v1.0.0. +// +// When viewed from the outside it also has a transitive dependency +// on v2.0.0+incompatible, but in lazy mode that transitive dependency +// is pruned out. +module example.net/lazy + +go 1.17 + +exclude example.com/retract/incompatible v2.0.0+incompatible + +require ( + example.com/retract/incompatible v1.0.0 + example.net/requireincompatible v0.1.0 +) +-- lazy/lazy.go -- +package lazy +-- lazy/lazy_test.go -- +package lazy_test + +import _ "example.com/retract/incompatible" +-- requireincompatible/go.mod -- +module example.net/requireincompatible + +go 1.15 + +require example.com/retract/incompatible v2.0.0+incompatible diff --git a/go/src/cmd/go/testdata/script/mod_tidy_compat_incompatible.txt b/go/src/cmd/go/testdata/script/mod_tidy_compat_incompatible.txt new file mode 100644 index 0000000000000000000000000000000000000000..c535658959e40190ea37fb3337d9240c9c761438 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_compat_incompatible.txt @@ -0,0 +1,152 @@ +# https://golang.org/issue/46141: 'go mod tidy' for a Go 1.17 module should by +# default preserve enough checksums for the module to be used by Go 1.16. +# +# We don't have a copy of Go 1.16 handy, but we can simulate it by editing the +# 'go' version in the go.mod file to 1.16, without actually updating the +# requirements to match. + +[short] skip + +env MODFMT='{{with .Module}}{{.Path}} {{.Version}}{{end}}' + + +# For this module, Go 1.17 prunes out a (transitive and otherwise-irrelevant) +# requirement on a retracted higher version of a dependency. +# However, when Go 1.16 reads the same requirements from the go.mod file, +# it does not prune out that requirement, and selects the retracted version. +# +# The Go 1.16 module graph looks like: +# +# m ---- lazy v0.1.0 ---- requireincompatible v0.1.0 ---- incompatible v2.0.0+incompatible +# | | +# + -------+------------- incompatible v1.0.0 +# +# The Go 1.17 module graph is the same except that the dependencies of +# requireincompatible are pruned out (because the module that requires +# it — lazy v0.1.0 — specifies 'go 1.17', and it is not otherwise relevant to +# the main module). + + +# 'go mod tidy' should by default diagnose the difference in dependencies as an +# error, with useful suggestions about how to resolve it. + +cp go.mod go.mod.orig +! go mod tidy +stderr '^go: example\.com/m imports\n\texample\.net/lazy imports\n\texample\.com/retract/incompatible loaded from example\.com/retract/incompatible@v1\.0\.0,\n\tbut go 1\.16 would select v2\.0\.0\+incompatible\n\n' +stderr '\n\nTo upgrade to the versions selected by go 1\.16:\n\tgo mod tidy -go=1\.16 && go mod tidy -go=1\.17\nIf reproducibility with go 1\.16 is not needed:\n\tgo mod tidy -compat=1.17\nFor information about ''go mod tidy'' compatibility, see:\n\thttps://go\.dev/ref/mod#graph-pruning\n' + +cmp go.mod go.mod.orig + +# Make sure that -diff behaves the same as tidy. +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! exists go.sum +[exec:patch] ! go mod tidy -diff +[exec:patch] ! stdout . +[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/lazy imports\n\texample\.com/retract/incompatible loaded from example\.com/retract/incompatible@v1\.0\.0,\n\tbut go 1\.16 would select v2\.0\.0\+incompatible\n\n' +[exec:patch] stderr '\n\nTo upgrade to the versions selected by go 1\.16:\n\tgo mod tidy -go=1\.16 && go mod tidy -go=1\.17\nIf reproducibility with go 1\.16 is not needed:\n\tgo mod tidy -compat=1.17\nFor information about ''go mod tidy'' compatibility, see:\n\thttps://go\.dev/ref/mod#graph-pruning\n' + +# The suggested '-compat' flag to ignore differences should silence the error +# and leave go.mod unchanged, resulting in checksum errors when Go 1.16 tries +# to load a module pruned out by Go 1.17. + +go mod tidy -compat=1.17 +! stderr . +cmp go.mod go.mod.orig + +# Make sure that -diff behaves the same as tidy. +[exec:patch] mv go.mod go.mod.tidyResult +[exec:patch] mv go.sum go.sum.tidyResult +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! go mod tidy -compat=1.17 -diff +[exec:patch] cp stdout diff.patch +[exec:patch] exec patch -p1 -i diff.patch +[exec:patch] go mod tidy -compat=1.17 -diff +[exec:patch] ! stdout . +[exec:patch] cmp go.mod go.mod.tidyResult +[exec:patch] cmp go.sum go.sum.tidyResult + +go mod edit -go=1.16 +! go list -f $MODFMT -deps ./... +stderr -count=1 '^go: example\.net/lazy@v0\.1\.0 requires\n\texample\.net/requireincompatible@v0\.1\.0 requires\n\texample\.com/retract/incompatible@v2\.0\.0\+incompatible: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/retract/incompatible$' + + +# There are two ways for the module author to bring the two into alignment. +# One is to *explicitly* 'exclude' the version that is already *implicitly* +# pruned out under 1.17. + +go mod edit -exclude=example.com/retract/incompatible@v2.0.0+incompatible +go list -f $MODFMT -deps ./... +stdout '^example.com/retract/incompatible v1\.0\.0$' +! stdout 'v2\.0\.0' + + +# The other is to explicitly upgrade the version required under Go 1.17 +# to match the version selected by Go 1.16. The commands suggested by +# 'go mod tidy' should do exactly that. + +cp go.mod.orig go.mod + +go mod tidy -go=1.16 +go list -f $MODFMT -deps ./... +stdout '^example.com/retract/incompatible v2\.0\.0\+incompatible$' +! stdout 'v1\.0\.0' + +go mod tidy -go=1.17 +go list -f $MODFMT -deps ./... +stdout '^example.com/retract/incompatible v2\.0\.0\+incompatible$' +! stdout 'v1\.0\.0' + +go mod edit -go=1.16 +go list -f $MODFMT -deps ./... +stdout '^example.com/retract/incompatible v2\.0\.0\+incompatible$' +! stdout 'v1\.0\.0' + + +-- go.mod -- +// Module m indirectly imports a package from +// example.com/retract/incompatible. Its selected version of +// that module is lower under Go 1.17 semantics than under Go 1.16. +module example.com/m + +go 1.17 + +replace ( + example.net/lazy v0.1.0 => ./lazy + example.net/requireincompatible v0.1.0 => ./requireincompatible +) + +require example.net/lazy v0.1.0 + +require example.com/retract/incompatible v1.0.0 // indirect +-- incompatible.go -- +package incompatible + +import _ "example.net/lazy" + +-- lazy/go.mod -- +// Module lazy requires example.com/retract/incompatible v1.0.0. +// +// When viewed from the outside it also has a transitive dependency +// on v2.0.0+incompatible, but in lazy mode that transitive dependency +// is pruned out. +module example.net/lazy + +go 1.17 + +exclude example.com/retract/incompatible v2.0.0+incompatible + +require ( + example.com/retract/incompatible v1.0.0 + example.net/requireincompatible v0.1.0 +) +-- lazy/lazy.go -- +package lazy + +import _ "example.com/retract/incompatible" + +-- requireincompatible/go.mod -- +module example.net/requireincompatible + +go 1.15 + +require example.com/retract/incompatible v2.0.0+incompatible diff --git a/go/src/cmd/go/testdata/script/mod_tidy_compat_irrelevant.txt b/go/src/cmd/go/testdata/script/mod_tidy_compat_irrelevant.txt new file mode 100644 index 0000000000000000000000000000000000000000..75c16d19184264cc1112205e231cc20988f65a04 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_compat_irrelevant.txt @@ -0,0 +1,116 @@ +# https://golang.org/issue/46141: 'go mod tidy' for a Go 1.17 module should by +# default preserve enough checksums for the module to be used by Go 1.16. +# +# We don't have a copy of Go 1.16 handy, but we can simulate it by editing the +# 'go' version in the go.mod file to 1.16, without actually updating the +# requirements to match. + +[short] skip + +env MODFMT='{{with .Module}}{{.Path}} {{.Version}}{{end}}' + + +# This module selects the same versions in Go 1.16 and 1.17 for all modules +# that provide packages (or test dependencies of packages) imported by the +# main module. However, in Go 1.16 it selects a higher version of a +# transitive module dependency that is not otherwise relevant to the main module. +# As a result, Go 1.16 needs an additional checksum for the go.mod file of +# that irrelevant dependency. +# +# The Go 1.16 module graph looks like: +# +# m ---- lazy v0.1.0 ---- incompatible v1.0.0 +# | +# + ------------- requireincompatible v0.1.0 ---- incompatible v2.0.0+incompatible + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod go.mod.orig + +# Make sure that -diff behaves the same as tidy. +[exec:patch] mv go.mod go.mod.tidyResult +[exec:patch] mv go.sum go.sum.tidyResult +[exec:patch] cp go.mod.orig go.mod +[exec:patch] ! go mod tidy -diff +[exec:patch] cp stdout diff.patch +[exec:patch] exec patch -p1 -i diff.patch +[exec:patch] go mod tidy -diff +[exec:patch] ! stdout . +[exec:patch] cmp go.mod go.mod.tidyResult +[exec:patch] cmp go.sum go.sum.tidyResult + +go list -deps -test -f $MODFMT all +cp stdout out-117.txt + +go mod edit -go=1.16 +go list -deps -test -f $MODFMT all +cmp stdout out-117.txt + + +# If we explicitly drop compatibility with 1.16, we retain fewer checksums, +# which gives a cleaner go.sum file but causes 1.16 to fail in readonly mode. + +cp go.mod.orig go.mod +go mod tidy -compat=1.17 +cmp go.mod go.mod.orig + +# Make sure that -diff behaves the same as tidy. +[exec:patch] cp go.mod.orig go.mod +[exec:patch] rm go.sum +[exec:patch] go mod tidy -compat=1.17 -diff +[exec:patch] ! stdout . + +go list -deps -test -f $MODFMT all +cmp stdout out-117.txt + +go mod edit -go=1.16 +! go list -deps -test -f $MODFMT all +stderr -count=1 '^go: example.net/lazy@v0.1.0 requires\n\texample.com/retract/incompatible@v1.0.0: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/retract/incompatible$' + + +-- go.mod -- +// Module m imports packages from the same versions under Go 1.17 +// as under Go 1.16, but under 1.16 its (implicit) external test dependencies +// are higher. +module example.com/m + +go 1.17 + +replace ( + example.net/lazy v0.1.0 => ./lazy + example.net/requireincompatible v0.1.0 => ./requireincompatible +) + +require example.net/lazy v0.1.0 +-- m.go -- +package m + +import _ "example.net/lazy" +-- lazy/go.mod -- +// Module lazy requires example.com/retract/incompatible v1.0.0. +// +// When viewed from the outside it also has a transitive dependency +// on v2.0.0+incompatible, but in lazy mode that transitive dependency +// is pruned out. +module example.net/lazy + +go 1.17 + +exclude example.com/retract/incompatible v2.0.0+incompatible + +require ( + example.com/retract/incompatible v1.0.0 + example.net/requireincompatible v0.1.0 +) +-- lazy/lazy.go -- +package lazy +-- lazy/unimported/unimported.go -- +package unimported + +import _ "example.com/retract/incompatible" +-- requireincompatible/go.mod -- +module example.net/requireincompatible + +go 1.15 + +require example.com/retract/incompatible v2.0.0+incompatible diff --git a/go/src/cmd/go/testdata/script/mod_tidy_convergence.txt b/go/src/cmd/go/testdata/script/mod_tidy_convergence.txt new file mode 100644 index 0000000000000000000000000000000000000000..45f74b43672342ebd2d3e12f11ddd82b79b26818 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_convergence.txt @@ -0,0 +1,202 @@ +# This test demonstrates a simple case in which 'go mod tidy' may resolve a +# missing package, only to remove that package when resolving its dependencies. +# +# If we naively iterate 'go mod tidy' until the dependency graph converges, this +# scenario may fail to converge. + +# The import graph used in this test looks like: +# +# m --- x +# | +# x_test --- y +# +# The module dependency graph of m is initially empty. +# Modules x and y look like: +# +# x.1 (provides package x that imports y, but does not depend on module y) +# +# x.2-pre (no dependencies, but does not provide package x) +# +# y.1 (no dependencies, but provides package y) +# +# y.2 --- x.2-pre (provides package y) +# +# +# When we resolve the missing import of y in x_test, we add y@latest — which is +# y.2, not y.1 — as a new dependency. That upgrades to x to x.2-pre, which +# removes package x (and also the need for module y). We can then safely remove +# the dependency on module y, because nothing imports package y any more! +# +# We might be tempted to remove the dependency on module x for the same reason: +# it no longer provides any imported package. However, that would cause 'go mod +# tidy -e' to become unstable: with x.2-pre out of the way, we could once again +# resolve the missing import of package x by re-adding x.1. + +cp go.mod go.mod.orig + +# 'go mod tidy' without -e should fail without modifying go.mod, +# because it cannot resolve x and y simultaneously. +! go mod tidy + +cmp go.mod go.mod.orig + +stderr '^go: found example\.net/y in example\.net/y v0.2.0$' +stderr '^go: finding module for package example\.net/x$' + + # TODO: This error message should be clearer — it doesn't indicate why v0.2.0-pre is required. +stderr '^go: example\.net/m imports\n\texample\.net/x: package example\.net/x provided by example\.net/x at latest version v0\.1\.0 but not at required version v0\.2\.0-pre$' + + +# 'go mod tidy -e' should follow upgrades to try to resolve the modules that it +# can, and then stop. When we resolve example.net/y, we upgrade to example.net/x +# to v0.2.0-pre. At that version, package x no longer exists and no longer +# imports package y, so the import of x should be left unsatisfied and the +# existing dependency on example.net/x removed. +# +# TODO(bcmills): It would be ever better if we could keep the original +# dependency on example.net/x v0.1.0, but I don't see a way to do that without +# making the algorithm way too complicated. (We would have to detect that the +# new dependency on example.net/y interferes with the package that caused us to +# to add that dependency in the first place, and back out that part of the change +# without also backing out any other needed changes.) + +go mod tidy -e +cmp go.mod go.mod.tidye +stderr '^go: found example\.net/y in example\.net/y v0.2.0$' + + # TODO: This error message should be clearer — it doesn't indicate why v0.2.0-pre is required. +stderr '^go: example\.net/m imports\n\texample\.net/x: package example\.net/x provided by example\.net/x at latest version v0\.1\.0 but not at required version v0\.2\.0-pre$' + + +# Since we attempt to resolve the dependencies of package x whenever we add x itself, +# this end state is stable. + +go mod tidy -e +cmp go.mod go.mod.tidye + + +# An explicit 'go get' with the correct versions should allow 'go mod tidy' to +# succeed and remain stable. y.1 does not upgrade x, and can therefore be used +# with it. + +go get example.net/x@v0.1.0 example.net/y@v0.1.0 +go mod tidy +cmp go.mod go.mod.postget + + +# The 'tidy' logic for a lazy main module is somewhat different from that for an +# eager main module, but the overall behavior is the same. + +cp go.mod.orig go.mod +go mod edit -go=1.17 go.mod +go mod edit -go=1.17 go.mod.tidye + +go mod tidy -e +cmp go.mod go.mod.tidye +stderr '^go: found example\.net/y in example\.net/y v0.2.0$' +stderr '^go: example\.net/m imports\n\texample\.net/x: package example\.net/x provided by example\.net/x at latest version v0\.1\.0 but not at required version v0\.2\.0-pre$' + +go get example.net/x@v0.1.0 example.net/y@v0.1.0 +go mod tidy +cmp go.mod go.mod.postget-117 + + +-- go.mod -- +module example.net/m + +go 1.16 + +replace ( + example.net/x v0.1.0 => ./x1 + example.net/x v0.2.0-pre => ./x2-pre + example.net/y v0.1.0 => ./y1 + example.net/y v0.2.0 => ./y2 +) + +require ( + example.net/x v0.1.0 +) +-- go.mod.tidye -- +module example.net/m + +go 1.16 + +replace ( + example.net/x v0.1.0 => ./x1 + example.net/x v0.2.0-pre => ./x2-pre + example.net/y v0.1.0 => ./y1 + example.net/y v0.2.0 => ./y2 +) +-- go.mod.postget -- +module example.net/m + +go 1.16 + +replace ( + example.net/x v0.1.0 => ./x1 + example.net/x v0.2.0-pre => ./x2-pre + example.net/y v0.1.0 => ./y1 + example.net/y v0.2.0 => ./y2 +) + +require ( + example.net/x v0.1.0 + example.net/y v0.1.0 // indirect +) +-- go.mod.postget-117 -- +module example.net/m + +go 1.17 + +replace ( + example.net/x v0.1.0 => ./x1 + example.net/x v0.2.0-pre => ./x2-pre + example.net/y v0.1.0 => ./y1 + example.net/y v0.2.0 => ./y2 +) + +require example.net/x v0.1.0 + +require example.net/y v0.1.0 // indirect +-- m.go -- +package m + +import _ "example.net/x" + +-- x1/go.mod -- +module example.net/x + +go 1.16 +-- x1/x.go -- +package x +-- x1/x_test.go -- +package x + +import _ "example.net/y" + +-- x2-pre/go.mod -- +module example.net/x + +go 1.16 +-- x2-pre/README.txt -- +There is no package x here. Use example.com/x/subpkg instead. +-- x2-pre/subpkg/subpkg.go -- +package subpkg // import "example.net/x/subpkg" + +-- y1/go.mod -- +module example.net/y + +go 1.16 +-- y1/y.go -- +package y + +-- y2/go.mod -- +module example.net/y + +go 1.16 + +require example.net/x v0.2.0-pre +-- y2/y.go -- +package y + +import _ "example.net/x/subpkg" diff --git a/go/src/cmd/go/testdata/script/mod_tidy_convergence_loop.txt b/go/src/cmd/go/testdata/script/mod_tidy_convergence_loop.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec58159702794b2f39ec9f7c168667d35f7da539 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_convergence_loop.txt @@ -0,0 +1,329 @@ +# This test demonstrates a simple case in which 'go mod tidy' may resolve a +# missing package, only to remove that package when resolving its dependencies. +# +# If we naively iterate 'go mod tidy' until the dependency graph converges, this +# scenario may fail to converge. + +# The import graph used in this test looks like: +# +# m --- w +# | +# + --- x +# | +# + --- y +# | +# + --- z +# +# The module dependency graph of m initially contains w.1 (and, by extension, +# y.2-pre and z.2-pre). This is an arbitrary point in the cycle of possible +# configurations. +# +# w.1 requires y.2-pre and z.2-pre +# x.1 requires z.2-pre and w.2-pre +# y.1 requires w.2-pre and x.2-pre +# z.1 requires x.2-pre and y.2-pre +# +# At each point, exactly one missing package can be resolved by adding a +# dependency on the .1 release of the module that provides that package. +# However, adding that dependency causes the module providing another package to +# roll over from its .1 release to its .2-pre release, which removes the +# package. Once the package is removed, 'go mod tidy -e' no longer sees the +# module as relevant to the main module, and will happily remove the existing +# dependency on it. +# +# The cycle is of length 4 so that at every step only one package can be +# resolved. This is important because it prevents the iteration from ever +# reaching a state in which every package is simultaneously over-upgraded — such +# a state is stable and does not exhibit failure to converge. + +cp go.mod go.mod.orig + +# 'go mod tidy' without -e should fail without modifying go.mod, +# because it cannot resolve x, y, and z simultaneously. +! go mod tidy + +cmp go.mod go.mod.orig + +stderr '^go: finding module for package example\.net/w$' +stderr '^go: finding module for package example\.net/x$' +stderr -count=2 '^go: finding module for package example\.net/y$' +stderr -count=2 '^go: finding module for package example\.net/z$' +stderr '^go: found example\.net/x in example\.net/x v0.1.0$' + + # TODO: These error messages should be clearer — it doesn't indicate why v0.2.0-pre is required. +stderr '^go: example\.net/m imports\n\texample\.net/w: package example\.net/w provided by example\.net/w at latest version v0\.1\.0 but not at required version v0\.2\.0-pre$' +stderr '^go: example\.net/m imports\n\texample\.net/y: package example\.net/y provided by example\.net/y at latest version v0\.1\.0 but not at required version v0\.2\.0-pre$' +stderr '^go: example\.net/m imports\n\texample\.net/z: package example\.net/z provided by example\.net/z at latest version v0\.1\.0 but not at required version v0\.2\.0-pre$' + + +# 'go mod tidy -e' should preserve all of the upgrades to modules that could +# provide the missing packages but don't. That would at least explain why they +# are missing, and why no individual module can be upgraded in order to satisfy +# a missing import. +# +# TODO(bcmills): Today, it doesn't preserve those upgrades, and instead advances +# the state by one through the cycle of semi-tidy states. + +go mod tidy -e + +cmp go.mod go.mod.tidye1 + +stderr '^go: finding module for package example\.net/w$' +stderr '^go: finding module for package example\.net/x$' +stderr -count=2 '^go: finding module for package example\.net/y$' +stderr -count=2 '^go: finding module for package example\.net/z$' +stderr '^go: found example\.net/x in example\.net/x v0.1.0$' + +stderr '^go: example\.net/m imports\n\texample\.net/w: package example\.net/w provided by example\.net/w at latest version v0\.1\.0 but not at required version v0\.2\.0-pre$' +stderr '^go: example\.net/m imports\n\texample\.net/y: package example\.net/y provided by example\.net/y at latest version v0\.1\.0 but not at required version v0\.2\.0-pre$' +stderr '^go: example\.net/m imports\n\texample\.net/z: package example\.net/z provided by example\.net/z at latest version v0\.1\.0 but not at required version v0\.2\.0-pre$' + + +go mod tidy -e +cmp go.mod go.mod.tidye2 + +go mod tidy -e +cmp go.mod go.mod.tidye3 + +go mod tidy -e +cmp go.mod go.mod.orig + + +# If we upgrade away all of the packages simultaneously, the resulting tidy +# state converges at "no dependencies", because simultaneously adding all of the +# packages simultaneously over-upgrades all of the dependencies, and 'go mod +# tidy' treats "no package can be added" as a terminal state. + +go get example.net/w@v0.2.0-pre example.net/x@v0.2.0-pre example.net/y@v0.2.0-pre example.net/z@v0.2.0-pre +go mod tidy -e +cmp go.mod go.mod.postget +go mod tidy -e +cmp go.mod go.mod.postget + + +# The 'tidy' logic for a lazy main module requires more iterations to converge, +# because it is willing to drop dependencies on non-root modules that do not +# otherwise provide imported packages. +# +# On the first iteration, it adds x.1 as a root, which upgrades z and w, +# dropping w.1's requirement on y. w.1 was initially a root, so the upgraded +# w.2-pre is retained as a root. +# +# On the second iteration, it adds y.1 as a root, which upgrades w and x, +# dropping x.1's requirement on z. x.1 was added as a root in the previous step, +# so the upgraded x.2-pre is retained as a root. +# +# On the third iteration, it adds z.1 as a root, which upgrades x and y. +# x and y were already roots (from the previous steps), so their upgraded versions +# are retained (not dropped) and the iteration stops. +# +# At that point, we have z.1 as a root providing package z, +# and w, x, and y have all been upgraded to no longer provide any packages. +# So only z is retained as a new root. +# +# (From the above, we can see that in a lazy module we still cycle through the +# same possible root states, but in a different order from the eager case.) +# +# TODO(bcmills): if we retained the upgrades on w, x, and y (since they are +# lexical prefixes for unresolved packages w, x, and y, respectively), then 'go +# mod tidy -e' itself would become stable and no longer cycle through states. + +cp go.mod.orig go.mod +go mod edit -go=1.17 go.mod +cp go.mod go.mod.117 +go mod edit -go=1.17 go.mod.tidye1 +go mod edit -go=1.17 go.mod.tidye2 +go mod edit -go=1.17 go.mod.tidye3 +go mod edit -go=1.17 go.mod.postget + +go list -m all + +go mod tidy -e +cmp go.mod go.mod.tidye3 + +go mod tidy -e +cmp go.mod go.mod.tidye2 + +go mod tidy -e +cmp go.mod go.mod.tidye1 + +go mod tidy -e +cmp go.mod go.mod.117 + + +# As in the eager case, for the lazy module the fully-upgraded dependency graph +# becomes empty, and the empty graph is stable. + +go get example.net/w@v0.2.0-pre example.net/x@v0.2.0-pre example.net/y@v0.2.0-pre example.net/z@v0.2.0-pre +go mod tidy -e +cmp go.mod go.mod.postget +go mod tidy -e +cmp go.mod go.mod.postget + + +-- m.go -- +package m + +import ( + _ "example.net/w" + _ "example.net/x" + _ "example.net/y" + _ "example.net/z" +) + +-- go.mod -- +module example.net/m + +go 1.16 + +replace ( + example.net/w v0.1.0 => ./w1 + example.net/w v0.2.0-pre => ./w2-pre + example.net/x v0.1.0 => ./x1 + example.net/x v0.2.0-pre => ./x2-pre + example.net/y v0.1.0 => ./y1 + example.net/y v0.2.0-pre => ./y2-pre + example.net/z v0.1.0 => ./z1 + example.net/z v0.2.0-pre => ./z2-pre +) + +require example.net/w v0.1.0 +-- go.mod.tidye1 -- +module example.net/m + +go 1.16 + +replace ( + example.net/w v0.1.0 => ./w1 + example.net/w v0.2.0-pre => ./w2-pre + example.net/x v0.1.0 => ./x1 + example.net/x v0.2.0-pre => ./x2-pre + example.net/y v0.1.0 => ./y1 + example.net/y v0.2.0-pre => ./y2-pre + example.net/z v0.1.0 => ./z1 + example.net/z v0.2.0-pre => ./z2-pre +) + +require example.net/x v0.1.0 +-- go.mod.tidye2 -- +module example.net/m + +go 1.16 + +replace ( + example.net/w v0.1.0 => ./w1 + example.net/w v0.2.0-pre => ./w2-pre + example.net/x v0.1.0 => ./x1 + example.net/x v0.2.0-pre => ./x2-pre + example.net/y v0.1.0 => ./y1 + example.net/y v0.2.0-pre => ./y2-pre + example.net/z v0.1.0 => ./z1 + example.net/z v0.2.0-pre => ./z2-pre +) + +require example.net/y v0.1.0 +-- go.mod.tidye3 -- +module example.net/m + +go 1.16 + +replace ( + example.net/w v0.1.0 => ./w1 + example.net/w v0.2.0-pre => ./w2-pre + example.net/x v0.1.0 => ./x1 + example.net/x v0.2.0-pre => ./x2-pre + example.net/y v0.1.0 => ./y1 + example.net/y v0.2.0-pre => ./y2-pre + example.net/z v0.1.0 => ./z1 + example.net/z v0.2.0-pre => ./z2-pre +) + +require example.net/z v0.1.0 +-- go.mod.postget -- +module example.net/m + +go 1.16 + +replace ( + example.net/w v0.1.0 => ./w1 + example.net/w v0.2.0-pre => ./w2-pre + example.net/x v0.1.0 => ./x1 + example.net/x v0.2.0-pre => ./x2-pre + example.net/y v0.1.0 => ./y1 + example.net/y v0.2.0-pre => ./y2-pre + example.net/z v0.1.0 => ./z1 + example.net/z v0.2.0-pre => ./z2-pre +) +-- w1/go.mod -- +module example.net/w + +go 1.16 + +require ( + example.net/y v0.2.0-pre + example.net/z v0.2.0-pre +) +-- w1/w.go -- +package w +-- w2-pre/go.mod -- +module example.net/w + +go 1.16 +-- w2-pre/README.txt -- +Package w has been removed. + +-- x1/go.mod -- +module example.net/x + +go 1.16 + +require ( + example.net/z v0.2.0-pre + example.net/w v0.2.0-pre +) +-- x1/x.go -- +package x +-- x2-pre/go.mod -- +module example.net/x + +go 1.16 +-- x2-pre/README.txt -- +Package x has been removed. + +-- y1/go.mod -- +module example.net/y + +go 1.16 + +require ( + example.net/w v0.2.0-pre + example.net/x v0.2.0-pre +) +-- y1/y.go -- +package y + +-- y2-pre/go.mod -- +module example.net/y + +go 1.16 +-- y2-pre/README.txt -- +Package y has been removed. + +-- z1/go.mod -- +module example.net/z + +go 1.16 + +require ( + example.net/x v0.2.0-pre + example.net/y v0.2.0-pre +) +-- z1/z.go -- +package z + +-- z2-pre/go.mod -- +module example.net/z + +go 1.16 +-- z2-pre/README.txt -- +Package z has been removed. diff --git a/go/src/cmd/go/testdata/script/mod_tidy_cycle.txt b/go/src/cmd/go/testdata/script/mod_tidy_cycle.txt new file mode 100644 index 0000000000000000000000000000000000000000..e46f37d7fa287858299b0aa1f2c8c2d04621d255 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_cycle.txt @@ -0,0 +1,75 @@ +# Regression test for https://golang.org/issue/34086: +# 'go mod tidy' produced different go.mod file from other +# subcommands when certain kinds of cycles were present +# in the build graph. + +env GO111MODULE=on + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod go.mod.orig + +# If the go.mod file is already tidy, 'go mod graph' should not modify it. +go mod graph +cmp go.mod go.mod.orig + +-- go.mod -- +module root + +go 1.13 + +replace ( + a v0.1.0 => ./a1 + b v0.1.0 => ./b1 + b v0.2.0 => ./b2 + c v0.1.0 => ./c1 + c v0.2.0 => ./c2 +) + +require ( + a v0.1.0 + b v0.2.0 // indirect +) +-- main.go -- +package main + +import _ "a" + +func main() {} + +-- a1/go.mod -- +module a + +go 1.13 + +require b v0.1.0 +-- a1/a.go -- +package a + +import _ "c" +-- b1/go.mod -- +module b + +go 1.13 + +require c v0.1.0 +-- b2/go.mod -- +module b + +go 1.13 + +require c v0.2.0 +-- c1/go.mod -- +module c + +go 1.13 +-- c2/c.go -- +package c +-- c2/go.mod -- +module c + +go 1.13 + +require b v0.2.0 +-- c2/c.go -- +package c diff --git a/go/src/cmd/go/testdata/script/mod_tidy_diff.txt b/go/src/cmd/go/testdata/script/mod_tidy_diff.txt new file mode 100644 index 0000000000000000000000000000000000000000..23138b70321c515ab48acbec16d4b4e9007c035c --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_diff.txt @@ -0,0 +1,99 @@ +# Test go mod tidy -diff +# If set, -diff should not update go.mod or go.sum and instead return a non-zero exit code if updates are needed. + +# Missing go.mod and go.sum should fail and not display diff. +! exists go.mod +! exists go.sum +! go mod tidy -diff +! exists go.mod +! exists go.sum +! stdout 'diff current/go.mod tidy/go.mod' +! stdout 'diff current/go.sum tidy/go.sum' +stderr 'go.mod file not found' + +# Missing go.mod and existing go.sum should fail and not display diff. +cp go.sum.orig go.sum +! exists go.mod +exists go.sum +! go mod tidy -diff +! exists go.mod +! stdout 'diff current/go.mod tidy/go.mod' +! stdout 'diff current/go.sum tidy/go.sum' +stderr 'go.mod file not found' + +# Existing go.mod and missing go.sum should display diff. +go mod init example.com +go mod tidy +rm go.sum +exists go.mod +! exists go.sum +! go mod tidy -diff +! exists go.sum +! stdout 'diff current/go.mod tidy/go.mod' +stdout 'diff current/go.sum tidy/go.sum' + +# Everything is tidy, should return zero exit code. +go mod tidy +go mod tidy -diff +! stdout 'diff current/go.mod tidy/go.mod' +! stdout 'diff current/go.sum tidy/go.sum' + +# go.mod requires updates, should return non-zero exit code. +cp go.mod.orig go.mod +! go mod tidy -diff +stdout 'diff current/go.mod tidy/go.mod' +! stdout 'diff current/go.sum tidy/go.sum' +cmp go.mod.orig go.mod + +# go.sum requires updates, should return non-zero exit code. +go mod tidy +cp go.sum.orig go.sum +! go mod tidy -diff +! stdout 'diff current/go.mod tidy/go.mod' +stdout 'diff current/go.sum tidy/go.sum' +cmp go.sum.orig go.sum + +# go.mod and go.sum require updates, should return non-zero exit code. +cp go.mod.orig go.mod +cp go.sum.orig go.sum +! go mod tidy -diff +stdout 'diff current/go.mod tidy/go.mod' +stdout 'diff current/go.sum tidy/go.sum' +cmp go.mod.orig go.mod +cmp go.sum.orig go.sum + +# Save the result from running tidy. +[exec:patch] cp go.mod.orig go.mod +[exec:patch] cp go.sum.orig go.sum +[exec:patch] go mod tidy +[exec:patch] cp go.mod go.mod.tidyResult +[exec:patch] cp go.sum go.sum.tidyResult + +# Compare output of -diff to running tidy. +# Apply the patch from -diff +[exec:patch] cp go.mod.orig go.mod +[exec:patch] cp go.sum.orig go.sum +[exec:patch] ! go mod tidy -diff +[exec:patch] cp stdout diff.patch +[exec:patch] exec patch -p1 -i diff.patch +[exec:patch] go mod tidy -diff +[exec:patch] ! stdout . +[exec:patch] cmp go.mod go.mod.tidyResult +[exec:patch] cmp go.sum go.sum.tidyResult + + +-- main.go -- +package main + +import "rsc.io/quote" + +func main() { + println(quote.Hello()) +} + +-- go.mod.orig -- +module example.com + +go 1.22 +-- go.sum.orig -- +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= diff --git a/go/src/cmd/go/testdata/script/mod_tidy_downgrade_ambiguous.txt b/go/src/cmd/go/testdata/script/mod_tidy_downgrade_ambiguous.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b508c7ea8a212c37d413ae93b0a6d8193801e1e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_downgrade_ambiguous.txt @@ -0,0 +1,58 @@ +# Verifies golang.org/issue/47738. + +# In this test, the user has rewritten their imports to use rsc.io/quote/v3, +# but their go.mod still requires rsc.io/quote@v1.5.2, and they indirectly +# require rsc.io/quote@v1.5.1 but don't import anything from it. +go list -m -f '{{.Path}}@{{.Version}}{{if .Indirect}} indirect{{end}}' all +stdout '^rsc.io/quote@v1.5.2$' +! stdout 'rsc.io/quote/v3' +go list -e all +! stdout '^rsc.io/quote$' + +# 'go mod tidy' should preserve the requirement on rsc.io/quote but mark it +# indirect. This prevents a downgrade to v1.5.1, which could introduce +# an ambiguity. +go mod tidy +go list -m -f '{{.Path}}@{{.Version}}{{if .Indirect}} indirect{{end}}' all +stdout '^rsc.io/quote@v1.5.2 indirect$' +stdout '^rsc.io/quote/v3@v3.0.0$' + +-- go.mod -- +module use + +go 1.16 + +require ( + old-indirect v0.0.0 + rsc.io/quote v1.5.2 +) + +replace old-indirect v0.0.0 => ./old-indirect +-- go.sum -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.1/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +-- use.go -- +package use + +import ( + _ "old-indirect/empty" + + _ "rsc.io/quote/v3" +) +-- old-indirect/empty/empty.go -- +package empty +-- old-indirect/go.mod -- +module old-indirect + +go 1.16 + +require rsc.io/quote v1.5.1 +-- old-indirect/go.sum -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/go/src/cmd/go/testdata/script/mod_tidy_duplicates.txt b/go/src/cmd/go/testdata/script/mod_tidy_duplicates.txt new file mode 100644 index 0000000000000000000000000000000000000000..d454c8dc829b2125178d536c6b8978cebf7bd98d --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_duplicates.txt @@ -0,0 +1,38 @@ +env GO111MODULE=on + +# Regression test for golang.org/issue/28456: +# 'go mod tidy' should not leave duplicate lines when re-writing the file. + +go mod tidy +cmp go.sum golden.sum + +-- go.mod -- +module use + +go 1.16 + +require rsc.io/quote v1.5.2 + +-- go.sum -- +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/testonly v1.0.0 h1:K/VWHdO+Jv7woUXG0GzVNx1czBXUt3Ib1deaMn+xk64= +rsc.io/testonly v1.0.0/go.mod h1:OqmGbIFOcF+XrFReLOGZ6BhMM7uMBiQwZsyNmh74SzY= +-- golden.sum -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/testonly v1.0.0 h1:K/VWHdO+Jv7woUXG0GzVNx1czBXUt3Ib1deaMn+xk64= +rsc.io/testonly v1.0.0/go.mod h1:OqmGbIFOcF+XrFReLOGZ6BhMM7uMBiQwZsyNmh74SzY= +-- main.go -- +package use + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_tidy_error.txt b/go/src/cmd/go/testdata/script/mod_tidy_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..fc6cd780a88e816e4d85f2d226e999251f4e1609 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_error.txt @@ -0,0 +1,39 @@ +env GO111MODULE=on + +# Regression test for golang.org/issue/27063: +# 'go mod tidy' and 'go mod vendor' should not hide loading errors. + +! go mod tidy +! stderr 'package nonexist is not in std' +stderr '^go: issue27063 imports\n\tnonexist.example.com: cannot find module providing package nonexist.example.com' +stderr '^go: issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: cannot find module providing package other.example.com/nonexist' + +! go mod vendor +! stderr 'package nonexist is not in std' +stderr '^go: issue27063 imports\n\tnonexist.example.com: no required module provides package nonexist.example.com; to add it:\n\tgo get nonexist.example.com$' +stderr '^go: issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: no required module provides package other.example.com/nonexist; to add it:\n\tgo get other.example.com/nonexist$' + +-- go.mod -- +module issue27063 + +go 1.13 + +require issue27063/other v0.0.0 +replace issue27063/other => ./other +-- x.go -- +package main + +import ( + "nonexist" + + "nonexist.example.com" + "issue27063/other" +) + +func main() {} +-- other/go.mod -- +module issue27063/other +-- other/other.go -- +package other + +import "other.example.com/nonexist" diff --git a/go/src/cmd/go/testdata/script/mod_tidy_ignore.txt b/go/src/cmd/go/testdata/script/mod_tidy_ignore.txt new file mode 100644 index 0000000000000000000000000000000000000000..d3019bb467fc0c1e617e100beaca4afe0aadacb4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_ignore.txt @@ -0,0 +1,78 @@ +# go mod tidy should skip 'ignore' directives +# See golang.org/issue/42965 +env ROOT=$WORK${/}gopath${/}src + +# no ignore directive; should not skip any directories. +cp go.mod.orig go.mod +go mod tidy -x +! stderr 'ignoring directory' + +# ignored ./foo should be skipped. +cp go.mod.relative go.mod +go mod tidy -x +stderr 'ignoring directory '$ROOT''${/}'foo' +! stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' +! stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'fo$' + +# ignored foo; any foo should be skipped. +cp go.mod.any go.mod +go mod tidy -x +stderr 'ignoring directory '$ROOT''${/}'foo' +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' +! stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'fo$' + +# non-existent ignore; should not skip any directories. +cp go.mod.dne go.mod +go mod tidy -x +! stderr 'ignoring directory' + +# ignored fo; should not skip foo/ but should skip fo/ +cp go.mod.partial go.mod +go mod tidy -x +stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'fo$' +! stderr 'ignoring directory '$ROOT''${/}'pkg'${/}'foo' +-- foo/secret/secret.go -- +package secret + +const Secret = "this should be ignored" +-- pkg/foo/foo.go -- +package example/pkg/foo + +const Bar = "Hello from foo!" +-- pkg/fo/fo.go -- +package fo + +const Gar = "Hello from fo!" +-- go.mod.orig -- +module example + +go 1.24 +-- go.mod.relative -- +module example + +go 1.24 + +ignore ./foo +-- go.mod.any -- +module example + +go 1.24 + +ignore foo +-- go.mod.dne -- +module example + +go 1.24 + +ignore bar +-- go.mod.partial -- +module example + +go 1.24 + +ignore fo + +-- main.go -- +package main + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_tidy_indirect.txt b/go/src/cmd/go/testdata/script/mod_tidy_indirect.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f092b223bd6357914de5e52b0eab24d094a14d0 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_indirect.txt @@ -0,0 +1,67 @@ +cp go.mod go.mod.orig +go mod tidy +cmp go.mod go.mod.orig + +-- go.mod -- +module example.com/tidy + +go 1.16 + +require ( + example.net/incomplete v0.1.0 + example.net/indirect v0.2.0 // indirect + example.net/toolow v0.1.0 +) + +replace ( + example.net/incomplete v0.1.0 => ./incomplete + example.net/indirect v0.1.0 => ./indirect.1 + example.net/indirect v0.2.0 => ./indirect.2 + example.net/toolow v0.1.0 => ./toolow +) +-- tidy.go -- +package tidy + +import ( + _ "example.net/incomplete" + _ "example.net/toolow" +) + +-- incomplete/go.mod -- +module example.net/incomplete + +go 1.16 + +// This module omits a needed requirement on example.net/indirect. +-- incomplete/incomplete.go -- +package incomplete + +import _ "example.net/indirect/newpkg" + +-- toolow/go.mod -- +module example.net/toolow + +go 1.16 + +require example.net/indirect v0.1.0 +-- toolow/toolow.go -- +package toolow + +import _ "example.net/indirect/oldpkg" + +-- indirect.1/go.mod -- +module example.net/indirect + +go 1.16 +-- indirect.1/oldpkg/oldpkg.go -- +package oldpkg + + +-- indirect.2/go.mod -- +module example.net/indirect + +go 1.16 +-- indirect.2/oldpkg/oldpkg.go -- +package oldpkg +-- indirect.2/newpkg/newpkg.go -- +package newpkg diff --git a/go/src/cmd/go/testdata/script/mod_tidy_issue60313.txt b/go/src/cmd/go/testdata/script/mod_tidy_issue60313.txt new file mode 100644 index 0000000000000000000000000000000000000000..6963994cdfa69178038a6528910fad39640cdc2f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_issue60313.txt @@ -0,0 +1,69 @@ +# Regression test for https://go.dev/issue/60313: 'go mod tidy' did not preserve +# dependencies needed to prevent 'ambiguous import' errors in external test +# dependencies. + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod go.mod.orig + +-- go.mod -- +module example + +go 1.21 + +require ( + example.net/a v0.1.0 + example.net/b v0.1.0 +) + +require example.net/outer/inner v0.1.0 // indirect + +replace ( + example.net/a v0.1.0 => ./a + example.net/b v0.1.0 => ./b + example.net/outer v0.1.0 => ./outer + example.net/outer/inner v0.1.0 => ./inner +) +-- example.go -- +package example + +import ( + _ "example.net/a" + _ "example.net/b" +) +-- a/go.mod -- +module example.net/a + +go 1.21 + +require example.net/outer/inner v0.1.0 +-- a/a.go -- +package a +-- a/a_test.go -- +package a_test + +import _ "example.net/outer/inner" +-- b/go.mod -- +module example.net/b + +go 1.21 + +require example.net/outer v0.1.0 +-- b/b.go -- +package b +-- b/b_test.go -- +package b_test + +import _ "example.net/outer/inner" +-- inner/go.mod -- +module example.net/outer/inner + +go 1.21 +-- inner/inner.go -- +package inner +-- outer/go.mod -- +module example.net/outer + +go 1.21 +-- outer/inner/inner.go -- +package inner diff --git a/go/src/cmd/go/testdata/script/mod_tidy_lazy_self.txt b/go/src/cmd/go/testdata/script/mod_tidy_lazy_self.txt new file mode 100644 index 0000000000000000000000000000000000000000..9abbabd2ebe47345e3e1cbe9067a9e98fcf76b7f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_lazy_self.txt @@ -0,0 +1,66 @@ +# Regression test for https://golang.org/issue/46078: +# 'go mod tidy' should not panic if the main module initially +# requires an older version of itself. + +# A module may require an older version of itself without error. This is +# inconsistent (the required version is never selected), but we still get +# a reproducible build list. +go list -m all +stdout '^golang.org/issue/46078$' + +# 'go mod tidy' should fix this (and not crash). +go mod tidy + + +# We prune out redundant roots very early on in module loading, and at that +# point the indirect requirement on example.net/x v0.1.0 appears to be +# irrelevant. It should be pruned out; when the import of "example.net/x" is +# later resolved, it should resolve at the latest version (v0.2.0), not the +# version implied by the (former) misleading requirement on the older version of +# the main module. + +cmp go.mod go.mod.tidy + + +-- go.mod -- +module golang.org/issue/46078 + +go 1.17 + +replace ( + example.net/x v0.1.0 => ./x + example.net/x v0.2.0 => ./x + golang.org/issue/46078 v0.1.0 => ./old +) + +require golang.org/issue/46078 v0.1.0 +-- go.mod.tidy -- +module golang.org/issue/46078 + +go 1.17 + +replace ( + example.net/x v0.1.0 => ./x + example.net/x v0.2.0 => ./x + golang.org/issue/46078 v0.1.0 => ./old +) + +require example.net/x v0.2.0 +-- issue46078/issue.go -- +package issue46078 + +import _ "example.net/x" + +-- old/go.mod -- +module golang.org/issue/46078 + +go 1.17 + +require example.net/x v0.1.0 + +-- x/go.mod -- +module example.net/x + +go 1.17 +-- x/x.go -- +package x diff --git a/go/src/cmd/go/testdata/script/mod_tidy_newroot.txt b/go/src/cmd/go/testdata/script/mod_tidy_newroot.txt new file mode 100644 index 0000000000000000000000000000000000000000..3abd5ef08a300858080657986c0e403e40d558fa --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_newroot.txt @@ -0,0 +1,82 @@ +# https://golang.org/issue/45952: 'go mod tidy' in an eager module failed due +# to an erroneous check on root completeness. +# +# Per the issue report: +# > It may have to do with: +# > +# > package A imports package B in go.mod, which imports package C in its own go.mod +# > package A drops direct dependency on package B … +# +# We infer from that that package C is still needed by some other indirect +# dependency, and must be at a higher version than what is required by that +# dependency (or else no new root would be needed). An additional package D +# in its own module satisfies that condition, reproducing the bug. + +go mod tidy +cmp go.mod go.mod.tidy + +-- go.mod -- +module example.net/a + +go 1.16 + +require ( + example.net/b v0.1.0 + example.net/d v0.1.0 +) + +replace ( + example.net/b v0.1.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d +) +-- go.mod.tidy -- +module example.net/a + +go 1.16 + +require ( + example.net/c v0.2.0 // indirect + example.net/d v0.1.0 +) + +replace ( + example.net/b v0.1.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d +) +-- a.go -- +package a + +import _ "example.net/d" + +-- b/go.mod -- +module example.net/b + +go 1.16 + +require example.net/c v0.2.0 +-- b/b.go -- +package b + +import _ "example.net/c" + +-- c/go.mod -- +module example.net/c + +go 1.16 +-- c/c.go -- +package c + +-- d/go.mod -- +module example.net/d + +go 1.16 + +require example.net/c v0.1.0 +-- d/d.go -- +package d + +import _ "example.net/c" diff --git a/go/src/cmd/go/testdata/script/mod_tidy_old.txt b/go/src/cmd/go/testdata/script/mod_tidy_old.txt new file mode 100644 index 0000000000000000000000000000000000000000..7428f0ce8ae671a30ed2e4d4e2fe49144b82db20 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_old.txt @@ -0,0 +1,46 @@ +# 'go mod tidy' should remove content sums for module versions that aren't +# in the build list. It should preserve go.mod sums for module versions that +# are in the module graph though. +# Verifies golang.org/issue/33008. +go mod tidy +! grep '^rsc.io/quote v1.5.0 h1:' go.sum +grep '^rsc.io/quote v1.5.0/go.mod h1:' go.sum + +-- go.mod -- +module m + +go 1.15 + +require ( + rsc.io/quote v1.5.2 + example.com/r v0.0.0 +) + +replace example.com/r => ./r + +-- go.sum -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote v1.5.0 h1:6fJa6E+wGadANKkUMlZ0DhXFpoKlslOQDCo259XtdIE= +rsc.io/quote v1.5.0/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= +rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0= +rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/testonly v1.0.0 h1:K/VWHdO+Jv7woUXG0GzVNx1czBXUt3Ib1deaMn+xk64= +rsc.io/testonly v1.0.0/go.mod h1:OqmGbIFOcF+XrFReLOGZ6BhMM7uMBiQwZsyNmh74SzY= + +-- r/go.mod -- +module example.com/r + +require rsc.io/quote v1.5.0 + +-- use.go -- +package use + +import _ "example.com/r" + +-- r/use.go -- +package use + +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_tidy_oldgo.txt b/go/src/cmd/go/testdata/script/mod_tidy_oldgo.txt new file mode 100644 index 0000000000000000000000000000000000000000..0e88b068a76bcfa815521221e8fec344c9a1ec18 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_oldgo.txt @@ -0,0 +1,21 @@ +# Modules were introduced in Go 1.11, but for various reasons users may +# decide to declare a (much!) older go version in their go.mod file. +# Modules with very old versions should not be rejected, and should have +# the same module-graph semantics as in Go 1.11. + +cp go.mod go.mod.orig +go mod tidy +cmp go.mod go.mod.orig + +-- go.mod -- +module example.com/legacy/go1 + +go 1.0 + +require golang.org/x/text v0.3.0 +-- main.go -- +package main + +import _ "golang.org/x/text/language" + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_tidy_quote.txt b/go/src/cmd/go/testdata/script/mod_tidy_quote.txt new file mode 100644 index 0000000000000000000000000000000000000000..423c7c246f9b84acbafee0c13aeea998c26db941 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_quote.txt @@ -0,0 +1,26 @@ +# Check that mod tidy does not introduce repeated +# require statements when input go.mod has quoted requirements. +env GO111MODULE=on + +go mod tidy +grep -count=1 rsc.io/quote go.mod + +cp go.mod2 go.mod +go mod tidy +grep -count=1 rsc.io/quote go.mod + + +-- go.mod -- +module x + +-- x.go -- +package x +import "rsc.io/quote" +func main() { _ = quote.Hello } + +-- go.mod2 -- +module x +require ( + "rsc.io/sampler" v1.3.0 + "rsc.io/quote" v1.5.2 +) diff --git a/go/src/cmd/go/testdata/script/mod_tidy_replace.txt b/go/src/cmd/go/testdata/script/mod_tidy_replace.txt new file mode 100644 index 0000000000000000000000000000000000000000..274f3bf5090f633bde9680ee2efca1819867772f --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_replace.txt @@ -0,0 +1,145 @@ +env GO111MODULE=on +env GOFLAGS=-mod=mod +[short] skip + +# golang.org/issue/30166: 'go mod tidy' should not crash if a replaced module is +# involved in a cycle. +cd cycle +env GOTRACEBACK=off +go mod tidy +cd .. + +# From inside the module, 'go list -m all' should NOT include transitive +# requirements of modules that have been replaced. +go list -m all +stdout 'rsc.io/quote/v3 v3.0.0' +! stdout 'rsc.io/sampler' +! stdout 'golang.org/x/text' + +# From outside the module, 'go list -m all' should include them. +cd outside +go list -m all +stdout 'rsc.io/quote/v3 v3.0.0' +stdout 'rsc.io/sampler v1.3.0' +stdout 'golang.org/x/text' +cd .. + +# 'go list all' should add indirect requirements to satisfy the packages +# imported from replacement modules. +! grep 'rsc.io/sampler' go.mod +! grep 'golang.org/x/text' go.mod +go list all +grep 'rsc.io/sampler' go.mod +grep 'golang.org/x/text' go.mod + +# 'go get' and 'go mod tidy' should follow the requirements of the replacements, +# not the originals, even if that results in a set of versions that are +# misleading or redundant without those replacements. +go get rsc.io/sampler@v1.2.0 +go mod tidy +go list -m all +stdout 'rsc.io/quote/v3 v3.0.0' +stdout 'rsc.io/sampler v1.2.0' +stdout 'golang.org/x/text' + +# The requirements seen from outside may be higher (or lower) +# than those seen from within the module. +grep 'rsc.io/sampler v1.2.0' go.mod +cd outside +go list -m all +stdout 'rsc.io/sampler v1.3.0' +cd .. + +# The same module can't be used as two different paths. +cd multiple-paths +! go mod tidy +stderr 'rsc.io/quote/v3@v3.0.0 used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)' + +-- go.mod -- +module example.com/tidy + +require rsc.io/quote/v3 v3.0.0 +replace rsc.io/quote/v3 => ./not-rsc.io/quote/v3 + +-- imports.go -- +package tidy + +import _ "rsc.io/quote/v3" + +-- outside/go.mod -- +module example.com/tidy/outside + +require example.com/tidy v0.0.0 +replace example.com/tidy => ./.. + +-- not-rsc.io/quote/v3/go.mod -- +module not-rsc.io/quote/v3 + +// No requirements specified! + +-- not-rsc.io/quote/v3/quote.go -- +package quote + +import ( + _ "rsc.io/sampler" + _ "golang.org/x/text/language" +) + +-- cycle/go.mod -- +module golang.org/issue/30166 + +require ( + golang.org/issue/30166/a v0.0.0 + golang.org/issue/30166/b v0.0.0 +) + +replace ( + golang.org/issue/30166/a => ./a + golang.org/issue/30166/b => ./b +) +-- cycle/cycle.go -- +package cycle + +import ( + _ "golang.org/issue/30166/a" + _ "golang.org/issue/30166/b" +) +-- cycle/a/a.go -- +package a +-- cycle/a/go.mod -- +module golang.org/issue/30166/a + +require golang.org/issue/30166/b v0.0.0 +-- cycle/b/b.go -- +package b +-- cycle/b/go.mod -- +module golang.org/issue/30166/b + +require golang.org/issue/30166/a v0.0.0 +-- multiple-paths/main.go -- +package main + +import ( + "fmt" + "rsc.io/quote/v3" +) + +func main() { + fmt.Println(quote.GoV3()) +} +-- multiple-paths/go.mod -- +module quoter + +require ( + rsc.io/quote/v3 v3.0.0 + not-rsc.io/quote/v3 v3.0.0 +) + +replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0 +-- multiple-paths/use.go -- +package quoter + +import ( + _ "not-rsc.io/quote/v3" + _ "rsc.io/quote/v3" +) diff --git a/go/src/cmd/go/testdata/script/mod_tidy_replace_old.txt b/go/src/cmd/go/testdata/script/mod_tidy_replace_old.txt new file mode 100644 index 0000000000000000000000000000000000000000..18605b1781e976bf338b521bc3dbd12f0c29ef2b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_replace_old.txt @@ -0,0 +1,34 @@ +# Regression test for https://golang.org/issue/46659. +# +# If a 'replace' directive specifies an older-than-selected version of a module, +# 'go mod tidy' shouldn't try to add that version to the build list to resolve a +# missing package: it won't be selected, and would cause the module loader to +# loop indefinitely trying to resolve the package. + +cp go.mod go.mod.orig + +! go mod tidy +! stderr panic +stderr '^go: golang\.org/issue46659 imports\n\texample\.com/missingpkg/deprecated: package example\.com/missingpkg/deprecated provided by example\.com/missingpkg at latest version v1\.0\.0 but not at required version v1\.0\.1-beta$' + +go mod tidy -e + +cmp go.mod go.mod.orig + +-- go.mod -- +module golang.org/issue46659 + +go 1.17 + +replace example.com/missingpkg v1.0.1-alpha => example.com/missingpkg v1.0.0 + +require example.com/usemissingpre v1.0.0 + +require example.com/missingpkg v1.0.1-beta // indirect +-- m.go -- +package m + +import ( + _ "example.com/missingpkg/deprecated" + _ "example.com/usemissingpre" +) diff --git a/go/src/cmd/go/testdata/script/mod_tidy_sum.txt b/go/src/cmd/go/testdata/script/mod_tidy_sum.txt new file mode 100644 index 0000000000000000000000000000000000000000..5a15818543ef2c4318d4f059624001ebc7d273df --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_sum.txt @@ -0,0 +1,33 @@ +env GO111MODULE=on + +# go.sum should list directly used modules and dependencies +go get rsc.io/quote@v1.5.2 +go mod tidy +grep rsc.io/sampler go.sum + +# go.sum should not normally lose old entries +go get rsc.io/quote@v1.0.0 +grep 'rsc.io/quote v1.0.0' go.sum +grep 'rsc.io/quote v1.5.2' go.sum +grep rsc.io/sampler go.sum + +# go mod tidy should clear dead entries from go.sum +go mod tidy +grep 'rsc.io/quote v1.0.0' go.sum +! grep 'rsc.io/quote v1.5.2' go.sum +! grep rsc.io/sampler go.sum + +# go.sum with no entries is OK to keep +# (better for version control not to delete and recreate.) +cp x.go.noimports x.go +go mod tidy +exists go.sum +! grep . go.sum + +-- go.mod -- +module x +-- x.go -- +package x +import _ "rsc.io/quote" +-- x.go.noimports -- +package x diff --git a/go/src/cmd/go/testdata/script/mod_tidy_support_buildx.txt b/go/src/cmd/go/testdata/script/mod_tidy_support_buildx.txt new file mode 100644 index 0000000000000000000000000000000000000000..d2135e1fff356bece05a0d35b90cdef0162da499 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_support_buildx.txt @@ -0,0 +1,18 @@ +# This test checks that "go mod tidy -x" print +# commands tidy executes. +# Verifies golang.org/issue/35849 + +rm $GOPATH/pkg/mod/cache/download/rsc.io/quote +go mod tidy +! stderr 'get '$GOPROXY + +rm $GOPATH/pkg/mod/cache/download/rsc.io/quote +go mod tidy -x +stderr 'get '$GOPROXY + +-- go.mod -- +module example.com/mod + +-- a.go -- +package mod +import _ "rsc.io/quote" \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_tidy_symlink_issue35941.txt b/go/src/cmd/go/testdata/script/mod_tidy_symlink_issue35941.txt new file mode 100644 index 0000000000000000000000000000000000000000..d4658c65d40c4e389242bc38e7ce8497dc6ec22e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_symlink_issue35941.txt @@ -0,0 +1,36 @@ +env GO111MODULE=on +[!symlink] skip + +cd m +symlink symlink -> ../outside + +cp go.mod go.mod.orig + +# Issue 35941: suppress symlink warnings when running 'go mod tidy'. +# 'go mod tidy' should not scan packages in symlinked subdirectories. +go mod tidy +! stderr 'warning: ignoring symlink' +cmp go.mod go.mod.orig + +! go build ./symlink +stderr '^symlink[\\/]symlink.go:3:8: module example.net/unresolved provides package example.net/unresolved and is replaced but not required; to add it:\n\tgo get example.net/unresolved@v0.1.0$' + +-- m/go.mod -- +module example.net/m + +go 1.16 + +replace example.net/unresolved v0.1.0 => ../unresolved +-- m/a.go -- +package a +-- outside/symlink.go -- +package symlink + +import _ "example.net/unresolved" +-- unresolved/go.mod -- +module example.net/unresolved + +go 1.16 +-- unresolved/unresolved.go -- +// Package unresolved exists, but 'go mod tidy' won't add it. +package unresolved diff --git a/go/src/cmd/go/testdata/script/mod_tidy_temp.txt b/go/src/cmd/go/testdata/script/mod_tidy_temp.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a2fa4ec10449120fb51db94ed4738f8273d3bd3 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_temp.txt @@ -0,0 +1,26 @@ +# Regression test for https://go.dev/issue/51992 + +# 'go mod tidy' should error instead of throwing panic in the situation below. +# 1. /tmp/go.mod exists +# 2. run 'go mod tidy' in /tmp or in the child directory not having go.mod. + +[GOOS:plan9] stop # Plan 9 has no $TMPDIR variable to set. + +env GOROOT=$TESTGO_GOROOT +env TMP=$WORK +env TMPDIR=$WORK +mkdir $WORK/child + +! go mod tidy +! stdout . +stderr 'go: go.mod file not found in current directory or any parent directory' + +cd $WORK/child +! go mod tidy +! stdout . +stderr 'go: go.mod file not found in current directory or any parent directory' + +-- $WORK/go.mod -- +module issue51992 + +go 1.18 diff --git a/go/src/cmd/go/testdata/script/mod_tidy_version.txt b/go/src/cmd/go/testdata/script/mod_tidy_version.txt new file mode 100644 index 0000000000000000000000000000000000000000..e86a9d9cbffe4e5918acbb5342e42e203188b5de --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_version.txt @@ -0,0 +1,392 @@ +# https://golang.org/issue/45094: 'go mod tidy' now accepts a '-go' flag +# to change the language version in use. +# +# The package import graph used in this test looks like: +# +# m --- a --- b +# | +# b_test --- c +# | +# c_test --- d +# +# The module diagram looks like: +# +# m --- a --- b +# | +# + --- c +# | +# + --- d +# +# Module b omits its dependency on c, and module c omits its dependency on d. +# +# In go 1.15, the tidy main module must require a (because it is direct), +# c (because it is a missing test dependency of an imported package), +# and d (because it is a missing transitive test dependency). +# +# In go 1.16, the tidy main module can omit d because it is no longer +# included in "all". +# +# In go 1.17, the main module must explicitly require b +# (because it is transitively imported by the main module). + +cp go.mod go.mod.orig + + # Pretend we're a release version so that we can theoretically + # write our version in toolchain lines. +env goversion=1.99.0 +env TESTGO_VERSION=go${goversion} + +# An invalid argument should be rejected. + +! go mod tidy -go=bananas +stderr '^invalid value "bananas" for flag -go: expecting a Go version like "'$goversion'"$' +cmp go.mod go.mod.orig + +! go mod tidy -go=0.9 +stderr '^invalid value "0.9" for flag -go: expecting a Go version like "'$goversion'"$' + +! go mod tidy -go=2000.0 +stderr '^invalid value "2000.0" for flag -go: maximum supported Go version is '$goversion'$' + + +# Supported versions should change the go.mod file to be tidy according to the +# indicated version. + +go mod tidy -go=1.15 +cmp go.mod go.mod.115 + +go mod tidy +cmp go.mod go.mod.115 + + +go mod tidy -go=1.16 +cmp go.mod go.mod.116 + +go mod tidy +cmp go.mod go.mod.116 + + +go mod tidy -go=1.17 +cmp go.mod go.mod.117 + +go mod tidy +cmp go.mod go.mod.117 + + +# If we downgrade back to 1.15, we should re-resolve d to v0.2.0 instead +# of the original v0.1.0 (because the original requirement is lost). + +go mod tidy -go=1.15 +cmp go.mod go.mod.115-2 + + +# -go= (with an empty argument) maintains the existing version or adds the +# default version (just like omitting the flag). + +go mod tidy -go='' +cmp go.mod go.mod.115-2 + +cp go.mod.orig go.mod +go mod tidy -go='' +cmpenv go.mod go.mod.latest + +# Repeat with go get go@ instead of mod tidy. + +# Go 1.16 -> 1.17 should be a no-op. +cp go.mod.116 go.mod +go get go@1.16 +cmp go.mod go.mod.116 + +# Go 1.17 -> 1.16 should leave b (go get is not tidy). +cp go.mod.117 go.mod +go get go@1.16 +cmp go.mod go.mod.116from117 + +# Go 1.15 -> 1.16 should leave d (go get is not tidy). +cp go.mod.115 go.mod +go get go@1.16 +cmp go.mod go.mod.116from115 + +# Go 1.16 -> 1.17 should add b. +cp go.mod.116 go.mod +go get go@1.17 +stderr '^\tnote: expanded dependencies to upgrade to go 1.17 or higher; run ''go mod tidy'' to clean up' +cmp go.mod go.mod.117 + +# Go 1.16 -> 1.15 should add d, +# but 'go get' doesn't load enough packages to know that. +# (This leaves the module untidy, but the user can fix it by running 'go mod tidy'.) +cp go.mod.116 go.mod +go get go@1.15 toolchain@none +cmp go.mod go.mod.115from116 +go mod tidy +cmp go.mod go.mod.115-2 + +# Updating the go line to 1.21 or higher also updates the toolchain line, +# only if the toolchain is higher than what would be implied by the go line. + +cp go.mod.117 go.mod +go mod tidy -go=$goversion +cmpenv go.mod go.mod.latest + +cp go.mod.117 go.mod +go mod tidy -go=1.21.0 # lower than $goversion +cmp go.mod go.mod.121toolchain + + +-- go.mod -- +module example.com/m + +require example.net/a v0.1.0 + +require ( + example.net/c v0.1.0 // indirect + example.net/d v0.1.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a + example.net/a v0.2.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d + example.net/d v0.2.0 => ./d +) +-- m.go -- +package m + +import _ "example.net/a" + +-- go.mod.115 -- +module example.com/m + +go 1.15 + +require example.net/a v0.1.0 + +require ( + example.net/c v0.1.0 // indirect + example.net/d v0.1.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a + example.net/a v0.2.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d + example.net/d v0.2.0 => ./d +) +-- go.mod.115from116 -- +module example.com/m + +go 1.15 + +require example.net/a v0.1.0 + +require example.net/c v0.1.0 // indirect + +replace ( + example.net/a v0.1.0 => ./a + example.net/a v0.2.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d + example.net/d v0.2.0 => ./d +) +-- go.mod.116from115 -- +module example.com/m + +go 1.16 + +require example.net/a v0.1.0 + +require ( + example.net/c v0.1.0 // indirect + example.net/d v0.1.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a + example.net/a v0.2.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d + example.net/d v0.2.0 => ./d +) +-- go.mod.115-2 -- +module example.com/m + +go 1.15 + +require example.net/a v0.1.0 + +require ( + example.net/c v0.1.0 // indirect + example.net/d v0.2.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a + example.net/a v0.2.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d + example.net/d v0.2.0 => ./d +) +-- go.mod.116 -- +module example.com/m + +go 1.16 + +require example.net/a v0.1.0 + +require example.net/c v0.1.0 // indirect + +replace ( + example.net/a v0.1.0 => ./a + example.net/a v0.2.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d + example.net/d v0.2.0 => ./d +) +-- go.mod.117 -- +module example.com/m + +go 1.17 + +require example.net/a v0.1.0 + +require ( + example.net/b v0.1.0 // indirect + example.net/c v0.1.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a + example.net/a v0.2.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d + example.net/d v0.2.0 => ./d +) +-- go.mod.116from117 -- +module example.com/m + +go 1.16 + +require example.net/a v0.1.0 + +require ( + example.net/b v0.1.0 // indirect + example.net/c v0.1.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a + example.net/a v0.2.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d + example.net/d v0.2.0 => ./d +) +-- go.mod.latest -- +module example.com/m + +go $goversion + +require example.net/a v0.1.0 + +require ( + example.net/b v0.1.0 // indirect + example.net/c v0.1.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a + example.net/a v0.2.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d + example.net/d v0.2.0 => ./d +) +-- go.mod.121toolchain -- +module example.com/m + +go 1.21.0 + +require example.net/a v0.1.0 + +require ( + example.net/b v0.1.0 // indirect + example.net/c v0.1.0 // indirect +) + +replace ( + example.net/a v0.1.0 => ./a + example.net/a v0.2.0 => ./a + example.net/b v0.1.0 => ./b + example.net/b v0.2.0 => ./b + example.net/c v0.1.0 => ./c + example.net/c v0.2.0 => ./c + example.net/d v0.1.0 => ./d + example.net/d v0.2.0 => ./d +) +-- a/go.mod -- +module example.net/a + +go 1.15 + +require example.net/b v0.1.0 +-- a/a.go -- +package a + +import _ "example.net/b" + +-- b/go.mod -- +module example.net/b + +go 1.15 +-- b/b.go -- +package b +-- b/b_test.go -- +package b_test + +import _ "example.net/c" + +-- c/go.mod -- +module example.net/c + +go 1.15 +-- c/c.go -- +package c +-- c/c_test.go -- +package c_test + +import _ "example.net/d" + +-- d/go.mod -- +module example.net/d + +go 1.15 +-- d/d.go -- +package d diff --git a/go/src/cmd/go/testdata/script/mod_tidy_version_tooold.txt b/go/src/cmd/go/testdata/script/mod_tidy_version_tooold.txt new file mode 100644 index 0000000000000000000000000000000000000000..713ef1a07a39b4efc90cf0d22f669695c90afda8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tidy_version_tooold.txt @@ -0,0 +1,23 @@ +env TESTGO_VERSION=go1.22.0 + +! go mod tidy -go=1.21 +stderr '^go: example.net/a@v0.1.0 requires go@1.22, but 1.21 is requested$' + +-- go.mod -- +module example + +go 1.22 + +require example.net/a v0.1.0 + +replace example.net/a v0.1.0 => ./a +-- example.go -- +package example + +import "example.net/a" +-- a/go.mod -- +module example.net/a + +go 1.22 +-- a/a.go -- +package a diff --git a/go/src/cmd/go/testdata/script/mod_tool_70582.txt b/go/src/cmd/go/testdata/script/mod_tool_70582.txt new file mode 100644 index 0000000000000000000000000000000000000000..7e2831783ad9095a54831d492967a7be17344f3a --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_tool_70582.txt @@ -0,0 +1,9 @@ +! go list all +stderr 'no required module provides package example.com/tools/cmd/hello' + +-- go.mod -- +go 1.24 + +module example.com/foo + +tool example.com/tools/cmd/hello diff --git a/go/src/cmd/go/testdata/script/mod_toolchain.txt b/go/src/cmd/go/testdata/script/mod_toolchain.txt new file mode 100644 index 0000000000000000000000000000000000000000..e96dfbcd8455c3ff7a850e863acd96a437b8e0ef --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_toolchain.txt @@ -0,0 +1,83 @@ +env TESTGO_VERSION=go1.100.0 +env TESTGO_VERSION_SWITCH=switch + +go get toolchain@go1.22.1 +stderr '^go: added toolchain go1.22.1$' +! stderr '(added|removed|upgraded|downgraded) go' +grep 'toolchain go1.22.1' go.mod + +go get toolchain@none +stderr '^go: removed toolchain go1.22.1$' +! stderr '(added|removed|upgraded|downgraded) go' +! grep toolchain go.mod + +go get toolchain@go1.22.1 +stderr '^go: added toolchain go1.22.1$' +! stderr '(added|removed|upgraded|downgraded) go' +grep 'toolchain go1.22.1' go.mod + +go get go@1.22.3 +stderr '^go: upgraded go 1.10 => 1.22.3$' +! stderr '^go: upgraded toolchain$' +grep 'go 1.22.3' go.mod + +go get toolchain@go1.100.0 +stderr '^go: added toolchain go1.100.0$' + +go get go@1.22.3 toolchain@1.22.3 +stderr '^go: removed toolchain go1.100.0$' +! grep toolchain go.mod + +go get go@1.22.1 toolchain@go1.22.3 +stderr '^go: downgraded go 1.22.3 => 1.22.1$' +stderr '^go: added toolchain go1.22.3$' +grep 'go 1.22.1' go.mod +grep 'toolchain go1.22.3' go.mod + +go get go@1.22.3 toolchain@1.22.3 +stderr '^go: upgraded go 1.22.1 => 1.22.3$' +stderr '^go: removed toolchain go1.22.3$' +grep 'go 1.22.3' go.mod +! grep toolchain go.mod + +go get toolchain@1.22.1 +stderr '^go: downgraded go 1.22.3 => 1.22.1$' +! stderr toolchain # already gone, was not added +grep 'go 1.22.1' go.mod +! grep toolchain go.mod + +env TESTGO_VERSION=go1.22.1 +env GOTOOLCHAIN=local +! go get go@1.22.3 +stderr 'go: updating go.mod requires go >= 1.22.3 \(running go 1.22.1; GOTOOLCHAIN=local\)$' + +env TESTGO_VERSION=go1.30 +go get toolchain@1.22.3 +grep 'toolchain go1.22.3' go.mod + +go get go@1.22.1 +grep 'go 1.22.1' go.mod +go get m2@v1.0.0 +stderr '^go: upgraded go 1.22.1 => 1.23$' +stderr '^go: added m2 v1.0.0$' +grep 'go 1.23$' go.mod + +go get toolchain@go1.23.9 go@1.23.5 +go get toolchain@none +stderr '^go: removed toolchain go1.23.9' +! stderr ' go 1' +grep 'go 1.23.5' go.mod + +go get toolchain@go1.23.0 go@1.22.0 +go get go@1.24.0 +! grep toolchain go.mod + +-- go.mod -- +module m +go 1.10 + +replace m2 v1.0.0 => ./m2 + +-- m2/go.mod -- +module m2 +go 1.23 diff --git a/go/src/cmd/go/testdata/script/mod_toolchain_slash.txt b/go/src/cmd/go/testdata/script/mod_toolchain_slash.txt new file mode 100644 index 0000000000000000000000000000000000000000..bb1f770a6a6256941488c93c132c0dab27103483 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_toolchain_slash.txt @@ -0,0 +1,32 @@ +[!exec:/bin/sh] skip + +chmod 0777 go1.999999-/run.sh +chmod 0777 run.sh + +! go list all +! stdout 'RAN SCRIPT' + +cd subdir +! go list all +! stdout 'RAN SCRIPT' + +-- go.mod -- +module exploit + +go 1.21 +toolchain go1.999999-/run.sh +-- go1.999999-/run.sh -- +#!/bin/sh +printf 'RAN SCRIPT\n' +exit 1 +-- run.sh -- +#!/bin/sh +printf 'RAN SCRIPT\n' +exit 1 +-- subdir/go.mod -- +module exploit + +go 1.21 +toolchain go1.999999-/../../run.sh +-- subdir/go1.999999-/README.txt -- +heh heh heh diff --git a/go/src/cmd/go/testdata/script/mod_unknown_block.txt b/go/src/cmd/go/testdata/script/mod_unknown_block.txt new file mode 100644 index 0000000000000000000000000000000000000000..071269bb8db0ea436871af86be3da466db024ae4 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_unknown_block.txt @@ -0,0 +1,11 @@ +env GOTOOLCHAIN=local +! go list . +stderr 'go: go.mod requires go >= 1.999' + + +-- go.mod -- +module example.com + +go 1.999 + +anewblock foo diff --git a/go/src/cmd/go/testdata/script/mod_update_sum_readonly.txt b/go/src/cmd/go/testdata/script/mod_update_sum_readonly.txt new file mode 100644 index 0000000000000000000000000000000000000000..41f12e4084d1f5d8dfe423ce24e116ed5a266021 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_update_sum_readonly.txt @@ -0,0 +1,34 @@ +# When finding the latest version of a module, we should not download version +# contents. Previously, we downloaded .zip files to determine whether a real +# .mod file was present in order to decide whether +incompatible versions +# could be "latest". +# +# Verifies #47377. + +# rsc.io/breaker has two versions, neither of which has a .mod file. +go list -m -versions rsc.io/breaker +stdout '^rsc.io/breaker v1.0.0 v2.0.0\+incompatible$' +go mod download rsc.io/breaker@v1.0.0 +! grep '^go' $GOPATH/pkg/mod/cache/download/rsc.io/breaker/@v/v1.0.0.mod +go mod download rsc.io/breaker@v2.0.0+incompatible +! grep '^go' $GOPATH/pkg/mod/cache/download/rsc.io/breaker/@v/v2.0.0+incompatible.mod + +# Delete downloaded .zip files. +go clean -modcache + +# Check for updates. +go list -m -u rsc.io/breaker +stdout '^rsc.io/breaker v1.0.0 \[v2.0.0\+incompatible\]$' + +# We should not have downloaded zips. +! exists $GOPATH/pkg/mod/cache/download/rsc.io/breaker/@v/v1.0.0.zip +! exists $GOPATH/pkg/mod/cache/download/rsc.io/breaker/@v/v2.0.0+incompatible.zip + +-- go.mod -- +module m + +go 1.16 + +require rsc.io/breaker v1.0.0 +-- go.sum -- +rsc.io/breaker v1.0.0/go.mod h1:s5yxDXvD88U1/ESC23I2FK3Lkv4YIKaB1ij/Hbm805g= diff --git a/go/src/cmd/go/testdata/script/mod_upgrade_patch.txt b/go/src/cmd/go/testdata/script/mod_upgrade_patch.txt new file mode 100644 index 0000000000000000000000000000000000000000..79a9808ef03796037489e0e44b17a70db4381b54 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_upgrade_patch.txt @@ -0,0 +1,110 @@ +env GO111MODULE=on +[short] skip + +# Initially, we are at v1.0.0 for all dependencies. +go get +cp go.mod go.mod.orig +go list -m all +stdout '^patch.example.com/direct v1.0.0' +stdout '^patch.example.com/indirect v1.0.0' +! stdout '^patch.example.com/depofdirectpatch' + +# @patch should be rejected for modules not already in the build list. +! go get patch.example.com/depofdirectpatch@patch +stderr '^go: can''t query version "patch" of module patch.example.com/depofdirectpatch: no existing version is required$' +cmp go.mod.orig go.mod + +# get -u=patch, with no arguments, should patch-update all dependencies +# of the package in the current directory, pulling in transitive dependencies +# and also patching those. +cp go.mod.orig go.mod +go get -u=patch +go list -m all +stdout '^patch.example.com/direct v1.0.1' +stdout '^patch.example.com/indirect v1.0.1' +stdout '^patch.example.com/depofdirectpatch v1.0.0' + +# 'get all@patch' should patch the modules that provide packages in 'all'. +cp go.mod.orig go.mod +go get all@patch +go list -m all +stdout '^patch.example.com/direct v1.0.1' +stdout '^patch.example.com/indirect v1.0.1' +stdout '^patch.example.com/depofdirectpatch v1.0.0' + +# ...but 'all@patch' should fail if any of the affected modules do not already +# have a selected version. +cp go.mod.orig go.mod +go mod edit -droprequire=patch.example.com/direct +cp go.mod go.mod.dropped +! go get all@patch +stderr '^go: all@patch: can''t query version "patch" of module patch.example.com/direct: no existing version is required$' +cmp go.mod.dropped go.mod + +# Requesting the direct dependency with -u=patch but without an explicit version +# should patch-update it and its dependencies. +cp go.mod.orig go.mod +go get -u=patch patch.example.com/direct +go list -m all +stdout '^patch.example.com/direct v1.0.1' +stdout '^patch.example.com/indirect v1.0.1' +stdout '^patch.example.com/depofdirectpatch v1.0.0' + +# Requesting only the indirect dependency should not update the direct one. +cp go.mod.orig go.mod +go get -u=patch patch.example.com/indirect +go list -m all +stdout '^patch.example.com/direct v1.0.0' +stdout '^patch.example.com/indirect v1.0.1' +! stdout '^patch.example.com/depofdirectpatch' + +# @patch should apply only to the specific module, +# but the result must reflect its upgraded requirements. +cp go.mod.orig go.mod +go get patch.example.com/direct@patch +go list -m all +stdout '^patch.example.com/direct v1.0.1' +stdout '^patch.example.com/indirect v1.0.0' +stdout '^patch.example.com/depofdirectpatch v1.0.0' + +# An explicit @patch should override a general -u. +cp go.mod.orig go.mod +go get -u patch.example.com/direct@patch +go list -m all +stdout '^patch.example.com/direct v1.0.1' +stdout '^patch.example.com/indirect v1.1.0' +stdout '^patch.example.com/depofdirectpatch v1.0.0' + +# An explicit @latest should override a general -u=patch. +cp go.mod.orig go.mod +go get -u=patch patch.example.com/direct@latest +go list -m all +stdout '^patch.example.com/direct v1.1.0' +stdout '^patch.example.com/indirect v1.0.1' +! stdout '^patch.example.com/depofdirectpatch' + +# Standard library packages cannot be upgraded explicitly. +cp go.mod.orig go.mod +! go get cmd/vet@patch +stderr 'go: can''t request explicit version "patch" of standard library package cmd/vet$' + +# However, standard-library packages without explicit versions are fine. +go get -u=patch cmd/go + +# We can upgrade to a new version of a module with no root package. +go get example.com/noroot@v1.0.0 +go list -m all +stdout '^example.com/noroot v1.0.0$' +go get example.com/noroot@patch +go list -m all +stdout '^example.com/noroot v1.0.1$' + + +-- go.mod -- +module x + +require patch.example.com/direct v1.0.0 + +-- main.go -- +package x +import _ "patch.example.com/direct" diff --git a/go/src/cmd/go/testdata/script/mod_vcs_missing.txt b/go/src/cmd/go/testdata/script/mod_vcs_missing.txt new file mode 100644 index 0000000000000000000000000000000000000000..7f63e9de217f53b6fd11b2b89cf7bdd056ee1392 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vcs_missing.txt @@ -0,0 +1,28 @@ +[exec:bzr] skip 'tests NOT having bzr' +[!net:launchpad.net] skip + +env GO111MODULE=on +env GOPROXY=direct + +cd empty +! go get launchpad.net/gocheck +stderr '"bzr": executable file not found' +cd .. + +# 1.11 used to give the cryptic error "cannot find module for path" here, but +# only for a main package. +cd main +! go build -mod=mod +stderr '"bzr": executable file not found' +cd .. + +-- empty/go.mod -- +module m +-- main/go.mod -- +module m +-- main/main.go -- +package main + +import _ "launchpad.net/gocheck" + +func main() {} diff --git a/go/src/cmd/go/testdata/script/mod_vendor.txt b/go/src/cmd/go/testdata/script/mod_vendor.txt new file mode 100644 index 0000000000000000000000000000000000000000..b02341d58d7ee2c5a4cfb856b4b3f7854ad5bd67 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor.txt @@ -0,0 +1,354 @@ +env GO111MODULE=on + +# Without vendoring, a build should succeed unless -mod=vendor is set. +[!short] go build +[!short] ! go build -mod=vendor + +# Without vendoring, 'go list' should report the replacement directory for +# a package in a replaced module. +go list -f {{.Dir}} x +stdout 'src[\\/]x' + +# 'go mod vendor' should copy all replaced modules to the vendor directory. +go mod vendor -v +stderr '^# x v1.0.0 => ./x' +stderr '^x' +stderr '^# y v1.0.0 => ./y' +stderr '^y' +stderr '^# z v1.0.0 => ./z' +stderr '^z' +! stderr '^w' +grep 'a/foo/bar/b\na/foo/bar/c' vendor/modules.txt # must be sorted + +# An explicit '-mod=mod' should ignore the vendor directory. +go list -mod=mod -f {{.Dir}} x +stdout 'src[\\/]x' + +go list -mod=mod -f {{.Dir}} -m x +stdout 'src[\\/]x' + +# An explicit '-mod=vendor' should report package directories within +# the vendor directory. +go list -mod=vendor -f {{.Dir}} x +stdout 'src[\\/]vendor[\\/]x' + +# 'go list -mod=vendor -m' should successfully list vendored modules, +# but should not provide a module directory because no directory contains +# the complete module. +go list -mod=vendor -f '{{.Version}} {{.Dir}}' -m x +stdout '^v1.0.0 $' + +# -mod=vendor should cause 'go list' flags that look up versions to fail. +! go list -mod=vendor -versions -m x +stderr '^go: can''t determine available versions using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$' +! go list -mod=vendor -u -m x +stderr '^go: can''t determine available upgrades using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$' + +# 'go list -mod=vendor -m' on a transitive dependency that does not +# provide vendored packages should give a helpful error rather than +# 'not a known dependency'. +! go list -mod=vendor -f '{{.Version}} {{.Dir}}' -m diamondright +stderr 'go: module diamondright: can''t resolve module using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)' + +# 'go list -mod=mod' should report packages outside the import graph, +# but 'go list -mod=vendor' should error out for them. +go list -mod=mod -f {{.Dir}} w +stdout 'src[\\/]w' +! go list -mod=vendor -f {{.Dir}} w +stderr 'package w is not in std' + +go list -mod=mod -f {{.Dir}} diamondright +stdout 'src[\\/]diamondright' + +# Test dependencies should not be copied. +! exists vendor/x/testdata +! exists vendor/a/foo/bar/b/ignored.go +! exists vendor/a/foo/bar/b/main_test.go + +# Licenses and other metadata for each module should be copied +# if any package within their module is copied. +exists vendor/a/foo/AUTHORS.txt +exists vendor/a/foo/CONTRIBUTORS +exists vendor/a/foo/LICENSE +exists vendor/a/foo/PATENTS +exists vendor/a/foo/COPYING +exists vendor/a/foo/COPYLEFT +exists vendor/x/NOTICE! +exists vendor/mysite/myname/mypkg/LICENSE.txt + +! exists vendor/a/foo/licensed-to-kill +! exists vendor/w +! exists vendor/w/LICENSE +! exists vendor/x/x2 +! exists vendor/x/x2/LICENSE + +# 'go mod vendor' should work with an alternative vendor directory if the -o flag is provided. +go mod vendor -v -o alternative-vendor-dir +exists alternative-vendor-dir/modules.txt +exists alternative-vendor-dir/a/foo/LICENSE + +# 'go mod vendor' should interpret paths relative to the current working directory when the -o flag is provided. +mkdir dir1 +mkdir dir2 + +cd dir1 +go mod vendor -v -o relative-vendor-dir + +go mod vendor -v -o ../dir2/relative-vendor-dir + +cd .. +exists dir1/relative-vendor-dir/modules.txt +exists dir1/relative-vendor-dir/a/foo/LICENSE +exists dir2/relative-vendor-dir/modules.txt +exists dir2/relative-vendor-dir/a/foo/LICENSE + +# 'go mod vendor' should fall back to the default 'vendor' directory when an empty argument is passed to the -o flag +# the same behavior should be exhibited both on the module root directory, as well as nested subdirectories + +go mod vendor -v -o '' +exists vendor/modules.txt + +env GOFLAGS=-o=foo +go mod vendor -v -o '' +exists vendor/modules.txt +env GOFLAGS='' + +mkdir -p nested/dir +cd nested/dir +go mod vendor -v -o '' +! exists vendor/ +exists ../../vendor/modules.txt +cd ../.. + +# 'go mod vendor' should work with absolute paths as well +go mod vendor -v -o $WORK/tmp/absolute-vendor-dir +exists $WORK/tmp/absolute-vendor-dir/modules.txt + +[short] stop + +# 'go build' and 'go test' using vendored packages should succeed. +go build -mod=mod +go build -mod=vendor +go test -mod=vendor . ./subdir +go test -mod=vendor ./... +go fmt -mod=vendor ./... + +-- go.mod -- +module m + +go 1.13 + +require ( + a v1.0.0 + diamondroot v0.0.0 + mysite/myname/mypkg v1.0.0 + w v1.0.0 // indirect + x v1.0.0 + y v1.0.0 + z v1.0.0 +) + +replace ( + a v1.0.0 => ./a + diamondleft => ./diamondleft + diamondpoint => ./diamondpoint + diamondright => ./diamondright + diamondroot => ./diamondroot + mysite/myname/mypkg v1.0.0 => ./mypkg + w v1.0.0 => ./w + x v1.0.0 => ./x + y v1.0.0 => ./y + z v1.0.0 => ./z +) + +-- a/foo/AUTHORS.txt -- +-- a/foo/CONTRIBUTORS -- +-- a/foo/LICENSE -- +-- a/foo/PATENTS -- +-- a/foo/COPYING -- +-- a/foo/COPYLEFT -- +-- a/foo/licensed-to-kill -- +-- w/LICENSE -- +-- x/NOTICE! -- +-- x/x2/LICENSE -- +-- mypkg/LICENSE.txt -- + +-- a/foo/bar/b/main.go -- +package b +-- a/foo/bar/b/ignored.go -- +// This file is intended for use with "go run"; it isn't really part of the package. + +// +build ignore + +package main + +func main() {} +-- a/foo/bar/b/main_test.go -- +package b + +import ( + "os" + "testing" +) + +func TestDir(t *testing.T) { + if _, err := os.Stat("../testdata/1"); err != nil { + t.Fatalf("testdata: %v", err) + } +} +-- a/foo/bar/c/main.go -- +package c +import _ "a/foo/bar/b" +-- a/foo/bar/c/main_test.go -- +package c + +import ( + "os" + "testing" +) + +func TestDir(t *testing.T) { + if _, err := os.Stat("../../../testdata/1"); err != nil { + t.Fatalf("testdata: %v", err) + } + if _, err := os.Stat("./testdata/1"); err != nil { + t.Fatalf("testdata: %v", err) + } +} +-- a/foo/bar/c/testdata/1 -- +-- a/foo/bar/testdata/1 -- +-- a/go.mod -- +module a +-- a/main.go -- +package a +-- a/main_test.go -- +package a + +import ( + "os" + "testing" +) + +func TestDir(t *testing.T) { + if _, err := os.Stat("./testdata/1"); err != nil { + t.Fatalf("testdata: %v", err) + } +} +-- a/testdata/1 -- +-- appengine.go -- +// +build appengine + +package m + +import _ "appengine" +import _ "appengine/datastore" +-- mypkg/go.mod -- +module me +-- mypkg/mydir/d.go -- +package mydir +-- subdir/v1_test.go -- +package m + +import _ "mysite/myname/mypkg/mydir" +-- testdata1.go -- +package m + +import _ "a" +-- testdata2.go -- +package m + +import _ "a/foo/bar/c" +-- v1.go -- +package m + +import _ "x" +-- v2.go -- +// +build abc + +package mMmMmMm + +import _ "y" +-- v3.go -- +// +build !abc + +package m + +import _ "z" +-- v4.go -- +// +build notmytag + +package m + +import _ "x/x1" +-- importdiamond.go -- +package m + +import _ "diamondroot" +-- w/go.mod -- +module w +-- w/w.go -- +package w +-- x/go.mod -- +module x +-- x/testdata/x.txt -- +placeholder - want directory with no go files +-- x/x.go -- +package x +-- x/x1/x1.go -- +// +build notmytag + +package x1 +-- x/x2/dummy.txt -- +dummy +-- x/x_test.go -- +package x + +import _ "w" +-- y/go.mod -- +module y +-- y/y.go -- +package y +-- z/go.mod -- +module z +-- z/z.go -- +package z + +-- diamondroot/go.mod -- +module diamondroot + +require ( + diamondleft v0.0.0 + diamondright v0.0.0 +) +-- diamondroot/x.go -- +package diamondroot + +import _ "diamondleft" +-- diamondroot/unused/unused.go -- +package unused + +import _ "diamondright" +-- diamondleft/go.mod -- +module diamondleft + +require ( + diamondpoint v0.0.0 +) +-- diamondleft/x.go -- +package diamondleft + +import _ "diamondpoint" +-- diamondright/go.mod -- +module diamondright + +require ( + diamondpoint v0.0.0 +) +-- diamondright/x.go -- +package diamondright + +import _ "diamondpoint" +-- diamondpoint/go.mod -- +module diamondpoint +-- diamondpoint/x.go -- +package diamondpoint diff --git a/go/src/cmd/go/testdata/script/mod_vendor_auto.txt b/go/src/cmd/go/testdata/script/mod_vendor_auto.txt new file mode 100644 index 0000000000000000000000000000000000000000..3c385c5b44c66f415f46d809cb8c46413f2bce96 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_auto.txt @@ -0,0 +1,262 @@ +# Integration test for golang.org/issue/33848: automatically check and use vendored packages. + +env GO111MODULE=on + +[short] skip + +cd $WORK/auto +cp go.mod go.mod.orig +cp $WORK/modules-1.13.txt $WORK/auto/modules.txt + +# An explicit -mod=vendor should force use of the vendor directory. +env GOFLAGS=-mod=vendor + +# Pass -e to permit an error: tools.go imports a main package +# "example.com/printversion". +# TODO(#59186): investigate why it didn't fail without -e. +go list -f {{.Dir}} -tags tools -e all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$' + +! go list -m all +stderr 'go: can''t compute ''all'' using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)' + +! go list -m -f '{{.Dir}}' all +stderr 'go: can''t compute ''all'' using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)' + +# An explicit -mod=mod should force the vendor directory to be ignored. +env GOFLAGS=-mod=mod + +go list -f {{.Dir}} -tags tools -e all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$' +stdout '^'$WORK'[/\\]auto[/\\]replacement-version$' + +go list -m all +stdout '^example.com/auto$' +stdout 'example.com/printversion v1.0.0' +stdout 'example.com/version v1.0.0' + +go list -m -f '{{.Dir}}' all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$' +stdout '^'$WORK'[/\\]auto[/\\]replacement-version$' + +# If the main module's "go" directive says 1.13, we should default to -mod=mod. +env GOFLAGS= +go mod edit -go=1.13 + +go list -f {{.Dir}} -tags tools -e all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$' +stdout '^'$WORK'[/\\]auto[/\\]replacement-version$' + +go list -m -f '{{.Dir}}' all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$' +stdout '^'$WORK'[/\\]auto[/\\]replacement-version$' + +# A 'go 1.14' directive in the main module's go.mod file should enable +# -mod=vendor by default, along with stronger checks for consistency +# between the go.mod file and vendor/modules.txt. +# A 'go 1.13' vendor/modules.txt file is not usually sufficient +# to pass those checks. +go mod edit -go=1.14 + +! go list -f {{.Dir}} -tags tools all +stderr '^go: inconsistent vendoring in '$WORK[/\\]auto':$' +stderr '^\texample.com/printversion@v1.0.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt' +stderr '^\texample.com/unused: is replaced in go.mod, but not marked as replaced in vendor/modules.txt' +stderr '^\texample.com/version@v1.2.0: is replaced in go.mod, but not marked as replaced in vendor/modules.txt' +stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor$' + +# Module-specific subcommands should continue to load the full module graph. +go mod graph +stdout '^example.com/printversion@v1.0.0 example.com/version@v1.0.0$' + +# An explicit -mod=mod should still force the vendor directory to be ignored. +env GOFLAGS=-mod=mod + +go list -f {{.Dir}} -tags tools -e all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$' +stdout '^'$WORK'[/\\]auto[/\\]replacement-version$' + +go list -m all +stdout '^example.com/auto$' +stdout 'example.com/printversion v1.0.0' +stdout 'example.com/version v1.0.0' + +go list -m -f '{{.Dir}}' all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$' +stdout '^'$WORK'[/\\]auto[/\\]replacement-version$' + +# 'go mod vendor' should repair vendor/modules.txt so that the implicit +# -mod=vendor works again. +env GOFLAGS= + +go mod edit -go=1.14 +go mod vendor + +go list -f {{.Dir}} -tags tools -e all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$' + +# ...but 'go list -m' should continue to fail, this time without +# referring to a -mod default that the user didn't set. +! go list -m all +stderr 'go: can''t compute ''all'' using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)' + +! go list -m -f '{{.Dir}}' all +stderr 'go: can''t compute ''all'' using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)' + + +# 'go mod init' should work if there is already a GOPATH-mode vendor directory +# present. If there are no module dependencies, -mod=vendor should be used by +# default and should not fail the consistency check even though no module +# information is present. +# Note: This behavior only applies pre-1.23. Go 1.23 and later require vendored +# packages to be present in modules.txt to be imported. + +rm go.mod +rm vendor/modules.txt + +go mod init example.com/auto +go mod edit -go=1.22 +go list -f {{.Dir}} -tags tools -e all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$' + +# If information about dependencies is added to a 1.14 go.mod file, subsequent +# list commands should error out if vendor/modules.txt is missing or incomplete. + +cp go.mod.orig go.mod +go mod edit -go=1.14 +! go list -f {{.Dir}} -tags tools -e all +stderr '^go: inconsistent vendoring in '$WORK[/\\]auto':$' +stderr '^\texample.com/printversion@v1.0.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt' +stderr '^\texample.com/unused: is replaced in go.mod, but not marked as replaced in vendor/modules.txt' +stderr '^\texample.com/version@v1.2.0: is replaced in go.mod, but not marked as replaced in vendor/modules.txt' +stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor$' + +# If -mod=vendor is set, limited consistency checks should apply even when +# the go version is 1.13 or earlier. +# An incomplete or missing vendor/modules.txt should resolve the vendored packages... +go mod edit -go=1.13 +go list -mod=vendor -f {{.Dir}} -tags tools -e all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$' + +# ...but a version mismatch for an explicit dependency should be noticed. +cp $WORK/modules-bad-1.13.txt vendor/modules.txt +! go list -mod=vendor -f {{.Dir}} -tags tools all +stderr '^go: inconsistent vendoring in '$WORK[/\\]auto':$' +stderr '^\texample.com/printversion@v1.0.0: is explicitly required in go.mod, but vendor/modules.txt indicates example.com/printversion@v1.1.0$' +stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor$' + +# If the go version is still 1.13, 'go mod vendor' should write a +# matching vendor/modules.txt containing the corrected 1.13 data. +go mod vendor +cmp $WORK/modules-1.13.txt vendor/modules.txt + +go list -mod=vendor -f {{.Dir}} -tags tools -e all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$' + +# When the version is upgraded to 1.14, 'go mod vendor' should write a +# vendor/modules.txt with the updated 1.14 annotations. +go mod edit -go=1.14 +go mod vendor +cmp $WORK/modules-1.14.txt vendor/modules.txt + +# Then, -mod=vendor should kick in automatically and succeed. +go list -f {{.Dir}} -tags tools -e all +stdout '^'$WORK'[/\\]auto$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$' +stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$' + +# 'go get' should update from the network or module cache, +# even if a vendor directory is present. +go get example.com/version@v1.1.0 +! go list -f {{.Dir}} -tags tools all +stderr '^go: inconsistent vendoring' + +-- $WORK/auto/go.mod -- +module example.com/auto + +go 1.13 + +require example.com/printversion v1.0.0 + +replace ( + example.com/unused => nonexistent.example.com/unused v1.0.0-whatever + example.com/version v1.0.0 => ./replacement-version + example.com/version v1.2.0 => nonexistent.example.com/version v1.2.0 +) +-- $WORK/auto/tools.go -- +// +build tools + +package auto + +import _ "example.com/printversion" +-- $WORK/auto/auto.go -- +package auto +-- $WORK/auto/replacement-version/go.mod -- +module example.com/version +-- $WORK/auto/replacement-version/version.go -- +package version + +const V = "v1.0.0-replaced" +-- $WORK/modules-1.14.txt -- +# example.com/printversion v1.0.0 +## explicit +example.com/printversion +# example.com/version v1.0.0 => ./replacement-version +example.com/version +# example.com/unused => nonexistent.example.com/unused v1.0.0-whatever +# example.com/version v1.2.0 => nonexistent.example.com/version v1.2.0 +-- $WORK/modules-1.13.txt -- +# example.com/printversion v1.0.0 +example.com/printversion +# example.com/version v1.0.0 => ./replacement-version +example.com/version +-- $WORK/modules-bad-1.13.txt -- +# example.com/printversion v1.1.0 +example.com/printversion +# example.com/version v1.1.0 +example.com/version +-- $WORK/auto/vendor/example.com/printversion/go.mod -- +module example.com/printversion + +require example.com/version v1.0.0 +replace example.com/version v1.0.0 => ../oops v0.0.0 +exclude example.com/version v1.0.1 +-- $WORK/auto/vendor/example.com/printversion/printversion.go -- +package main + +import ( + "fmt" + "os" + "runtime/debug" + + _ "example.com/version" +) + +func main() { + info, _ := debug.ReadBuildInfo() + fmt.Fprintf(os.Stdout, "path is %s\n", info.Path) + fmt.Fprintf(os.Stdout, "main is %s %s\n", info.Main.Path, info.Main.Version) + for _, m := range info.Deps { + fmt.Fprintf(os.Stdout, "using %s %s\n", m.Path, m.Version) + } +} +-- $WORK/auto/vendor/example.com/version/version.go -- +package version + +const V = "v1.0.0-replaced" diff --git a/go/src/cmd/go/testdata/script/mod_vendor_build.txt b/go/src/cmd/go/testdata/script/mod_vendor_build.txt new file mode 100644 index 0000000000000000000000000000000000000000..4efda55e08f10fb391c12324bbd2e52813be9f2b --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_build.txt @@ -0,0 +1,41 @@ +env GO111MODULE=on +[short] skip + +# Populate go.mod and go.sum. +go mod tidy + +# initial conditions: using sampler v1.3.0, not listed in go.mod. +go list -deps +stdout rsc.io/sampler +! grep 'rsc.io/sampler v1.3.0' go.mod + +# update to v1.3.1, now indirect in go.mod. +go get rsc.io/sampler@v1.3.1 +grep 'rsc.io/sampler v1.3.1 // indirect' go.mod +cp go.mod go.mod.good + +# vendoring can but should not need to make changes. +go mod vendor +cmp go.mod go.mod.good + +# go list -mod=vendor (or go build -mod=vendor) must not modify go.mod. +# golang.org/issue/26704 +go list -mod=vendor +cmp go.mod go.mod.good + +# With a clean (and empty) module cache, 'go list -mod=vendor' should not download modules. +go clean -modcache +env GOPROXY=off +! go list ... +go list -mod=vendor ... + +# However, it should still list packages in the main module. +go list -mod=vendor m/... +stdout m + +-- go.mod -- +module m +go 1.12 +-- x.go -- +package x +import _ "rsc.io/quote" diff --git a/go/src/cmd/go/testdata/script/mod_vendor_collision.txt b/go/src/cmd/go/testdata/script/mod_vendor_collision.txt new file mode 100644 index 0000000000000000000000000000000000000000..e15b7ed478c729a4b59c26a73919bb239ba7e3e6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_collision.txt @@ -0,0 +1,38 @@ +! go build +stderr 'case-insensitive import collision' + +! go mod vendor +stderr 'case-insensitive import collision' + +-- foo.go -- +package main + +import ( + _ "example.com/Foo" + _ "example.com/foo" +) + +func main() {} +-- go.mod -- +module play.ground + +go 1.14 + +require ( + example.com/foo v0.1.0 + example.com/Foo v0.1.0 +) + +replace ( + example.com/foo => ./foo + example.com/Foo => ./foo_alt +) +-- foo/go.mod -- +module example.com/foo +-- foo/foo.go -- +package foo + +-- foo_alt/go.mod -- +module example.com/Foo +-- foo_alt/foo.go -- +package Foo \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_vendor_embed.txt b/go/src/cmd/go/testdata/script/mod_vendor_embed.txt new file mode 100644 index 0000000000000000000000000000000000000000..4a27b1431fbdf1ce2ba8362e29bb7f33cf44c4ee --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_embed.txt @@ -0,0 +1,213 @@ +go mod vendor +cmp vendor/example.com/a/samedir_embed.txt a/samedir_embed.txt +cmp vendor/example.com/a/subdir/embed.txt a/subdir/embed.txt +cmp vendor/example.com/a/subdir/test/embed.txt a/subdir/test/embed.txt +cmp vendor/example.com/a/subdir/test/xtest/embed.txt a/subdir/test/xtest/embed.txt + +cd broken_no_matching_files +! go mod vendor +stderr '^go: resolving embeds in example.com/brokendep: pattern foo.txt: no matching files found$' +go mod vendor -e +stderr '^go: resolving embeds in example.com/brokendep: pattern foo.txt: no matching files found$' + +cd ../broken_bad_pattern +! go mod vendor +stderr '^go: resolving embeds in example.com/brokendep: pattern ../foo.txt: invalid pattern syntax$' +go mod vendor -e +stderr '^go: resolving embeds in example.com/brokendep: pattern ../foo.txt: invalid pattern syntax$' + +cd ../embed_go122 +go mod vendor +cmp vendor/example.com/a/samedir_embed.txt ../a/samedir_embed.txt +cmp vendor/example.com/a/subdir/embed.txt ../a/subdir/embed.txt +! exists vendor/example.com/a/subdir/test/embed.txt +! exists vendor/example.com/a/subdir/test/xtest/embed.txt +-- embed_go122/go.mod -- +module example.com/foo +go 1.22 + +require ( + example.com/a v0.1.0 +) + +replace ( + example.com/a v0.1.0 => ../a +) +-- embed_go122/foo.go -- +package main + +import ( + "fmt" + + "example.com/a" +) + +func main() { + fmt.Println(a.Str()) +} + +# matchPotentialSourceFile prunes out tests and unbuilt code. +# Make sure that they are vendored if they are embedded files. +cd ../embed_unbuilt +go mod vendor +cmp vendor/example.com/dep/unbuilt.go dep/unbuilt.go +cmp vendor/example.com/dep/dep_test.go dep/dep_test.go +! exists vendor/example.com/dep/not_embedded_unbuilt.go +! exists vendor/example.com/dep/not_embedded_dep_test.go +-- go.mod -- +module example.com/foo +go 1.16 + +require ( + example.com/a v0.1.0 +) + +replace ( + example.com/a v0.1.0 => ./a +) +-- foo.go -- +package main + +import ( + "fmt" + + "example.com/a" +) + +func main() { + fmt.Println(a.Str()) +} +-- a/go.mod -- +module example.com/a +-- a/a.go -- +package a + +import _ "embed" + +//go:embed samedir_embed.txt +var sameDir string + +//go:embed subdir/embed.txt +var subDir string + +func Str() string { + return sameDir + subDir +} +-- a/a_test.go -- +package a + +import _ "embed" + +//go:embed subdir/test/embed.txt +var subderTest string +-- a/a_x_test.go -- +package a_test + +import _ "embed" + +//go:embed subdir/test/xtest/embed.txt +var subdirXtest string +-- a/samedir_embed.txt -- +embedded file in same directory as package +-- a/subdir/embed.txt -- +embedded file in subdirectory of package +-- a/subdir/test/embed.txt -- +embedded file of test in subdirectory of package +-- a/subdir/test/xtest/embed.txt -- +embedded file of xtest in subdirectory of package +-- broken_no_matching_files/go.mod -- +module example.com/broken +go 1.16 + +require ( + example.com/brokendep v0.1.0 +) + +replace ( + example.com/brokendep v0.1.0 => ./brokendep +) +-- broken_no_matching_files/f.go -- +package broken + +import _ "example.com/brokendep" + +func F() {} +-- broken_no_matching_files/brokendep/go.mod -- +module example.com/brokendep +go 1.16 +-- broken_no_matching_files/brokendep/f.go -- +package brokendep + +import _ "embed" + +//go:embed foo.txt +var foo string +-- broken_bad_pattern/go.mod -- +module example.com/broken +go 1.16 + +require ( + example.com/brokendep v0.1.0 +) + +replace ( + example.com/brokendep v0.1.0 => ./brokendep +) +-- broken_bad_pattern/f.go -- +package broken + +import _ "example.com/brokendep" + +func F() {} +-- broken_bad_pattern/brokendep/go.mod -- +module example.com/brokendep +go 1.16 +-- broken_bad_pattern/brokendep/f.go -- +package brokendep + +import _ "embed" + +//go:embed ../foo.txt +var foo string +-- embed_unbuilt/go.mod -- +module example.com/foo +go 1.16 + +require ( + example.com/dep v0.1.0 +) + +replace ( + example.com/dep v0.1.0 => ./dep +) +-- embed_unbuilt/foo.go -- +package a + +import _ "example.com/dep" + +func F() {} +-- embed_unbuilt/dep/go.mod -- +module example.com/dep +go 1.16 +-- embed_unbuilt/dep/dep.go -- +package dep + +import _ "embed" + +//go:embed unbuilt.go +var unbuilt string + +//go:embed dep_test.go +var depTest string +-- embed_unbuilt/dep/unbuilt.go -- +// +build ignore + +package dep +-- embed_unbuilt/dep/not_embedded_unbuilt.go -- +// +build ignore + +package dep +-- embed_unbuilt/dep/dep_test.go -- +package dep +-- embed_unbuilt/dep/not_embedded_dep_test.go -- +package dep diff --git a/go/src/cmd/go/testdata/script/mod_vendor_gomod.txt b/go/src/cmd/go/testdata/script/mod_vendor_gomod.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f6ea3561a44b12461057023ee1e75506ed74def --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_gomod.txt @@ -0,0 +1,38 @@ +# https://golang.org/issue/42970: As of Go 1.17, go.mod and go.sum files should +# be stripped from vendored dependencies. + +go mod vendor +cd vendor/example.net/x +go list all +! stdout '^example.net/m' +stdout '^example.net/x$' +exists ./go.sum + +cd ../../.. +go mod edit -go=1.17 +go mod vendor +cd vendor/example.net/x +go list all +stdout '^example.net/m$' +stdout '^example.net/x$' +! exists ./go.sum + +-- go.mod -- +module example.net/m + +go 1.16 + +require example.net/x v0.1.0 + +replace example.net/x v0.1.0 => ./x +-- m.go -- +package m + +import _ "example.net/x" +-- x/go.mod -- +module example.net/x + +go 1.16 +-- x/go.sum -- +-- x/x.go -- +package x diff --git a/go/src/cmd/go/testdata/script/mod_vendor_goversion.txt b/go/src/cmd/go/testdata/script/mod_vendor_goversion.txt new file mode 100644 index 0000000000000000000000000000000000000000..18cd030fcdcda391ea004c6c5ce30bd2d82dca52 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_goversion.txt @@ -0,0 +1,102 @@ +# https://golang.org/issue/36876: As of Go 1.17, vendor/modules.txt should +# indicate the language version used by each dependency. + +[short] skip + +# Control case: without a vendor directory, need117 builds and bad114 doesn't. + +go build example.net/need117 +! go build example.net/bad114 +stderr '^bad114[/\\]bad114.go:15:2: duplicate method .?Y.?( .*)?$' + + +# With a vendor/modules.txt lacking language versions, the world is topsy-turvy, +# because we have to guess a uniform version for everything. +# +# We always guess Go 1.16, because that was the last version for which +# 'go mod vendor' failed to record dependency versions, and it has most of +# the language features added since modules were introduced in Go 1.11. +# +# Even so, modules that declare 'go 1.17' and use 1.17 features spuriously fail +# to build, and modules that declare an older version and use features from a +# newer one spuriously build (instead of failing as they ought to). + +go mod vendor + +! grep 1.17 vendor/modules.txt +! go build example.net/need117 +stderr '^vendor[/\\]example\.net[/\\]need117[/\\]need117.go:5:1[89]:' +stderr 'conversion of slice to array pointer requires go1\.17 or later' + +! grep 1.13 vendor/modules.txt +go build example.net/bad114 + + +# Upgrading the main module to 1.17 adds version annotations. +# Then everything is once again consistent with the non-vendored world. + +go mod edit -go=1.17 +go mod vendor + +grep '^## explicit; go 1.17$' vendor/modules.txt +go build example.net/need117 + +grep '^## explicit; go 1.13$' vendor/modules.txt +! go build example.net/bad114 +stderr '^vendor[/\\]example\.net[/\\]bad114[/\\]bad114.go:15:2: duplicate method .?Y.?( .*)?$' + +-- go.mod -- +module example.net/m + +go 1.16 + +require ( + example.net/bad114 v0.1.0 + example.net/need117 v0.1.0 +) + +replace ( + example.net/bad114 v0.1.0 => ./bad114 + example.net/need117 v0.1.0 => ./need117 +) +-- m.go -- +package m + +import _ "example.net/bad114" +import _ "example.net/need117" + +-- bad114/go.mod -- +// Module bad114 requires Go 1.14 or higher, but declares Go 1.13. +module example.net/bad114 + +go 1.13 +-- bad114/bad114.go -- +package bad114 + +type XY interface { + X() + Y() +} + +type YZ interface { + Y() + Z() +} + +type XYZ interface { + XY + YZ +} + +-- need117/go.mod -- +// Module need117 requires Go 1.17 or higher. +module example.net/need117 + +go 1.17 +-- need117/need117.go -- +package need117 + +func init() { + s := make([]byte, 4) + _ = (*[4]byte)(s) +} diff --git a/go/src/cmd/go/testdata/script/mod_vendor_issue46867.txt b/go/src/cmd/go/testdata/script/mod_vendor_issue46867.txt new file mode 100644 index 0000000000000000000000000000000000000000..38ae87b44a981e145b1321b7a9a3a13a560312df --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_issue46867.txt @@ -0,0 +1,31 @@ +# Regression test for golang.org/issue/46867: +# 'go mod vendor' on Windows attempted to open and copy +# files from directories outside of the module. + +cd subdir +go mod vendor +! exists vendor/example.net/NOTICE +exists vendor/example.net/m/NOTICE + +-- subdir/go.mod -- +module golang.org/issue46867 + +go 1.17 + +replace example.net/m v0.1.0 => ./m + +require example.net/m v0.1.0 +-- subdir/issue.go -- +package issue + +import _ "example.net/m/n" +-- subdir/m/go.mod -- +module example.net/m + +go 1.17 +-- subdir/m/n/n.go -- +package n +-- subdir/m/NOTICE -- +This notice is in module m and SHOULD be vendored. +-- subdir/NOTICE -- +This notice is outside of module m and SHOULD NOT be vendored. diff --git a/go/src/cmd/go/testdata/script/mod_vendor_nodeps.txt b/go/src/cmd/go/testdata/script/mod_vendor_nodeps.txt new file mode 100644 index 0000000000000000000000000000000000000000..e9a84ca9860d9dd17b726346c8d9852355238102 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_nodeps.txt @@ -0,0 +1,9 @@ +env GO111MODULE=on + +go mod vendor +stderr '^go: no dependencies to vendor' + +-- go.mod -- +module x +-- x.go -- +package x diff --git a/go/src/cmd/go/testdata/script/mod_vendor_redundant_requirement.txt b/go/src/cmd/go/testdata/script/mod_vendor_redundant_requirement.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f6f5c5276b9752f9445840181aa9689801731f5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_redundant_requirement.txt @@ -0,0 +1,29 @@ +# 'go list -mod=vendor' should succeed even when go.mod contains redundant +# requirements. Verifies #47565. +go list -mod=vendor + +-- go.mod -- +module m + +go 1.17 + +require example.com/m v0.0.0 +require example.com/m v0.0.0 + +replace example.com/m v0.0.0 => ./m +-- m/go.mod -- +module example.com/m + +go 1.17 +-- m/m.go -- +package m +-- use.go -- +package use + +import _ "example.com/m" +-- vendor/example.com/m/m.go -- +package m +-- vendor/modules.txt -- +# example.com/m v0.0.0 => ./m +## explicit; go 1.17 +example.com/m diff --git a/go/src/cmd/go/testdata/script/mod_vendor_replace.txt b/go/src/cmd/go/testdata/script/mod_vendor_replace.txt new file mode 100644 index 0000000000000000000000000000000000000000..c492999f1ee61a7d4b8c01a42e18ecd8bbacbb37 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_replace.txt @@ -0,0 +1,89 @@ +env GO111MODULE=on + +# Replacement should not use a vendor directory as the target. +! go mod vendor +stderr 'replacement path ./vendor/not-rsc.io/quote/v3 inside vendor directory' + +cp go.mod1 go.mod +rm -r vendor + +# Before vendoring, we expect to see the original directory. +go list -f '{{with .Module}}{{.Version}}{{end}} {{.Dir}}' rsc.io/quote/v3 +stdout 'v3.0.0' +stdout '.*[/\\]not-rsc.io[/\\]quote[/\\]v3' + +# Since all dependencies are replaced, 'go mod vendor' should not +# have to download anything from the network. +go mod vendor +! stderr 'downloading' +! stderr 'finding' + +# After vendoring, we expect to see the replacement in the vendor directory, +# without attempting to look up the non-replaced version. +cmp vendor/rsc.io/quote/v3/quote.go local/not-rsc.io/quote/v3/quote.go + +go list -mod=vendor -f '{{with .Module}}{{.Version}}{{end}} {{.Dir}}' rsc.io/quote/v3 +stdout 'v3.0.0' +stdout '.*[/\\]vendor[/\\]rsc.io[/\\]quote[/\\]v3' +! stderr 'finding' +! stderr 'lookup disabled' + +# 'go list' should provide the original replacement directory as the module's +# replacement path. +go list -mod=vendor -f '{{with .Module}}{{with .Replace}}{{.Path}}{{end}}{{end}}' rsc.io/quote/v3 +stdout '.*[/\\]not-rsc.io[/\\]quote[/\\]v3' + +# The same module can't be used as two different paths. +cd multiple-paths +! go mod vendor +stderr 'rsc.io/quote/v3@v3.0.0 used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)' + +-- go.mod -- +module example.com/replace + +require rsc.io/quote/v3 v3.0.0 +replace rsc.io/quote/v3 => ./vendor/not-rsc.io/quote/v3 + +-- go.mod1 -- +module example.com/replace + +require rsc.io/quote/v3 v3.0.0 +replace rsc.io/quote/v3 => ./local/not-rsc.io/quote/v3 + +-- imports.go -- +package replace + +import _ "rsc.io/quote/v3" + +-- local/not-rsc.io/quote/v3/go.mod -- +module not-rsc.io/quote/v3 + +-- local/not-rsc.io/quote/v3/quote.go -- +package quote + +-- multiple-paths/main.go -- +package main +import ( + "fmt" + "rsc.io/quote/v3" +) +func main() { + fmt.Println(quote.GoV3()) +} +-- multiple-paths/go.mod -- +module quoter +require ( + rsc.io/quote/v3 v3.0.0 + not-rsc.io/quote/v3 v3.0.0 +) +replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0 +-- multiple-paths/go.sum -- +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +rsc.io/quote/v3 v3.0.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= + +-- vendor/not-rsc.io/quote/v3/go.mod -- +module not-rsc.io/quote/v3 + +-- vendor/not-rsc.io/quote/v3/quote.go -- +package quote diff --git a/go/src/cmd/go/testdata/script/mod_vendor_trimpath.txt b/go/src/cmd/go/testdata/script/mod_vendor_trimpath.txt new file mode 100644 index 0000000000000000000000000000000000000000..d9d9d9889741cdf58ef3c1c771a9cae60beb6583 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_trimpath.txt @@ -0,0 +1,49 @@ +# Check that when -trimpath and -mod=vendor are used together, +# paths in vendored packages are properly trimmed. +# Verifies golang.org/issue/36566. + +[short] skip + +# Only the main module has a root directory in vendor mode. +go mod vendor +go list -f {{.Module.Dir}} example.com/main +stdout $PWD +go list -f {{.Module.Dir}} example.com/stack +! stdout . + +# The program prints a file name from a vendored package. +# Without -trimpath, the name should include the vendor directory. +go run main.go +stdout vendor + +# With -trimpath, everything before the package path should be trimmed. +# As with -mod=mod, the version should appear as part of the module path. +go run -mod=vendor -trimpath main.go +stdout '^example.com/stack@v1.0.0/stack.go$' + +# With pristinely vendored source code, a trimmed binary built from vendored +# code should have the same behavior as one build from the module cache. +go run -mod=mod -trimpath main.go +stdout '^example.com/stack@v1.0.0/stack.go$' + +-- go.mod -- +module example.com/main + +go 1.17 + +require example.com/stack v1.0.0 +-- go.sum -- +example.com/stack v1.0.0 h1:IEDLeew5NytZ8vrgCF/QVem3H3SR3QMttdu9HfJvk9I= +example.com/stack v1.0.0/go.mod h1:7wFEbaV5e5O7wJ8aBdqQOR//UXppm/pwnwziMKViuI4= +-- main.go -- +package main + +import ( + "fmt" + + "example.com/stack" +) + +func main() { + fmt.Println(stack.TopFile()) +} diff --git a/go/src/cmd/go/testdata/script/mod_vendor_unused.txt b/go/src/cmd/go/testdata/script/mod_vendor_unused.txt new file mode 100644 index 0000000000000000000000000000000000000000..96251bb25ae1bbc7cd72e60e93cae589d31f5733 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_unused.txt @@ -0,0 +1,67 @@ +# Auxiliary test for inclusion of otherwise-unused replacements in +# vendor/modules.txt for golang.org/issue/33848. +# We need metadata about replacements in order to verify that modules.txt +# remains in sync with the main module's go.mod file. + +env GO111MODULE=on + +go mod vendor +cmp go1.14-modules.txt vendor/modules.txt + +-- go.mod -- +module example.com/foo +go 1.14 + +require ( + example.com/a v0.1.0 +) + +replace ( + example.com/a v0.1.0 => ./a + example.com/b v0.1.0 => ./b1 + example.com/b v0.2.0-unused => ./b2 + example.com/c => ./c + example.com/d v0.1.0 => ./d1 + example.com/d v0.2.0 => ./d2 + example.com/e => example.com/e v0.1.0-unused +) +-- foo.go -- +package foo +import _ "example.com/a" +-- a/go.mod -- +module example.com/a +require ( + example.com/b v0.1.0 // indirect + example.com/c v0.1.0 // indirect +) +-- a/a.go -- +package a +import _ "example.com/d" +-- b1/go.mod -- +module example.com/b +require example.com/d v0.1.0 +-- b2/go.mod -- +module example.com/b +require example.com/c v0.2.0 +-- c/go.mod -- +module example.com/c +require example.com/d v0.2.0 +-- d1/go.mod -- +module example.com/d +-- d1/d1.go -- +package d +-- d2/go.mod -- +module example.com/d +-- d2/d2.go -- +package d +-- go1.14-modules.txt -- +# example.com/a v0.1.0 => ./a +## explicit +example.com/a +# example.com/d v0.2.0 => ./d2 +example.com/d +# example.com/b v0.1.0 => ./b1 +# example.com/b v0.2.0-unused => ./b2 +# example.com/c => ./c +# example.com/d v0.1.0 => ./d1 +# example.com/e => example.com/e v0.1.0-unused diff --git a/go/src/cmd/go/testdata/script/mod_vendor_unused_only.txt b/go/src/cmd/go/testdata/script/mod_vendor_unused_only.txt new file mode 100644 index 0000000000000000000000000000000000000000..accd9f373deb0e59c4ca10ee18c2c690ee508b2e --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_vendor_unused_only.txt @@ -0,0 +1,19 @@ +# Ensure that we generate a vendor/modules.txt file even when the only +# requirements in go.mod are unused. Regression test for +# golang.org/issue/36580 + +env GO111MODULE=on + +go mod vendor +cmp go1.14-modules.txt vendor/modules.txt + +-- go.mod -- +module example.com/m +go 1.14 + +require example.com v1.0.0 // indirect +-- go.sum -- +example.com v1.0.0/go.mod h1:WRiieAqDBb1hVdDXLLdxNtCDWNfehn7FWyPC5Oz2vB4= +-- go1.14-modules.txt -- +# example.com v1.0.0 +## explicit diff --git a/go/src/cmd/go/testdata/script/mod_verify.txt b/go/src/cmd/go/testdata/script/mod_verify.txt new file mode 100644 index 0000000000000000000000000000000000000000..018709e33b42e3032df92363bad95d0296ef85ef --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_verify.txt @@ -0,0 +1,82 @@ +env GO111MODULE=on +[short] skip + +# With good go.sum, verify succeeds by avoiding download. +cp go.sum.good go.sum +go mod verify +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip + +# With bad go.sum, verify succeeds by avoiding download. +cp go.sum.bad go.sum +go mod verify +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip + +# With bad go.sum, sync (which must download) fails. +rm go.sum +cp go.sum.bad go.sum +! go mod tidy +stderr 'checksum mismatch' +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip + +# With good go.sum, sync works. +rm go.sum +cp go.sum.good go.sum +go mod tidy +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip +exists $GOPATH/pkg/mod/rsc.io/quote@v1.1.0/quote.go + +# go.sum should have the new checksum for go.mod +grep '^rsc.io/quote v1.1.0/go.mod ' go.sum + +# verify should work +go mod verify + +# basic loading of module graph should detect incorrect go.mod files. +go mod graph +cp go.sum.bad2 go.sum +! go mod graph +stderr 'go.mod: checksum mismatch' + +# go.sum should be created and updated automatically. +rm go.sum +go mod tidy +grep '^rsc.io/quote v1.1.0/go.mod ' go.sum +grep '^rsc.io/quote v1.1.0 ' go.sum + +# verify should fail on a missing ziphash. tidy should restore it. +rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.ziphash +! go mod verify +stderr '^rsc.io/quote v1.1.0: missing ziphash: open '$GOPATH'[/\\]pkg[/\\]mod[/\\]cache[/\\]download[/\\]rsc.io[/\\]quote[/\\]@v[/\\]v1.1.0.ziphash' +go mod tidy +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.ziphash +go mod verify + +# Packages below module root should not be mentioned in go.sum. +rm go.sum +go mod edit -droprequire rsc.io/quote +go get rsc.io/quote/buggy +grep '^rsc.io/quote v1.5.2/go.mod ' go.sum +! grep buggy go.sum + +# non-existent packages below module root should not be mentioned in go.sum +go mod edit -droprequire rsc.io/quote +! go list rsc.io/quote/morebuggy +grep '^rsc.io/quote v1.5.2/go.mod ' go.sum +! grep buggy go.sum + +-- go.mod -- +module x +require rsc.io/quote v1.1.0 + +-- x.go -- +package x +import _ "rsc.io/quote" + +-- go.sum.good -- +rsc.io/quote v1.1.0 h1:a3YaZoizPtXyv6ZsJ74oo2L4/bwOSTKMY7MAyo4O/0c= + +-- go.sum.bad -- +rsc.io/quote v1.1.0 h1:a3YaZoizPtXyv6ZsJ74oo2L4/bwOSTKMY7MAyo4O/1c= + +-- go.sum.bad2 -- +rsc.io/quote v1.1.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl1= diff --git a/go/src/cmd/go/testdata/script/mod_verify_work.txt b/go/src/cmd/go/testdata/script/mod_verify_work.txt new file mode 100644 index 0000000000000000000000000000000000000000..d9f5a545857810c57f9a069bd6defb67e7749514 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_verify_work.txt @@ -0,0 +1,24 @@ +# Regression test for Issue #62663: we would filter out the toolchain and +# main modules from the build list incorrectly, leading to the workspace +# modules being checked for correct sums. Specifically this would happen when +# the module name sorted after the virtual 'go' version module name because +# it could not get chopped off when we removed the MainModules.Len() modules +# at the beginning of the build list and we would remove the go module instead. + +go mod verify + +-- go.work -- +go 1.21 + +use ( + ./a + ./b +) +-- a/go.mod -- +module hexample.com/a // important for test that module name sorts after 'go' + +go 1.21 +-- b/go.mod -- +module hexample.com/b // important for test that module name sorts after 'go' + +go 1.21 \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/mod_versions.txt b/go/src/cmd/go/testdata/script/mod_versions.txt new file mode 100644 index 0000000000000000000000000000000000000000..aaa42167a09d39976bc8b0edc1e51fbd75f6aeb8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_versions.txt @@ -0,0 +1,14 @@ +# Test rejection of pkg@version in GOPATH mode. +env GO111MODULE=off +! go get rsc.io/quote@v1.5.1 +stderr '^go: modules disabled by GO111MODULE=off' +! go build rsc.io/quote@v1.5.1 +stderr '^package rsc.io/quote@v1.5.1: can only use path@version syntax with ''go get'' and ''go install'' in module-aware mode$' + +env GO111MODULE=on +cd x +! go build rsc.io/quote@v1.5.1 +stderr '^package rsc.io/quote@v1.5.1: can only use path@version syntax with ''go get'' and ''go install'' in module-aware mode$' + +-- x/go.mod -- +module x diff --git a/go/src/cmd/go/testdata/script/mod_why.txt b/go/src/cmd/go/testdata/script/mod_why.txt new file mode 100644 index 0000000000000000000000000000000000000000..b3036fa83040c0b1c69623041c93086547fb3caf --- /dev/null +++ b/go/src/cmd/go/testdata/script/mod_why.txt @@ -0,0 +1,130 @@ +env GO111MODULE=on +[short] skip + +# Populate go.sum. +go mod tidy +cp go.mod go.mod.orig + +go list -test all +stdout rsc.io/quote +stdout golang.org/x/text/language + +# why a package? +go mod why golang.org/x/text/language +cmp stdout why-language.txt + +# why a module? +go mod why -m golang.org... +cmp stdout why-text-module.txt + +# why a package used only in tests? +go mod why rsc.io/testonly +cmp stdout why-testonly.txt + +# why a module used only in a test of a dependency? +go mod why -m rsc.io/testonly +cmp stdout why-testonly.txt + +# test package not needed +go mod why golang.org/x/text/unused +cmp stdout why-unused.txt + +# vendor doesn't use packages used only in tests. +go mod why -vendor rsc.io/testonly +cmp stdout why-vendor.txt + +# vendor doesn't use modules used only in tests. +go mod why -vendor -m rsc.io/testonly +cmp stdout why-vendor-module.txt + +# test multiple packages +go mod why golang.org/x/text/language golang.org/x/text/unused +cmp stdout why-both.txt + +# test multiple modules +go mod why -m rsc.io/quote rsc.io/sampler +cmp stdout why-both-module.txt + +# package in a module that isn't even in the module graph +# (https://golang.org/issue/26977) +go mod why rsc.io/fortune +cmp stdout why-missing.txt + +# None of these command should have changed the go.mod file. +cmp go.mod go.mod.orig + +-- go.mod -- +module mymodule +require rsc.io/quote v1.5.2 + +-- x/x.go -- +package x +import _ "mymodule/z" + +-- y/y.go -- +package y + +-- y/y_test.go -- +package y +import _ "rsc.io/quote" + +-- z/z.go -- +package z +import _ "mymodule/y" + + +-- why-language.txt -- +# golang.org/x/text/language +mymodule/y +mymodule/y.test +rsc.io/quote +rsc.io/sampler +golang.org/x/text/language +-- why-unused.txt -- +# golang.org/x/text/unused +(main module does not need package golang.org/x/text/unused) +-- why-text-module.txt -- +# golang.org/x/text +mymodule/y +mymodule/y.test +rsc.io/quote +rsc.io/sampler +golang.org/x/text/language +-- why-testonly.txt -- +# rsc.io/testonly +mymodule/y +mymodule/y.test +rsc.io/quote +rsc.io/sampler +rsc.io/sampler.test +rsc.io/testonly +-- why-vendor.txt -- +# rsc.io/testonly +(main module does not need to vendor package rsc.io/testonly) +-- why-vendor-module.txt -- +# rsc.io/testonly +(main module does not need to vendor module rsc.io/testonly) +-- why-both.txt -- +# golang.org/x/text/language +mymodule/y +mymodule/y.test +rsc.io/quote +rsc.io/sampler +golang.org/x/text/language + +# golang.org/x/text/unused +(main module does not need package golang.org/x/text/unused) +-- why-both-module.txt -- +# rsc.io/quote +mymodule/y +mymodule/y.test +rsc.io/quote + +# rsc.io/sampler +mymodule/y +mymodule/y.test +rsc.io/quote +rsc.io/sampler +-- why-missing.txt -- +# rsc.io/fortune +(main module does not need package rsc.io/fortune) diff --git a/go/src/cmd/go/testdata/script/modfile_flag.txt b/go/src/cmd/go/testdata/script/modfile_flag.txt new file mode 100644 index 0000000000000000000000000000000000000000..7260cf656b1f1dbdf48301cf0ec7e531d2a9cc10 --- /dev/null +++ b/go/src/cmd/go/testdata/script/modfile_flag.txt @@ -0,0 +1,102 @@ +# Tests the behavior of the -modfile flag in commands that support it. +# The go.mod file exists but should not be read or written. +# Same with go.sum. + +env GOFLAGS=-modfile=go.alt.mod +cp go.mod go.mod.orig +cp go.sum go.sum.orig + + +# go mod init should create a new file, even though go.mod already exists. +go mod init example.com/m +grep example.com/m go.alt.mod + +# 'go env GOMOD' should print the path to the real file. +# 'go env' does not recognize the '-modfile' flag. +go env GOMOD +stdout '^'$WORK${/}gopath${/}src${/}'go\.mod$' + +# 'go list -m' should print the effective go.mod file as GoMod though. +go list -m -f '{{.GoMod}}' +stdout '^go.alt.mod$' + +# go mod edit should operate on the alternate file +go mod edit -require rsc.io/quote@v1.5.2 +grep rsc.io/quote go.alt.mod + +# 'go list -m' should add sums to the alternate go.sum. +go list -m -mod=mod all +grep '^rsc.io/quote v1.5.2/go.mod ' go.alt.sum +! grep '^rsc.io/quote v1.5.2 ' go.alt.sum + +# other 'go mod' commands should work. 'go mod vendor' is tested later. +go mod download rsc.io/quote +go mod graph +stdout rsc.io/quote +go mod tidy +grep rsc.io/quote go.alt.sum +go mod verify +go mod why rsc.io/quote + + +# 'go list' and other commands with build flags should work. +# They should update the alternate go.mod when a dependency is missing. +go mod edit -droprequire rsc.io/quote +go list -mod=mod . +grep rsc.io/quote go.alt.mod +go build -n -mod=mod . +go test -n -mod=mod . +go get rsc.io/quote + +# 'go tool' and tool management should work. +go get -tool example.com/tools/cmd/hello@v1.0.0 +grep cmd/hello go.alt.mod +go tool hello + +# 'go mod vendor' should work. +go mod vendor +exists vendor + +# Automatic vendoring should be broken by editing an explicit requirement +# in the alternate go.mod file. +go mod edit -require rsc.io/quote@v1.5.1 +! go list . +go list -mod=mod +rm vendor + + +# 'go generate' should use the alternate file when resolving packages. +# Recursive go commands started with 'go generate' should not get an explicitly +# passed -modfile, but they should see arguments from GOFLAGS. +cp go.alt.mod go.gen.mod +env OLD_GOFLAGS=$GOFLAGS +env GOFLAGS=-modfile=go.gen.mod +go generate -modfile=go.alt.mod . +env GOFLAGS=$OLD_GOFLAGS +grep example.com/exclude go.gen.mod +! grep example.com/exclude go.alt.mod + + +# The original files should not have been modified. +cmp go.mod go.mod.orig +cmp go.sum go.sum.orig + + +# If the alternate mod file does not have a ".mod" suffix, an error +# should be reported. +cp go.alt.mod goaltmod +! go mod tidy -modfile=goaltmod +stderr '-modfile=goaltmod: file does not have .mod extension' + +-- go.mod -- +ʕ◔ϖ◔ʔ +-- go.sum -- +ʕ◔ϖ◔ʔ +-- use.go -- +package main + +import _ "rsc.io/quote" +-- gen.go -- +//go:generate go mod edit -exclude example.com/exclude@v1.0.0 + +package main diff --git a/go/src/cmd/go/testdata/script/netrc_issue66832.txt b/go/src/cmd/go/testdata/script/netrc_issue66832.txt new file mode 100644 index 0000000000000000000000000000000000000000..19c2406305983991470e2f00faec98b585029746 --- /dev/null +++ b/go/src/cmd/go/testdata/script/netrc_issue66832.txt @@ -0,0 +1,48 @@ +# This test ensures .netrc and _netrc are both supported on windows. +# See golang.org/issue/66832 + +[!GOOS:windows] skip +[short] skip + +env GOPROXY=direct +env GOSUMDB=off +mkdir $WORK\home +env USERPROFILE=$WORK\home + +# Make sure _netrc works. +cp netrc_file $WORK\home\_netrc +cp go.mod.orig go.mod +go mod tidy +go list all +stdout vcs-test.golang.org/auth/or401 +stdout vcs-test.golang.org/auth/or404 +rm $WORK\home\_netrc + +# Without credentials, downloading a module from a path that requires HTTPS +# basic auth should fail. +cp go.mod.orig go.mod +! go mod tidy +stderr '^\tserver response: ACCESS DENIED, buddy$' +stderr '^\tserver response: File\? What file\?$' + +# Make sure .netrc works as a fallback. +cp netrc_file $WORK\home\.netrc +cp go.mod.orig go.mod +go mod tidy +go list all +stdout vcs-test.golang.org/auth/or401 +stdout vcs-test.golang.org/auth/or404 + +-- go.mod.orig -- +module private.example.com +-- main.go -- +package useprivate + +import ( + _ "vcs-test.golang.org/auth/or401" + _ "vcs-test.golang.org/auth/or404" +) +-- netrc_file -- +machine vcs-test.golang.org + login aladdin + password opensesame diff --git a/go/src/cmd/go/testdata/script/noncanonical_import.txt b/go/src/cmd/go/testdata/script/noncanonical_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..018cb01ca662e9b2bb68a66d6e02da0a4bc1299d --- /dev/null +++ b/go/src/cmd/go/testdata/script/noncanonical_import.txt @@ -0,0 +1,19 @@ +env GO111MODULE=off + +! go build canonical/d +stderr '^canonical[/\\]b[/\\]b.go:3:8: non-canonical import path "canonical/a/": should be "canonical/a"$' + +-- canonical/a/a.go -- +package a + +import _ "c" +-- canonical/b/b.go -- +package b + +import _ "canonical/a/" +-- canonical/a/vendor/c/c.go -- +package c +-- canonical/d/d.go -- +package d + +import _ "canonical/b" diff --git a/go/src/cmd/go/testdata/script/old_tidy_toolchain.txt b/go/src/cmd/go/testdata/script/old_tidy_toolchain.txt new file mode 100644 index 0000000000000000000000000000000000000000..d4b5af2f76f0e9b6df439801ffbc3bb5a5b95551 --- /dev/null +++ b/go/src/cmd/go/testdata/script/old_tidy_toolchain.txt @@ -0,0 +1,28 @@ +# Commands in an old module with no go line and no toolchain line, +# or with only a go line, should succeed. +# (They should not fail due to the go.mod not being tidy.) + +# No go line, no toolchain line. +go list + +# Old go line, no toolchain line. +go mod edit -go=1.16 +go list + +go mod edit -go=1.20 +go list + +# New go line, no toolchain line, using same toolchain. +env TESTGO_VERSION=1.21 +go mod edit -go=1.21 +go list + +# New go line, no toolchain line, using newer Go version. +# (Until we need to update the go line, no toolchain addition.) +env TESTGO_VERSION=1.21.0 +go list + +-- go.mod -- +module m +-- p.go -- +package p diff --git a/go/src/cmd/go/testdata/script/pattern_syntax_error.txt b/go/src/cmd/go/testdata/script/pattern_syntax_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..9a1f5e52f07a168dac7d442a02f42210a463e5a5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/pattern_syntax_error.txt @@ -0,0 +1,12 @@ +env GO111MODULE=off + +# patterns match directories with syntax errors +! go list ./... +! go build ./... +! go install ./... + +-- mypkg/x.go -- +package mypkg + +-- mypkg/y.go -- +pkg mypackage diff --git a/go/src/cmd/go/testdata/script/prevent_sys_unix_import.txt b/go/src/cmd/go/testdata/script/prevent_sys_unix_import.txt new file mode 100644 index 0000000000000000000000000000000000000000..ea1ad78d71de41c0416974c61775e24db087e6dd --- /dev/null +++ b/go/src/cmd/go/testdata/script/prevent_sys_unix_import.txt @@ -0,0 +1,6 @@ +# Policy decision: we shouldn't vendor golang.org/x/sys/unix in std +# See https://golang.org/issue/32102 + +env GO111MODULE=on +go list std +! stdout vendor/golang.org/x/sys/unix diff --git a/go/src/cmd/go/testdata/script/repro_build.txt b/go/src/cmd/go/testdata/script/repro_build.txt new file mode 100644 index 0000000000000000000000000000000000000000..7c6e317cec3b8982f1f4a488a240a22bb0b71c4c --- /dev/null +++ b/go/src/cmd/go/testdata/script/repro_build.txt @@ -0,0 +1,22 @@ +# Check that goroutine scheduling does not affect compiler output. +# If it does, reproducible builds will not work very well. +[short] skip +[GOOS:aix] env CGO_ENABLED=0 # go.dev/issue/56896 +env GOMAXPROCS=16 +go build -a -o http16.o net/http +env GOMAXPROCS=17 +go build -a -o http17.o net/http +cmp -q http16.o http17.o +env GOMAXPROCS=18 +go build -a -o http18.o net/http +cmp -q http16.o http18.o + +# Check that goroutine scheduling does not affect linker output. +env GOMAXPROCS=16 +go build -a -o gofmt16.exe cmd/gofmt +env GOMAXPROCS=17 +go build -a -o gofmt17.exe cmd/gofmt +cmp -q gofmt16.exe gofmt17.exe +env GOMAXPROCS=18 +go build -a -o gofmt18.exe cmd/gofmt +cmp -q gofmt16.exe gofmt18.exe diff --git a/go/src/cmd/go/testdata/script/reuse_git.txt b/go/src/cmd/go/testdata/script/reuse_git.txt new file mode 100644 index 0000000000000000000000000000000000000000..faf2124db56620368047e6e1c45fff7e29c67fe6 --- /dev/null +++ b/go/src/cmd/go/testdata/script/reuse_git.txt @@ -0,0 +1,480 @@ +[short] skip +[!git] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +# go mod download with the pseudo-version should invoke git but not have a TagSum or Ref or RepoSum. +go mod download -x -json vcs-test.golang.org/git/hello.git@v0.0.0-20170922010558-fc3a09f3dc5c +stderr 'git( .*)* fetch' +cp stdout hellopseudo.json +! stdout '"(Query|TagPrefix|TagSum|Ref|RepoSum)"' +stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/hello"' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +go clean -modcache + +# go mod download vcstest/hello should invoke git, print origin info +go mod download -x -json vcs-test.golang.org/git/hello.git@latest +stderr 'git( .*)* fetch' +cp stdout hello.json +stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/hello"' +stdout '"Query": "latest"' +! stdout '"TagPrefix"' +stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Ref": "HEAD"' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +! stdout '"RepoSum"' + +# pseudo-version again should not invoke git fetch (it has the version from the @latest query) +# but still be careful not to include a TagSum or a Ref, especially not Ref set to HEAD, +# which is easy to do when reusing the cached version from the @latest query. +go mod download -x -json vcs-test.golang.org/git/hello.git@v0.0.0-20170922010558-fc3a09f3dc5c +! stderr 'git( .*)* fetch' +cp stdout hellopseudo2.json +cmpenv hellopseudo.json hellopseudo2.json + +# go mod download vcstest/hello@hash needs to check TagSum to find pseudoversion base. +go mod download -x -json vcs-test.golang.org/git/hello.git@fc3a09f3dc5c +! stderr 'git( .*)* fetch' +cp stdout hellohash.json +stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"' +stdout '"Query": "fc3a09f3dc5c"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/hello"' +stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +! stdout '"RepoSum"' + +# go mod download vcstest/hello/v9 should fail, still print origin info +! go mod download -x -json vcs-test.golang.org/git/hello.git/v9@latest +cp stdout hellov9.json +stdout '"Version": "latest"' +stdout '"Error":.*no matching versions' +! stdout '"TagPrefix"' +stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Ref": "HEAD"' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +! stdout 'RepoSum' + +# go mod download vcstest/hello/sub/v9 should also fail, print origin info with TagPrefix +! go mod download -x -json vcs-test.golang.org/git/hello.git/sub/v9@latest +cp stdout hellosubv9.json +stdout '"Version": "latest"' +stdout '"Error":.*no matching versions' +stdout '"TagPrefix": "sub/"' +stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Ref": "HEAD"' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +! stdout 'RepoSum' + +# go mod download vcstest/hello@nonexist should fail, still print origin info +! go mod download -x -json vcs-test.golang.org/git/hello.git@nonexist +cp stdout hellononexist.json +stdout '"Version": "nonexist"' +stdout '"Error":.*unknown revision nonexist' +stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' + +# go mod download vcstest/hello@1234567890123456789012345678901234567890 should fail, still print origin info +# (40 hex digits is assumed to be a full hash and is a slightly different code path from @nonexist) +! go mod download -x -json vcs-test.golang.org/git/hello.git@1234567890123456789012345678901234567890 +cp stdout hellononhash.json +stdout '"Version": "1234567890123456789012345678901234567890"' +stdout '"Error":.*unknown revision 1234567890123456789012345678901234567890' +stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' + +# go mod download vcstest/hello@v0.0.0-20220101120101-123456789abc should fail, still print origin info +# (non-existent pseudoversion) +! go mod download -x -json vcs-test.golang.org/git/hello.git@v0.0.0-20220101120101-123456789abc +cp stdout hellononpseudo.json +stdout '"Version": "v0.0.0-20220101120101-123456789abc"' +stdout '"Error":.*unknown revision 123456789abc' +stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' + +# go mod download vcstest/tagtests should invoke git, print origin info +go mod download -x -json vcs-test.golang.org/git/tagtests.git@latest +stderr 'git( .*)* fetch' +cp stdout tagtests.json +stdout '"Version": "v0.2.2"' +stdout '"Query": "latest"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/tagtests"' +! stdout '"TagPrefix"' +stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="' +stdout '"Ref": "refs/tags/v0.2.2"' +stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"' +! stdout '"RepoSum"' + +# go mod download vcstest/tagtests@v0.2.2 should print origin info, no TagSum needed +go mod download -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2 +cp stdout tagtestsv022.json +stdout '"Version": "v0.2.2"' +! stdout '"Query":' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/tagtests"' +! stdout '"TagPrefix"' +! stdout '"TagSum"' +stdout '"Ref": "refs/tags/v0.2.2"' +stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"' +! stdout '"RepoSum"' + +# go mod download vcstest/tagtests@master needs a TagSum again +go mod download -x -json vcs-test.golang.org/git/tagtests.git@master +cp stdout tagtestsmaster.json +stdout '"Version": "v0.2.3-0.20190509225625-c7818c24fa2f"' +stdout '"Query": "master"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/tagtests"' +! stdout '"TagPrefix"' +stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="' +stdout '"Ref": "refs/heads/master"' +stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"' +! stdout '"RepoSum"' + +# go mod download vcstest/prefixtagtests should invoke git, print origin info +go mod download -x -json vcs-test.golang.org/git/prefixtagtests.git/sub@latest +stderr 'git( .*)* fetch' +cp stdout prefixtagtests.json +stdout '"Version": "v0.0.10"' +stdout '"Query": "latest"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/prefixtagtests"' +stdout '"Subdir": "sub"' +stdout '"TagPrefix": "sub/"' +stdout '"TagSum": "t1:YGSbWkJ8dn9ORAr[+]BlKHFK/2ZhXLb9hVuYfTZ9D8C7g="' +stdout '"Ref": "refs/tags/sub/v0.0.10"' +stdout '"Hash": "2b7c4692e12c109263cab51b416fcc835ddd7eae"' +! stdout '"RepoSum"' + +# go mod download of a bunch of these should fail (some are invalid) but write good JSON for later +! go mod download -json vcs-test.golang.org/git/hello.git@latest vcs-test.golang.org/git/hello.git/v9@latest vcs-test.golang.org/git/hello.git/sub/v9@latest vcs-test.golang.org/git/tagtests.git@latest vcs-test.golang.org/git/tagtests.git@v0.2.2 vcs-test.golang.org/git/tagtests.git@master +cp stdout all.json + +# clean the module cache, make sure that makes go mod download re-run git fetch, clean again +go clean -modcache +go mod download -x -json vcs-test.golang.org/git/hello.git@latest +stderr 'git( .*)* fetch' +go clean -modcache + +# reuse go mod download vcstest/hello result +go clean -modcache +go mod download -reuse=hello.json -x -json vcs-test.golang.org/git/hello.git@latest +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/hello"' +! stdout '"TagPrefix"' +stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Ref": "HEAD"' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"' + +# reuse go mod download vcstest/hello pseudoversion result +go clean -modcache +go mod download -reuse=hellopseudo.json -x -json vcs-test.golang.org/git/hello.git@v0.0.0-20170922010558-fc3a09f3dc5c +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/hello"' +! stdout '"(Query|TagPrefix|TagSum|Ref)"' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"' + +# reuse go mod download vcstest/hello@hash +go clean -modcache +go mod download -reuse=hellohash.json -x -json vcs-test.golang.org/git/hello.git@fc3a09f3dc5c +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Query": "fc3a09f3dc5c"' +stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/hello"' +! stdout '"(TagPrefix|Ref)"' +stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"' + +# reuse go mod download vcstest/hello/v9 error result +go clean -modcache +! go mod download -reuse=hellov9.json -x -json vcs-test.golang.org/git/hello.git/v9@latest +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Error":.*no matching versions' +! stdout '"TagPrefix"' +stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Ref": "HEAD"' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"' + +# reuse go mod download vcstest/hello/sub/v9 error result +go clean -modcache +! go mod download -reuse=hellosubv9.json -x -json vcs-test.golang.org/git/hello.git/sub/v9@latest +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Error":.*no matching versions' +stdout '"TagPrefix": "sub/"' +stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Ref": "HEAD"' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"' + +# reuse go mod download vcstest/hello@nonexist +go clean -modcache +! go mod download -reuse=hellononexist.json -x -json vcs-test.golang.org/git/hello.git@nonexist +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Version": "nonexist"' +stdout '"Error":.*unknown revision nonexist' +stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/hello@1234567890123456789012345678901234567890 +go clean -modcache +! go mod download -reuse=hellononhash.json -x -json vcs-test.golang.org/git/hello.git@1234567890123456789012345678901234567890 +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Version": "1234567890123456789012345678901234567890"' +stdout '"Error":.*unknown revision 1234567890123456789012345678901234567890' +stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/hello@v0.0.0-20220101120101-123456789abc +go clean -modcache +! go mod download -reuse=hellononpseudo.json -x -json vcs-test.golang.org/git/hello.git@v0.0.0-20220101120101-123456789abc +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Version": "v0.0.0-20220101120101-123456789abc"' +stdout '"Error":.*unknown revision 123456789abc' +stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/tagtests result +go clean -modcache +go mod download -reuse=tagtests.json -x -json vcs-test.golang.org/git/tagtests.git@latest +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Version": "v0.2.2"' +stdout '"Query": "latest"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/tagtests"' +! stdout '"TagPrefix"' +stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="' +stdout '"Ref": "refs/tags/v0.2.2"' +stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"' +! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"' + +# reuse go mod download vcstest/tagtests@v0.2.2 result +go clean -modcache +go mod download -reuse=tagtestsv022.json -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2 +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Version": "v0.2.2"' +! stdout '"Query":' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/tagtests"' +! stdout '"TagPrefix"' +! stdout '"TagSum"' +stdout '"Ref": "refs/tags/v0.2.2"' +stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"' +! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"' + +# reuse go mod download vcstest/tagtests@master result +go clean -modcache +go mod download -reuse=tagtestsmaster.json -x -json vcs-test.golang.org/git/tagtests.git@master +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Version": "v0.2.3-0.20190509225625-c7818c24fa2f"' +stdout '"Query": "master"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/tagtests"' +! stdout '"TagPrefix"' +stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="' +stdout '"Ref": "refs/heads/master"' +stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"' +! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"' + +# reuse go mod download vcstest/tagtests@master result again with all.json +go clean -modcache +go mod download -reuse=all.json -x -json vcs-test.golang.org/git/tagtests.git@master +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Version": "v0.2.3-0.20190509225625-c7818c24fa2f"' +stdout '"Query": "master"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/tagtests"' +! stdout '"TagPrefix"' +stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="' +stdout '"Ref": "refs/heads/master"' +stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"' +! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"' + +# go mod download vcstest/prefixtagtests result with json +go clean -modcache +go mod download -reuse=prefixtagtests.json -x -json vcs-test.golang.org/git/prefixtagtests.git/sub@latest +! stderr 'git( .*)* fetch' +stdout '"Version": "v0.0.10"' +stdout '"Query": "latest"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/prefixtagtests"' +stdout '"Subdir": "sub"' +stdout '"TagPrefix": "sub/"' +stdout '"TagSum": "t1:YGSbWkJ8dn9ORAr[+]BlKHFK/2ZhXLb9hVuYfTZ9D8C7g="' +stdout '"Ref": "refs/tags/sub/v0.0.10"' +stdout '"Hash": "2b7c4692e12c109263cab51b416fcc835ddd7eae"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse the bulk results with all.json +go clean -modcache +! go mod download -reuse=all.json -json vcs-test.golang.org/git/hello.git@latest vcs-test.golang.org/git/hello.git/v9@latest vcs-test.golang.org/git/hello.git/sub/v9@latest vcs-test.golang.org/git/tagtests.git@latest vcs-test.golang.org/git/tagtests.git@v0.2.2 vcs-test.golang.org/git/tagtests.git@master +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse attempt with stale hash should reinvoke git, not report reuse +go clean -modcache +cp tagtestsv022.json tagtestsv022badhash.json +replace '57952' '56952XXX' tagtestsv022badhash.json +go mod download -reuse=tagtestsv022badhash.json -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2 +stderr 'git( .*)* fetch' +! stdout '"Reuse": true' +stdout '"Version": "v0.2.2"' +! stdout '"Query"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/tagtests"' +! stdout '"(TagPrefix|TagSum|RepoSum)"' +stdout '"Ref": "refs/tags/v0.2.2"' +stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"' +stdout '"Dir"' +stdout '"Info"' +stdout '"GoMod"' +stdout '"Zip"' + +# reuse with stale repo URL +go clean -modcache +cp tagtestsv022.json tagtestsv022badurl.json +replace 'git/tagtests\"' 'git/tagtestsXXX\"' tagtestsv022badurl.json +go mod download -reuse=tagtestsv022badurl.json -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2 +! stdout '"Reuse": true' +stdout '"URL": ".*/git/tagtests"' +stdout '"Dir"' +stdout '"Info"' +stdout '"GoMod"' +stdout '"Zip"' + +# reuse with stale VCS +go clean -modcache +cp tagtestsv022.json tagtestsv022badvcs.json +replace '\"git\"' '\"gitXXX\"' tagtestsv022badvcs.json +go mod download -reuse=tagtestsv022badvcs.json -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2 +! stdout '"Reuse": true' +stdout '"URL": ".*/git/tagtests"' +! stdout '"RepoSum"' + +# reuse with stale Dir +go clean -modcache +cp tagtestsv022.json tagtestsv022baddir.json +replace '\t\t\"Ref\":' '\t\t\"Subdir\": \"subdir\",\n\t\t\"Ref\":' tagtestsv022baddir.json +go mod download -reuse=tagtestsv022baddir.json -x -json vcs-test.golang.org/git/tagtests.git@v0.2.2 +! stdout '"Reuse": true' +stdout '"URL": ".*/git/tagtests"' +! stdout '"RepoSum"' + +# reuse with stale TagSum +go clean -modcache +cp tagtests.json tagtestsbadtagsum.json +replace 'sMEOGo=' 'sMEoGo=XXX' tagtestsbadtagsum.json +go mod download -reuse=tagtestsbadtagsum.json -x -json vcs-test.golang.org/git/tagtests.git@latest +! stdout '"Reuse": true' +stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="' +! stdout '"RepoSum"' + +# go list on repo with no tags +go clean -modcache +go list -x -json -m -retracted -versions vcs-test.golang.org/git/hello.git@latest +stderr 'git( .*)* fetch' +cp stdout hellolist.json +! stdout '"Versions"' +stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/hello"' +stdout '"Query": "latest"' +! stdout '"TagPrefix"' +stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +! stdout '"RepoSum"' + +# reuse go list on repo with no tags +go clean -modcache +go list -x -reuse=hellolist.json -json -m -retracted -versions vcs-test.golang.org/git/hello.git@latest +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +! stdout '"Versions"' +stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/hello"' +stdout '"Query": "latest"' +! stdout '"TagPrefix"' +stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="' +stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"' +! stdout '"RepoSum"' + +# reuse with stale list +go clean -modcache +cp hellolist.json hellolistbad.json +replace '47DEQ' 'ZZZ' hellolistbad.json +go clean -modcache +go list -x -reuse=hellolistbad.json -json -m -retracted -versions vcs-test.golang.org/git/hello.git@latest +stderr 'git( .*)* fetch' +! stdout '"Reuse": true' +stdout '"TagSum": "t1:47DEQpj8HBSa[+]/TImW[+]5JCeuQeRkm5NMpJWZG3hSuFU="' + +# go list on repo with tags +go clean -modcache +go list -x -json -m -retracted -versions vcs-test.golang.org/git/tagtests.git@latest +cp stdout taglist.json +stderr 'git( .*)* fetch' +stdout '"Versions":' +stdout '"v0.2.1"' +stdout '"v0.2.2"' +stdout '"Version": "v0.2.2"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/tagtests"' +stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"' +stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="' +stdout '"Ref": "refs/tags/v0.2.2"' + +# reuse go list on repo with tags +go clean -modcache +go list -reuse=taglist.json -x -json -m -retracted -versions vcs-test.golang.org/git/tagtests.git@latest +! stderr 'git( .*)* fetch' +stdout '"Reuse": true' +stdout '"Versions":' +stdout '"v0.2.1"' +stdout '"v0.2.2"' +stdout '"Version": "v0.2.2"' +stdout '"VCS": "git"' +stdout '"URL": ".*/git/tagtests"' +stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"' +stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="' +stdout '"Ref": "refs/tags/v0.2.2"' + +# reuse with stale list +go clean -modcache +cp taglist.json taglistbad.json +replace 'Dp7yRKDu' 'ZZZ' taglistbad.json +go list -reuse=taglistbad.json -x -json -m -retracted -versions vcs-test.golang.org/git/tagtests.git@latest +stderr 'git( .*)* fetch' +! stdout '"Reuse": true' +stdout '"TagSum": "t1:Dp7yRKDuE8WjG0429PN9hYWjqhy2te7P9Oki/sMEOGo="' diff --git a/go/src/cmd/go/testdata/script/reuse_hg.txt b/go/src/cmd/go/testdata/script/reuse_hg.txt new file mode 100644 index 0000000000000000000000000000000000000000..d7637a9c55228e8d095dee1e4bdd22ca01cbb9fa --- /dev/null +++ b/go/src/cmd/go/testdata/script/reuse_hg.txt @@ -0,0 +1,471 @@ +[short] skip +[!exec:hg] skip + +env GO111MODULE=on +env GOPROXY=direct +env GOSUMDB=off + +# go mod download with the pseudo-version should invoke hg but not have a TagSum or Ref or RepoSum. +go mod download -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922011414-e483a7d9f8c9 +stderr 'hg( .*)* pull' +cp stdout hellopseudo.json +! stdout '"(Query|TagPrefix|TagSum|Ref|RepoSum)"' +stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/hello"' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' +! stdout '"RepoSum"' +go clean -modcache + +# go mod download vcstest/hello should invoke hg, print origin info +go mod download -x -json vcs-test.golang.org/hg/hello.hg@latest +stderr 'hg( .*)* pull' +cp stdout hello.json +stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/hello"' +stdout '"Query": "latest"' +! stdout '"TagPrefix"' +! stdout '"TagSum"' +stdout '"Ref": "tip"' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' + +# pseudo-version again should not invoke hg pull (it has the version from the @latest query) +# but still be careful not to include a TagSum or a Ref, especially not Ref set to HEAD, +# which is easy to do when reusing the cached version from the @latest query. +go mod download -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922011414-e483a7d9f8c9 +! stderr 'hg( .*)* pull' +cp stdout hellopseudo2.json +cmpenv hellopseudo.json hellopseudo2.json + +# go mod download hg/hello@hash needs to check RepoSum to find pseudoversion base, +# which does a refreshing hg pull. +go mod download -x -json vcs-test.golang.org/hg/hello.hg@e483a7d9f8c9 +stderr 'hg( .*)* pull' +cp stdout hellohash.json +stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"' +stdout '"Query": "e483a7d9f8c9"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/hello"' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' + +# go mod download vcstest/hello/v9 should fail, still print origin info +# hg uses RepoSum instead of TagSum to describe failure condition. +! go mod download -x -json vcs-test.golang.org/hg/hello.hg/v9@latest +cp stdout hellov9.json +stdout '"Version": "latest"' +stdout '"Error":.*no matching versions' +! stdout '"TagPrefix"' +! stdout '"TagSum"' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' + +# go mod download vcstest/hello/sub/v9 should also fail, print origin info +# hg uses RepoSum instead of TagSum to describe failure condition. +! go mod download -x -json vcs-test.golang.org/hg/hello.hg/sub/v9@latest +cp stdout hellosubv9.json +stdout '"Version": "latest"' +stdout '"Error":.*no matching versions' +! stdout '"TagPrefix"' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' + +# go mod download vcstest/hello@nonexist should fail, still print origin info +! go mod download -x -json vcs-test.golang.org/hg/hello.hg@nonexist +cp stdout hellononexist.json +stdout '"Version": "nonexist"' +stdout '"Error":.*unknown revision nonexist' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' + +# go mod download vcstest/hello@1234567890123456789012345678901234567890 should fail, still print origin info +# (40 hex digits is assumed to be a full hash and is a slightly different code path from @nonexist) +! go mod download -x -json vcs-test.golang.org/hg/hello.hg@1234567890123456789012345678901234567890 +cp stdout hellononhash.json +stdout '"Version": "1234567890123456789012345678901234567890"' +stdout '"Error":.*unknown revision 1234567890123456789012345678901234567890' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' + +# go mod download vcstest/hello@v0.0.0-20220101120101-123456789abc should fail, still print origin info +# (non-existent pseudoversion) +! go mod download -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20220101120101-123456789abc +cp stdout hellononpseudo.json +stdout '"Version": "v0.0.0-20220101120101-123456789abc"' +stdout '"Error":.*unknown revision 123456789abc' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' + +# go mod download vcstest/tagtests should invoke hg, print origin info +# Need RepoSum to lock in tagged "latest". +go mod download -x -json vcs-test.golang.org/hg/tagtests.hg@latest +stderr 'hg( .*)* pull' +cp stdout tagtests.json +stdout '"Version": "v0.2.2"' +stdout '"Query": "latest"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/tagtests"' +! stdout '"TagPrefix"' +! stdout '"TagSum"' +stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="' +stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"' + +# go mod download vcstest/tagtests@v0.2.2 should print origin info, no TagSum or RepoSum needed. +go mod download -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2 +cp stdout tagtestsv022.json +stdout '"Version": "v0.2.2"' +! stdout '"Query":' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/tagtests"' +! stdout '"TagPrefix"' +! stdout '"TagSum"' +! stdout '"RepoSum"' +stdout '"Ref": "v0.2.2"' +stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"' + +# go mod download vcstest/tagtests@default needs a RepoSum again +go mod download -x -json vcs-test.golang.org/hg/tagtests.hg@default +cp stdout tagtestsdefault.json +stdout '"Version": "v0.2.3-0.20190509225625-8d0b18b816df"' +stdout '"Query": "default"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/tagtests"' +! stdout '"TagPrefix"' +! stdout '"TagSum"' +stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="' +stdout '"Hash": "8d0b18b816df5e9c564761b405b1d7949c24ee6b"' + +# go mod download vcstest/prefixtagtests should invoke hg, print origin info +go mod download -x -json vcs-test.golang.org/hg/prefixtagtests.hg/sub@latest +stderr 'hg( .*)* pull' +cp stdout prefixtagtests.json +stdout '"Version": "v0.0.10"' +stdout '"Query": "latest"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/prefixtagtests"' +stdout '"Subdir": "sub"' +stdout '"Ref": "sub/v0.0.10"' +! stdout '"TagPrefix"' +! stdout '"TagSum"' +stdout '"RepoSum": "r1:YWOcei109p5Kohsr5xnSYlaQXmpT3iWZHZhRbfMoTkc="' +stdout '"Hash": "1cc0dfcc254cb8901799e7f7ae182c04019b7a88"' + +# go mod download of a bunch of these should fail (some are invalid) but write good JSON for later +! go mod download -json vcs-test.golang.org/hg/hello.hg@latest vcs-test.golang.org/hg/hello.hg/v9@latest vcs-test.golang.org/hg/hello.hg/sub/v9@latest vcs-test.golang.org/hg/tagtests.hg@latest vcs-test.golang.org/hg/tagtests.hg@v0.2.2 vcs-test.golang.org/hg/tagtests.hg@default +cp stdout all.json + +# clean the module cache, make sure that makes go mod download re-run hg pull, clean again +go clean -modcache +go mod download -x -json vcs-test.golang.org/hg/hello.hg@latest +stderr 'hg( .*)* pull' +go clean -modcache + +# reuse go mod download vcstest/hello result +go clean -modcache +go mod download -reuse=hello.json -x -json vcs-test.golang.org/hg/hello.hg@latest +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/hello"' +! stdout '"TagPrefix"' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +stdout '"Ref": "tip"' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/hello pseudoversion result +go clean -modcache +go mod download -reuse=hellopseudo.json -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20170922011414-e483a7d9f8c9 +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/hello"' +! stdout '"(Query|TagPrefix|TagSum|Ref)"' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' +! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"' + +# reuse go mod download vcstest/hello@hash +go clean -modcache +go mod download -reuse=hellohash.json -x -json vcs-test.golang.org/hg/hello.hg@e483a7d9f8c9 +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Query": "e483a7d9f8c9"' +stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/hello"' +! stdout '"(TagPrefix|Ref)"' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/hello/v9 error result +go clean -modcache +! go mod download -reuse=hellov9.json -x -json vcs-test.golang.org/hg/hello.hg/v9@latest +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Error":.*no matching versions' +! stdout '"TagPrefix"' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/hello/sub/v9 error result +go clean -modcache +! go mod download -reuse=hellosubv9.json -x -json vcs-test.golang.org/hg/hello.hg/sub/v9@latest +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Error":.*no matching versions' +! stdout '"TagPrefix"' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +stdout '"Ref": "tip"' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/hello@nonexist +go clean -modcache +! go mod download -reuse=hellononexist.json -x -json vcs-test.golang.org/hg/hello.hg@nonexist +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Version": "nonexist"' +stdout '"Error":.*unknown revision nonexist' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/hello@1234567890123456789012345678901234567890 +go clean -modcache +! go mod download -reuse=hellononhash.json -x -json vcs-test.golang.org/hg/hello.hg@1234567890123456789012345678901234567890 +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Version": "1234567890123456789012345678901234567890"' +stdout '"Error":.*unknown revision 1234567890123456789012345678901234567890' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/hello@v0.0.0-20220101120101-123456789abc +go clean -modcache +! go mod download -reuse=hellononpseudo.json -x -json vcs-test.golang.org/hg/hello.hg@v0.0.0-20220101120101-123456789abc +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Version": "v0.0.0-20220101120101-123456789abc"' +stdout '"Error":.*unknown revision 123456789abc' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +! stdout '"(TagPrefix|TagSum|Ref|Hash)"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/tagtests result +go clean -modcache +go mod download -reuse=tagtests.json -x -json vcs-test.golang.org/hg/tagtests.hg@latest +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Version": "v0.2.2"' +stdout '"Query": "latest"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/tagtests"' +! stdout '"TagPrefix"' +stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="' +stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/tagtests@v0.2.2 result +go clean -modcache +go mod download -reuse=tagtestsv022.json -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2 +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Version": "v0.2.2"' +! stdout '"Query":' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/tagtests"' +! stdout '"TagPrefix"' +! stdout '"TagSum"' +stdout '"Ref": "v0.2.2"' +stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"' +! stdout '"(Dir|Info|GoMod|Zip|RepoSum)"' + +# reuse go mod download vcstest/tagtests@default result +go clean -modcache +go mod download -reuse=tagtestsdefault.json -x -json vcs-test.golang.org/hg/tagtests.hg@default +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Version": "v0.2.3-0.20190509225625-8d0b18b816df"' +stdout '"Query": "default"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/tagtests"' +! stdout '"TagPrefix"' +stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="' +stdout '"Ref": "default"' +stdout '"Hash": "8d0b18b816df5e9c564761b405b1d7949c24ee6b"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse go mod download vcstest/tagtests@default result again with all.json +go clean -modcache +go mod download -reuse=all.json -x -json vcs-test.golang.org/hg/tagtests.hg@default +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Version": "v0.2.3-0.20190509225625-8d0b18b816df"' +stdout '"Query": "default"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/tagtests"' +! stdout '"TagPrefix"' +stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="' +stdout '"Ref": "default"' +stdout '"Hash": "8d0b18b816df5e9c564761b405b1d7949c24ee6b"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# go mod download vcstest/prefixtagtests result with json +go clean -modcache +go mod download -reuse=prefixtagtests.json -x -json vcs-test.golang.org/hg/prefixtagtests.hg/sub@latest +! stderr 'hg( .*)* pull' +stdout '"Version": "v0.0.10"' +stdout '"Query": "latest"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/prefixtagtests"' +stdout '"Subdir": "sub"' +stdout '"RepoSum": "r1:YWOcei109p5Kohsr5xnSYlaQXmpT3iWZHZhRbfMoTkc="' +stdout '"Ref": "sub/v0.0.10"' +stdout '"Hash": "1cc0dfcc254cb8901799e7f7ae182c04019b7a88"' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse the bulk results with all.json +go clean -modcache +! go mod download -reuse=all.json -json vcs-test.golang.org/hg/hello.hg@latest vcs-test.golang.org/hg/hello.hg/v9@latest vcs-test.golang.org/hg/hello.hg/sub/v9@latest vcs-test.golang.org/hg/tagtests.hg@latest vcs-test.golang.org/hg/tagtests.hg@v0.2.2 vcs-test.golang.org/hg/tagtests.hg@default +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +! stdout '"(Dir|Info|GoMod|Zip)"' + +# reuse attempt with stale hash should reinvoke hg, not report reuse +go clean -modcache +cp tagtestsv022.json tagtestsv022badhash.json +replace '1e5315' '1e5315XXX' tagtestsv022badhash.json +go mod download -reuse=tagtestsv022badhash.json -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2 +stderr 'hg( .*)* pull' +! stdout '"Reuse": true' +stdout '"Version": "v0.2.2"' +! stdout '"Query"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/tagtests"' +! stdout '"(TagPrefix|TagSum|RepoSum)"' +stdout '"Ref": "v0.2.2"' +stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"' +stdout '"Dir"' +stdout '"Info"' +stdout '"GoMod"' +stdout '"Zip"' + +# reuse with stale repo URL +go clean -modcache +cp tagtestsv022.json tagtestsv022badurl.json +replace 'hg/tagtests\"' 'hg/tagtestsXXX\"' tagtestsv022badurl.json +go mod download -reuse=tagtestsv022badurl.json -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2 +! stdout '"Reuse": true' +stdout '"URL": ".*/hg/tagtests"' +stdout '"Dir"' +stdout '"Info"' +stdout '"GoMod"' +stdout '"Zip"' + +# reuse with stale VCS +go clean -modcache +cp tagtestsv022.json tagtestsv022badvcs.json +replace '\"hg\"' '\"hgXXX\"' tagtestsv022badvcs.json +go mod download -reuse=tagtestsv022badvcs.json -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2 +! stdout '"Reuse": true' +stdout '"URL": ".*/hg/tagtests"' +! stdout '"RepoSum"' + +# reuse with stale Dir +go clean -modcache +cp tagtestsv022.json tagtestsv022baddir.json +replace '\"VCS\":' '\"Subdir\":\"subdir\", \"VCS\":' tagtestsv022baddir.json +go mod download -reuse=tagtestsv022baddir.json -x -json vcs-test.golang.org/hg/tagtests.hg@v0.2.2 +! stdout '"Reuse": true' +stdout '"URL": ".*/hg/tagtests"' +! stdout '"RepoSum"' + +# reuse with stale RepoSum +go clean -modcache +cp tagtests.json tagtestsbadreposum.json +replace '8dnv90' '8dnv90XXX' tagtestsbadreposum.json +go mod download -reuse=tagtestsbadreposum.json -x -json vcs-test.golang.org/hg/tagtests.hg@latest +! stdout '"Reuse": true' +stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="' + +# go list on repo with no tags +go clean -modcache +go list -x -json -m -retracted -versions vcs-test.golang.org/hg/hello.hg@latest +stderr 'hg( .*)* pull' +cp stdout hellolist.json +! stdout '"Versions"' +stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/hello"' +stdout '"Query": "latest"' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' + +# reuse go list on repo with no tags +go clean -modcache +go list -x -reuse=hellolist.json -json -m -retracted -versions vcs-test.golang.org/hg/hello.hg@latest +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +! stdout '"Versions"' +stdout '"Version": "v0.0.0-20170922011414-e483a7d9f8c9"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/hello"' +stdout '"Query": "latest"' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' +stdout '"Hash": "e483a7d9f8c9b4bc57430bdd8f81f0a65e4011c0"' + +# reuse with stale list +go clean -modcache +cp hellolist.json hellolistbad.json +replace 'blLvkhBri' 'ZZZ' hellolistbad.json +go clean -modcache +go list -x -reuse=hellolistbad.json -json -m -retracted -versions vcs-test.golang.org/hg/hello.hg@latest +stderr 'hg( .*)* pull' +! stdout '"Reuse": true' +stdout '"RepoSum": "r1:blLvkhBriVMV[+]6Il4Ub43wlyWXIe1NpobTelF0peaG0="' + +# go list on repo with tags +go clean -modcache +go list -x -json -m -retracted -versions vcs-test.golang.org/hg/tagtests.hg@latest +cp stdout taglist.json +stderr 'hg( .*)* pull' +stdout '"Versions":' +stdout '"v0.2.1"' +stdout '"v0.2.2"' +stdout '"Version": "v0.2.2"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/tagtests"' +stdout '"Ref": "v0.2.2"' +stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"' +stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="' + +# reuse go list on repo with tags +go clean -modcache +go list -reuse=taglist.json -x -json -m -retracted -versions vcs-test.golang.org/hg/tagtests.hg@latest +! stderr 'hg( .*)* pull' +stdout '"Reuse": true' +stdout '"Versions":' +stdout '"v0.2.1"' +stdout '"v0.2.2"' +stdout '"Version": "v0.2.2"' +stdout '"VCS": "hg"' +stdout '"URL": ".*/hg/tagtests"' +stdout '"Ref": "v0.2.2"' +stdout '"Hash": "1e531550e864b16f25013cfbbf2d8e7cf07a0374"' +stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="' + +# reuse with stale list +go clean -modcache +cp taglist.json taglistbad.json +replace '8dnv906' 'ZZZ' taglistbad.json +go list -reuse=taglistbad.json -x -json -m -retracted -versions vcs-test.golang.org/hg/tagtests.hg@latest +stderr 'hg( .*)* pull' +! stdout '"Reuse": true' +stdout '"RepoSum": "r1:8dnv906Aq1vb9YpNl9pslfva0VfG9enKb6O6NWs0xF0="' diff --git a/go/src/cmd/go/testdata/script/run_dirs.txt b/go/src/cmd/go/testdata/script/run_dirs.txt new file mode 100644 index 0000000000000000000000000000000000000000..bd5cfbe3fb272cb8e0095375f9fcd9be42439666 --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_dirs.txt @@ -0,0 +1,21 @@ +cd rundir + +! go run x.go sub/sub.go +stderr 'named files must all be in one directory; have . and sub' +! go run sub/sub.go x.go +stderr 'named files must all be in one directory; have sub and .' + +cd ../ +go run rundir/foo.go ./rundir/bar.go +stderr 'hello world' + +-- rundir/sub/sub.go -- +package main +-- rundir/x.go -- +package main +-- rundir/foo.go -- +package main +func main() { println(msg) } +-- rundir/bar.go -- +package main +const msg = "hello world" diff --git a/go/src/cmd/go/testdata/script/run_goroot_PATH.txt b/go/src/cmd/go/testdata/script/run_goroot_PATH.txt new file mode 100644 index 0000000000000000000000000000000000000000..a103cf645eb25ef74fa9e2313b8e00884fa557b5 --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_goroot_PATH.txt @@ -0,0 +1,42 @@ +# https://go.dev/issue/68005: 'go run' should run the program with its own GOROOT/bin +# at the beginning of $PATH. + +[short] skip + +[!GOOS:plan9] env PATH= +[GOOS:plan9] env path= +go run . + +[!GOOS:plan9] env PATH=$WORK${/}bin +[GOOS:plan9] env path=$WORK${/}bin +go run . + +-- go.mod -- +module example + +go 1.19 +-- main.go -- +package main + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" +) + +func main() { + got, err := exec.LookPath("go") + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + want := filepath.Join(os.Getenv("GOROOT"), "bin", "go" + os.Getenv("GOEXE")) + if got != want { + fmt.Printf(`exec.LookPath("go") = %q; want %q\n`, got, want) + os.Exit(1) + } +} +-- $WORK/bin/README.txt -- +This directory contains no executables. diff --git a/go/src/cmd/go/testdata/script/run_hello.txt b/go/src/cmd/go/testdata/script/run_hello.txt new file mode 100644 index 0000000000000000000000000000000000000000..939b661e58f378ede7fc0735759d0628c7e7d99c --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_hello.txt @@ -0,0 +1,9 @@ +env GO111MODULE=off + +# hello world +go run hello.go +stderr 'hello world' + +-- hello.go -- +package main +func main() { println("hello world") } diff --git a/go/src/cmd/go/testdata/script/run_hello_pkg.txt b/go/src/cmd/go/testdata/script/run_hello_pkg.txt new file mode 100644 index 0000000000000000000000000000000000000000..ea2b4d7cdeef908e178d496294a161a070c1f894 --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_hello_pkg.txt @@ -0,0 +1,17 @@ +go run m/hello +stderr 'hello, world' + +cd hello +go run . +stderr 'hello, world' + +-- go.mod -- +module m + +go 1.16 +-- hello/hello.go -- +package main + +func main() { + println("hello, world") +} diff --git a/go/src/cmd/go/testdata/script/run_internal.txt b/go/src/cmd/go/testdata/script/run_internal.txt new file mode 100644 index 0000000000000000000000000000000000000000..d02185017b37a750198c37b181a29679f0dbc297 --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_internal.txt @@ -0,0 +1,64 @@ +env GO111MODULE=off + +go list -e -f '{{.Incomplete}}' m/runbad1.go +stdout true +! go run m/runbad1.go +stderr 'use of internal package m/x/internal not allowed' + +go list -e -f '{{.Incomplete}}' m/runbad2.go +stdout true +! go run m/runbad2.go +stderr 'use of internal package m/x/internal/y not allowed' + +go list -e -f '{{.Incomplete}}' m/runok.go +stdout false +go run m/runok.go + +cd m +env GO111MODULE=on + +go list -e -f '{{.Incomplete}}' runbad1.go +stdout true +! go run runbad1.go +stderr 'use of internal package m/x/internal not allowed' + +go list -e -f '{{.Incomplete}}' runbad2.go +stdout true +! go run runbad2.go +stderr 'use of internal package m/x/internal/y not allowed' + +go list -e -f '{{.Incomplete}}' runok.go +stdout false +go run runok.go + + +-- m/go.mod -- +module m + +-- m/x/internal/internal.go -- +package internal + +-- m/x/internal/y/y.go -- +package y + +-- m/internal/internal.go -- +package internal + +-- m/internal/z/z.go -- +package z + +-- m/runbad1.go -- +package main +import _ "m/x/internal" +func main() {} + +-- m/runbad2.go -- +package main +import _ "m/x/internal/y" +func main() {} + +-- m/runok.go -- +package main +import _ "m/internal" +import _ "m/internal/z" +func main() {} diff --git a/go/src/cmd/go/testdata/script/run_issue11709.txt b/go/src/cmd/go/testdata/script/run_issue11709.txt new file mode 100644 index 0000000000000000000000000000000000000000..c8ba9982b20039a2000305687c1e8a0ea071829e --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_issue11709.txt @@ -0,0 +1,15 @@ +# 'go run' should not pass extraneous environment variables to the subprocess. +go run run.go +! stdout . +! stderr . + +-- run.go -- +package main + +import "os" + +func main() { + if os.Getenv("TERM") != "" { + os.Exit(1) + } +} \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/run_issue51125.txt b/go/src/cmd/go/testdata/script/run_issue51125.txt new file mode 100644 index 0000000000000000000000000000000000000000..8fa4486ca4186d375087edba0b4c2ce6c04eae21 --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_issue51125.txt @@ -0,0 +1,54 @@ +# Regression test for https://go.dev/issue/51125: +# Relative import paths (a holdover from GOPATH) were accidentally allowed in module mode. + +cd $WORK + +# Relative imports should not be allowed with a go.mod file. + +! go run driver.go +stderr '^driver.go:3:8: "./mypkg" is relative, but relative import paths are not supported in module mode$' + +go list -e -f '{{with .Error}}{{.}}{{end}}' -deps driver.go +stdout '^driver.go:3:8: "./mypkg" is relative, but relative import paths are not supported in module mode$' +! stderr . + + +# Relative imports should not be allowed in module mode even without a go.mod file. +rm go.mod + +! go run driver.go +stderr '^driver.go:3:8: "./mypkg" is relative, but relative import paths are not supported in module mode$' + +go list -e -f '{{with .Error}}{{.}}{{end}}' -deps driver.go +stdout '^driver.go:3:8: "./mypkg" is relative, but relative import paths are not supported in module mode$' +! stderr . + + +# In GOPATH mode, they're still allowed (but only outside of GOPATH/src). +env GO111MODULE=off + +[!short] go run driver.go + +go list -deps driver.go + + +-- $WORK/go.mod -- +module example + +go 1.17 +-- $WORK/driver.go -- +package main + +import "./mypkg" + +func main() { + mypkg.MyFunc() +} +-- $WORK/mypkg/code.go -- +package mypkg + +import "fmt" + +func MyFunc() { + fmt.Println("Hello, world!") +} diff --git a/go/src/cmd/go/testdata/script/run_set_executable_name.txt b/go/src/cmd/go/testdata/script/run_set_executable_name.txt new file mode 100644 index 0000000000000000000000000000000000000000..54ddee9ae1f82a0a06120aa479fb32dd6422e6ec --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_set_executable_name.txt @@ -0,0 +1,50 @@ +env GO111MODULE=on +[short] skip + +# Check for correct naming of temporary executable + +#Test for single file specified +cd x/y/z +go run foo.go +stderr 'foo' + +#Test for current directory +go run . +stderr 'z' + +#Test for set path +go run m/x/y/z/ +stderr 'z' + +-- m/x/y/z/foo.go -- +package main +import( + "os" + "path/filepath" +) +func main() { + println(filepath.Base(os.Args[0])) +} + +-- x/y/z/foo.go -- +package main +import( + "os" + "path/filepath" +) +func main() { + println(filepath.Base(os.Args[0])) +} + +-- x/y/z/foo.go -- +package main +import( + "os" + "path/filepath" +) +func main() { + println(filepath.Base(os.Args[0])) +} + +-- go.mod -- +module m \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/run_vendor.txt b/go/src/cmd/go/testdata/script/run_vendor.txt new file mode 100644 index 0000000000000000000000000000000000000000..46cac06bf44c0a1e3a63c77a27e8366452ebc098 --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_vendor.txt @@ -0,0 +1,34 @@ +# Run +env GO111MODULE=off +cd vend/hello +go run hello.go +stdout 'hello, world' + +-- vend/hello/hello.go -- +package main + +import ( + "fmt" + "strings" // really ../vendor/strings +) + +func main() { + fmt.Printf("%s\n", strings.Msg) +} +-- vend/hello/hello_test.go -- +package main + +import ( + "strings" // really ../vendor/strings + "testing" +) + +func TestMsgInternal(t *testing.T) { + if strings.Msg != "hello, world" { + t.Fatalf("unexpected msg: %v", strings.Msg) + } +} +-- vend/vendor/strings/msg.go -- +package strings + +var Msg = "hello, world" diff --git a/go/src/cmd/go/testdata/script/run_vers.txt b/go/src/cmd/go/testdata/script/run_vers.txt new file mode 100644 index 0000000000000000000000000000000000000000..770481a6cd13d61f43c8021160841e6f71a094e7 --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_vers.txt @@ -0,0 +1,10 @@ +# go.dev/issue/66092 +# This test ensures that files listed on the commandline will pass +# the language version to the compiler. +# All compilations should specify some -lang. + +go build -n x.go +stderr '-lang=go1\.[0-9]+' + +-- x.go -- +package main \ No newline at end of file diff --git a/go/src/cmd/go/testdata/script/run_wildcard.txt b/go/src/cmd/go/testdata/script/run_wildcard.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e7e7b7e42f3066f4328677f6466e4059629f04b --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_wildcard.txt @@ -0,0 +1,7 @@ +env GO111MODULE=off + +# Fix for https://github.com/golang/go/issues/28696: +# go run x/... should not panic when directory x doesn't exist. + +! go run nonexistent/... +stderr '^go: no packages loaded from nonexistent/...$' diff --git a/go/src/cmd/go/testdata/script/run_work_versioned.txt b/go/src/cmd/go/testdata/script/run_work_versioned.txt new file mode 100644 index 0000000000000000000000000000000000000000..eb0f22d1c0780b1f0129af08111ae4efc8a446b8 --- /dev/null +++ b/go/src/cmd/go/testdata/script/run_work_versioned.txt @@ -0,0 +1,16 @@ +[short] skip +go run example.com/printversion@v0.1.0 +stdout '^main is example.com/printversion v0.1.0$' + +-- go.work -- +go 1.18 + +use ( + . +) +-- go.mod -- +module example + +go 1.18 + +require example.com/printversion v1.0.0 diff --git a/go/src/cmd/go/testdata/script/script_help.txt b/go/src/cmd/go/testdata/script/script_help.txt new file mode 100644 index 0000000000000000000000000000000000000000..dd7f2035ef8352394df92f683fef853a63d5c21f --- /dev/null +++ b/go/src/cmd/go/testdata/script/script_help.txt @@ -0,0 +1,7 @@ +help -v + +# To see help for a specific command or condition, run 'help' for it here. +# For example: +help wait +help [verbose] +help [exec:bash] diff --git a/go/src/cmd/go/testdata/vendormod.txt b/go/src/cmd/go/testdata/vendormod.txt new file mode 100644 index 0000000000000000000000000000000000000000..1bdaf2abb054cfc11c8e9a4ae9e7753548f38dcc --- /dev/null +++ b/go/src/cmd/go/testdata/vendormod.txt @@ -0,0 +1,160 @@ +generated by: go run savedir.go vendormod + +-- a/foo/AUTHORS.txt -- +-- a/foo/CONTRIBUTORS -- +-- a/foo/LICENSE -- +-- a/foo/PATENTS -- +-- a/foo/COPYING -- +-- a/foo/COPYLEFT -- +-- a/foo/licensed-to-kill -- +-- w/LICENSE -- +-- x/NOTICE! -- +-- x/x2/LICENSE -- +-- mypkg/LICENSE.txt -- +-- a/foo/bar/b/main.go -- +package b +-- a/foo/bar/b/main_test.go -- +package b + +import ( + "os" + "testing" +) + +func TestDir(t *testing.T) { + if _, err := os.Stat("../testdata/1"); err != nil { + t.Fatalf("testdata: %v", err) + } +} +-- a/foo/bar/c/main.go -- +package c +-- a/foo/bar/c/main_test.go -- +package c + +import ( + "os" + "testing" +) + +func TestDir(t *testing.T) { + if _, err := os.Stat("../../../testdata/1"); err != nil { + t.Fatalf("testdata: %v", err) + } + if _, err := os.Stat("./testdata/1"); err != nil { + t.Fatalf("testdata: %v", err) + } +} +-- a/foo/bar/c/testdata/1 -- +-- a/foo/bar/testdata/1 -- +-- a/go.mod -- +module a +-- a/main.go -- +package a +-- a/main_test.go -- +package a + +import ( + "os" + "testing" +) + +func TestDir(t *testing.T) { + if _, err := os.Stat("./testdata/1"); err != nil { + t.Fatalf("testdata: %v", err) + } +} +-- a/testdata/1 -- +-- appengine.go -- +// +build appengine + +package m + +import _ "appengine" +import _ "appengine/datastore" +-- go.mod -- +module m + +require ( + a v1.0.0 + mysite/myname/mypkg v1.0.0 + w v1.0.0 // indirect + x v1.0.0 + y v1.0.0 + z v1.0.0 +) + +replace ( + a v1.0.0 => ./a + mysite/myname/mypkg v1.0.0 => ./mypkg + w v1.0.0 => ./w + x v1.0.0 => ./x + y v1.0.0 => ./y + z v1.0.0 => ./z +) +-- mypkg/go.mod -- +module me +-- mypkg/mydir/d.go -- +package mydir +-- subdir/v1_test.go -- +package m + +import _ "mysite/myname/mypkg/mydir" +-- testdata1.go -- +package m + +import _ "a" +-- testdata2.go -- +package m + +import _ "a/foo/bar/b" +import _ "a/foo/bar/c" +-- v1.go -- +package m + +import _ "x" +-- v2.go -- +// +build abc + +package mMmMmMm + +import _ "y" +-- v3.go -- +// +build !abc + +package m + +import _ "z" +-- v4.go -- +// +build notmytag + +package m + +import _ "x/x1" +-- w/go.mod -- +module w +-- w/w.go -- +package w +-- x/go.mod -- +module x +-- x/testdata/x.txt -- +placeholder - want directory with no go files +-- x/x.go -- +package x +-- x/x1/x1.go -- +// +build notmytag + +package x1 +-- x/x2/dummy.txt -- +dummy +-- x/x_test.go -- +package x + +import _ "w" +-- y/go.mod -- +module y +-- y/y.go -- +package y +-- z/go.mod -- +module z +-- z/z.go -- +package z diff --git a/go/src/cmd/gofmt/testdata/comments.golden b/go/src/cmd/gofmt/testdata/comments.golden new file mode 100644 index 0000000000000000000000000000000000000000..ad6bcafafa2382a02bd9c83fbc8c7ed61773f318 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/comments.golden @@ -0,0 +1,9 @@ +package main + +func main() {} + +// comment here + +func f() {} + +//line foo.go:1 diff --git a/go/src/cmd/gofmt/testdata/comments.input b/go/src/cmd/gofmt/testdata/comments.input new file mode 100644 index 0000000000000000000000000000000000000000..ad6bcafafa2382a02bd9c83fbc8c7ed61773f318 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/comments.input @@ -0,0 +1,9 @@ +package main + +func main() {} + +// comment here + +func f() {} + +//line foo.go:1 diff --git a/go/src/cmd/gofmt/testdata/composites.golden b/go/src/cmd/gofmt/testdata/composites.golden new file mode 100644 index 0000000000000000000000000000000000000000..a06a69d0965ed26233fe0a8ff243581e84456703 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/composites.golden @@ -0,0 +1,218 @@ +//gofmt -s + +package P + +type T struct { + x, y int +} + +type T2 struct { + w, z int +} + +var _ = [42]T{ + {}, + {1, 2}, + {3, 4}, +} + +var _ = [...]T{ + {}, + {1, 2}, + {3, 4}, +} + +var _ = []T{ + {}, + {1, 2}, + {3, 4}, +} + +var _ = []T{ + {}, + 10: {1, 2}, + 20: {3, 4}, +} + +var _ = []struct { + x, y int +}{ + {}, + 10: {1, 2}, + 20: {3, 4}, +} + +var _ = []interface{}{ + T{}, + 10: T{1, 2}, + 20: T{3, 4}, +} + +var _ = [][]int{ + {}, + {1, 2}, + {3, 4}, +} + +var _ = [][]int{ + ([]int{}), + ([]int{1, 2}), + {3, 4}, +} + +var _ = [][][]int{ + {}, + { + {}, + {0, 1, 2, 3}, + {4, 5}, + }, +} + +var _ = map[string]T{ + "foo": {}, + "bar": {1, 2}, + "bal": {3, 4}, +} + +var _ = map[string]struct { + x, y int +}{ + "foo": {}, + "bar": {1, 2}, + "bal": {3, 4}, +} + +var _ = map[string]interface{}{ + "foo": T{}, + "bar": T{1, 2}, + "bal": T{3, 4}, +} + +var _ = map[string][]int{ + "foo": {}, + "bar": {1, 2}, + "bal": {3, 4}, +} + +var _ = map[string][]int{ + "foo": ([]int{}), + "bar": ([]int{1, 2}), + "bal": {3, 4}, +} + +// from exp/4s/data.go +var pieces4 = []Piece{ + {0, 0, Point{4, 1}, []Point{{0, 0}, {1, 0}, {1, 0}, {1, 0}}, nil, nil}, + {1, 0, Point{1, 4}, []Point{{0, 0}, {0, 1}, {0, 1}, {0, 1}}, nil, nil}, + {2, 0, Point{4, 1}, []Point{{0, 0}, {1, 0}, {1, 0}, {1, 0}}, nil, nil}, + {3, 0, Point{1, 4}, []Point{{0, 0}, {0, 1}, {0, 1}, {0, 1}}, nil, nil}, +} + +var _ = [42]*T{ + {}, + {1, 2}, + {3, 4}, +} + +var _ = [...]*T{ + {}, + {1, 2}, + {3, 4}, +} + +var _ = []*T{ + {}, + {1, 2}, + {3, 4}, +} + +var _ = []*T{ + {}, + 10: {1, 2}, + 20: {3, 4}, +} + +var _ = []*struct { + x, y int +}{ + {}, + 10: {1, 2}, + 20: {3, 4}, +} + +var _ = []interface{}{ + &T{}, + 10: &T{1, 2}, + 20: &T{3, 4}, +} + +var _ = []*[]int{ + {}, + {1, 2}, + {3, 4}, +} + +var _ = []*[]int{ + (&[]int{}), + (&[]int{1, 2}), + {3, 4}, +} + +var _ = []*[]*[]int{ + {}, + { + {}, + {0, 1, 2, 3}, + {4, 5}, + }, +} + +var _ = map[string]*T{ + "foo": {}, + "bar": {1, 2}, + "bal": {3, 4}, +} + +var _ = map[string]*struct { + x, y int +}{ + "foo": {}, + "bar": {1, 2}, + "bal": {3, 4}, +} + +var _ = map[string]interface{}{ + "foo": &T{}, + "bar": &T{1, 2}, + "bal": &T{3, 4}, +} + +var _ = map[string]*[]int{ + "foo": {}, + "bar": {1, 2}, + "bal": {3, 4}, +} + +var _ = map[string]*[]int{ + "foo": (&[]int{}), + "bar": (&[]int{1, 2}), + "bal": {3, 4}, +} + +var pieces4 = []*Piece{ + {0, 0, Point{4, 1}, []Point{{0, 0}, {1, 0}, {1, 0}, {1, 0}}, nil, nil}, + {1, 0, Point{1, 4}, []Point{{0, 0}, {0, 1}, {0, 1}, {0, 1}}, nil, nil}, + {2, 0, Point{4, 1}, []Point{{0, 0}, {1, 0}, {1, 0}, {1, 0}}, nil, nil}, + {3, 0, Point{1, 4}, []Point{{0, 0}, {0, 1}, {0, 1}, {0, 1}}, nil, nil}, +} + +var _ = map[T]T2{ + {1, 2}: {3, 4}, + {5, 6}: {7, 8}, +} + +var _ = map[*T]*T2{ + {1, 2}: {3, 4}, + {5, 6}: {7, 8}, +} diff --git a/go/src/cmd/gofmt/testdata/composites.input b/go/src/cmd/gofmt/testdata/composites.input new file mode 100644 index 0000000000000000000000000000000000000000..9d28ac7ed31256463839d13e357e9557b29d3dea --- /dev/null +++ b/go/src/cmd/gofmt/testdata/composites.input @@ -0,0 +1,218 @@ +//gofmt -s + +package P + +type T struct { + x, y int +} + +type T2 struct { + w, z int +} + +var _ = [42]T{ + T{}, + T{1, 2}, + T{3, 4}, +} + +var _ = [...]T{ + T{}, + T{1, 2}, + T{3, 4}, +} + +var _ = []T{ + T{}, + T{1, 2}, + T{3, 4}, +} + +var _ = []T{ + T{}, + 10: T{1, 2}, + 20: T{3, 4}, +} + +var _ = []struct { + x, y int +}{ + struct{ x, y int }{}, + 10: struct{ x, y int }{1, 2}, + 20: struct{ x, y int }{3, 4}, +} + +var _ = []interface{}{ + T{}, + 10: T{1, 2}, + 20: T{3, 4}, +} + +var _ = [][]int{ + []int{}, + []int{1, 2}, + []int{3, 4}, +} + +var _ = [][]int{ + ([]int{}), + ([]int{1, 2}), + []int{3, 4}, +} + +var _ = [][][]int{ + [][]int{}, + [][]int{ + []int{}, + []int{0, 1, 2, 3}, + []int{4, 5}, + }, +} + +var _ = map[string]T{ + "foo": T{}, + "bar": T{1, 2}, + "bal": T{3, 4}, +} + +var _ = map[string]struct { + x, y int +}{ + "foo": struct{ x, y int }{}, + "bar": struct{ x, y int }{1, 2}, + "bal": struct{ x, y int }{3, 4}, +} + +var _ = map[string]interface{}{ + "foo": T{}, + "bar": T{1, 2}, + "bal": T{3, 4}, +} + +var _ = map[string][]int{ + "foo": []int{}, + "bar": []int{1, 2}, + "bal": []int{3, 4}, +} + +var _ = map[string][]int{ + "foo": ([]int{}), + "bar": ([]int{1, 2}), + "bal": []int{3, 4}, +} + +// from exp/4s/data.go +var pieces4 = []Piece{ + Piece{0, 0, Point{4, 1}, []Point{Point{0, 0}, Point{1, 0}, Point{1, 0}, Point{1, 0}}, nil, nil}, + Piece{1, 0, Point{1, 4}, []Point{Point{0, 0}, Point{0, 1}, Point{0, 1}, Point{0, 1}}, nil, nil}, + Piece{2, 0, Point{4, 1}, []Point{Point{0, 0}, Point{1, 0}, Point{1, 0}, Point{1, 0}}, nil, nil}, + Piece{3, 0, Point{1, 4}, []Point{Point{0, 0}, Point{0, 1}, Point{0, 1}, Point{0, 1}}, nil, nil}, +} + +var _ = [42]*T{ + &T{}, + &T{1, 2}, + &T{3, 4}, +} + +var _ = [...]*T{ + &T{}, + &T{1, 2}, + &T{3, 4}, +} + +var _ = []*T{ + &T{}, + &T{1, 2}, + &T{3, 4}, +} + +var _ = []*T{ + &T{}, + 10: &T{1, 2}, + 20: &T{3, 4}, +} + +var _ = []*struct { + x, y int +}{ + &struct{ x, y int }{}, + 10: &struct{ x, y int }{1, 2}, + 20: &struct{ x, y int }{3, 4}, +} + +var _ = []interface{}{ + &T{}, + 10: &T{1, 2}, + 20: &T{3, 4}, +} + +var _ = []*[]int{ + &[]int{}, + &[]int{1, 2}, + &[]int{3, 4}, +} + +var _ = []*[]int{ + (&[]int{}), + (&[]int{1, 2}), + &[]int{3, 4}, +} + +var _ = []*[]*[]int{ + &[]*[]int{}, + &[]*[]int{ + &[]int{}, + &[]int{0, 1, 2, 3}, + &[]int{4, 5}, + }, +} + +var _ = map[string]*T{ + "foo": &T{}, + "bar": &T{1, 2}, + "bal": &T{3, 4}, +} + +var _ = map[string]*struct { + x, y int +}{ + "foo": &struct{ x, y int }{}, + "bar": &struct{ x, y int }{1, 2}, + "bal": &struct{ x, y int }{3, 4}, +} + +var _ = map[string]interface{}{ + "foo": &T{}, + "bar": &T{1, 2}, + "bal": &T{3, 4}, +} + +var _ = map[string]*[]int{ + "foo": &[]int{}, + "bar": &[]int{1, 2}, + "bal": &[]int{3, 4}, +} + +var _ = map[string]*[]int{ + "foo": (&[]int{}), + "bar": (&[]int{1, 2}), + "bal": &[]int{3, 4}, +} + +var pieces4 = []*Piece{ + &Piece{0, 0, Point{4, 1}, []Point{Point{0, 0}, Point{1, 0}, Point{1, 0}, Point{1, 0}}, nil, nil}, + &Piece{1, 0, Point{1, 4}, []Point{Point{0, 0}, Point{0, 1}, Point{0, 1}, Point{0, 1}}, nil, nil}, + &Piece{2, 0, Point{4, 1}, []Point{Point{0, 0}, Point{1, 0}, Point{1, 0}, Point{1, 0}}, nil, nil}, + &Piece{3, 0, Point{1, 4}, []Point{Point{0, 0}, Point{0, 1}, Point{0, 1}, Point{0, 1}}, nil, nil}, +} + +var _ = map[T]T2{ + T{1, 2}: T2{3, 4}, + T{5, 6}: T2{7, 8}, +} + +var _ = map[*T]*T2{ + &T{1, 2}: &T2{3, 4}, + &T{5, 6}: &T2{7, 8}, +} diff --git a/go/src/cmd/gofmt/testdata/crlf.golden b/go/src/cmd/gofmt/testdata/crlf.golden new file mode 100644 index 0000000000000000000000000000000000000000..65de9cf19946d5f44e7f4e602374710838f817a5 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/crlf.golden @@ -0,0 +1,13 @@ +/* +Source containing CR/LF line endings. +The gofmt'ed output must only have LF +line endings. +Test case for issue 3961. +*/ +package main + +func main() { + // line comment + println("hello, world!") // another line comment + println() +} diff --git a/go/src/cmd/gofmt/testdata/crlf.input b/go/src/cmd/gofmt/testdata/crlf.input new file mode 100644 index 0000000000000000000000000000000000000000..3cd4934caf2ef8794ee7c096de082e441cef7d7e --- /dev/null +++ b/go/src/cmd/gofmt/testdata/crlf.input @@ -0,0 +1,13 @@ +/* +Source containing CR/LF line endings. +The gofmt'ed output must only have LF +line endings. +Test case for issue 3961. +*/ +package main + +func main() { + // line comment + println("hello, world!") // another line comment + println() +} diff --git a/go/src/cmd/gofmt/testdata/emptydecl.golden b/go/src/cmd/gofmt/testdata/emptydecl.golden new file mode 100644 index 0000000000000000000000000000000000000000..33d6435e0a99dc63d16abb9cf6edaf9799b2de23 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/emptydecl.golden @@ -0,0 +1,14 @@ +//gofmt -s + +// Test case for issue 7631. + +package main + +// Keep this declaration +var () + +const ( +// Keep this declaration +) + +func main() {} diff --git a/go/src/cmd/gofmt/testdata/emptydecl.input b/go/src/cmd/gofmt/testdata/emptydecl.input new file mode 100644 index 0000000000000000000000000000000000000000..4948a61f0de2285960ebb54ed0392c474f69d503 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/emptydecl.input @@ -0,0 +1,16 @@ +//gofmt -s + +// Test case for issue 7631. + +package main + +// Keep this declaration +var () + +const ( +// Keep this declaration +) + +type () + +func main() {} \ No newline at end of file diff --git a/go/src/cmd/gofmt/testdata/exitcode.golden b/go/src/cmd/gofmt/testdata/exitcode.golden new file mode 100644 index 0000000000000000000000000000000000000000..06ab7d0f9a35a7d1070711496d6ca1cb892a258f --- /dev/null +++ b/go/src/cmd/gofmt/testdata/exitcode.golden @@ -0,0 +1 @@ +package main diff --git a/go/src/cmd/gofmt/testdata/exitcode.input b/go/src/cmd/gofmt/testdata/exitcode.input new file mode 100644 index 0000000000000000000000000000000000000000..4f2f092ce508decb899355c5f03e67ed956c3557 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/exitcode.input @@ -0,0 +1 @@ + package main diff --git a/go/src/cmd/gofmt/testdata/go2numbers.golden b/go/src/cmd/gofmt/testdata/go2numbers.golden new file mode 100644 index 0000000000000000000000000000000000000000..0184aaa6ced8fb4125f5d9f3576c4004d4b7a5dd --- /dev/null +++ b/go/src/cmd/gofmt/testdata/go2numbers.golden @@ -0,0 +1,186 @@ +package p + +const ( + // 0-octals + _ = 0 + _ = 0123 + _ = 0123456 + + _ = 0_123 + _ = 0123_456 + + // decimals + _ = 1 + _ = 1234 + _ = 1234567 + + _ = 1_234 + _ = 1_234_567 + + // hexadecimals + _ = 0x0 + _ = 0x1234 + _ = 0xcafef00d + + _ = 0x0 + _ = 0x1234 + _ = 0xCAFEf00d + + _ = 0x_0 + _ = 0x_1234 + _ = 0x_CAFE_f00d + + // octals + _ = 0o0 + _ = 0o1234 + _ = 0o01234567 + + _ = 0o0 + _ = 0o1234 + _ = 0o01234567 + + _ = 0o_0 + _ = 0o_1234 + _ = 0o0123_4567 + + _ = 0o_0 + _ = 0o_1234 + _ = 0o0123_4567 + + // binaries + _ = 0b0 + _ = 0b1011 + _ = 0b00101101 + + _ = 0b0 + _ = 0b1011 + _ = 0b00101101 + + _ = 0b_0 + _ = 0b10_11 + _ = 0b_0010_1101 + + // decimal floats + _ = 0. + _ = 123. + _ = 0123. + + _ = .0 + _ = .123 + _ = .0123 + + _ = 0e0 + _ = 123e+0 + _ = 0123e-1 + + _ = 0e-0 + _ = 123e+0 + _ = 0123e123 + + _ = 0.e+1 + _ = 123.e-10 + _ = 0123.e123 + + _ = .0e-1 + _ = .123e+10 + _ = .0123e123 + + _ = 0.0 + _ = 123.123 + _ = 0123.0123 + + _ = 0.0e1 + _ = 123.123e-10 + _ = 0123.0123e+456 + + _ = 1_2_3. + _ = 0_123. + + _ = 0_0e0 + _ = 1_2_3e0 + _ = 0_123e0 + + _ = 0e-0_0 + _ = 1_2_3e+0 + _ = 0123e1_2_3 + + _ = 0.e+1 + _ = 123.e-1_0 + _ = 01_23.e123 + + _ = .0e-1 + _ = .123e+10 + _ = .0123e123 + + _ = 1_2_3.123 + _ = 0123.01_23 + + // hexadecimal floats + _ = 0x0.p+0 + _ = 0xdeadcafe.p-10 + _ = 0x1234.p123 + + _ = 0x.1p-0 + _ = 0x.deadcafep2 + _ = 0x.1234p+10 + + _ = 0x0p0 + _ = 0xdeadcafep+1 + _ = 0x1234p-10 + + _ = 0x0.0p0 + _ = 0xdead.cafep+1 + _ = 0x12.34p-10 + + _ = 0xdead_cafep+1 + _ = 0x_1234p-10 + + _ = 0x_dead_cafe.p-10 + _ = 0x12_34.p1_2_3 + _ = 0x1_2_3_4.p-1_2_3 + + // imaginaries + _ = 0i + _ = 0i + _ = 8i + _ = 0i + _ = 123i + _ = 123i + _ = 56789i + _ = 1234i + _ = 1234567i + + _ = 0i + _ = 0i + _ = 8i + _ = 0i + _ = 123i + _ = 123i + _ = 56_789i + _ = 1_234i + _ = 1_234_567i + + _ = 0.i + _ = 123.i + _ = 0123.i + _ = 000123.i + + _ = 0e0i + _ = 123e0i + _ = 0123e0i + _ = 000123e0i + + _ = 0.e+1i + _ = 123.e-1_0i + _ = 01_23.e123i + _ = 00_01_23.e123i + + _ = 0b1010i + _ = 0b1010i + _ = 0o660i + _ = 0o660i + _ = 0xabcDEFi + _ = 0xabcDEFi + _ = 0xabcDEFp0i + _ = 0xabcDEFp0i +) diff --git a/go/src/cmd/gofmt/testdata/go2numbers.input b/go/src/cmd/gofmt/testdata/go2numbers.input new file mode 100644 index 0000000000000000000000000000000000000000..f3e7828d948496582951ee196069864d83ef2737 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/go2numbers.input @@ -0,0 +1,186 @@ +package p + +const ( + // 0-octals + _ = 0 + _ = 0123 + _ = 0123456 + + _ = 0_123 + _ = 0123_456 + + // decimals + _ = 1 + _ = 1234 + _ = 1234567 + + _ = 1_234 + _ = 1_234_567 + + // hexadecimals + _ = 0x0 + _ = 0x1234 + _ = 0xcafef00d + + _ = 0X0 + _ = 0X1234 + _ = 0XCAFEf00d + + _ = 0X_0 + _ = 0X_1234 + _ = 0X_CAFE_f00d + + // octals + _ = 0o0 + _ = 0o1234 + _ = 0o01234567 + + _ = 0O0 + _ = 0O1234 + _ = 0O01234567 + + _ = 0o_0 + _ = 0o_1234 + _ = 0o0123_4567 + + _ = 0O_0 + _ = 0O_1234 + _ = 0O0123_4567 + + // binaries + _ = 0b0 + _ = 0b1011 + _ = 0b00101101 + + _ = 0B0 + _ = 0B1011 + _ = 0B00101101 + + _ = 0b_0 + _ = 0b10_11 + _ = 0b_0010_1101 + + // decimal floats + _ = 0. + _ = 123. + _ = 0123. + + _ = .0 + _ = .123 + _ = .0123 + + _ = 0e0 + _ = 123e+0 + _ = 0123E-1 + + _ = 0e-0 + _ = 123E+0 + _ = 0123E123 + + _ = 0.e+1 + _ = 123.E-10 + _ = 0123.e123 + + _ = .0e-1 + _ = .123E+10 + _ = .0123E123 + + _ = 0.0 + _ = 123.123 + _ = 0123.0123 + + _ = 0.0e1 + _ = 123.123E-10 + _ = 0123.0123e+456 + + _ = 1_2_3. + _ = 0_123. + + _ = 0_0e0 + _ = 1_2_3e0 + _ = 0_123e0 + + _ = 0e-0_0 + _ = 1_2_3E+0 + _ = 0123E1_2_3 + + _ = 0.e+1 + _ = 123.E-1_0 + _ = 01_23.e123 + + _ = .0e-1 + _ = .123E+10 + _ = .0123E123 + + _ = 1_2_3.123 + _ = 0123.01_23 + + // hexadecimal floats + _ = 0x0.p+0 + _ = 0Xdeadcafe.p-10 + _ = 0x1234.P123 + + _ = 0x.1p-0 + _ = 0X.deadcafep2 + _ = 0x.1234P+10 + + _ = 0x0p0 + _ = 0Xdeadcafep+1 + _ = 0x1234P-10 + + _ = 0x0.0p0 + _ = 0Xdead.cafep+1 + _ = 0x12.34P-10 + + _ = 0Xdead_cafep+1 + _ = 0x_1234P-10 + + _ = 0X_dead_cafe.p-10 + _ = 0x12_34.P1_2_3 + _ = 0X1_2_3_4.P-1_2_3 + + // imaginaries + _ = 0i + _ = 00i + _ = 08i + _ = 0000000000i + _ = 0123i + _ = 0000000123i + _ = 0000056789i + _ = 1234i + _ = 1234567i + + _ = 0i + _ = 0_0i + _ = 0_8i + _ = 0_000_000_000i + _ = 0_123i + _ = 0_000_000_123i + _ = 0_000_056_789i + _ = 1_234i + _ = 1_234_567i + + _ = 0.i + _ = 123.i + _ = 0123.i + _ = 000123.i + + _ = 0e0i + _ = 123e0i + _ = 0123E0i + _ = 000123E0i + + _ = 0.e+1i + _ = 123.E-1_0i + _ = 01_23.e123i + _ = 00_01_23.e123i + + _ = 0b1010i + _ = 0B1010i + _ = 0o660i + _ = 0O660i + _ = 0xabcDEFi + _ = 0XabcDEFi + _ = 0xabcDEFP0i + _ = 0XabcDEFp0i +) diff --git a/go/src/cmd/gofmt/testdata/import.golden b/go/src/cmd/gofmt/testdata/import.golden new file mode 100644 index 0000000000000000000000000000000000000000..1125b70cb76c6f7115cf7640cebd6baf2c507c13 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/import.golden @@ -0,0 +1,194 @@ +// package comment +package main + +import ( + "errors" + "fmt" + "io" + "log" + "math" +) + +import ( + "fmt" + + "math" + + "log" + + "errors" + + "io" +) + +// We reset the line numbering to test that +// the formatting works independent of line directives +//line :19 + +import ( + "errors" + "fmt" + "io" + "log" + "math" + + "fmt" + + "math" + + "log" + + "errors" + + "io" +) + +import ( + // a block with comments + "errors" + "fmt" // for Printf + "io" // for Reader + "log" // for Fatal + "math" +) + +import ( + "fmt" // for Printf + + "math" + + "log" // for Fatal + + "errors" + + "io" // for Reader +) + +import ( + // for Printf + "fmt" + + "math" + + // for Fatal + "log" + + "errors" + + // for Reader + "io" +) + +import ( + "errors" + "fmt" // for Printf + "io" // for Reader + "log" // for Fatal + "math" + + "fmt" // for Printf + + "math" + + "log" // for Fatal + + "errors" + + "io" // for Reader +) + +import ( + "fmt" // for Printf + + "errors" + "io" // for Reader + "log" // for Fatal + "math" + + "errors" + "fmt" // for Printf + "io" // for Reader + "log" // for Fatal + "math" +) + +// Test deduping and extended sorting +import ( + a "A" // aA + b "A" // bA1 + b "A" // bA2 + "B" // B + . "B" // .B + _ "B" // _b + "C" + a "D" // aD +) + +import ( + "dedup_by_group" + + "dedup_by_group" +) + +import ( + "fmt" // for Printf + /* comment */ io1 "io" + /* comment */ io2 "io" + /* comment */ "log" +) + +import ( + "fmt" + /* comment */ io1 "io" + /* comment */ io2 "io" // hello + "math" /* right side */ + // end +) + +import ( + "errors" // for New + "fmt" + /* comment */ io1 "io" /* before */ // after + io2 "io" // another + // end +) + +import ( + "errors" // for New + /* left */ "fmt" /* right */ + "log" // for Fatal + /* left */ "math" /* right */ +) + +import /* why */ /* comment here? */ ( + /* comment */ "fmt" + "math" +) + +// Reset it again +//line :100 + +// Dedup with different import styles +import ( + "path" + . "path" + _ "path" + pathpkg "path" +) + +/* comment */ +import ( + "fmt" + "math" // for Abs + // This is a new run + "errors" + "fmt" +) + +// End an import declaration in the same line +// as the last import. See golang.org/issue/33538. +// Note: Must be the last (or 2nd last) line of the file. +import ( + "fmt" + "math" +) diff --git a/go/src/cmd/gofmt/testdata/import.input b/go/src/cmd/gofmt/testdata/import.input new file mode 100644 index 0000000000000000000000000000000000000000..040b8722d47d3edf1a84c8d214239ff34bccc255 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/import.input @@ -0,0 +1,199 @@ +// package comment +package main + +import ( + "fmt" + "math" + "log" + "errors" + "io" +) + +import ( + "fmt" + + "math" + + "log" + + "errors" + + "io" +) + +// We reset the line numbering to test that +// the formatting works independent of line directives +//line :19 + +import ( + "fmt" + "math" + "log" + "errors" + "io" + + "fmt" + + "math" + + "log" + + "errors" + + "io" +) + +import ( + // a block with comments + "fmt" // for Printf + "math" + "log" // for Fatal + "errors" + "io" // for Reader +) + +import ( + "fmt" // for Printf + + "math" + + "log" // for Fatal + + "errors" + + "io" // for Reader +) + +import ( + // for Printf + "fmt" + + "math" + + // for Fatal + "log" + + "errors" + + // for Reader + "io" +) + +import ( + "fmt" // for Printf + "math" + "log" // for Fatal + "errors" + "io" // for Reader + + "fmt" // for Printf + + "math" + + "log" // for Fatal + + "errors" + + "io" // for Reader +) + +import ( + "fmt" // for Printf + + "math" + "log" // for Fatal + "errors" + "io" // for Reader + + "fmt" // for Printf + "math" + "log" // for Fatal + "errors" + "io" // for Reader +) + +// Test deduping and extended sorting +import ( + "B" // B + a "A" // aA + b "A" // bA2 + b "A" // bA1 + . "B" // .B + . "B" + "C" + "C" + "C" + a "D" // aD + "B" + _ "B" // _b +) + +import ( + "dedup_by_group" + "dedup_by_group" + + "dedup_by_group" +) + +import ( + /* comment */ io1 "io" + "fmt" // for Printf + /* comment */ "log" + /* comment */ io2 "io" +) + +import ( + /* comment */ io2 "io" // hello + /* comment */ io1 "io" + "math" /* right side */ + "fmt" + // end +) + +import ( + /* comment */ io1 "io" /* before */ // after + "fmt" + "errors" // for New + io2 "io" // another + // end +) + +import ( + /* left */ "fmt" /* right */ + "errors" // for New + /* left */ "math" /* right */ + "log" // for Fatal +) + +import /* why */ /* comment here? */ ( + /* comment */ "fmt" + "math" +) + +// Reset it again +//line :100 + +// Dedup with different import styles +import ( + "path" + . "path" + _ "path" + "path" + pathpkg "path" +) + +/* comment */ +import ( + "math" // for Abs + "fmt" + // This is a new run + "errors" + "fmt" + "errors" +) + +// End an import declaration in the same line +// as the last import. See golang.org/issue/33538. +// Note: Must be the last (or 2nd last) line of the file. +import("fmt" +"math") \ No newline at end of file diff --git a/go/src/cmd/gofmt/testdata/issue28082.golden b/go/src/cmd/gofmt/testdata/issue28082.golden new file mode 100644 index 0000000000000000000000000000000000000000..5837fd52912daca70267188c34d42298ade76239 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/issue28082.golden @@ -0,0 +1,13 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +// testcase for issue #28082 + +func foo() {} + +func main() {} + +func bar() {} diff --git a/go/src/cmd/gofmt/testdata/issue28082.input b/go/src/cmd/gofmt/testdata/issue28082.input new file mode 100644 index 0000000000000000000000000000000000000000..ab7d2186cea1f9ace37cf0e47b0e581a208dc054 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/issue28082.input @@ -0,0 +1,13 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +// testcase for issue #28082 + +func foo( ) {} + +func main( ) {} + +func bar() {} diff --git a/go/src/cmd/gofmt/testdata/ranges.golden b/go/src/cmd/gofmt/testdata/ranges.golden new file mode 100644 index 0000000000000000000000000000000000000000..506b3a035a3684b783b29d5113087f42fbfaf87e --- /dev/null +++ b/go/src/cmd/gofmt/testdata/ranges.golden @@ -0,0 +1,30 @@ +//gofmt -s + +// Test cases for range simplification. +package p + +func _() { + for a, b = range x { + } + for a = range x { + } + for _, b = range x { + } + for range x { + } + + for a = range x { + } + for range x { + } + + for a, b := range x { + } + for a := range x { + } + for _, b := range x { + } + + for a := range x { + } +} diff --git a/go/src/cmd/gofmt/testdata/ranges.input b/go/src/cmd/gofmt/testdata/ranges.input new file mode 100644 index 0000000000000000000000000000000000000000..df5f8333c21c91af3de98d58fe2aa52582491ce4 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/ranges.input @@ -0,0 +1,20 @@ +//gofmt -s + +// Test cases for range simplification. +package p + +func _() { + for a, b = range x {} + for a, _ = range x {} + for _, b = range x {} + for _, _ = range x {} + + for a = range x {} + for _ = range x {} + + for a, b := range x {} + for a, _ := range x {} + for _, b := range x {} + + for a := range x {} +} diff --git a/go/src/cmd/gofmt/testdata/rewrite1.golden b/go/src/cmd/gofmt/testdata/rewrite1.golden new file mode 100644 index 0000000000000000000000000000000000000000..3ee5373a79094a6b05328b2114d75946cb4c4575 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite1.golden @@ -0,0 +1,14 @@ +//gofmt -r=Foo->Bar + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Bar int + +func main() { + var a Bar + println(a) +} diff --git a/go/src/cmd/gofmt/testdata/rewrite1.input b/go/src/cmd/gofmt/testdata/rewrite1.input new file mode 100644 index 0000000000000000000000000000000000000000..a84c8f781659ba5ebd9ae62ac351d680167551cd --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite1.input @@ -0,0 +1,14 @@ +//gofmt -r=Foo->Bar + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type Foo int + +func main() { + var a Foo + println(a) +} diff --git a/go/src/cmd/gofmt/testdata/rewrite10.golden b/go/src/cmd/gofmt/testdata/rewrite10.golden new file mode 100644 index 0000000000000000000000000000000000000000..1dd781fbb094457b6304cddc08ae3814d468216d --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite10.golden @@ -0,0 +1,19 @@ +//gofmt -r=a->a + +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 33103, 33104, and 33105. + +package pkg + +func fn() { + _ = func() { + switch { + default: + } + } + _ = func() string {} + _ = func() { var ptr *string; println(ptr) } +} diff --git a/go/src/cmd/gofmt/testdata/rewrite10.input b/go/src/cmd/gofmt/testdata/rewrite10.input new file mode 100644 index 0000000000000000000000000000000000000000..1dd781fbb094457b6304cddc08ae3814d468216d --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite10.input @@ -0,0 +1,19 @@ +//gofmt -r=a->a + +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 33103, 33104, and 33105. + +package pkg + +func fn() { + _ = func() { + switch { + default: + } + } + _ = func() string {} + _ = func() { var ptr *string; println(ptr) } +} diff --git a/go/src/cmd/gofmt/testdata/rewrite2.golden b/go/src/cmd/gofmt/testdata/rewrite2.golden new file mode 100644 index 0000000000000000000000000000000000000000..f980e035309e1a6958b6bb02458ee055dac98431 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite2.golden @@ -0,0 +1,12 @@ +//gofmt -r=int->bool + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +// Slices have nil Len values in the corresponding ast.ArrayType +// node and reflect.NewValue(slice.Len) is an invalid reflect.Value. +// The rewriter must not crash in that case. Was issue 1696. +func f() []bool {} diff --git a/go/src/cmd/gofmt/testdata/rewrite2.input b/go/src/cmd/gofmt/testdata/rewrite2.input new file mode 100644 index 0000000000000000000000000000000000000000..489be4e07dc80facb5a7ee72a6b8f5c7ba2cf18e --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite2.input @@ -0,0 +1,12 @@ +//gofmt -r=int->bool + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +// Slices have nil Len values in the corresponding ast.ArrayType +// node and reflect.NewValue(slice.Len) is an invalid reflect.Value. +// The rewriter must not crash in that case. Was issue 1696. +func f() []int {} diff --git a/go/src/cmd/gofmt/testdata/rewrite3.golden b/go/src/cmd/gofmt/testdata/rewrite3.golden new file mode 100644 index 0000000000000000000000000000000000000000..261a220c65d7f1988a2ae55fa31af59b32bb6dec --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite3.golden @@ -0,0 +1,14 @@ +//gofmt -r=x->x + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +// Field tags are *ast.BasicLit nodes that are nil when the tag is +// absent. These nil nodes must not be mistaken for expressions, +// the rewriter should not try to dereference them. Was issue 2410. +type Foo struct { + Field int +} diff --git a/go/src/cmd/gofmt/testdata/rewrite3.input b/go/src/cmd/gofmt/testdata/rewrite3.input new file mode 100644 index 0000000000000000000000000000000000000000..261a220c65d7f1988a2ae55fa31af59b32bb6dec --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite3.input @@ -0,0 +1,14 @@ +//gofmt -r=x->x + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +// Field tags are *ast.BasicLit nodes that are nil when the tag is +// absent. These nil nodes must not be mistaken for expressions, +// the rewriter should not try to dereference them. Was issue 2410. +type Foo struct { + Field int +} diff --git a/go/src/cmd/gofmt/testdata/rewrite4.golden b/go/src/cmd/gofmt/testdata/rewrite4.golden new file mode 100644 index 0000000000000000000000000000000000000000..b05547b4bf08216357c7f7bfc2622916aa976165 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite4.golden @@ -0,0 +1,76 @@ +//gofmt -r=(x)->x + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Rewriting of parenthesized expressions (x) -> x +// must not drop parentheses if that would lead to +// wrong association of the operands. +// Was issue 1847. + +package main + +// From example 1 of issue 1847. +func _() { + var t = (&T{1000}).Id() +} + +// From example 2 of issue 1847. +func _() { + fmt.Println((*xpp).a) +} + +// Some more test cases. +func _() { + _ = (-x).f + _ = (*x).f + _ = (&x).f + _ = (!x).f + _ = -x.f + _ = *x.f + _ = &x.f + _ = !x.f + (-x).f() + (*x).f() + (&x).f() + (!x).f() + _ = -x.f() + _ = *x.f() + _ = &x.f() + _ = !x.f() + + _ = (-x).f + _ = (*x).f + _ = (&x).f + _ = (!x).f + _ = -x.f + _ = *x.f + _ = &x.f + _ = !x.f + (-x).f() + (*x).f() + (&x).f() + (!x).f() + _ = -x.f() + _ = *x.f() + _ = &x.f() + _ = !x.f() + + _ = -x.f + _ = *x.f + _ = &x.f + _ = !x.f + _ = -x.f + _ = *x.f + _ = &x.f + _ = !x.f + _ = -x.f() + _ = *x.f() + _ = &x.f() + _ = !x.f() + _ = -x.f() + _ = *x.f() + _ = &x.f() + _ = !x.f() +} diff --git a/go/src/cmd/gofmt/testdata/rewrite4.input b/go/src/cmd/gofmt/testdata/rewrite4.input new file mode 100644 index 0000000000000000000000000000000000000000..0817099209c0e87ce5c422bd7750c0d01a38b839 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite4.input @@ -0,0 +1,76 @@ +//gofmt -r=(x)->x + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Rewriting of parenthesized expressions (x) -> x +// must not drop parentheses if that would lead to +// wrong association of the operands. +// Was issue 1847. + +package main + +// From example 1 of issue 1847. +func _() { + var t = (&T{1000}).Id() +} + +// From example 2 of issue 1847. +func _() { + fmt.Println((*xpp).a) +} + +// Some more test cases. +func _() { + _ = (-x).f + _ = (*x).f + _ = (&x).f + _ = (!x).f + _ = (-x.f) + _ = (*x.f) + _ = (&x.f) + _ = (!x.f) + (-x).f() + (*x).f() + (&x).f() + (!x).f() + _ = (-x.f()) + _ = (*x.f()) + _ = (&x.f()) + _ = (!x.f()) + + _ = ((-x)).f + _ = ((*x)).f + _ = ((&x)).f + _ = ((!x)).f + _ = ((-x.f)) + _ = ((*x.f)) + _ = ((&x.f)) + _ = ((!x.f)) + ((-x)).f() + ((*x)).f() + ((&x)).f() + ((!x)).f() + _ = ((-x.f())) + _ = ((*x.f())) + _ = ((&x.f())) + _ = ((!x.f())) + + _ = -(x).f + _ = *(x).f + _ = &(x).f + _ = !(x).f + _ = -x.f + _ = *x.f + _ = &x.f + _ = !x.f + _ = -(x).f() + _ = *(x).f() + _ = &(x).f() + _ = !(x).f() + _ = -x.f() + _ = *x.f() + _ = &x.f() + _ = !x.f() +} diff --git a/go/src/cmd/gofmt/testdata/rewrite5.golden b/go/src/cmd/gofmt/testdata/rewrite5.golden new file mode 100644 index 0000000000000000000000000000000000000000..9beb34aee76d13da7fafce9f32006f4c16b9092a --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite5.golden @@ -0,0 +1,17 @@ +//gofmt -r=x+x->2*x + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Rewriting of expressions containing nodes with associated comments to +// expressions without those nodes must also eliminate the associated +// comments. + +package p + +func f(x int) int { + _ = 2 * x // this comment remains in the rewrite + _ = 2 * x + return 2 * x +} diff --git a/go/src/cmd/gofmt/testdata/rewrite5.input b/go/src/cmd/gofmt/testdata/rewrite5.input new file mode 100644 index 0000000000000000000000000000000000000000..d7a6122d07a7a99c20e3ce7e0f57d27b054d2bcc --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite5.input @@ -0,0 +1,17 @@ +//gofmt -r=x+x->2*x + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Rewriting of expressions containing nodes with associated comments to +// expressions without those nodes must also eliminate the associated +// comments. + +package p + +func f(x int) int { + _ = x + x // this comment remains in the rewrite + _ = x /* this comment must not be in the rewrite */ + x + return x /* this comment must not be in the rewrite */ + x +} diff --git a/go/src/cmd/gofmt/testdata/rewrite6.golden b/go/src/cmd/gofmt/testdata/rewrite6.golden new file mode 100644 index 0000000000000000000000000000000000000000..48ec9aa0df7780e1dea1567071240fee46d1b2f9 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite6.golden @@ -0,0 +1,17 @@ +//gofmt -r=fun(x)->Fun(x) + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Rewriting of calls must take the ... (ellipsis) +// attribute for the last argument into account. + +package p + +func fun(x []int) {} + +func g(x []int) { + Fun(x) // -r='fun(x)->Fun(x)' should rewrite this to Fun(x) + fun(x...) // -r='fun(x)->Fun(x)' should not rewrite this +} diff --git a/go/src/cmd/gofmt/testdata/rewrite6.input b/go/src/cmd/gofmt/testdata/rewrite6.input new file mode 100644 index 0000000000000000000000000000000000000000..b085a84fef4a878b41bdd90716dce23acb90ecb9 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite6.input @@ -0,0 +1,17 @@ +//gofmt -r=fun(x)->Fun(x) + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Rewriting of calls must take the ... (ellipsis) +// attribute for the last argument into account. + +package p + +func fun(x []int) {} + +func g(x []int) { + fun(x) // -r='fun(x)->Fun(x)' should rewrite this to Fun(x) + fun(x...) // -r='fun(x)->Fun(x)' should not rewrite this +} diff --git a/go/src/cmd/gofmt/testdata/rewrite7.golden b/go/src/cmd/gofmt/testdata/rewrite7.golden new file mode 100644 index 0000000000000000000000000000000000000000..8386a0b2a3eb791bd1bb5a68d4277ea75b660441 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite7.golden @@ -0,0 +1,17 @@ +//gofmt -r=fun(x...)->Fun(x) + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Rewriting of calls must take the ... (ellipsis) +// attribute for the last argument into account. + +package p + +func fun(x []int) {} + +func g(x []int) { + fun(x) // -r='fun(x...)->Fun(x)' should not rewrite this + Fun(x) // -r='fun(x...)->Fun(x)' should rewrite this to Fun(x) +} diff --git a/go/src/cmd/gofmt/testdata/rewrite7.input b/go/src/cmd/gofmt/testdata/rewrite7.input new file mode 100644 index 0000000000000000000000000000000000000000..c1984708e71b34b96a1e78292ba8cca8ce1280f5 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite7.input @@ -0,0 +1,17 @@ +//gofmt -r=fun(x...)->Fun(x) + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Rewriting of calls must take the ... (ellipsis) +// attribute for the last argument into account. + +package p + +func fun(x []int) {} + +func g(x []int) { + fun(x) // -r='fun(x...)->Fun(x)' should not rewrite this + fun(x...) // -r='fun(x...)->Fun(x)' should rewrite this to Fun(x) +} diff --git a/go/src/cmd/gofmt/testdata/rewrite8.golden b/go/src/cmd/gofmt/testdata/rewrite8.golden new file mode 100644 index 0000000000000000000000000000000000000000..62f0419dfb460297d64aef8850d228c507f411f9 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite8.golden @@ -0,0 +1,12 @@ +//gofmt -r=interface{}->int + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check that literal type expression rewrites are accepted. +// Was issue 4406. + +package p + +type T int diff --git a/go/src/cmd/gofmt/testdata/rewrite8.input b/go/src/cmd/gofmt/testdata/rewrite8.input new file mode 100644 index 0000000000000000000000000000000000000000..7964c5c75c78fb0551487b8ae637353081990851 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite8.input @@ -0,0 +1,12 @@ +//gofmt -r=interface{}->int + +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check that literal type expression rewrites are accepted. +// Was issue 4406. + +package p + +type T interface{} diff --git a/go/src/cmd/gofmt/testdata/rewrite9.golden b/go/src/cmd/gofmt/testdata/rewrite9.golden new file mode 100644 index 0000000000000000000000000000000000000000..fffbd3d05ba3df5272edc4141103bb7a4461b8fb --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite9.golden @@ -0,0 +1,11 @@ +//gofmt -r=a&&b!=2->a + +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 18987. + +package p + +const _ = x != 1 diff --git a/go/src/cmd/gofmt/testdata/rewrite9.input b/go/src/cmd/gofmt/testdata/rewrite9.input new file mode 100644 index 0000000000000000000000000000000000000000..106ad94bc52bf3a125180df8835ecfce697ae3d2 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/rewrite9.input @@ -0,0 +1,11 @@ +//gofmt -r=a&&b!=2->a + +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 18987. + +package p + +const _ = x != 1 && x != 2 diff --git a/go/src/cmd/gofmt/testdata/slices1.golden b/go/src/cmd/gofmt/testdata/slices1.golden new file mode 100644 index 0000000000000000000000000000000000000000..04bc16f2160b62e330346aa424afc395b4be200a --- /dev/null +++ b/go/src/cmd/gofmt/testdata/slices1.golden @@ -0,0 +1,66 @@ +//gofmt -s + +// Test cases for slice expression simplification. +package p + +var ( + a [10]byte + b [20]float32 + s []int + t struct { + s []byte + } + + _ = a[0:] + _ = a[1:10] + _ = a[2:] + _ = a[3:(len(a))] + _ = a[len(a) : len(a)-1] + _ = a[0:len(b)] + _ = a[2:len(a):len(a)] + + _ = a[:] + _ = a[:10] + _ = a[:] + _ = a[:(len(a))] + _ = a[:len(a)-1] + _ = a[:len(b)] + _ = a[:len(a):len(a)] + + _ = s[0:] + _ = s[1:10] + _ = s[2:] + _ = s[3:(len(s))] + _ = s[len(a) : len(s)-1] + _ = s[0:len(b)] + _ = s[2:len(s):len(s)] + + _ = s[:] + _ = s[:10] + _ = s[:] + _ = s[:(len(s))] + _ = s[:len(s)-1] + _ = s[:len(b)] + _ = s[:len(s):len(s)] + + _ = t.s[0:] + _ = t.s[1:10] + _ = t.s[2:len(t.s)] + _ = t.s[3:(len(t.s))] + _ = t.s[len(a) : len(t.s)-1] + _ = t.s[0:len(b)] + _ = t.s[2:len(t.s):len(t.s)] + + _ = t.s[:] + _ = t.s[:10] + _ = t.s[:len(t.s)] + _ = t.s[:(len(t.s))] + _ = t.s[:len(t.s)-1] + _ = t.s[:len(b)] + _ = t.s[:len(t.s):len(t.s)] +) + +func _() { + s := s[0:] + _ = s +} diff --git a/go/src/cmd/gofmt/testdata/slices1.input b/go/src/cmd/gofmt/testdata/slices1.input new file mode 100644 index 0000000000000000000000000000000000000000..1f25c43ccbc825ba1a89cee7e0362c43c4eba257 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/slices1.input @@ -0,0 +1,66 @@ +//gofmt -s + +// Test cases for slice expression simplification. +package p + +var ( + a [10]byte + b [20]float32 + s []int + t struct { + s []byte + } + + _ = a[0:] + _ = a[1:10] + _ = a[2:len(a)] + _ = a[3:(len(a))] + _ = a[len(a) : len(a)-1] + _ = a[0:len(b)] + _ = a[2:len(a):len(a)] + + _ = a[:] + _ = a[:10] + _ = a[:len(a)] + _ = a[:(len(a))] + _ = a[:len(a)-1] + _ = a[:len(b)] + _ = a[:len(a):len(a)] + + _ = s[0:] + _ = s[1:10] + _ = s[2:len(s)] + _ = s[3:(len(s))] + _ = s[len(a) : len(s)-1] + _ = s[0:len(b)] + _ = s[2:len(s):len(s)] + + _ = s[:] + _ = s[:10] + _ = s[:len(s)] + _ = s[:(len(s))] + _ = s[:len(s)-1] + _ = s[:len(b)] + _ = s[:len(s):len(s)] + + _ = t.s[0:] + _ = t.s[1:10] + _ = t.s[2:len(t.s)] + _ = t.s[3:(len(t.s))] + _ = t.s[len(a) : len(t.s)-1] + _ = t.s[0:len(b)] + _ = t.s[2:len(t.s):len(t.s)] + + _ = t.s[:] + _ = t.s[:10] + _ = t.s[:len(t.s)] + _ = t.s[:(len(t.s))] + _ = t.s[:len(t.s)-1] + _ = t.s[:len(b)] + _ = t.s[:len(t.s):len(t.s)] +) + +func _() { + s := s[0:len(s)] + _ = s +} diff --git a/go/src/cmd/gofmt/testdata/stdin1.golden b/go/src/cmd/gofmt/testdata/stdin1.golden new file mode 100644 index 0000000000000000000000000000000000000000..9e4dcd20fe0d563ed51b2bac27567fbc7f5ee63c --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin1.golden @@ -0,0 +1,5 @@ + //gofmt -stdin + + if x { + y + } diff --git a/go/src/cmd/gofmt/testdata/stdin1.input b/go/src/cmd/gofmt/testdata/stdin1.input new file mode 100644 index 0000000000000000000000000000000000000000..9e4dcd20fe0d563ed51b2bac27567fbc7f5ee63c --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin1.input @@ -0,0 +1,5 @@ + //gofmt -stdin + + if x { + y + } diff --git a/go/src/cmd/gofmt/testdata/stdin2.golden b/go/src/cmd/gofmt/testdata/stdin2.golden new file mode 100644 index 0000000000000000000000000000000000000000..57df35540358c1c15f8cb3dfbdc292ae7d59c225 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin2.golden @@ -0,0 +1,11 @@ +//gofmt -stdin + +var x int + +func f() { + y := z + /* this is a comment */ + // this is a comment too +} + + diff --git a/go/src/cmd/gofmt/testdata/stdin2.input b/go/src/cmd/gofmt/testdata/stdin2.input new file mode 100644 index 0000000000000000000000000000000000000000..69d6bdd682efe8f90e157ef1f93f549c7cc7b4a4 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin2.input @@ -0,0 +1,11 @@ +//gofmt -stdin + +var x int + + +func f() { y := z + /* this is a comment */ + // this is a comment too +} + + diff --git a/go/src/cmd/gofmt/testdata/stdin3.golden b/go/src/cmd/gofmt/testdata/stdin3.golden new file mode 100644 index 0000000000000000000000000000000000000000..d6da0e417a06ce11d31cab2bea97606987ee3288 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin3.golden @@ -0,0 +1,7 @@ + //gofmt -stdin + + /* note: no newline at end of file */ + for i := 0; i < 10; i++ { + s += i + } + \ No newline at end of file diff --git a/go/src/cmd/gofmt/testdata/stdin3.input b/go/src/cmd/gofmt/testdata/stdin3.input new file mode 100644 index 0000000000000000000000000000000000000000..ab46c1063beba078cd8a18c4fd2beb64186e9d0a --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin3.input @@ -0,0 +1,5 @@ + //gofmt -stdin + + /* note: no newline at end of file */ + for i := 0; i < 10; i++ { s += i } + \ No newline at end of file diff --git a/go/src/cmd/gofmt/testdata/stdin4.golden b/go/src/cmd/gofmt/testdata/stdin4.golden new file mode 100644 index 0000000000000000000000000000000000000000..0c7acace5d0fa8c557e988699f92311ad74aa659 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin4.golden @@ -0,0 +1,5 @@ + //gofmt -stdin + + // comment + + i := 0 diff --git a/go/src/cmd/gofmt/testdata/stdin4.input b/go/src/cmd/gofmt/testdata/stdin4.input new file mode 100644 index 0000000000000000000000000000000000000000..1fc73f31e5e68aadf77ed9a334655e98754812bf --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin4.input @@ -0,0 +1,5 @@ + //gofmt -stdin + + // comment + + i := 0 diff --git a/go/src/cmd/gofmt/testdata/stdin5.golden b/go/src/cmd/gofmt/testdata/stdin5.golden new file mode 100644 index 0000000000000000000000000000000000000000..31ce6b248528bfdc416f712bafc33bd88b99a9fc --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin5.golden @@ -0,0 +1,3 @@ +//gofmt -stdin + +i := 5 // Line comment without newline. \ No newline at end of file diff --git a/go/src/cmd/gofmt/testdata/stdin5.input b/go/src/cmd/gofmt/testdata/stdin5.input new file mode 100644 index 0000000000000000000000000000000000000000..0a7c97d180c2ffff94327dc1d506d81a60df58ee --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin5.input @@ -0,0 +1,3 @@ +//gofmt -stdin + +i :=5// Line comment without newline. \ No newline at end of file diff --git a/go/src/cmd/gofmt/testdata/stdin6.golden b/go/src/cmd/gofmt/testdata/stdin6.golden new file mode 100644 index 0000000000000000000000000000000000000000..ffcea8011ba53e1c0197eb3c369f4000f9da302a --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin6.golden @@ -0,0 +1,19 @@ + //gofmt -stdin + + if err != nil { + source := strings.NewReader(`line 1. +line 2. +`) + return source + } + + f := func(hat, tail string) { + + fmt.Println(hat+` +foo + + +`+tail, + "more", + "and more") + } diff --git a/go/src/cmd/gofmt/testdata/stdin6.input b/go/src/cmd/gofmt/testdata/stdin6.input new file mode 100644 index 0000000000000000000000000000000000000000..78330020c659e07f6a89bcb70d0abbcb73aae123 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin6.input @@ -0,0 +1,21 @@ + //gofmt -stdin + + if err != nil { + source := strings.NewReader(`line 1. +line 2. +`) + return source + } + + f:=func( hat, tail string){ + + + + fmt. Println ( hat+ ` +foo + + +`+ tail , + "more" , + "and more" ) + } diff --git a/go/src/cmd/gofmt/testdata/stdin7.golden b/go/src/cmd/gofmt/testdata/stdin7.golden new file mode 100644 index 0000000000000000000000000000000000000000..bbac7133c86dfbb61b7d65cdbcecb45d16f2f703 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin7.golden @@ -0,0 +1,19 @@ + //gofmt -stdin + + if err != nil { + source := strings.NewReader(`line 1. +line 2. +`) + return source + } + + f := func(hat, tail string) { + + fmt.Println(hat+` + foo + + + `+tail, + "more", + "and more") + } diff --git a/go/src/cmd/gofmt/testdata/stdin7.input b/go/src/cmd/gofmt/testdata/stdin7.input new file mode 100644 index 0000000000000000000000000000000000000000..fd772a3c4e44fa62b022b2357efe6586c1b4f347 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/stdin7.input @@ -0,0 +1,21 @@ + //gofmt -stdin + + if err != nil { + source := strings.NewReader(`line 1. +line 2. +`) + return source + } + + f:=func( hat, tail string){ + + + + fmt. Println ( hat+ ` + foo + + + `+ tail , + "more" , + "and more" ) + } diff --git a/go/src/cmd/gofmt/testdata/tabs.golden b/go/src/cmd/gofmt/testdata/tabs.golden new file mode 100644 index 0000000000000000000000000000000000000000..287678cfc9d777b2992fc3d051d752b7083e6db1 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/tabs.golden @@ -0,0 +1,33 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//gofmt + +package main + +var _ = []struct { + S string + Integer int +}{ + { + S: "Hello World", + Integer: 42, + }, + { + S: "\t", + Integer: 42, + }, + { + S: " ", // an actual + Integer: 42, + }, + { + S: ` `, // an actual + Integer: 42, + }, + { + S: "\u0009", + Integer: 42, + }, +} diff --git a/go/src/cmd/gofmt/testdata/tabs.input b/go/src/cmd/gofmt/testdata/tabs.input new file mode 100644 index 0000000000000000000000000000000000000000..635be797c9868be699fa5cf7832369aeb0b624e2 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/tabs.input @@ -0,0 +1,33 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//gofmt + +package main + +var _ = []struct{ + S string + Integer int +}{ + { + S: "Hello World", + Integer: 42, + }, + { + S: "\t", + Integer: 42, + }, + { + S: " ", // an actual + Integer: 42, + }, + { + S: ` `, // an actual + Integer: 42, + }, + { + S: "\u0009", + Integer: 42, + }, +} diff --git a/go/src/cmd/gofmt/testdata/typealias.golden b/go/src/cmd/gofmt/testdata/typealias.golden new file mode 100644 index 0000000000000000000000000000000000000000..bbbbf321214bde1845a238bc0c54db6075ef01b3 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/typealias.golden @@ -0,0 +1,24 @@ +package q + +import "p" + +type _ = int +type a = struct{ x int } +type b = p.B + +type ( + _ = chan<- int + aa = interface{} + bb = p.BB +) + +// TODO(gri) We may want to put the '=' into a separate column if +// we have mixed (regular and alias) type declarations in a group. +type ( + _ chan<- int + _ = chan<- int + aa0 interface{} + aaa = interface{} + bb0 p.BB + bbb = p.BB +) diff --git a/go/src/cmd/gofmt/testdata/typealias.input b/go/src/cmd/gofmt/testdata/typealias.input new file mode 100644 index 0000000000000000000000000000000000000000..6e49328e34668d13bb746ed08c5c616b74f18046 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/typealias.input @@ -0,0 +1,24 @@ +package q + +import "p" + +type _ = int +type a = struct{ x int } +type b = p.B + +type ( + _ = chan<- int + aa = interface{} + bb = p.BB +) + +// TODO(gri) We may want to put the '=' into a separate column if +// we have mixed (regular and alias) type declarations in a group. +type ( + _ chan<- int + _ = chan<- int + aa0 interface{} + aaa = interface{} + bb0 p.BB + bbb = p.BB +) diff --git a/go/src/cmd/gofmt/testdata/typeparams.golden b/go/src/cmd/gofmt/testdata/typeparams.golden new file mode 100644 index 0000000000000000000000000000000000000000..d57a2ba59b03e6b42ff96656a08c2910c7c2b984 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/typeparams.golden @@ -0,0 +1,35 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//gofmt + +package typeparams + +type T[P any] struct{} +type T[P1, P2, P3 any] struct{} + +type T[P C] struct{} +type T[P1, P2, P3 C] struct{} + +type T[P C[P]] struct{} +type T[P1, P2, P3 C[P1, P2, P3]] struct{} + +func f[P any](x P) +func f[P1, P2, P3 any](x1 P1, x2 P2, x3 P3) struct{} + +func f[P interface{}](x P) +func f[P1, P2, P3 interface { + m1(P1) + ~P2 | ~P3 +}](x1 P1, x2 P2, x3 P3) struct{} +func f[P any](T1[P], T2[P]) T3[P] + +func (x T[P]) m() +func (T[P]) m(x T[P]) P + +func _() { + type _ []T[P] + var _ []T[P] + _ = []T[P]{} +} diff --git a/go/src/cmd/gofmt/testdata/typeparams.input b/go/src/cmd/gofmt/testdata/typeparams.input new file mode 100644 index 0000000000000000000000000000000000000000..775cf9eb7bdc85242b3af2864803855976e08c5c --- /dev/null +++ b/go/src/cmd/gofmt/testdata/typeparams.input @@ -0,0 +1,32 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//gofmt + +package typeparams + +type T[ P any] struct{} +type T[P1, P2, P3 any] struct{} + +type T[P C] struct{} +type T[P1,P2, P3 C] struct{} + +type T[P C[P]] struct{} +type T[P1, P2, P3 C[P1,P2,P3]] struct{} + +func f[P any](x P) +func f[P1, P2, P3 any](x1 P1, x2 P2, x3 P3) struct{} + +func f[P interface{}](x P) +func f[P1, P2, P3 interface{ m1(P1); ~P2|~P3 }](x1 P1, x2 P2, x3 P3) struct{} +func f[P any](T1[P], T2[P]) T3[P] + +func (x T[P]) m() +func ((T[P])) m(x T[P]) P + +func _() { + type _ []T[P] + var _ []T[P] + _ = []T[P]{} +} diff --git a/go/src/cmd/gofmt/testdata/typeswitch.golden b/go/src/cmd/gofmt/testdata/typeswitch.golden new file mode 100644 index 0000000000000000000000000000000000000000..3cf4dca7d4d6b8cf88ad31a9c5df5b848be57602 --- /dev/null +++ b/go/src/cmd/gofmt/testdata/typeswitch.golden @@ -0,0 +1,60 @@ +/* +Parenthesized type switch expressions originally +accepted by gofmt must continue to be rewritten +into the correct unparenthesized form. + +Only type-switches that didn't declare a variable +in the type switch type assertion and which +contained only "expression-like" (named) types in their +cases were permitted to have their type assertion parenthesized +by go/parser (due to a weak predicate in the parser). All others +were rejected always, either with a syntax error in the +type switch header or in the case. + +See also issue 4470. +*/ +package p + +func f() { + var x interface{} + switch x.(type) { // should remain the same + } + switch x.(type) { // should become: switch x.(type) { + } + + switch x.(type) { // should remain the same + case int: + } + switch x.(type) { // should become: switch x.(type) { + case int: + } + + switch x.(type) { // should remain the same + case []int: + } + + // Parenthesized (x.(type)) in type switches containing cases + // with unnamed (literal) types were never permitted by gofmt; + // thus there won't be any code in the wild using this style if + // the code was gofmt-ed. + /* + switch (x.(type)) { + case []int: + } + */ + + switch t := x.(type) { // should remain the same + default: + _ = t + } + + // Parenthesized (x.(type)) in type switches declaring a variable + // were never permitted by gofmt; thus there won't be any code in + // the wild using this style if the code was gofmt-ed. + /* + switch t := (x.(type)) { + default: + _ = t + } + */ +} diff --git a/go/src/cmd/gofmt/testdata/typeswitch.input b/go/src/cmd/gofmt/testdata/typeswitch.input new file mode 100644 index 0000000000000000000000000000000000000000..992a772d5210be32a6945644a57e570c1de3d57a --- /dev/null +++ b/go/src/cmd/gofmt/testdata/typeswitch.input @@ -0,0 +1,60 @@ +/* +Parenthesized type switch expressions originally +accepted by gofmt must continue to be rewritten +into the correct unparenthesized form. + +Only type-switches that didn't declare a variable +in the type switch type assertion and which +contained only "expression-like" (named) types in their +cases were permitted to have their type assertion parenthesized +by go/parser (due to a weak predicate in the parser). All others +were rejected always, either with a syntax error in the +type switch header or in the case. + +See also issue 4470. +*/ +package p + +func f() { + var x interface{} + switch x.(type) { // should remain the same + } + switch (x.(type)) { // should become: switch x.(type) { + } + + switch x.(type) { // should remain the same + case int: + } + switch (x.(type)) { // should become: switch x.(type) { + case int: + } + + switch x.(type) { // should remain the same + case []int: + } + + // Parenthesized (x.(type)) in type switches containing cases + // with unnamed (literal) types were never permitted by gofmt; + // thus there won't be any code in the wild using this style if + // the code was gofmt-ed. + /* + switch (x.(type)) { + case []int: + } + */ + + switch t := x.(type) { // should remain the same + default: + _ = t + } + + // Parenthesized (x.(type)) in type switches declaring a variable + // were never permitted by gofmt; thus there won't be any code in + // the wild using this style if the code was gofmt-ed. + /* + switch t := (x.(type)) { + default: + _ = t + } + */ +} diff --git a/go/src/cmd/internal/archive/testdata/go1.go b/go/src/cmd/internal/archive/testdata/go1.go new file mode 100644 index 0000000000000000000000000000000000000000..37d1ec19bbc0730f013f026479654be29eb98857 --- /dev/null +++ b/go/src/cmd/internal/archive/testdata/go1.go @@ -0,0 +1,11 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mypkg + +import "fmt" + +func go1() { + fmt.Println("go1") +} diff --git a/go/src/cmd/internal/archive/testdata/go2.go b/go/src/cmd/internal/archive/testdata/go2.go new file mode 100644 index 0000000000000000000000000000000000000000..0e9c0d7338c8f9728c417b068508877fc52d6a2f --- /dev/null +++ b/go/src/cmd/internal/archive/testdata/go2.go @@ -0,0 +1,11 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mypkg + +import "fmt" + +func go2() { + fmt.Println("go2") +} diff --git a/go/src/cmd/internal/archive/testdata/mycgo/c1.c b/go/src/cmd/internal/archive/testdata/mycgo/c1.c new file mode 100644 index 0000000000000000000000000000000000000000..869a324a8bca62debf49005e481203549666509d --- /dev/null +++ b/go/src/cmd/internal/archive/testdata/mycgo/c1.c @@ -0,0 +1,9 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include + +void c1(void) { + puts("c1"); +} diff --git a/go/src/cmd/internal/archive/testdata/mycgo/c2.c b/go/src/cmd/internal/archive/testdata/mycgo/c2.c new file mode 100644 index 0000000000000000000000000000000000000000..1cf904fb6f529cbdfcb8642ce0b4d9ea7d025157 --- /dev/null +++ b/go/src/cmd/internal/archive/testdata/mycgo/c2.c @@ -0,0 +1,9 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include + +void c2(void) { + puts("c2"); +} diff --git a/go/src/cmd/internal/archive/testdata/mycgo/go.go b/go/src/cmd/internal/archive/testdata/mycgo/go.go new file mode 100644 index 0000000000000000000000000000000000000000..7b74f9138a62d3a7aec01e48041c94eda257d132 --- /dev/null +++ b/go/src/cmd/internal/archive/testdata/mycgo/go.go @@ -0,0 +1,5 @@ +package mycgo + +// void c1(void); +// void c2(void); +import "C" diff --git a/go/src/cmd/internal/archive/testdata/mycgo/go1.go b/go/src/cmd/internal/archive/testdata/mycgo/go1.go new file mode 100644 index 0000000000000000000000000000000000000000..eb3924cc4c836baf1574e7f56fc6c126dd1de2dd --- /dev/null +++ b/go/src/cmd/internal/archive/testdata/mycgo/go1.go @@ -0,0 +1,11 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mycgo + +import "fmt" + +func go1() { + fmt.Println("go1") +} diff --git a/go/src/cmd/internal/archive/testdata/mycgo/go2.go b/go/src/cmd/internal/archive/testdata/mycgo/go2.go new file mode 100644 index 0000000000000000000000000000000000000000..ea3e26fa913ad0835b75c1d5a65b53610560ef7c --- /dev/null +++ b/go/src/cmd/internal/archive/testdata/mycgo/go2.go @@ -0,0 +1,11 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mycgo + +import "fmt" + +func go2() { + fmt.Println("go2") +} diff --git a/go/src/cmd/internal/buildid/testdata/a.elf.base64 b/go/src/cmd/internal/buildid/testdata/a.elf.base64 new file mode 100644 index 0000000000000000000000000000000000000000..fa855217358f92134e82dfc99917e7c4c372097e --- /dev/null +++ b/go/src/cmd/internal/buildid/testdata/a.elf.base64 @@ -0,0 +1 @@ +f0VMRgIBAQAAAAAAAAAAAAIAPgABAAAAABBAAAAAAABAAAAAAAAAAMgBAAAAAAAAAAAAAEAAOAAHAEAADQADAAYAAAAEAAAAQAAAAAAAAABAAEAAAAAAAEAAQAAAAAAAiAEAAAAAAACIAQAAAAAAAAAQAAAAAAAABAAAAAQAAACUDwAAAAAAAJQPQAAAAAAAlA9AAAAAAABsAAAAAAAAAGwAAAAAAAAABAAAAAAAAAABAAAABQAAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAABAQAAAAAAAAEBAAAAAAAAAAEAAAAAAAAAEAAAAEAAAAACAAAAAAAAAAIEAAAAAAAAAgQAAAAAAAfgEAAAAAAAB+AQAAAAAAAAAQAAAAAAAAAQAAAAYAAAAAMAAAAAAAAAAwQAAAAAAAADBAAAAAAADgAQAAAAAAAOABAAAAAAAAABAAAAAAAABR5XRkBgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAIAVBGUAKgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAABgAAAAAAAAAAEEAAAAAAAAAQAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAABBAAAAAQAAAAIAAAAAAAAAACBAAAAAAAAAIAAAAAAAADgAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAcgAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAQCAAAAAAAAB8AAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAEkAAAABAAAAAgAAAAAAAAC8IEAAAAAAALwgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAABTAAAAAQAAAAIAAAAAAAAAvCBAAAAAAAC8IAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXQAAAAEAAAACAAAAAAAAALwgQAAAAAAAvCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAGcAAAABAAAAAgAAAAAAAADAIEAAAAAAAMAgAAAAAAAAvgAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAHAAAAAQAAAAMAAAAAAAAAADBAAAAAAAAAMAAAAAAAAOABAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAEgAAAAgAAAADAAAAAAAAAOAxQAAAAAAA4DEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAIAAAAAwAAAAAAAADgMUAAAAAAAOAxAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAdAAAACAAAAAMAAAAAAAAA4DFAAAAAAADgMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJwAAAAcAAAACAAAAAAAAAJQPQAAAAAAAlA8AAAAAAABsAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAABbAAAABAAAAEdvAABhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ei4xMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0AMPMzMzMzMzMzMzMzMzMzMwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAEEAAAAAAAAAAAAAAAAAAAC50ZXh0AC5ub3B0cmRhdGEALmRhdGEALmJzcwAubm9wdHJic3MALm5vdGUuZ28uYnVpbGRpZAAuZWxmZGF0YQAucm9kYXRhAC50eXBlbGluawAuaXRhYmxpbmsALmdvc3ltdGFiAC5nb3BjbG50YWIALnNoc3RydGFiAAAAAAD7////AAABCAEAAAAAAAAAABBAAAAAAAAwAAAAAAAAAAEQQAAAAAAAgAAAAAAAAAAAEEAAAAAAAGgAAAAAAAAAZ0UjAXMAAAB2AAAAeQAAAAAAAAACAAAAACBAAAAAAAAAIEAAAAAAAG1haW4ubWFpbgAAAgEABAEABgEAAAAAAAIAAACIAAAAL1VzZXJzL3JzYy9nby9zcmMvY21kL2ludGVybmFsL2J1aWxkaWQvdGVzdGRhdGEvcC5nbwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIDBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAIEAAAAAAAL4AAAAAAAAAvgAAAAAAAADQIEAAAAAAAAIAAAAAAAAAAgAAAAAAAABAIUAAAAAAAAIAAAAAAAAAAgAAAAAAAAAMIEAAAAAAAAAQQAAAAAAAARBAAAAAAAAAEEAAAAAAABAQQAAAAAAAADBAAAAAAADgMUAAAAAAAOAxQAAAAAAA4DFAAAAAAADgMUAAAAAAAOAxQAAAAAAA4DFAAAAAAADgMUAAAAAAAOAxQAAAAAAACSBAAAAAAAAIIEAAAAAAAAAgQAAAAAAAOCBAAAAAAAAgIEAAAAAAAAEAAAAAAAAAAQAAAAAAAAC8IEAAAAAAAAAAAAAAAAAAAAAAAAAAAAC8IEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA diff --git a/go/src/cmd/internal/buildid/testdata/a.macho.base64 b/go/src/cmd/internal/buildid/testdata/a.macho.base64 new file mode 100644 index 0000000000000000000000000000000000000000..2e9f6a7dff35e2c75834edc674e30e5c3507309b --- /dev/null +++ b/go/src/cmd/internal/buildid/testdata/a.macho.base64 @@ -0,0 +1 @@ +z/rt/gcAAAEDAAAAAgAAAAkAAAAwBgAAAQAAAAAAAAAZAAAASAAAAF9fUEFHRVpFUk8AAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAeAIAAF9fVEVYVAAAAAAAAAAAAAAAAAABAAAAAAAgAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAcAAAAFAAAABwAAAAAAAABfX3RleHQAAAAAAAAAAAAAX19URVhUAAAAAAAAAAAAAAAQAAEAAAAAgAAAAAAAAAAAEAAABAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAF9fcm9kYXRhAAAAAAAAAABfX1RFWFQAAAAAAAAAAAAAgBAAAQAAAAA4AAAAAAAAAIAQAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAX19zeW1ib2xfc3R1YjEAAF9fVEVYVAAAAAAAAAAAAAC4EAABAAAAAAAAAAAAAAAAuBAAAAAAAAAAAAAAAAAAAAgEAIAAAAAABgAAAAAAAABfX3R5cGVsaW5rAAAAAAAAX19URVhUAAAAAAAAAAAAALgQAAEAAAAAAAAAAAAAAAC4EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAF9faXRhYmxpbmsAAAAAAABfX1RFWFQAAAAAAAAAAAAAuBAAAQAAAAAAAAAAAAAAALgQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAX19nb3N5bXRhYgAAAAAAAF9fVEVYVAAAAAAAAAAAAAC4EAABAAAAAAAAAAAAAAAAuBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABfX2dvcGNsbnRhYgAAAAAAX19URVhUAAAAAAAAAAAAAMAQAAEAAAAABgEAAAAAAADAEAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABkAAADYAQAAX19EQVRBAAAAAAAAAAAAAAAgAAEAAAAA4AEAAAAAAAAAIAAAAAAAAOABAAAAAAAAAwAAAAMAAAAFAAAAAAAAAF9fbmxfc3ltYm9sX3B0cgBfX0RBVEEAAAAAAAAAAAAAACAAAQAAAAAAAAAAAAAAAAAgAAACAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAX19ub3B0cmRhdGEAAAAAAF9fREFUQQAAAAAAAAAAAAAAIAABAAAAAOABAAAAAAAAACAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABfX2RhdGEAAAAAAAAAAAAAX19EQVRBAAAAAAAAAAAAAOAhAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAF9fYnNzAAAAAAAAAAAAAABfX0RBVEEAAAAAAAAAAAAA4CEAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAX19ub3B0cmJzcwAAAAAAAF9fREFUQQAAAAAAAAAAAADgIQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAZAAAASAAAAF9fTElOS0VESVQAAAAAAAAAMAABAAAAAKAEAAAAAAAAADAAAAAAAACgBAAAAAAAAAcAAAADAAAAAAAAAAAAAAAFAAAAuAAAAAQAAAAqAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwEAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAABgAAAAAMAAAJQAAAFAyAABQAgAACwAAAFAAAAAAAAAAJQAAACUAAAAAAAAAJQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQMgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAIAAAAAwAAAAvdXNyL2xpYi9keWxkAAAAAAAAACQAAAAQAAAAAAcKAAAHCgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP8gR28gYnVpbGQgSUQ6ICJhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ei4xMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0Igog/8zDzMzMzMzMzMzMzMzMzMzMAQAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAABAAAQAAAAAAAAAAAAAAAPv///8AAAEIAgAAAAAAAAAAEAABAAAAAEAAAAAAAAAAcBAAAQAAAAB4AAAAAAAAAHEQAAEAAAAAyAAAAAAAAAAAEAABAAAAAGgAAAAAAAAAZ0UjAQAAAAAAAAAAAAAAAAAAAAAAAAAAZ28uYnVpbGRpZAAAAAAAAHAQAAEAAAAAsAAAAAAAAABnRSMBuwAAAL4AAADBAAAAAAAAAAIAAACAEAABAAAAAIAQAAEAAAAAbWFpbi5tYWluAAACAQAEAQAGAQAAAAAAAgAAANAAAAAvVXNlcnMvcnNjL2dvL3NyYy9jbWQvaW50ZXJuYWwvYnVpbGRpZC90ZXN0ZGF0YS9wLmdvAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgIAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAQAAEAAAAABgEAAAAAAAAGAQAAAAAAANAQAAEAAAAAAwAAAAAAAAADAAAAAAAAAIgRAAEAAAAAAgAAAAAAAAACAAAAAAAAAIwQAAEAAAAAABAAAQAAAABxEAABAAAAAAAQAAEAAAAAgBAAAQAAAAAAIAABAAAAAOAhAAEAAAAA4CEAAQAAAADgIQABAAAAAOAhAAEAAAAA4CEAAQAAAADgIQABAAAAAOAhAAEAAAAA4CEAAQAAAACJEAABAAAAAIgQAAEAAAAAgBAAAQAAAAC4EAABAAAAAKAQAAEAAAAAAQAAAAAAAAABAAAAAAAAALgQAAEAAAAAAAAAAAAAAAAAAAAAAAAAALgQAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAA4BAAAAEAABAAAAAA0AAAAOAgAAgBAAAQAAAAAXAAAADgIAAIAQAAEAAAAAIwAAAA4BAABwEAABAAAAAC0AAAAOCwAA4CEAAQAAAAA5AAAADgoAAOAhAAEAAAAARgAAAA4LAADgIQABAAAAAFMAAAAOCgAA4CEAAQAAAABhAAAADgIAAIkQAAEAAAAAcAAAAA4CAACKEAABAAAAAIAAAAAOBQAAuBAAAQAAAACSAAAADgwAAOAhAAEAAAAAngAAAA4MAADgIQABAAAAALAAAAAOCQAA4CEAAQAAAADDAAAADgcAAMYRAAEAAAAA1AAAAA4CAAC4EAABAAAAAOQAAAAOBgAAuBAAAQAAAAD0AAAADgEAAIAQAAEAAAAAAgEAAA4CAAC4EAABAAAAABEBAAAOAgAAjBAAAQAAAAAlAQAADgkAACAgAAEAAAAAPQEAAA4CAACKEAABAAAAAFoBAAAOAgAAiBAAAQAAAABrAQAADgIAAIgQAAEAAAAAeQEAAA4CAACJEAABAAAAAIgBAAAOBQAAuBAAAQAAAACZAQAADgkAAAAgAAEAAAAAsQEAAA4MAADgIQABAAAAAMIBAAAOCQAAACAAAQAAAADUAQAADgcAAMAQAAEAAAAA5AEAAA4CAACAEAABAAAAAPMBAAAOBgAAuBAAAQAAAAACAgAADgEAAAAQAAEAAAAADwIAAA4CAACgEAABAAAAACYCAAAOBAAAuBAAAQAAAAA3AgAADgIAAIAQAAEAAAAARQIAAA4CAACAEAABAAAAACAAZ28uYnVpbGRpZABnby5mdW5jLioAZ28uc3RyaW5nLioAbWFpbi5tYWluAHJ1bnRpbWUuYnNzAHJ1bnRpbWUuZGF0YQBydW50aW1lLmVic3MAcnVudGltZS5lZGF0YQBydW50aW1lLmVnY2JzcwBydW50aW1lLmVnY2RhdGEAcnVudGltZS5laXRhYmxpbmsAcnVudGltZS5lbmQAcnVudGltZS5lbm9wdHJic3MAcnVudGltZS5lbm9wdHJkYXRhAHJ1bnRpbWUuZXBjbG50YWIAcnVudGltZS5lcm9kYXRhAHJ1bnRpbWUuZXN5bXRhYgBydW50aW1lLmV0ZXh0AHJ1bnRpbWUuZXR5cGVzAHJ1bnRpbWUuZmluZGZ1bmN0YWIAcnVudGltZS5maXJzdG1vZHVsZWRhdGEAcnVudGltZS5mcmFtZXBvaW50ZXJfZW5hYmxlZABydW50aW1lLmdjYml0cy4qAHJ1bnRpbWUuZ2Nic3MAcnVudGltZS5nY2RhdGEAcnVudGltZS5pdGFibGluawBydW50aW1lLmxhc3Rtb2R1bGVkYXRhcABydW50aW1lLm5vcHRyYnNzAHJ1bnRpbWUubm9wdHJkYXRhAHJ1bnRpbWUucGNsbnRhYgBydW50aW1lLnJvZGF0YQBydW50aW1lLnN5bXRhYgBydW50aW1lLnRleHQAcnVudGltZS50ZXh0c2VjdGlvbm1hcABydW50aW1lLnR5cGVsaW5rAHJ1bnRpbWUudHlwZXMAdHlwZS4qAAAAAAA= diff --git a/go/src/cmd/internal/buildid/testdata/a.pe.base64 b/go/src/cmd/internal/buildid/testdata/a.pe.base64 new file mode 100644 index 0000000000000000000000000000000000000000..d3a31a3a627aad50491138f1d48c7c8f93bc6bbc --- /dev/null +++ b/go/src/cmd/internal/buildid/testdata/a.pe.base64 @@ -0,0 +1 @@ +TVqQAAMABAAAAAAA//8AAIsAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYEAAAAAAAADAAAAAAAAPAAIwILAgMAAAIAAAACAAAAAAAAcBAAAAAQAAAAAEAAAAAAAAAQAAAAAgAABAAAAAEAAAAEAAAAAAAAAABQAAAABgAAAAAAAAMAAAAAACAAAAAAAADgHwAAAAAAAAAQAAAAAAAAEAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAMAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAudGV4dAAAAMYBAAAAEAAAAAIAAAAGAAAAAAAAAAAAAAAAAABgAABgLmRhdGEAAADgAQAAACAAAAACAAAACAAAAAAAAAAAAAAAAAAAQAAAwC5pZGF0YQAAFAAAAAAwAAAAAgAAAAoAAAAAAAAAAAAAAAAAAEAAAMAuc3ltdGFiAAQAAAAAQAAAAAIAAAAMAAAAAAAAAAAAAAAAAAAAAABCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/yBHbyBidWlsZCBJRDogImFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6LjEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQiCiD/zMPMzMzMzMzMzMzMzMzMzMwBAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAEEAAAAAAAAAAAAAAAAAA+////wAAAQgCAAAAAAAAAAAQQAAAAAAAQAAAAAAAAABwEEAAAAAAAHgAAAAAAAAAcRBAAAAAAADIAAAAAAAAAAAQQAAAAAAAaAAAAAAAAABnRSMBAAAAAAAAAAAAAAAAAAAAAAAAAABnby5idWlsZGlkAAAAAAAAcBBAAAAAAACwAAAAAAAAAGdFIwG7AAAAvgAAAMEAAAAAAAAAAgAAAIAQQAAAAAAAgBBAAAAAAABtYWluLm1haW4AAAIBAAQBAAYBAAAAAAACAAAA0AAAAC9Vc2Vycy9yc2MvZ28vc3JjL2NtZC9pbnRlcm5hbC9idWlsZGlkL3Rlc3RkYXRhL3AuZ28AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgIEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAQQAAAAAAABgEAAAAAAAAGAQAAAAAAANAQQAAAAAAAAwAAAAAAAAADAAAAAAAAAIgRQAAAAAAAAgAAAAAAAAACAAAAAAAAAIwQQAAAAAAAABBAAAAAAABxEEAAAAAAAAAQQAAAAAAAgBBAAAAAAAAAIEAAAAAAAOAhQAAAAAAA4CFAAAAAAADgIUAAAAAAAOAhQAAAAAAA4CFAAAAAAADgIUAAAAAAAOAhQAAAAAAA4CFAAAAAAACJEEAAAAAAAIgQQAAAAAAAgBBAAAAAAAC4EEAAAAAAAKAQQAAAAAAAAQAAAAAAAAABAAAAAAAAALgQQAAAAAAAAAAAAAAAAAAAAAAAAAAAALgQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= diff --git a/go/src/cmd/internal/buildid/testdata/p.a.base64 b/go/src/cmd/internal/buildid/testdata/p.a.base64 new file mode 100644 index 0000000000000000000000000000000000000000..ba96c10ca50383c0cb139c3c4af686dd879ed9b8 --- /dev/null +++ b/go/src/cmd/internal/buildid/testdata/p.a.base64 @@ -0,0 +1 @@ +ITxhcmNoPgpfXy5QS0dERUYgICAgICAgMCAgICAgICAgICAgMCAgICAgMCAgICAgNjQ0ICAgICAzMzAgICAgICAgYApnbyBvYmplY3QgZGFyd2luIGFtZDY0IGRldmVsICszYjMzYWY1ZDY4IFRodSBPY3QgNSAxNjo1OTowMCAyMDE3IC0wNDAwIFg6ZnJhbWVwb2ludGVyCmJ1aWxkIGlkICJhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ei4xMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0IgotLS0tCgpidWlsZCBpZCAiYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXouMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNCIKCiQkQgp2ZXJzaW9uIDUKCgACAQFwAAsACwABAAokJApfZ29fLm8gICAgICAgICAgMCAgICAgICAgICAgMCAgICAgMCAgICAgNjQ0ICAgICAyMjMgICAgICAgYApnbyBvYmplY3QgZGFyd2luIGFtZDY0IGRldmVsICszYjMzYWY1ZDY4IFRodSBPY3QgNSAxNjo1OTowMCAyMDE3IC0wNDAwIFg6ZnJhbWVwb2ludGVyCmJ1aWxkIGlkICJhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ei4xMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0IgotLS0tCgoKIQoAAGdvMTlsZAEA/wAAAAAAAP//Z28xOWxkAA== diff --git a/go/src/cmd/internal/cov/testdata/small.go b/go/src/cmd/internal/cov/testdata/small.go new file mode 100644 index 0000000000000000000000000000000000000000..d81cb70624c699a996de9f96e2022c34fca99825 --- /dev/null +++ b/go/src/cmd/internal/cov/testdata/small.go @@ -0,0 +1,7 @@ +package main + +import "os" + +func main() { + println(len(os.Args)) +}