blob: 7e9a548661071e8308b1a732411c98c0eb423925 [file] [log] [blame]
# go list shows patterns and files
go list -f '{{.EmbedPatterns}}'
stdout '\[x\*t\*t\]'
go list -f '{{.EmbedFiles}}'
stdout '\[x.txt\]'
# build embeds x.txt
go build -x
stderr 'x.txt'
# build uses cache correctly
go build -x
! stderr 'x.txt'
cp x.txt2 x.txt
go build -x
stderr 'x.txt'
# build rejects invalid names
cp x.go2 x.go
go build -x
cp x.txt .git
! go build -x
stderr 'pattern [*]t: cannot embed file [.]git'
rm .git
# build rejects symlinks
[symlink] symlink x.tzt -> x.txt
[symlink] ! go build -x
[symlink] stderr 'pattern [*]t: cannot embed irregular file x.tzt'
[symlink] rm x.tzt
# build rejects empty directories
mkdir t
! go build -x
stderr 'pattern [*]t: cannot embed directory t: contains no embeddable files'
# build ignores symlinks and invalid names in directories
cp x.txt t/.git
! go build -x
stderr 'pattern [*]t: cannot embed directory t: contains no embeddable files'
[symlink] symlink t/x.link -> ../x.txt
[symlink] ! go build -x
[symlink] stderr 'pattern [*]t: cannot embed directory t: contains no embeddable files'
cp x.txt t/x.txt
go build -x
-- x.go --
package p
import "embed"
//go:embed x*t*t
var X embed.FS
-- x.go2 --
package p
import "embed"
//go:embed *t
var X embed.FS
-- x.txt --
hello
-- x.txt2 --
not hello
-- go.mod --
module m