Skip to content

Commit 03a6860

Browse files
author
Jay Conrod
committed
cmd/go: update tests to work with -mod=readonly on by default
For #40728 Change-Id: Ic2b025ff75c6e73c0cb58c1737e44e2a41c71571 Reviewed-on: https://go-review.googlesource.com/c/go/+/253837 Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent d277a36 commit 03a6860

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+146
-76
lines changed

src/cmd/go/testdata/mod/example.com_retract_missingmod_v1.0.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ module example.com/retract/missingmod
66
go 1.14
77
-- .info --
88
{"Version":"v1.0.0"}
9+
-- missingmod.go --
10+
package missingmod

src/cmd/go/testdata/script/mod_auth.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ env GOSUMDB=off
77
# Without credentials, downloading a module from a path that requires HTTPS
88
# basic auth should fail.
99
env NETRC=$WORK/empty
10-
! go list all
10+
! go mod tidy
1111
stderr '^\tserver response: ACCESS DENIED, buddy$'
1212
stderr '^\tserver response: File\? What file\?$'
1313

src/cmd/go/testdata/script/mod_case.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
env GO111MODULE=on
22

3-
go get rsc.io/QUOTE
3+
go get -d
44
go list -m all
55
stdout '^rsc.io/quote v1.5.2'
66
stdout '^rsc.io/QUOTE v1.5.2'
@@ -18,3 +18,8 @@ stdout '[email protected]!p!r!e'
1818

1919
-- go.mod --
2020
module x
21+
22+
-- use.go --
23+
package use
24+
25+
import _ "rsc.io/QUOTE/QUOTE"

src/cmd/go/testdata/script/mod_concurrent.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
env GO111MODULE=on
22

33
# Concurrent builds should succeed, even if they need to download modules.
4+
go get -d ./x ./y
45
go build ./x &
56
go build ./y
67
wait

src/cmd/go/testdata/script/mod_doc.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# go doc should find module documentation
22

33
env GO111MODULE=on
4+
env GOFLAGS=-mod=mod
45
[short] skip
56

67
# Check when module x is inside GOPATH/src.
@@ -48,6 +49,7 @@ stderr '^doc: cannot find module providing package example.com/hello: module loo
4849
# path used in source code, not to the absolute path relative to GOROOT.
4950

5051
cd $GOROOT/src
52+
env GOFLAGS=
5153
go doc cryptobyte
5254
stdout '// import "golang.org/x/crypto/cryptobyte"'
5355

src/cmd/go/testdata/script/mod_domain_root.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# (example.com not example.com/something)
33

44
env GO111MODULE=on
5-
go build
5+
go get -d
66

77
-- go.mod --
88
module x

src/cmd/go/testdata/script/mod_download.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ go mod edit -require rsc.io/[email protected]
4646
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
4747

4848
# module loading will page in the info and mod files
49-
go list -m all
49+
go list -m -mod=mod all
5050
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
5151
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
5252
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip

src/cmd/go/testdata/script/mod_download_partial.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Download a module
2-
go mod download -modcacherw rsc.io/quote
1+
# Download modules and populate go.sum.
2+
go get -d -modcacherw
33
exists $GOPATH/pkg/mod/rsc.io/[email protected]/go.mod
44

55
# 'go mod verify' should fail if we delete a file.
@@ -61,4 +61,9 @@ go 1.14
6161

6262
require rsc.io/quote v1.5.2
6363

64+
-- use.go --
65+
package use
66+
67+
import _ "rsc.io/quote"
68+
6469
-- empty --

src/cmd/go/testdata/script/mod_get_incompatible.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
env GO111MODULE=on
22

3-
go list x
3+
go get -d x
44
go list -m all
55
stdout 'rsc.io/breaker v2.0.0\+incompatible'
66

src/cmd/go/testdata/script/mod_get_indirect.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ grep 'golang.org/x/text v0.3.0 // indirect$' go.mod
2727

2828
# indirect tag should be removed upon seeing direct import.
2929
cp $WORK/tmp/uselang.go x.go
30-
go list
30+
go get -d
3131
grep 'rsc.io/quote v1.5.2$' go.mod
3232
grep 'golang.org/x/text [v0-9a-f\.-]+$' go.mod
3333

src/cmd/go/testdata/script/mod_get_latest_pseudo.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
env GO111MODULE=on
66

77
go mod init m
8-
go list example.com/notags
8+
go get -d example.com/notags
99
go list -m all
1010
stdout '^example.com/notags v0.0.0-20190507143103-cc8cbe209b64$'

src/cmd/go/testdata/script/mod_get_trailing_slash.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Populate go.sum
2+
go mod download
3+
14
# go list should succeed to load a package ending with ".go" if the path does
25
# not correspond to an existing local file. Listing a pattern ending with
36
# ".go/" should try to list a package regardless of whether a file exists at the

src/cmd/go/testdata/script/mod_import.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
env GO111MODULE=on
22

33
# latest rsc.io/quote should be v1.5.2 not v1.5.3-pre1
4-
go list
4+
go get -d
55
go list -m all
66
stdout 'rsc.io/quote v1.5.2'
77

src/cmd/go/testdata/script/mod_in_testdata_dir.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ env GO111MODULE=on
88
cd $WORK/testdata
99
go mod init testdata.tld/foo
1010

11-
# Building a package within that module should resolve its dependencies.
12-
go build
11+
# Getting a package within that module should resolve its dependencies.
12+
go get -d
1313
grep 'rsc.io/quote' go.mod
1414

1515
# Tidying the module should preserve those dependencies.
@@ -26,7 +26,7 @@ exists vendor/rsc.io/quote
2626
cd $WORK/_ignored
2727
go mod init testdata.tld/foo
2828

29-
go build
29+
go get
3030
grep 'rsc.io/quote' go.mod
3131

3232
go mod tidy

src/cmd/go/testdata/script/mod_init_dep.txt

+4-17
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,21 @@
11
env GO111MODULE=on
2+
env GOFLAGS=-mod=mod
23

34
# modconv uses git directly to examine what old 'go get' would
45
[!net] skip
56
[!exec:git] skip
67

7-
# go build should populate go.mod from Gopkg.lock
8-
cp go.mod1 go.mod
9-
go build
8+
# go mod init should populate go.mod from Gopkg.lock
9+
go mod init x
1010
stderr 'copying requirements from Gopkg.lock'
1111
go list -m all
12-
! stderr 'copying requirements from Gopkg.lock'
13-
stdout 'rsc.io/sampler v1.0.0'
14-
15-
# go list should populate go.mod from Gopkg.lock
16-
cp go.mod1 go.mod
17-
go list
18-
stderr 'copying requirements from Gopkg.lock'
19-
go list
20-
! stderr 'copying requirements from Gopkg.lock'
21-
go list -m all
2212
stdout 'rsc.io/sampler v1.0.0'
2313

2414
# test dep replacement
2515
cd y
2616
go mod init
2717
cmpenv go.mod go.mod.replace
2818

29-
-- go.mod1 --
30-
module x
31-
3219
-- x.go --
3320
package x
3421

@@ -54,4 +41,4 @@ go $goversion
5441

5542
replace z v1.0.0 => rsc.io/quote v1.0.0
5643

57-
require rsc.io/quote v1.0.0
44+
require rsc.io/quote v1.0.0

src/cmd/go/testdata/script/mod_install_versioned.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
env GO111MODULE=on
22

3+
go get -d rsc.io/fortune
34
go list -f '{{.Target}}' rsc.io/fortune
45
! stdout fortune@v1
56
stdout 'fortune(\.exe)?$'
67

8+
go get -d rsc.io/fortune/v2
79
go list -f '{{.Target}}' rsc.io/fortune/v2
810
! stdout v2
911
stdout 'fortune(\.exe)?$'

src/cmd/go/testdata/script/mod_internal.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,52 @@ env GO111MODULE=on
33

44
# golang.org/x/internal should be importable from other golang.org/x modules.
55
go mod edit -module=golang.org/x/anything
6-
go build .
6+
go get -d .
77

88
# ...and their tests...
99
go test
1010
stdout PASS
1111

1212
# ...but that should not leak into other modules.
13+
go get -d ./baddep
1314
! go build ./baddep
1415
stderr golang.org[/\\]notx[/\\]useinternal
1516
stderr 'use of internal package golang.org/x/.* not allowed'
1617

1718
# Internal packages in the standard library should not leak into modules.
19+
go get -d ./fromstd
1820
! go build ./fromstd
1921
stderr 'use of internal package internal/testenv not allowed'
2022

2123
# Dependencies should be able to use their own internal modules...
2224
go mod edit -module=golang.org/notx
23-
go build ./throughdep
25+
go get -d ./throughdep
2426

2527
# ... but other modules should not, even if they have transitive dependencies.
28+
go get -d .
2629
! go build .
2730
stderr 'use of internal package golang.org/x/.* not allowed'
2831

2932
# And transitive dependencies still should not leak.
33+
go get -d ./baddep
3034
! go build ./baddep
3135
stderr golang.org[/\\]notx[/\\]useinternal
3236
stderr 'use of internal package golang.org/x/.* not allowed'
3337

3438
# Replacing an internal module should keep it internal to the same paths.
3539
go mod edit -module=golang.org/notx
3640
go mod edit -replace golang.org/x/internal=./replace/golang.org/notx/internal
37-
go build ./throughdep
41+
go get -d ./throughdep
3842

43+
go get -d ./baddep
3944
! go build ./baddep
4045
stderr golang.org[/\\]notx[/\\]useinternal
4146
stderr 'use of internal package golang.org/x/.* not allowed'
4247

4348
go mod edit -replace golang.org/x/internal=./vendor/golang.org/x/internal
44-
go build ./throughdep
49+
go get -d ./throughdep
4550

51+
go get -d ./baddep
4652
! go build ./baddep
4753
stderr golang.org[/\\]notx[/\\]useinternal
4854
stderr 'use of internal package golang.org/x/.* not allowed'

src/cmd/go/testdata/script/mod_invalid_version.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
env GO111MODULE=on
55
env GOPROXY=direct
66
env GOSUMDB=off
7+
env GOFLAGS=-mod=mod
78

89
# Regression test for golang.org/issue/27173: if the user (or go.mod file)
910
# requests a pseudo-version that does not match both the module path and commit

src/cmd/go/testdata/script/mod_list.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ env GO111MODULE=on
22
[short] skip
33

44
# list {{.Dir}} shows main module and go.mod but not not-yet-downloaded dependency dir.
5-
go list -m -f '{{.Path}} {{.Main}} {{.GoMod}} {{.Dir}}' all
5+
go list -mod=mod -m -f '{{.Path}} {{.Main}} {{.GoMod}} {{.Dir}}' all
66
stdout '^x true .*[\\/]src[\\/]go.mod .*[\\/]src$'
77
stdout '^rsc.io/quote false .*[\\/]v1.5.2.mod $'
88

99
# list {{.Dir}} shows dependency after download (and go list without -m downloads it)
10-
go list -f '{{.Dir}}' rsc.io/quote
10+
go list -mod=mod -f '{{.Dir}}' rsc.io/quote
1111
stdout '.*mod[\\/]rsc.io[\\/][email protected]$'
1212

1313
# downloaded dependencies are read-only
@@ -20,7 +20,7 @@ go clean -modcache
2020

2121
# list {{.Dir}} shows replaced directories
2222
cp go.mod2 go.mod
23-
go list -f {{.Dir}} rsc.io/quote
23+
go list -mod=mod -f {{.Dir}} rsc.io/quote
2424
go list -m -f '{{.Path}} {{.Version}} {{.Dir}}{{with .Replace}} {{.GoMod}} => {{.Version}} {{.Dir}} {{.GoMod}}{{end}}' all
2525
stdout 'mod[\\/]rsc.io[\\/][email protected]'
2626
stdout 'v1.3.0.*mod[\\/]rsc.io[\\/][email protected] .*[\\/]v1.3.1.mod => v1.3.1.*[email protected] .*[\\/]v1.3.1.mod'
@@ -30,7 +30,7 @@ go list std
3030
stdout ^math/big
3131

3232
# rsc.io/quote/buggy should be listable as a package
33-
go list rsc.io/quote/buggy
33+
go list -mod=mod rsc.io/quote/buggy
3434

3535
# rsc.io/quote/buggy should not be listable as a module
3636
go list -m -e -f '{{.Error.Err}}' nonexist rsc.io/quote/buggy

src/cmd/go/testdata/script/mod_list_dir.txt

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
# go list with path to directory should work
44

5+
# populate go.sum
6+
go get -d
7+
58
env GO111MODULE=off
69
go list -f '{{.ImportPath}}' $GOROOT/src/math
710
stdout ^math$
@@ -29,3 +32,5 @@ require rsc.io/quote v1.5.2
2932

3033
-- x.go --
3134
package x
35+
36+
import _ "rsc.io/quote"

src/cmd/go/testdata/script/mod_list_direct.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env GOSUMDB=off
1010
# For a while, (*modfetch.codeRepo).Stat was not checking for a go.mod file,
1111
# which would produce a hard error at the subsequent call to GoMod.
1212

13-
go list all
13+
go get -d
1414

1515
-- go.mod --
1616
module example.com

src/cmd/go/testdata/script/mod_list_replace_dir.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
# module within the module cache.
33
# Verifies golang.org/issue/29548
44

5-
env GO111MODULE=on
6-
go mod download rsc.io/[email protected] rsc.io/[email protected]
5+
# Populate go.sum and download dependencies.
6+
go get -d
7+
8+
# Ensure v1.5.2 is also in the cache so we can list it.
9+
go mod download rsc.io/[email protected]
710

811
! go list $GOPATH/pkg/mod/rsc.io/[email protected]
912
stderr '^directory ..[/\\]pkg[/\\]mod[/\\]rsc.io[/\\][email protected] outside available modules$'
@@ -17,3 +20,8 @@ module example.com/quoter
1720
require rsc.io/quote v1.5.2
1821

1922
replace rsc.io/quote => rsc.io/quote v1.5.1
23+
24+
-- use.go --
25+
package use
26+
27+
import _ "rsc.io/quote"

src/cmd/go/testdata/script/mod_list_upgrade.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
env GO111MODULE=on
22

3+
# Populate go.sum
4+
go list -m -mod=mod all
5+
6+
# Check for upgrades.
37
go list -m -u all
48
stdout 'rsc.io/quote v1.2.0 \[v1\.5\.2\]'
59

src/cmd/go/testdata/script/mod_load_badchain.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ cmp stderr list-expected
2828
# Try listing a package that imports a package
2929
# in a module without a requirement.
3030
go mod edit -droprequire example.com/badchain/a
31-
! go list m/use
31+
! go list -mod=mod m/use
3232
cmp stderr list-missing-expected
3333

34-
! go list -test m/testuse
34+
! go list -mod=mod -test m/testuse
3535
cmp stderr list-missing-test-expected
3636

3737
-- go.mod.orig --

src/cmd/go/testdata/script/mod_load_badmod.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# Unknown lines should be ignored in dependency go.mod files.
2-
env GO111MODULE=on
3-
go list -m all
2+
go list -m -mod=mod all
43

54
# ... and in replaced dependency go.mod files.
65
cp go.mod go.mod.usesub
7-
go list -m all
6+
go list -m -mod=mod all
87

98
# ... but not in the main module.
109
cp go.mod.bad go.mod
11-
! go list -m all
10+
! go list -m -mod=mod all
1211
stderr 'unknown directive: hello'
1312

1413
-- go.mod --

0 commit comments

Comments
 (0)