| 1 |
# If the root requirements in a lazy module are inconsistent |
| 2 |
# (for example, due to a bad hand-edit or git merge), |
| 3 |
# they can go unnoticed as long as the module with the violated |
| 4 |
# requirement is not used. |
| 5 |
# When we load a package from that module, we should spot-check its |
| 6 |
# requirements and either emit an error or update the go.mod file. |
| 7 |
|
| 8 |
cp go.mod go.mod.orig |
| 9 |
|
| 10 |
|
| 11 |
# If we load package x from x.1, we only check the requirements of x, |
| 12 |
# which are fine: loading succeeds. |
| 13 |
|
| 14 |
go list -deps ./usex |
| 15 |
stdout '^example.net/x$' |
| 16 |
cmp go.mod go.mod.orig |
| 17 |
|
| 18 |
|
| 19 |
# However, if we load needx2, we should load the requirements of needx2. |
| 20 |
# Those requirements indicate x.2, not x.1, so the module graph is |
| 21 |
# inconsistent and needs to be fixed. |
| 22 |
|
| 23 |
! go list -deps ./useneedx2 |
| 24 |
stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$' |
| 25 |
|
| 26 |
! go list -deps example.net/needx2 |
| 27 |
stderr '^go: updates to go.mod needed; to update it:\n\tgo mod tidy$' |
| 28 |
|
| 29 |
|
| 30 |
# The command printed in the error message should fix the problem. |
| 31 |
|
| 32 |
go mod tidy |
| 33 |
go list -deps ./useneedx2 |
| 34 |
stdout '^example.net/m/useneedx2$' |
| 35 |
stdout '^example.net/needx2$' |
| 36 |
stdout '^example.net/x$' |
| 37 |
|
| 38 |
go list -m all |
| 39 |
stdout '^example.net/needx2 v0\.1\.0 ' |
| 40 |
stdout '^example.net/x v0\.2\.0 ' |
| 41 |
|
| 42 |
|
| 43 |
-- go.mod -- |
| 44 |
module example.net/m |
| 45 |
|
| 46 |
go 1.17 |
| 47 |
|
| 48 |
require ( |
| 49 |
example.net/needx2 v0.1.0 |
| 50 |
example.net/x v0.1.0 |
| 51 |
) |
| 52 |
|
| 53 |
replace ( |
| 54 |
example.net/needx2 v0.1.0 => ./needx2.1 |
| 55 |
example.net/x v0.1.0 => ./x.1 |
| 56 |
example.net/x v0.2.0 => ./x.2 |
| 57 |
) |
| 58 |
-- useneedx2/useneedx2.go -- |
| 59 |
package useneedx2 |
| 60 |
|
| 61 |
import _ "example.net/needx2" |
| 62 |
-- usex/usex.go -- |
| 63 |
package usex |
| 64 |
|
| 65 |
import _ "example.net/x" |
| 66 |
|
| 67 |
-- x.1/go.mod -- |
| 68 |
module example.com/x |
| 69 |
|
| 70 |
go 1.17 |
| 71 |
-- x.1/x.go -- |
| 72 |
package x |
| 73 |
|
| 74 |
-- x.2/go.mod -- |
| 75 |
module example.com/x |
| 76 |
|
| 77 |
go 1.17 |
| 78 |
-- x.2/x.go -- |
| 79 |
package x |
| 80 |
|
| 81 |
const AddedInV2 = true |
| 82 |
|
| 83 |
-- needx2.1/go.mod -- |
| 84 |
module example.com/x |
| 85 |
|
| 86 |
go 1.17 |
| 87 |
|
| 88 |
require example.net/x v0.2.0 |
| 89 |
-- needx2.1/needx2.go -- |
| 90 |
// Package needx2 needs x v0.2.0 or higher. |
| 91 |
package needx2 |
| 92 |
|
| 93 |
import "example.net/x" |
| 94 |
|
| 95 |
var _ = x.AddedInV2 |