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
35 [symlink] symlink x.tzt -> x.txt
36 [symlink] ! go build -x
37 [symlink] stderr 'pattern [*]t: cannot embed irregular file x.tzt'
38 [symlink] rm x.tzt
39
40 # build rejects empty directories
41 mkdir t
42 ! go build -x
43 stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
44
45 # build ignores symlinks and invalid names in directories
46 cp x.txt t/.git
47 ! go build -x
48 stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
49 go list -e -f '{{.Incomplete}}'
50 stdout 'true'
51 [symlink] symlink t/x.link -> ../x.txt
52 [symlink] ! go build -x
53 [symlink] stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
54
55 cp x.txt t/x.txt
56 go build -x
57
58 # build reports errors with positions in imported packages
59 rm t/x.txt
60 ! go build m/use
61 stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
62
63 # all still ignores .git and symlinks
64 cp x.go3 x.go
65 ! go build -x
66 stderr '^x.go:5:12: pattern all:t: cannot embed directory t: contains no embeddable files$'
67
68 # all finds dot files and underscore files
69 cp x.txt t/.x.txt
70 go build -x
71 rm t/.x.txt
72 cp x.txt t/_x.txt
73 go build -x
74
75 -- x.go --
76 package p
77
78 import "embed"
79
80 //go:embed x*t*t
81 var X embed.FS
82
83 -- x_test.go --
84 package p
85
86 import "embed"
87
88 //go:embed y*t*t
89 var Y string
90
91 -- x_x_test.go --
92 package p_test
93
94 import "embed"
95
96 //go:embed z*t*t
97 var Z string
98
99 -- x.go2 --
100 package p
101
102 import "embed"
103
104 //go:embed *t
105 var X embed.FS
106
107 -- x.go3 --
108 package p
109
110 import "embed"
111
112 //go:embed all:t
113 var X embed.FS
114
115 -- x.txt --
116 hello
117
118 -- y.txt --
119 -- z.txt --
120 -- x.txt2 --
121 not hello
122
123 -- use/use.go --
124 package use
125
126 import _ "m"
127 -- go.mod --
128 module m
129
130 go 1.16
131
View as plain text