1 # Regression test for #56222: 'go get -t' and 'go mod tidy'
2 # should save enough checksums to run 'go test' on the named
3 # packages or any package in "all" respectively.
4
5 # 'go mod tidy' in a module at go 1.21 or higher should preserve
6 # checksums needed to run 'go test all'.
7 cd m1
8 go mod tidy
9
10 go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q
11 stdout 1.18
12 [!short] go test -o $devnull -c all
13
14 cat go.sum
15 replace 'example.com/generics v1.0.0/go.mod' 'example.com/notgenerics v1.0.0/go.mod' go.sum
16
17 ! go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q
18 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$'
19
20 go mod download -json example.com/generics
21 stdout '"GoModSum":'
22 go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q
23 stdout 1.18
24
25
26 # At go 1.20 or earlier, 'go mod tidy' should preserve the historical go.sum
27 # contents, but 'go test' should flag the missing checksums (instead of trying
28 # to build the test dependency with the wrong language version).
29
30 go mod tidy -go=1.20
31 ! go test -o $devnull -c all
32 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$'
33
34 go mod download -json example.com/generics
35 go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q
36 stdout 1.18
37
38
39 # Even at go 1.20 or earlier, 'go mod tidy' shouldn't need go.mod files or
40 # checksums that it won't record.
41
42 go mod tidy -go=1.20
43 go clean -modcache # Remove checksums from the module cache, so that only go.sum is used.
44
45 # Issue 60667: 'go list' without -mod=mod shouldn't report the checksums as
46 # dirty either.
47 go list -m -u all
48
49 env OLDSUMDB=$GOSUMDB
50 env GOSUMDB=bad
51 go mod tidy
52
53 env GOSUMDB=$OLDSUMDB
54
55
56 # Regardless of the go version in go.mod, 'go get -t' should fetch
57 # enough checksums to run 'go test' on the named package.
58
59 rm p
60 go mod tidy -go=1.20
61 go list -m all
62 ! stdout example.com/generics
63 go get -t example.com/m2/q@v1.0.0
64 go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q
65 stdout 1.18
66 [!short] go test -o $devnull -c example.com/m2/q
67
68
69 -- m1/go.mod --
70 module example.com/m1
71
72 go 1.21
73
74 require example.com/m2 v1.0.0
75 replace example.com/m2 => ../m2
76 -- m1/p/p.go --
77 package p
78
79 import _ "example.com/m2/q"
80 -- m2/go.mod --
81 module example.com/m2
82
83 go 1.19
84
85 require example.com/generics v1.0.0
86 -- m2/q/q.go --
87 package q
88 -- m2/q/q_test.go --
89 package q
90
91 import _ "example.com/generics"
92
View as plain text