1 cp go.mod go.mod.orig
2
3
4 # If a dependency cannot be resolved, 'go mod tidy' fails with an error message
5 # explaining the problem and does not update the go.mod file.
6 # TODO(bcmills): Ideally, with less redundancy than these error messages!
7
8 ! go mod tidy
9
10 stderr '^example.com/untidy imports\n\texample.net/directnotfound: cannot find module providing package example.net/directnotfound: module example.net/directnotfound: reading http://.*: 404 Not Found$'
11
12 stderr '^example.com/untidy imports\n\texample.net/m imports\n\texample.net/indirectnotfound: cannot find module providing package example.net/indirectnotfound: module example.net/indirectnotfound: reading http://.*: 404 Not Found$'
13
14 stderr '^example.com/untidy tested by\n\texample.com/untidy.test imports\n\texample.net/directtestnotfound: cannot find module providing package example.net/directtestnotfound: module example.net/directtestnotfound: reading http://.*: 404 Not Found$'
15
16 stderr '^example.com/untidy imports\n\texample.net/m tested by\n\texample.net/m.test imports\n\texample.net/indirecttestnotfound: cannot find module providing package example.net/indirecttestnotfound: module example.net/indirecttestnotfound: reading http://.*: 404 Not Found$'
17
18 cmp go.mod.orig go.mod
19
20
21 # If a dependency cannot be resolved, 'go mod vendor' fails with an error message
22 # explaining the problem, does not update the go.mod file, and does not create
23 # the vendor directory.
24
25 ! go mod vendor
26
27 stderr '^example.com/untidy imports\n\texample.net/directnotfound: no required module provides package example.net/directnotfound; to add it:\n\tgo get example.net/directnotfound$'
28
29 stderr '^example.com/untidy imports\n\texample.net/m: module example.net/m provides package example.net/m and is replaced but not required; to add it:\n\tgo get example.net/m@v0.1.0$'
30
31 stderr '^example.com/untidy tested by\n\texample.com/untidy.test imports\n\texample.net/directtestnotfound: no required module provides package example.net/directtestnotfound; to add it:\n\tgo get example.net/directtestnotfound$'
32
33 ! stderr 'indirecttestnotfound' # Vendor prunes test dependencies.
34
35 cmp go.mod.orig go.mod
36 ! exists vendor
37
38
39 # 'go mod tidy' still logs the errors, but succeeds and updates go.mod.
40
41 go mod tidy -e
42 stderr -count=4 'cannot find module providing package'
43 cmp go.mod.final go.mod
44
45
46 # 'go mod vendor -e' still logs the errors, but creates a vendor directory
47 # and exits with status 0.
48 # 'go mod vendor -e' does not update go.mod and will not vendor packages that
49 # would require changing go.mod, for example, by adding a requirement.
50 cp go.mod.orig go.mod
51 go mod vendor -e
52 stderr -count=2 'no required module provides package'
53 stderr '^example.com/untidy imports\n\texample.net/m: module example.net/m provides package example.net/m and is replaced but not required; to add it:\n\tgo get example.net/m@v0.1.0$'
54 exists vendor/modules.txt
55 ! exists vendor/example.net
56
57 go mod edit -require example.net/m@v0.1.0
58 go mod vendor -e
59 stderr -count=3 'no required module provides package'
60 exists vendor/modules.txt
61 exists vendor/example.net/m/m.go
62
63 -- go.mod --
64 module example.com/untidy
65 go 1.16
66 replace example.net/m v0.1.0 => ./m
67 -- go.mod.final --
68 module example.com/untidy
69
70 go 1.16
71
72 replace example.net/m v0.1.0 => ./m
73
74 require example.net/m v0.1.0
75 -- untidy.go --
76 package untidy
77
78 import (
79 _ "example.net/m"
80 _ "example.net/directnotfound"
81 )
82 -- untidy_test.go --
83 package untidy_test
84
85 import _ "example.net/directtestnotfound"
86 -- m/go.mod --
87 module example.net/m
88 go 1.16
89 -- m/m.go --
90 package m
91
92 import _ "example.net/indirectnotfound"
93 -- m/m_test.go --
94 package m_test
95
96 import _ "example.net/indirecttestnotfound"
97
View as plain text