Black Lives Matter. Support the Equal Justice Initiative.

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

Documentation: cmd/go/testdata/script

     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
    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
    41  mkdir t
    42  ! go build -x
    43  stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
    44  
    45  # build ignores symlinks and invalid names in directories
    46  cp x.txt t/.git
    47  ! go build -x
    48  stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
    49  go list -e -f '{{.Incomplete}}'
    50  stdout '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  
    55  cp x.txt t/x.txt
    56  go build -x
    57  
    58  # build reports errors with positions in imported packages
    59  rm t/x.txt
    60  ! go build m/use
    61  stderr '^x.go:5:12: pattern [*]t: cannot embed directory t: contains no embeddable files$'
    62  
    63  -- x.go --
    64  package p
    65  
    66  import "embed"
    67  
    68  //go:embed x*t*t
    69  var X embed.FS
    70  
    71  -- x_test.go --
    72  package p
    73  
    74  import "embed"
    75  
    76  //go:embed y*t*t
    77  var Y string
    78  
    79  -- x_x_test.go --
    80  package p_test
    81  
    82  import "embed"
    83  
    84  //go:embed z*t*t
    85  var Z string
    86  
    87  -- x.go2 --
    88  package p
    89  
    90  import "embed"
    91  
    92  //go:embed *t
    93  var X embed.FS
    94  
    95  -- x.txt --
    96  hello
    97  
    98  -- y.txt --
    99  -- z.txt --
   100  -- x.txt2 --
   101  not hello
   102  
   103  -- use/use.go --
   104  package use
   105  
   106  import _ "m"
   107  -- go.mod --
   108  module m
   109  
   110  go 1.16
   111  

View as plain text