...

Text file src/cmd/go/testdata/script/embed.txt

Documentation: cmd/go/testdata/script

     1# go list shows patterns and files
     2go list -f '{{.EmbedPatterns}}'
     3stdout '\[x\*t\*t\]'
     4go list -f '{{.EmbedFiles}}'
     5stdout '\[x.txt\]'
     6go list -test -f '{{.TestEmbedPatterns}}'
     7stdout '\[y\*t\*t\]'
     8go list -test -f '{{.TestEmbedFiles}}'
     9stdout '\[y.txt\]'
    10go list -test -f '{{.XTestEmbedPatterns}}'
    11stdout '\[z\*t\*t\]'
    12go list -test -f '{{.XTestEmbedFiles}}'
    13stdout '\[z.txt\]'
    14
    15# build embeds x.txt
    16go build -x
    17stderr 'x.txt'
    18
    19# build uses cache correctly
    20go build -x
    21! stderr 'x.txt'
    22cp x.txt2 x.txt
    23go build -x
    24stderr 'x.txt'
    25
    26# build rejects invalid names
    27cp x.go2 x.go
    28go build -x
    29cp x.txt .git
    30! go build -x
    31stderr '^x.go:5:12: pattern [*]t: cannot embed file [.]git: invalid name [.]git$'
    32rm .git
    33
    34# build rejects symlinks by default
    35[symlink] symlink x.tzt -> x.txt
    36[symlink] ! go build -x
    37[symlink] stderr 'pattern [*]t: cannot embed irregular file x.tzt'
    38# with GODEBUG embedfollowsymlinks=1, build allows symlinks of leaf files
    39[symlink] env 'GODEBUG=embedfollowsymlinks=1'
    40[symlink] go build -x
    41[symlink] stderr 'x.tzt'
    42[symlink] rm x.tzt
    43[symlink] env 'GODEBUG='
    44
    45# build rejects empty directories
    46mkdir t
    47! go build -x
    48stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
    49
    50# build ignores symlinks and invalid names in directories
    51cp x.txt t/.git
    52! go build -x
    53stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
    54go list -e -f '{{.Incomplete}}'
    55stdout 'true'
    56[symlink] symlink t/x.link -> ../x.txt
    57[symlink] ! go build -x
    58[symlink] stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
    59
    60cp x.txt t/x.txt
    61go build -x
    62
    63# build reports errors with positions in imported packages
    64rm t/x.txt
    65! go build m/use
    66stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
    67
    68# all still ignores .git and symlinks
    69cp x.go3 x.go
    70! go build -x
    71stderr '^x.go:5:12: pattern all:t: cannot embed directory t: contains no embeddable files$'
    72
    73# all finds dot files and underscore files
    74cp x.txt t/.x.txt
    75go build -x
    76rm t/.x.txt
    77cp x.txt t/_x.txt
    78go build -x
    79
    80# build disallows symlinks of directories
    81[symlink] symlink symdir -> symdirdst
    82[symlink] cp x.go4 x.go
    83[symlink] ! go build -x
    84[symlink] stderr 'x.go:5:12: pattern symdir/[*]: cannot embed file symdir[\\/]x.txt: in non-directory symdir'
    85[symlink] cp x.go5 x.go
    86[symlink] ! go build -x
    87[symlink] stderr 'x.go:5:12: pattern symdir/x.txt: cannot embed file symdir[\\/]x.txt: in non-directory symdir'
    88# even with GODEBUG=embedfollowsymlinks=1
    89[symlink] env 'GODEBUG=embedfollowsymlinks=1'
    90[symlink] cp x.go4 x.go
    91[symlink] ! go build -x
    92[symlink] stderr 'x.go:5:12: pattern symdir/[*]: cannot embed file symdir[\\/]x.txt: in non-directory symdir'
    93[symlink] cp x.go5 x.go
    94[symlink] ! go build -x
    95[symlink] stderr 'x.go:5:12: pattern symdir/x.txt: cannot embed file symdir[\\/]x.txt: in non-directory symdir'
    96[symlink] env 'GODEBUG='
    97
    98# build rejects names in subdirectories with invalid punctuation
    99cp x.go6 x.go
   100mkdir photos/subdir
   101cp x.txt photos/subdir/foo.jpg
   102cp x.txt 'photos/subdir/2022-07-22T15''02''45Z.jpg'
   103! go build -x
   104stderr '^x.go:5:12: pattern photos/\*: cannot embed file photos/subdir/2022-07-22T15''02''45Z.jpg: invalid name 2022-07-22T15''02''45Z.jpg$'
   105[!GOOS:windows] mv 'photos/subdir/2022-07-22T15''02''45Z.jpg' photos/subdir/2022-07-22T15:02:45Z.jpg
   106[!GOOS:windows] ! go build -x
   107[!GOOS:windows] stderr '^x.go:5:12: pattern photos/\*: cannot embed file photos/subdir/2022-07-22T15:02:45Z.jpg: invalid name 2022-07-22T15:02:45Z.jpg$'
   108rm photos
   109
   110# build ignores hidden names in subdirectories with invalid punctuation
   111cp x.go6 x.go
   112mkdir photos/subdir
   113[!GOOS:windows] cp x.txt photos/subdir/.2022-07-22T15:02:45Z.jpg
   114[!GOOS:windows] cp x.txt photos/subdir/_2022-07-22T15:02:45Z.jpg
   115cp x.txt 'photos/subdir/.2022-07-22T15''02''45Z.jpg'
   116cp x.txt 'photos/subdir/_2022-07-22T15''02''45Z.jpg'
   117cp x.txt photos/subdir/foo.jpg
   118go build -x
   119rm photos
   120
   121-- x.go --
   122package p
   123
   124import "embed"
   125
   126//go:embed x*t*t
   127var X embed.FS
   128
   129-- x_test.go --
   130package p
   131
   132import "embed"
   133
   134//go:embed y*t*t
   135var Y string
   136
   137-- x_x_test.go --
   138package p_test
   139
   140import "embed"
   141
   142//go:embed z*t*t
   143var Z string
   144
   145-- x.go2 --
   146package p
   147
   148import "embed"
   149
   150//go:embed *t
   151var X embed.FS
   152
   153-- x.go3 --
   154package p
   155
   156import "embed"
   157
   158//go:embed all:t
   159var X embed.FS
   160
   161-- x.go4 --
   162package p
   163
   164import "embed"
   165
   166//go:embed symdir/*
   167var X embed.FS
   168
   169-- x.go5 --
   170package p
   171
   172import "embed"
   173
   174//go:embed symdir/x.txt
   175var Z string
   176
   177-- x.go6 --
   178package p
   179
   180import "embed"
   181
   182//go:embed photos/*
   183var X embed.FS
   184
   185-- x.txt --
   186hello
   187
   188-- y.txt --
   189-- z.txt --
   190-- x.txt2 --
   191not hello
   192
   193-- use/use.go --
   194package use
   195
   196import _ "m"
   197-- symdirdst/x.txt --
   198-- go.mod --
   199module m
   200
   201go 1.16

View as plain text