| 1 |
# https://golang.org/issue/45979: after 'go get' on a package, |
| 2 |
# that package should be importable without error. |
| 3 |
|
| 4 |
|
| 5 |
# We start out with an unresolved dependency. |
| 6 |
# 'go list' suggests that we run 'go get' on that dependency. |
| 7 |
|
| 8 |
! go list -deps . |
| 9 |
stderr '^m.go:3:8: no required module provides package rsc\.io/quote; to add it:\n\tgo get rsc.io/quote$' |
| 10 |
|
| 11 |
|
| 12 |
# When we run the suggested 'go get' command, the new dependency can be used |
| 13 |
# immediately. |
| 14 |
# |
| 15 |
# 'go get' marks the new dependency as 'indirect', because it doesn't scan |
| 16 |
# enough source code to know whether it is direct, and it is easier and less |
| 17 |
# invasive to remove an incorrect indirect mark (e.g. using 'go get') than to |
| 18 |
# add one that is missing ('go mod tidy' or 'go mod vendor'). |
| 19 |
|
| 20 |
go get rsc.io/quote |
| 21 |
grep 'rsc.io/quote v\d+\.\d+\.\d+ // indirect$' go.mod |
| 22 |
! grep 'rsc.io/quote v\d+\.\d+\.\d+$' go.mod |
| 23 |
|
| 24 |
go list -deps . |
| 25 |
! stderr . |
| 26 |
[!short] go build . |
| 27 |
[!short] ! stderr . |
| 28 |
|
| 29 |
|
| 30 |
# 'go get .' (or 'go mod tidy') removes the indirect mark. |
| 31 |
|
| 32 |
go get . |
| 33 |
grep 'rsc.io/quote v\d+\.\d+\.\d+$' go.mod |
| 34 |
! grep 'rsc.io/quote v\d+\.\d+\.\d+ // indirect$' go.mod |
| 35 |
|
| 36 |
|
| 37 |
-- go.mod -- |
| 38 |
module example.com/m |
| 39 |
|
| 40 |
go 1.17 |
| 41 |
-- m.go -- |
| 42 |
package m |
| 43 |
|
| 44 |
import _ "rsc.io/quote" |