aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/list_constraints.txt
blob: 7115c365f05198c263694b06da65bfb00b1995c0 (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
# Check that files and their imports are not included in 'go list' output
# when they are excluded by build constraints.

# Linux and cgo files should be included when building in that configuration.
env GOOS=linux
env GOARCH=amd64
env CGO_ENABLED=1
go list -f '{{range .GoFiles}}{{.}} {{end}}'
stdout '^cgotag.go empty.go suffix_linux.go tag.go $'
go list -f '{{range .CgoFiles}}{{.}} {{end}}'
stdout '^cgoimport.go $'
go list -f '{{range .Imports}}{{.}} {{end}}'
stdout '^C cgoimport cgotag suffix tag $'

# Disabling cgo should exclude cgo files and their imports.
env CGO_ENABLED=0
go list -f '{{range .GoFiles}}{{.}} {{end}}'
stdout 'empty.go suffix_linux.go tag.go'
go list -f '{{range .CgoFiles}}{{.}} {{end}}'
! stdout .
go list -f '{{range .Imports}}{{.}} {{end}}'
stdout '^suffix tag $'

# Changing OS should exclude linux sources.
env GOOS=darwin
go list -f '{{range .GoFiles}}{{.}} {{end}}'
stdout '^empty.go $'
go list -f '{{range .Imports}}{{.}} {{end}}'
stdout '^$'

# Enabling a tag should include files that require it.
go list -tags=extra -f '{{range .GoFiles}}{{.}} {{end}}'
stdout '^empty.go extra.go $'
go list -tags=extra -f '{{range .Imports}}{{.}} {{end}}'
stdout '^extra $'

# Packages that require a tag should not be listed unless the tag is on.
! go list ./tagonly
go list -tags=extra ./tagonly
stdout m/tagonly

-- go.mod --
module m

go 1.13

-- empty.go --
package p

-- extra.go --
// +build extra

package p

import _ "extra"

-- suffix_linux.go --
package p

import _ "suffix"

-- tag.go --
// +build linux

package p

import _ "tag"

-- cgotag.go --
// +build cgo

package p

import _ "cgotag"

-- cgoimport.go --
package p

import "C"

import _ "cgoimport"

-- tagonly/tagonly.go --
// +build extra

package tagonly