...
1env GO111MODULE=on
2
3# 'mod download' should download the module to the cache.
4go mod download rsc.io/quote@v1.5.0
5exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
6exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
7exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip
8
9# '-n' should print commands but not actually execute them.
10go clean -modcache -n
11stdout '^rm -rf .*pkg.mod$'
12exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
13exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
14exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip
15
16# 'go clean -modcache' should actually delete the files.
17go clean -modcache
18! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
19! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
20! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip
21
22# 'go clean -r -modcache' should clean only the dependencies that are within the
23# main module.
24# BUG(golang.org/issue/28680): Today, it cleans across module boundaries.
25cd r
26exists ./test.out
27exists ../replaced/test.out
28go clean -r -modcache
29! exists ./test.out
30! exists ../replaced/test.out # BUG: should still exist
31
32# 'go clean -modcache' should not download anything before cleaning.
33go mod edit -require rsc.io/quote@v1.99999999.0-not-a-real-version
34go clean -modcache
35! stderr 'finding rsc.io'
36go mod edit -droprequire rsc.io/quote
37
38! go clean -modcache m
39stderr 'go: clean -modcache cannot be used with package arguments'
40
41-- go.mod --
42module m
43-- m.go --
44package m
45
46-- r/go.mod --
47module example.com/r
48require example.com/r/replaced v0.0.0
49replace example.com/r/replaced => ../replaced
50-- r/r.go --
51package r
52import _ "example.com/r/replaced"
53-- r/test.out --
54DELETE ME
55
56-- replaced/go.mod --
57module example.com/r/replaced
58-- replaced/replaced.go --
59package replaced
60-- replaced/test.out --
61DO NOT DELETE
View as plain text