...

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
    35[symlink] symlink x.tzt -> x.txt
    36[symlink] ! go build -x
    37[symlink] stderr 'pattern [*]t: cannot embed irregular file x.tzt'
    38[symlink] rm x.tzt
    39
    40# build rejects empty directories
    41mkdir t
    42! go build -x
    43stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
    44
    45# build ignores symlinks and invalid names in directories
    46cp x.txt t/.git
    47! go build -x
    48stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
    49go list -e -f '{{.Incomplete}}'
    50stdout 'true'
    51[symlink] symlink t/x.link -> ../x.txt
    52[symlink] ! go build -x
    53[symlink] stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
    54
    55cp x.txt t/x.txt
    56go build -x
    57
    58# build reports errors with positions in imported packages
    59rm t/x.txt
    60! go build m/use
    61stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
    62
    63# all still ignores .git and symlinks
    64cp x.go3 x.go
    65! go build -x
    66stderr '^x.go:5:12: pattern all:t: cannot embed directory t: contains no embeddable files$'
    67
    68# all finds dot files and underscore files
    69cp x.txt t/.x.txt
    70go build -x
    71rm t/.x.txt
    72cp x.txt t/_x.txt
    73go build -x
    74
    75-- x.go --
    76package p
    77
    78import "embed"
    79
    80//go:embed x*t*t
    81var X embed.FS
    82
    83-- x_test.go --
    84package p
    85
    86import "embed"
    87
    88//go:embed y*t*t
    89var Y string
    90
    91-- x_x_test.go --
    92package p_test
    93
    94import "embed"
    95
    96//go:embed z*t*t
    97var Z string
    98
    99-- x.go2 --
   100package p
   101
   102import "embed"
   103
   104//go:embed *t
   105var X embed.FS
   106
   107-- x.go3 --
   108package p
   109
   110import "embed"
   111
   112//go:embed all:t
   113var X embed.FS
   114
   115-- x.txt --
   116hello
   117
   118-- y.txt --
   119-- z.txt --
   120-- x.txt2 --
   121not hello
   122
   123-- use/use.go --
   124package use
   125
   126import _ "m"
   127-- go.mod --
   128module m
   129
   130go 1.16

View as plain text