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

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

View as plain text