aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_vendor_embed.txt
blob: be114159a1fbf7475fc1fba69ff18bae2e7ac0a1 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
go mod vendor
cmp vendor/example.com/a/samedir_embed.txt a/samedir_embed.txt
cmp vendor/example.com/a/subdir/embed.txt a/subdir/embed.txt
cmp vendor/example.com/a/subdir/test/embed.txt a/subdir/test/embed.txt
cmp vendor/example.com/a/subdir/test/xtest/embed.txt a/subdir/test/xtest/embed.txt

cd broken_no_matching_files
! go mod vendor
stderr 'go mod vendor: pattern foo.txt: no matching files found'

cd ../broken_bad_pattern
! go mod vendor
stderr 'go mod vendor: pattern ../foo.txt: invalid pattern syntax'

# matchPotentialSourceFile prunes out tests and unbuilt code.
# Make sure that they are vendored if they are embedded files.
cd ../embed_unbuilt
go mod vendor
cmp vendor/example.com/dep/unbuilt.go dep/unbuilt.go
cmp vendor/example.com/dep/dep_test.go dep/dep_test.go
! exists vendor/example.com/dep/not_embedded_unbuilt.go
! exists vendor/example.com/dep/not_embedded_dep_test.go
-- go.mod --
module example.com/foo
go 1.16

require (
	example.com/a v0.1.0
)

replace (
	example.com/a v0.1.0 => ./a
)
-- foo.go --
package main

import (
	"fmt"

	"example.com/a"
)

func main() {
    fmt.Println(a.Str())
}
-- a/go.mod --
module example.com/a
-- a/a.go --
package a

import _ "embed"

//go:embed samedir_embed.txt
var sameDir string

//go:embed subdir/embed.txt
var subDir string

func Str() string {
	return sameDir + subDir
}
-- a/a_test.go --
package a

import _ "embed"

//go:embed subdir/test/embed.txt
var subderTest string
-- a/a_x_test.go --
package a_test

import _ "embed"

//go:embed subdir/test/xtest/embed.txt
var subdirXtest string
-- a/samedir_embed.txt --
embedded file in same directory as package
-- a/subdir/embed.txt --
embedded file in subdirectory of package
-- a/subdir/test/embed.txt --
embedded file of test in subdirectory of package
-- a/subdir/test/xtest/embed.txt --
embedded file of xtest in subdirectory of package
-- broken_no_matching_files/go.mod --
module example.com/broken
go 1.16

require (
	example.com/brokendep v0.1.0
)

replace (
	example.com/brokendep v0.1.0 => ./brokendep
)
-- broken_no_matching_files/f.go --
package broken

import _ "example.com/brokendep"

func F() {}
-- broken_no_matching_files/brokendep/go.mod --
module example.com/brokendep
go 1.16
-- broken_no_matching_files/brokendep/f.go --
package brokendep

import _ "embed"

//go:embed foo.txt
var foo string
-- broken_bad_pattern/go.mod --
module example.com/broken
go 1.16

require (
	example.com/brokendep v0.1.0
)

replace (
	example.com/brokendep v0.1.0 => ./brokendep
)
-- broken_bad_pattern/f.go --
package broken

import _ "example.com/brokendep"

func F() {}
-- broken_bad_pattern/brokendep/go.mod --
module example.com/brokendep
go 1.16
-- broken_bad_pattern/brokendep/f.go --
package brokendep

import _ "embed"

//go:embed ../foo.txt
var foo string
-- embed_unbuilt/go.mod --
module example.com/foo
go 1.16

require (
	example.com/dep v0.1.0
)

replace (
	example.com/dep v0.1.0 => ./dep
)
-- embed_unbuilt/foo.go --
package a

import _ "example.com/dep"

func F() {}
-- embed_unbuilt/dep/go.mod --
module example.com/dep
go 1.16
-- embed_unbuilt/dep/dep.go --
package dep

import _ "embed"

//go:embed unbuilt.go
var unbuilt string

//go:embed dep_test.go
var depTest string
-- embed_unbuilt/dep/unbuilt.go --
// +build ignore

package dep
-- embed_unbuilt/dep/not_embedded_unbuilt.go --
// +build ignore

package dep
-- embed_unbuilt/dep/dep_test.go --
package dep
-- embed_unbuilt/dep/not_embedded_dep_test.go --
package dep