aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_get_pkgtags.txt
blob: 2e2ab720321bde38a4b58752397013ef40b5bd80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# https://golang.org/issue/44106
# 'go get' should fetch the transitive dependencies of packages regardless of
# tags, but shouldn't error out if the package is missing tag-guarded
# dependencies.

# Control case: just adding the top-level module to the go.mod file does not
# fetch its dependencies.

go mod edit -require example.net/tools@v0.1.0
! go list -deps example.net/cmd/tool
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$'
go mod edit -droprequire example.net/tools


# 'go get -d' makes a best effort to fetch those dependencies, but shouldn't
# error out if dependencies of tag-guarded files are missing.

go get -d example.net/tools@v0.1.0
! stderr 'no Go source files'

! go list example.net/tools
stderr '^package example.net/tools: build constraints exclude all Go files in .*[/\\]tools$'

go list -tags=tools -e -deps example.net/tools
stdout '^example.net/cmd/tool$'
stdout '^example.net/missing$'

go list -deps example.net/cmd/tool

! go list example.net/missing
stderr '^no required module provides package example.net/missing; to add it:\n\tgo get example.net/missing$'


# https://golang.org/issue/33526: 'go get' without '-d' should succeed
# for a module whose root is a constrained-out package.
#
# Ideally it should silently succeed, but today it logs the "no Go source files"
# error and succeeds anyway.

go get example.net/tools@v0.1.0
! stderr .

! go build example.net/tools
stderr '^package example.net/tools: build constraints exclude all Go files in .*[/\\]tools$'


# https://golang.org/issue/29268
# 'go get' should fetch modules whose roots contain test-only packages, but
# without the -t flag shouldn't error out if the test has missing dependencies.

go get -d example.net/testonly@v0.1.0

# With the -t flag, the test dependencies must resolve successfully.
! go get -d -t example.net/testonly@v0.1.0
stderr '^example.net/testonly tested by\n\texample.net/testonly\.test imports\n\texample.net/missing: cannot find module providing package example.net/missing$'


# 'go get -d' should succeed for a module path that does not contain a package,
# but fail for a non-package subdirectory of a module.

! go get -d example.net/missing/subdir@v0.1.0
stderr '^go: module example.net/missing@v0.1.0 found \(replaced by ./missing\), but does not contain package example.net/missing/subdir$'

go get -d example.net/missing@v0.1.0


# Getting the subdirectory should continue to fail even if the corresponding
# module is already present in the build list.

! go get -d example.net/missing/subdir@v0.1.0
stderr '^go: module example.net/missing@v0.1.0 found \(replaced by ./missing\), but does not contain package example.net/missing/subdir$'


-- go.mod --
module example.net/m

go 1.15

replace (
	example.net/tools v0.1.0 => ./tools
	example.net/cmd v0.1.0 => ./cmd
	example.net/testonly v0.1.0 => ./testonly
	example.net/missing v0.1.0 => ./missing
)

-- tools/go.mod --
module example.net/tools

go 1.15

// Requirements intentionally omitted.

-- tools/tools.go --
// +build tools

package tools

import (
	_ "example.net/cmd/tool"
	_ "example.net/missing"
)

-- cmd/go.mod --
module example.net/cmd

go 1.16
-- cmd/tool/tool.go --
package main

func main() {}

-- testonly/go.mod --
module example.net/testonly

go 1.15
-- testonly/testonly_test.go --
package testonly_test

import _ "example.net/missing"

func Test(t *testing.T) {}

-- missing/go.mod --
module example.net/missing

go 1.15
-- missing/README.txt --
There are no Go source files here.
-- missing/subdir/README.txt --
There are no Go source files here either.