diff options
author | Bryan C. Mills <bcmills@google.com> | 2021-03-15 12:40:34 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2021-03-17 21:24:05 +0000 |
commit | 7e00049b5545cac8705d6df1e337c5ddc70e65e4 (patch) | |
tree | f0ae39ba49ac7c649d14412d1949dd9fdf516de8 /src/cmd/go/testdata/script/mod_outside.txt | |
parent | 4313c2886160613ca62742d0f46665cf8954213c (diff) | |
download | go-7e00049b5545cac8705d6df1e337c5ddc70e65e4.tar.gz go-7e00049b5545cac8705d6df1e337c5ddc70e65e4.zip |
cmd/go: only add a 'go' directive to the main module when the go.mod file will be written
Then, write the 'go.mod' file with that version before further
processing. That way, if the command errors out due to a change in
behavior, the reason for the change in behavior will be visible in the
file diffs.
If the 'go.mod' file cannot be written (due to -mod=readonly or
-mod=vendor), assume Go 1.11 instead of the current Go release.
(cmd/go has added 'go' directives automatically, including in 'go mod
init', since Go 1.12.)
For #44976
Change-Id: If9d4af557366f134f40ce4c5638688ba3bab8380
Reviewed-on: https://go-review.googlesource.com/c/go/+/302051
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/testdata/script/mod_outside.txt')
-rw-r--r-- | src/cmd/go/testdata/script/mod_outside.txt | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/cmd/go/testdata/script/mod_outside.txt b/src/cmd/go/testdata/script/mod_outside.txt index 7c57db9f7c..0b01492cde 100644 --- a/src/cmd/go/testdata/script/mod_outside.txt +++ b/src/cmd/go/testdata/script/mod_outside.txt @@ -169,6 +169,8 @@ 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. @@ -331,3 +333,15 @@ 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 +} |