| 1 |
# Tests the behavior of the -modfile flag in commands that support it. |
| 2 |
# The go.mod file exists but should not be read or written. |
| 3 |
# Same with go.sum. |
| 4 |
|
| 5 |
env GOFLAGS=-modfile=go.alt.mod |
| 6 |
cp go.mod go.mod.orig |
| 7 |
cp go.sum go.sum.orig |
| 8 |
|
| 9 |
|
| 10 |
# go mod init should create a new file, even though go.mod already exists. |
| 11 |
go mod init example.com/m |
| 12 |
grep example.com/m go.alt.mod |
| 13 |
|
| 14 |
# 'go env GOMOD' should print the path to the real file. |
| 15 |
# 'go env' does not recognize the '-modfile' flag. |
| 16 |
go env GOMOD |
| 17 |
stdout '^'$WORK${/}gopath${/}src${/}'go\.mod$' |
| 18 |
|
| 19 |
# 'go list -m' should print the effective go.mod file as GoMod though. |
| 20 |
go list -m -f '{{.GoMod}}' |
| 21 |
stdout '^go.alt.mod$' |
| 22 |
|
| 23 |
# go mod edit should operate on the alternate file |
| 24 |
go mod edit -require rsc.io/[email protected] |
| 25 |
grep rsc.io/quote go.alt.mod |
| 26 |
|
| 27 |
# 'go list -m' should add sums to the alternate go.sum. |
| 28 |
go list -m -mod=mod all |
| 29 |
grep '^rsc.io/quote v1.5.2/go.mod ' go.alt.sum |
| 30 |
! grep '^rsc.io/quote v1.5.2 ' go.alt.sum |
| 31 |
|
| 32 |
# other 'go mod' commands should work. 'go mod vendor' is tested later. |
| 33 |
go mod download rsc.io/quote |
| 34 |
go mod graph |
| 35 |
stdout rsc.io/quote |
| 36 |
go mod tidy |
| 37 |
grep rsc.io/quote go.alt.sum |
| 38 |
go mod verify |
| 39 |
go mod why rsc.io/quote |
| 40 |
|
| 41 |
|
| 42 |
# 'go list' and other commands with build flags should work. |
| 43 |
# They should update the alternate go.mod when a dependency is missing. |
| 44 |
go mod edit -droprequire rsc.io/quote |
| 45 |
go list -mod=mod . |
| 46 |
grep rsc.io/quote go.alt.mod |
| 47 |
go build -n -mod=mod . |
| 48 |
go test -n -mod=mod . |
| 49 |
go get rsc.io/quote |
| 50 |
|
| 51 |
# 'go tool' and tool management should work. |
| 52 |
go get -tool example.com/tools/cmd/[email protected] |
| 53 |
grep cmd/hello go.alt.mod |
| 54 |
go tool hello |
| 55 |
|
| 56 |
# 'go mod vendor' should work. |
| 57 |
go mod vendor |
| 58 |
exists vendor |
| 59 |
|
| 60 |
# Automatic vendoring should be broken by editing an explicit requirement |
| 61 |
# in the alternate go.mod file. |
| 62 |
go mod edit -require rsc.io/[email protected] |
| 63 |
! go list . |
| 64 |
go list -mod=mod |
| 65 |
rm vendor |
| 66 |
|
| 67 |
|
| 68 |
# 'go generate' should use the alternate file when resolving packages. |
| 69 |
# Recursive go commands started with 'go generate' should not get an explicitly |
| 70 |
# passed -modfile, but they should see arguments from GOFLAGS. |
| 71 |
cp go.alt.mod go.gen.mod |
| 72 |
env OLD_GOFLAGS=$GOFLAGS |
| 73 |
env GOFLAGS=-modfile=go.gen.mod |
| 74 |
go generate -modfile=go.alt.mod . |
| 75 |
env GOFLAGS=$OLD_GOFLAGS |
| 76 |
grep example.com/exclude go.gen.mod |
| 77 |
! grep example.com/exclude go.alt.mod |
| 78 |
|
| 79 |
|
| 80 |
# The original files should not have been modified. |
| 81 |
cmp go.mod go.mod.orig |
| 82 |
cmp go.sum go.sum.orig |
| 83 |
|
| 84 |
|
| 85 |
# If the alternate mod file does not have a ".mod" suffix, an error |
| 86 |
# should be reported. |
| 87 |
cp go.alt.mod goaltmod |
| 88 |
! go mod tidy -modfile=goaltmod |
| 89 |
stderr '-modfile=goaltmod: file does not have .mod extension' |
| 90 |
|
| 91 |
-- go.mod -- |
| 92 |
ʕ◔ϖ◔ʔ |
| 93 |
-- go.sum -- |
| 94 |
ʕ◔ϖ◔ʔ |
| 95 |
-- use.go -- |
| 96 |
package main |
| 97 |
|
| 98 |
import _ "rsc.io/quote" |
| 99 |
-- gen.go -- |
| 100 |
//go:generate go mod edit -exclude example.com/[email protected] |
| 101 |
|
| 102 |
package main |