1 # https://golang.org/issue/44106
2 # 'go get' should fetch the transitive dependencies of packages regardless of
3 # tags, but shouldn't error out if the package is missing tag-guarded
4 # dependencies.
5
6 # Control case: just adding the top-level module to the go.mod file does not
7 # fetch its dependencies.
8
9 go mod edit -require example.net/tools@v0.1.0
10 ! go list -deps example.net/cmd/tool
11 stderr '^module example\.net/cmd provides package example\.net/cmd/tool and is replaced but not required; to add it:\n\tgo get example\.net/cmd@v0\.1\.0$'
12 go mod edit -droprequire example.net/tools
13
14
15 # 'go get' makes a best effort to fetch those dependencies, but shouldn't
16 # error out if dependencies of tag-guarded files are missing.
17
18 go get example.net/tools@v0.1.0
19 ! stderr 'no Go source files'
20
21 ! go list example.net/tools
22 stderr '^package example.net/tools: build constraints exclude all Go files in .*[/\\]tools$'
23
24 go list -tags=tools -e -deps example.net/tools
25 stdout '^example.net/cmd/tool$'
26 stdout '^example.net/missing$'
27
28 go list -deps example.net/cmd/tool
29
30 ! go list example.net/missing
31 stderr '^no required module provides package example.net/missing; to add it:\n\tgo get example.net/missing$'
32
33
34 # https://golang.org/issue/33526: 'go get' without '-d' should succeed
35 # for a module whose root is a constrained-out package.
36 #
37 # Ideally it should silently succeed, but today it logs the "no Go source files"
38 # error and succeeds anyway.
39
40 go get example.net/tools@v0.1.0
41 ! stderr .
42
43 ! go build example.net/tools
44 stderr '^package example.net/tools: build constraints exclude all Go files in .*[/\\]tools$'
45
46
47 # https://golang.org/issue/29268
48 # 'go get' should fetch modules whose roots contain test-only packages, but
49 # without the -t flag shouldn't error out if the test has missing dependencies.
50
51 go get example.net/testonly@v0.1.0
52
53 # With the -t flag, the test dependencies must resolve successfully.
54 ! go get -t example.net/testonly@v0.1.0
55 stderr '^go: example.net/testonly tested by\n\texample.net/testonly\.test imports\n\texample.net/missing: cannot find module providing package example.net/missing$'
56
57
58 # 'go get' should succeed for a module path that does not contain a package,
59 # but fail for a non-package subdirectory of a module.
60
61 ! go get example.net/missing/subdir@v0.1.0
62 stderr '^go: module example.net/missing@v0.1.0 found \(replaced by ./missing\), but does not contain package example.net/missing/subdir$'
63
64 go get example.net/missing@v0.1.0
65
66
67 # Getting the subdirectory should continue to fail even if the corresponding
68 # module is already present in the build list.
69
70 ! go get example.net/missing/subdir@v0.1.0
71 stderr '^go: module example.net/missing@v0.1.0 found \(replaced by ./missing\), but does not contain package example.net/missing/subdir$'
72
73
74 -- go.mod --
75 module example.net/m
76
77 go 1.15
78
79 replace (
80 example.net/tools v0.1.0 => ./tools
81 example.net/cmd v0.1.0 => ./cmd
82 example.net/testonly v0.1.0 => ./testonly
83 example.net/missing v0.1.0 => ./missing
84 )
85
86 -- tools/go.mod --
87 module example.net/tools
88
89 go 1.15
90
91 // Requirements intentionally omitted.
92
93 -- tools/tools.go --
94 // +build tools
95
96 package tools
97
98 import (
99 _ "example.net/cmd/tool"
100 _ "example.net/missing"
101 )
102
103 -- cmd/go.mod --
104 module example.net/cmd
105
106 go 1.16
107 -- cmd/tool/tool.go --
108 package main
109
110 func main() {}
111
112 -- testonly/go.mod --
113 module example.net/testonly
114
115 go 1.15
116 -- testonly/testonly_test.go --
117 package testonly_test
118
119 import _ "example.net/missing"
120
121 func Test(t *testing.T) {}
122
123 -- missing/go.mod --
124 module example.net/missing
125
126 go 1.15
127 -- missing/README.txt --
128 There are no Go source files here.
129 -- missing/subdir/README.txt --
130 There are no Go source files here either.
131
View as plain text