Skip to content

Commit 97fb97b

Browse files
committed
modcmd: do not copy test embed files when vendoring
Currently, `go mod vendor` copy all files matched by //go:embed, even when it is in a _test.go file. According to the documentation, it should not include test code for vendored packages. Fixes #63473
1 parent dacf1f1 commit 97fb97b

File tree

2 files changed

+1
-17
lines changed

2 files changed

+1
-17
lines changed

src/cmd/go/internal/modcmd/vendor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func vendorPkg(vdir, pkg string) {
313313
base.Fatalf("internal error: failed to find embedded files of %s: %v\n", pkg, err)
314314
}
315315
}
316-
embedPatterns := str.StringList(bp.EmbedPatterns, bp.TestEmbedPatterns, bp.XTestEmbedPatterns)
316+
embedPatterns := str.StringList(bp.EmbedPatterns)
317317
embeds, err := load.ResolveEmbed(bp.Dir, embedPatterns)
318318
if err != nil {
319319
base.Fatal(err)

src/cmd/go/testdata/script/mod_vendor_embed.txt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
go mod vendor
22
cmp vendor/example.com/a/samedir_embed.txt a/samedir_embed.txt
33
cmp vendor/example.com/a/subdir/embed.txt a/subdir/embed.txt
4-
cmp vendor/example.com/a/subdir/test/embed.txt a/subdir/test/embed.txt
5-
cmp vendor/example.com/a/subdir/test/xtest/embed.txt a/subdir/test/xtest/embed.txt
64

75
cd broken_no_matching_files
86
! go mod vendor
@@ -59,20 +57,6 @@ var subDir string
5957
func Str() string {
6058
return sameDir + subDir
6159
}
62-
-- a/a_test.go --
63-
package a
64-
65-
import _ "embed"
66-
67-
//go:embed subdir/test/embed.txt
68-
var subderTest string
69-
-- a/a_x_test.go --
70-
package a_test
71-
72-
import _ "embed"
73-
74-
//go:embed subdir/test/xtest/embed.txt
75-
var subdirXtest string
7660
-- a/samedir_embed.txt --
7761
embedded file in same directory as package
7862
-- a/subdir/embed.txt --

0 commit comments

Comments
 (0)