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

     1  go mod vendor
     2  cmp vendor/example.com/a/samedir_embed.txt a/samedir_embed.txt
     3  cmp vendor/example.com/a/subdir/embed.txt a/subdir/embed.txt
     4  cmp vendor/example.com/a/subdir/test/embed.txt a/subdir/test/embed.txt
     5  cmp vendor/example.com/a/subdir/test/xtest/embed.txt a/subdir/test/xtest/embed.txt
     6  
     7  cd broken_no_matching_files
     8  ! go mod vendor
     9  stderr '^go: resolving embeds in example.com/brokendep: pattern foo.txt: no matching files found$'
    10  go mod vendor -e
    11  stderr '^go: resolving embeds in example.com/brokendep: pattern foo.txt: no matching files found$'
    12  
    13  cd ../broken_bad_pattern
    14  ! go mod vendor
    15  stderr '^go: resolving embeds in example.com/brokendep: pattern ../foo.txt: invalid pattern syntax$'
    16  go mod vendor -e
    17  stderr '^go: resolving embeds in example.com/brokendep: pattern ../foo.txt: invalid pattern syntax$'
    18  
    19  cd ../embed_go122
    20  go mod vendor
    21  cmp vendor/example.com/a/samedir_embed.txt ../a/samedir_embed.txt
    22  cmp vendor/example.com/a/subdir/embed.txt ../a/subdir/embed.txt
    23  ! exists vendor/example.com/a/subdir/test/embed.txt
    24  ! exists vendor/example.com/a/subdir/test/xtest/embed.txt
    25  -- embed_go122/go.mod --
    26  module example.com/foo
    27  go 1.22
    28  
    29  require (
    30  	example.com/a v0.1.0
    31  )
    32  
    33  replace (
    34  	example.com/a v0.1.0 => ../a
    35  )
    36  -- embed_go122/foo.go --
    37  package main
    38  
    39  import (
    40  	"fmt"
    41  
    42  	"example.com/a"
    43  )
    44  
    45  func main() {
    46      fmt.Println(a.Str())
    47  }
    48  
    49  # matchPotentialSourceFile prunes out tests and unbuilt code.
    50  # Make sure that they are vendored if they are embedded files.
    51  cd ../embed_unbuilt
    52  go mod vendor
    53  cmp vendor/example.com/dep/unbuilt.go dep/unbuilt.go
    54  cmp vendor/example.com/dep/dep_test.go dep/dep_test.go
    55  ! exists vendor/example.com/dep/not_embedded_unbuilt.go
    56  ! exists vendor/example.com/dep/not_embedded_dep_test.go
    57  -- go.mod --
    58  module example.com/foo
    59  go 1.16
    60  
    61  require (
    62  	example.com/a v0.1.0
    63  )
    64  
    65  replace (
    66  	example.com/a v0.1.0 => ./a
    67  )
    68  -- foo.go --
    69  package main
    70  
    71  import (
    72  	"fmt"
    73  
    74  	"example.com/a"
    75  )
    76  
    77  func main() {
    78      fmt.Println(a.Str())
    79  }
    80  -- a/go.mod --
    81  module example.com/a
    82  -- a/a.go --
    83  package a
    84  
    85  import _ "embed"
    86  
    87  //go:embed samedir_embed.txt
    88  var sameDir string
    89  
    90  //go:embed subdir/embed.txt
    91  var subDir string
    92  
    93  func Str() string {
    94  	return sameDir + subDir
    95  }
    96  -- a/a_test.go --
    97  package a
    98  
    99  import _ "embed"
   100  
   101  //go:embed subdir/test/embed.txt
   102  var subderTest string
   103  -- a/a_x_test.go --
   104  package a_test
   105  
   106  import _ "embed"
   107  
   108  //go:embed subdir/test/xtest/embed.txt
   109  var subdirXtest string
   110  -- a/samedir_embed.txt --
   111  embedded file in same directory as package
   112  -- a/subdir/embed.txt --
   113  embedded file in subdirectory of package
   114  -- a/subdir/test/embed.txt --
   115  embedded file of test in subdirectory of package
   116  -- a/subdir/test/xtest/embed.txt --
   117  embedded file of xtest in subdirectory of package
   118  -- broken_no_matching_files/go.mod --
   119  module example.com/broken
   120  go 1.16
   121  
   122  require (
   123  	example.com/brokendep v0.1.0
   124  )
   125  
   126  replace (
   127  	example.com/brokendep v0.1.0 => ./brokendep
   128  )
   129  -- broken_no_matching_files/f.go --
   130  package broken
   131  
   132  import _ "example.com/brokendep"
   133  
   134  func F() {}
   135  -- broken_no_matching_files/brokendep/go.mod --
   136  module example.com/brokendep
   137  go 1.16
   138  -- broken_no_matching_files/brokendep/f.go --
   139  package brokendep
   140  
   141  import _ "embed"
   142  
   143  //go:embed foo.txt
   144  var foo string
   145  -- broken_bad_pattern/go.mod --
   146  module example.com/broken
   147  go 1.16
   148  
   149  require (
   150  	example.com/brokendep v0.1.0
   151  )
   152  
   153  replace (
   154  	example.com/brokendep v0.1.0 => ./brokendep
   155  )
   156  -- broken_bad_pattern/f.go --
   157  package broken
   158  
   159  import _ "example.com/brokendep"
   160  
   161  func F() {}
   162  -- broken_bad_pattern/brokendep/go.mod --
   163  module example.com/brokendep
   164  go 1.16
   165  -- broken_bad_pattern/brokendep/f.go --
   166  package brokendep
   167  
   168  import _ "embed"
   169  
   170  //go:embed ../foo.txt
   171  var foo string
   172  -- embed_unbuilt/go.mod --
   173  module example.com/foo
   174  go 1.16
   175  
   176  require (
   177  	example.com/dep v0.1.0
   178  )
   179  
   180  replace (
   181  	example.com/dep v0.1.0 => ./dep
   182  )
   183  -- embed_unbuilt/foo.go --
   184  package a
   185  
   186  import _ "example.com/dep"
   187  
   188  func F() {}
   189  -- embed_unbuilt/dep/go.mod --
   190  module example.com/dep
   191  go 1.16
   192  -- embed_unbuilt/dep/dep.go --
   193  package dep
   194  
   195  import _ "embed"
   196  
   197  //go:embed unbuilt.go
   198  var unbuilt string
   199  
   200  //go:embed dep_test.go
   201  var depTest string
   202  -- embed_unbuilt/dep/unbuilt.go --
   203  // +build ignore
   204  
   205  package dep
   206  -- embed_unbuilt/dep/not_embedded_unbuilt.go --
   207  // +build ignore
   208  
   209  package dep
   210  -- embed_unbuilt/dep/dep_test.go --
   211  package dep
   212  -- embed_unbuilt/dep/not_embedded_dep_test.go --
   213  package dep
   214  

View as plain text