...
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'.
7cd m1
8go mod tidy
9
10go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q
11stdout 1.18
12[!short] go test -o $devnull -c all
13
14cat go.sum
15replace '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
18stderr '^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
20go mod download -json example.com/generics
21stdout '"GoModSum":'
22go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q
23stdout 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
30go mod tidy -go=1.20
31! go test -o $devnull -c all
32stderr '^# 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
34go mod download -json example.com/generics
35go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q
36stdout 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
42go mod tidy -go=1.20
43go 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.
47go list -m -u all
48
49env OLDSUMDB=$GOSUMDB
50env GOSUMDB=bad
51go mod tidy
52
53env 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
59rm p
60go mod tidy -go=1.20
61go list -m all
62! stdout example.com/generics
63go get -t example.com/m2/q@v1.0.0
64go list -f '{{if eq .ImportPath "example.com/generics"}}{{.Module.GoVersion}}{{end}}' -deps -test example.com/m2/q
65stdout 1.18
66[!short] go test -o $devnull -c example.com/m2/q
67
68
69-- m1/go.mod --
70module example.com/m1
71
72go 1.21
73
74require example.com/m2 v1.0.0
75replace example.com/m2 => ../m2
76-- m1/p/p.go --
77package p
78
79import _ "example.com/m2/q"
80-- m2/go.mod --
81module example.com/m2
82
83go 1.19
84
85require example.com/generics v1.0.0
86-- m2/q/q.go --
87package q
88-- m2/q/q_test.go --
89package q
90
91import _ "example.com/generics"
View as plain text