...
1go mod vendor
2cmp vendor/example.com/a/samedir_embed.txt a/samedir_embed.txt
3cmp vendor/example.com/a/subdir/embed.txt a/subdir/embed.txt
4cmp vendor/example.com/a/subdir/test/embed.txt a/subdir/test/embed.txt
5cmp vendor/example.com/a/subdir/test/xtest/embed.txt a/subdir/test/xtest/embed.txt
6
7cd broken_no_matching_files
8! go mod vendor
9stderr '^go: resolving embeds in example.com/brokendep: pattern foo.txt: no matching files found$'
10go mod vendor -e
11stderr '^go: resolving embeds in example.com/brokendep: pattern foo.txt: no matching files found$'
12
13cd ../broken_bad_pattern
14! go mod vendor
15stderr '^go: resolving embeds in example.com/brokendep: pattern ../foo.txt: invalid pattern syntax$'
16go mod vendor -e
17stderr '^go: resolving embeds in example.com/brokendep: pattern ../foo.txt: invalid pattern syntax$'
18
19cd ../embed_go122
20go mod vendor
21cmp vendor/example.com/a/samedir_embed.txt ../a/samedir_embed.txt
22cmp vendor/example.com/a/subdir/embed.txt ../a/subdir/embed.txt
23! exists vendor/example.com/a/subdir/test/embed.txt
24! exists vendor/example.com/a/subdir/test/xtest/embed.txt
25-- embed_go122/go.mod --
26module example.com/foo
27go 1.22
28
29require (
30 example.com/a v0.1.0
31)
32
33replace (
34 example.com/a v0.1.0 => ../a
35)
36-- embed_go122/foo.go --
37package main
38
39import (
40 "fmt"
41
42 "example.com/a"
43)
44
45func main() {
46 fmt.Println(a.Str())
47}
48
49# matchPotentialSourceFile prunes out tests and unbuilt code.
50# Make sure that they are vendored if they are embedded files.
51cd ../embed_unbuilt
52go mod vendor
53cmp vendor/example.com/dep/unbuilt.go dep/unbuilt.go
54cmp vendor/example.com/dep/dep_test.go dep/dep_test.go
55! exists vendor/example.com/dep/not_embedded_unbuilt.go
56! exists vendor/example.com/dep/not_embedded_dep_test.go
57-- go.mod --
58module example.com/foo
59go 1.16
60
61require (
62 example.com/a v0.1.0
63)
64
65replace (
66 example.com/a v0.1.0 => ./a
67)
68-- foo.go --
69package main
70
71import (
72 "fmt"
73
74 "example.com/a"
75)
76
77func main() {
78 fmt.Println(a.Str())
79}
80-- a/go.mod --
81module example.com/a
82-- a/a.go --
83package a
84
85import _ "embed"
86
87//go:embed samedir_embed.txt
88var sameDir string
89
90//go:embed subdir/embed.txt
91var subDir string
92
93func Str() string {
94 return sameDir + subDir
95}
96-- a/a_test.go --
97package a
98
99import _ "embed"
100
101//go:embed subdir/test/embed.txt
102var subderTest string
103-- a/a_x_test.go --
104package a_test
105
106import _ "embed"
107
108//go:embed subdir/test/xtest/embed.txt
109var subdirXtest string
110-- a/samedir_embed.txt --
111embedded file in same directory as package
112-- a/subdir/embed.txt --
113embedded file in subdirectory of package
114-- a/subdir/test/embed.txt --
115embedded file of test in subdirectory of package
116-- a/subdir/test/xtest/embed.txt --
117embedded file of xtest in subdirectory of package
118-- broken_no_matching_files/go.mod --
119module example.com/broken
120go 1.16
121
122require (
123 example.com/brokendep v0.1.0
124)
125
126replace (
127 example.com/brokendep v0.1.0 => ./brokendep
128)
129-- broken_no_matching_files/f.go --
130package broken
131
132import _ "example.com/brokendep"
133
134func F() {}
135-- broken_no_matching_files/brokendep/go.mod --
136module example.com/brokendep
137go 1.16
138-- broken_no_matching_files/brokendep/f.go --
139package brokendep
140
141import _ "embed"
142
143//go:embed foo.txt
144var foo string
145-- broken_bad_pattern/go.mod --
146module example.com/broken
147go 1.16
148
149require (
150 example.com/brokendep v0.1.0
151)
152
153replace (
154 example.com/brokendep v0.1.0 => ./brokendep
155)
156-- broken_bad_pattern/f.go --
157package broken
158
159import _ "example.com/brokendep"
160
161func F() {}
162-- broken_bad_pattern/brokendep/go.mod --
163module example.com/brokendep
164go 1.16
165-- broken_bad_pattern/brokendep/f.go --
166package brokendep
167
168import _ "embed"
169
170//go:embed ../foo.txt
171var foo string
172-- embed_unbuilt/go.mod --
173module example.com/foo
174go 1.16
175
176require (
177 example.com/dep v0.1.0
178)
179
180replace (
181 example.com/dep v0.1.0 => ./dep
182)
183-- embed_unbuilt/foo.go --
184package a
185
186import _ "example.com/dep"
187
188func F() {}
189-- embed_unbuilt/dep/go.mod --
190module example.com/dep
191go 1.16
192-- embed_unbuilt/dep/dep.go --
193package dep
194
195import _ "embed"
196
197//go:embed unbuilt.go
198var unbuilt string
199
200//go:embed dep_test.go
201var depTest string
202-- embed_unbuilt/dep/unbuilt.go --
203// +build ignore
204
205package dep
206-- embed_unbuilt/dep/not_embedded_unbuilt.go --
207// +build ignore
208
209package dep
210-- embed_unbuilt/dep/dep_test.go --
211package dep
212-- embed_unbuilt/dep/not_embedded_dep_test.go --
213package dep
View as plain text