1 # go list shows patterns and files
2 go list -f '{{.EmbedPatterns}}'
3 stdout '\[x\*t\*t\]'
4 go list -f '{{.EmbedFiles}}'
5 stdout '\[x.txt\]'
6 go list -test -f '{{.TestEmbedPatterns}}'
7 stdout '\[y\*t\*t\]'
8 go list -test -f '{{.TestEmbedFiles}}'
9 stdout '\[y.txt\]'
10 go list -test -f '{{.XTestEmbedPatterns}}'
11 stdout '\[z\*t\*t\]'
12 go list -test -f '{{.XTestEmbedFiles}}'
13 stdout '\[z.txt\]'
14
15 # build embeds x.txt
16 go build -x
17 stderr 'x.txt'
18
19 # build uses cache correctly
20 go build -x
21 ! stderr 'x.txt'
22 cp x.txt2 x.txt
23 go build -x
24 stderr 'x.txt'
25
26 # build rejects invalid names
27 cp x.go2 x.go
28 go build -x
29 cp x.txt .git
30 ! go build -x
31 stderr '^x.go:5:12: pattern [*]t: cannot embed file [.]git: invalid name [.]git$'
32 rm .git
33
34 # build rejects symlinks by default
35 [symlink] symlink x.tzt -> x.txt
36 [symlink] ! go build -x
37 [symlink] stderr 'pattern [*]t: cannot embed irregular file x.tzt'
38 # with GODEBUG embedfollowsymlinks=1, build allows symlinks of leaf files
39 [symlink] env 'GODEBUG=embedfollowsymlinks=1'
40 [symlink] go build -x
41 [symlink] stderr 'x.tzt'
42 [symlink] rm x.tzt
43 [symlink] env 'GODEBUG='
44
45 # build rejects empty directories
46 mkdir t
47 ! go build -x
48 stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
49
50 # build ignores symlinks and invalid names in directories
51 cp x.txt t/.git
52 ! go build -x
53 stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
54 go list -e -f '{{.Incomplete}}'
55 stdout 'true'
56 [symlink] symlink t/x.link -> ../x.txt
57 [symlink] ! go build -x
58 [symlink] stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
59
60 cp x.txt t/x.txt
61 go build -x
62
63 # build reports errors with positions in imported packages
64 rm t/x.txt
65 ! go build m/use
66 stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
67
68 # all still ignores .git and symlinks
69 cp x.go3 x.go
70 ! go build -x
71 stderr '^x.go:5:12: pattern all:t: cannot embed directory t: contains no embeddable files$'
72
73 # all finds dot files and underscore files
74 cp x.txt t/.x.txt
75 go build -x
76 rm t/.x.txt
77 cp x.txt t/_x.txt
78 go build -x
79
80 # build disallows symlinks of directories
81 [symlink] symlink symdir -> symdirdst
82 [symlink] cp x.go4 x.go
83 [symlink] ! go build -x
84 [symlink] stderr 'x.go:5:12: pattern symdir/[*]: cannot embed file symdir[\\/]x.txt: in non-directory symdir'
85 [symlink] cp x.go5 x.go
86 [symlink] ! go build -x
87 [symlink] stderr 'x.go:5:12: pattern symdir/x.txt: cannot embed file symdir[\\/]x.txt: in non-directory symdir'
88 # even with GODEBUG=embedfollowsymlinks=1
89 [symlink] env 'GODEBUG=embedfollowsymlinks=1'
90 [symlink] cp x.go4 x.go
91 [symlink] ! go build -x
92 [symlink] stderr 'x.go:5:12: pattern symdir/[*]: cannot embed file symdir[\\/]x.txt: in non-directory symdir'
93 [symlink] cp x.go5 x.go
94 [symlink] ! go build -x
95 [symlink] stderr 'x.go:5:12: pattern symdir/x.txt: cannot embed file symdir[\\/]x.txt: in non-directory symdir'
96 [symlink] env 'GODEBUG='
97
98 -- x.go --
99 package p
100
101 import "embed"
102
103 //go:embed x*t*t
104 var X embed.FS
105
106 -- x_test.go --
107 package p
108
109 import "embed"
110
111 //go:embed y*t*t
112 var Y string
113
114 -- x_x_test.go --
115 package p_test
116
117 import "embed"
118
119 //go:embed z*t*t
120 var Z string
121
122 -- x.go2 --
123 package p
124
125 import "embed"
126
127 //go:embed *t
128 var X embed.FS
129
130 -- x.go3 --
131 package p
132
133 import "embed"
134
135 //go:embed all:t
136 var X embed.FS
137
138 -- x.go4 --
139 package p
140
141 import "embed"
142
143 //go:embed symdir/*
144 var X embed.FS
145 -- x.go5 --
146 package p
147
148 import "embed"
149
150 //go:embed symdir/x.txt
151 var Z string
152 -- x.txt --
153 hello
154
155 -- y.txt --
156 -- z.txt --
157 -- x.txt2 --
158 not hello
159
160 -- use/use.go --
161 package use
162
163 import _ "m"
164 -- symdirdst/x.txt --
165 -- go.mod --
166 module m
167
168 go 1.16
169
View as plain text