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