Black Lives Matter. Support the Equal Justice Initiative.

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

Documentation: cmd/go/testdata/script

     1  # Integration test for golang.org/issue/33848: automatically check and use vendored packages.
     2  
     3  env GO111MODULE=on
     4  
     5  [short] skip
     6  
     7  cd $WORK/auto
     8  cp go.mod go.mod.orig
     9  cp $WORK/modules-1.13.txt $WORK/auto/modules.txt
    10  
    11  # An explicit -mod=vendor should force use of the vendor directory.
    12  env GOFLAGS=-mod=vendor
    13  
    14  go list -f {{.Dir}} -tags tools all
    15  stdout '^'$WORK'[/\\]auto$'
    16  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
    17  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
    18  
    19  ! go list -m all
    20  stderr 'go list -m: can''t compute ''all'' using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)'
    21  
    22  ! go list -m -f '{{.Dir}}' all
    23  stderr 'go list -m: can''t compute ''all'' using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)'
    24  
    25  # An explicit -mod=mod should force the vendor directory to be ignored.
    26  env GOFLAGS=-mod=mod
    27  
    28  go list -f {{.Dir}} -tags tools all
    29  stdout '^'$WORK'[/\\]auto$'
    30  stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$'
    31  stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
    32  
    33  go list -m all
    34  stdout '^example.com/auto$'
    35  stdout 'example.com/printversion v1.0.0'
    36  stdout 'example.com/version v1.0.0'
    37  
    38  go list -m -f '{{.Dir}}' all
    39  stdout '^'$WORK'[/\\]auto$'
    40  stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$'
    41  stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
    42  
    43  # If the main module's "go" directive says 1.13, we should default to -mod=mod.
    44  env GOFLAGS=
    45  go mod edit -go=1.13
    46  
    47  go list -f {{.Dir}} -tags tools all
    48  stdout '^'$WORK'[/\\]auto$'
    49  stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$'
    50  stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
    51  
    52  go list -m -f '{{.Dir}}' all
    53  stdout '^'$WORK'[/\\]auto$'
    54  stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$'
    55  stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
    56  
    57  # A 'go 1.14' directive in the main module's go.mod file should enable
    58  # -mod=vendor by default, along with stronger checks for consistency
    59  # between the go.mod file and vendor/modules.txt.
    60  # A 'go 1.13' vendor/modules.txt file is not usually sufficient
    61  # to pass those checks.
    62  go mod edit -go=1.14
    63  
    64  ! go list -f {{.Dir}} -tags tools all
    65  stderr '^go: inconsistent vendoring in '$WORK[/\\]auto':$'
    66  stderr '^\texample.com/printversion@v1.0.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt'
    67  stderr '^\texample.com/unused: is replaced in go.mod, but not marked as replaced in vendor/modules.txt'
    68  stderr '^\texample.com/version@v1.2.0: is replaced in go.mod, but not marked as replaced in vendor/modules.txt'
    69  stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor$'
    70  
    71  # Module-specific subcommands should continue to load the full module graph.
    72  go mod graph
    73  stdout '^example.com/printversion@v1.0.0 example.com/version@v1.0.0$'
    74  
    75  # An explicit -mod=mod should still force the vendor directory to be ignored.
    76  env GOFLAGS=-mod=mod
    77  
    78  go list -f {{.Dir}} -tags tools all
    79  stdout '^'$WORK'[/\\]auto$'
    80  stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$'
    81  stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
    82  
    83  go list -m all
    84  stdout '^example.com/auto$'
    85  stdout 'example.com/printversion v1.0.0'
    86  stdout 'example.com/version v1.0.0'
    87  
    88  go list -m -f '{{.Dir}}' all
    89  stdout '^'$WORK'[/\\]auto$'
    90  stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\]printversion@v1.0.0$'
    91  stdout '^'$WORK'[/\\]auto[/\\]replacement-version$'
    92  
    93  # 'go mod vendor' should repair vendor/modules.txt so that the implicit
    94  # -mod=vendor works again.
    95  env GOFLAGS=
    96  
    97  go mod edit -go=1.14
    98  go mod vendor
    99  
   100  go list -f {{.Dir}} -tags tools all
   101  stdout '^'$WORK'[/\\]auto$'
   102  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
   103  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
   104  
   105  # ...but 'go list -m' should continue to fail, this time without
   106  # referring to a -mod default that the user didn't set.
   107  ! go list -m all
   108  stderr 'go list -m: can''t compute ''all'' using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)'
   109  
   110  ! go list -m -f '{{.Dir}}' all
   111  stderr 'go list -m: can''t compute ''all'' using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)'
   112  
   113  
   114  # 'go mod init' should work if there is already a GOPATH-mode vendor directory
   115  # present. If there are no module dependencies, -mod=vendor should be used by
   116  # default and should not fail the consistency check even though no module
   117  # information is present.
   118  
   119  rm go.mod
   120  rm vendor/modules.txt
   121  
   122  go mod init example.com/auto
   123  go list -f {{.Dir}} -tags tools all
   124  stdout '^'$WORK'[/\\]auto$'
   125  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
   126  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
   127  
   128  # If information about dependencies is added to a 1.14 go.mod file, subsequent
   129  # list commands should error out if vendor/modules.txt is missing or incomplete.
   130  
   131  cp go.mod.orig go.mod
   132  go mod edit -go=1.14
   133  ! go list -f {{.Dir}} -tags tools all
   134  stderr '^go: inconsistent vendoring in '$WORK[/\\]auto':$'
   135  stderr '^\texample.com/printversion@v1.0.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt'
   136  stderr '^\texample.com/unused: is replaced in go.mod, but not marked as replaced in vendor/modules.txt'
   137  stderr '^\texample.com/version@v1.2.0: is replaced in go.mod, but not marked as replaced in vendor/modules.txt'
   138  stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor$'
   139  
   140  # If -mod=vendor is set, limited consistency checks should apply even when
   141  # the go version is 1.13 or earlier.
   142  # An incomplete or missing vendor/modules.txt should resolve the vendored packages...
   143  go mod edit -go=1.13
   144  go list -mod=vendor -f {{.Dir}} -tags tools all
   145  stdout '^'$WORK'[/\\]auto$'
   146  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
   147  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
   148  
   149  # ...but a version mismatch for an explicit dependency should be noticed.
   150  cp $WORK/modules-bad-1.13.txt vendor/modules.txt
   151  ! go list -mod=vendor -f {{.Dir}} -tags tools all
   152  stderr '^go: inconsistent vendoring in '$WORK[/\\]auto':$'
   153  stderr '^\texample.com/printversion@v1.0.0: is explicitly required in go.mod, but vendor/modules.txt indicates example.com/printversion@v1.1.0$'
   154  stderr '^\tTo ignore the vendor directory, use -mod=readonly or -mod=mod.\n\tTo sync the vendor directory, run:\n\t\tgo mod vendor$'
   155  
   156  # If the go version is still 1.13, 'go mod vendor' should write a
   157  # matching vendor/modules.txt containing the corrected 1.13 data.
   158  go mod vendor
   159  cmp $WORK/modules-1.13.txt vendor/modules.txt
   160  
   161  go list -mod=vendor -f {{.Dir}} -tags tools all
   162  stdout '^'$WORK'[/\\]auto$'
   163  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
   164  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
   165  
   166  # When the version is upgraded to 1.14, 'go mod vendor' should write a
   167  # vendor/modules.txt with the updated 1.14 annotations.
   168  go mod edit -go=1.14
   169  go mod vendor
   170  cmp $WORK/modules-1.14.txt vendor/modules.txt
   171  
   172  # Then, -mod=vendor should kick in automatically and succeed.
   173  go list -f {{.Dir}} -tags tools all
   174  stdout '^'$WORK'[/\\]auto$'
   175  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
   176  stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
   177  
   178  # 'go get' should update from the network or module cache,
   179  # even if a vendor directory is present.
   180  go get -d example.com/version@v1.1.0
   181  ! go list -f {{.Dir}} -tags tools all
   182  stderr '^go: inconsistent vendoring'
   183  
   184  -- $WORK/auto/go.mod --
   185  module example.com/auto
   186  
   187  go 1.13
   188  
   189  require example.com/printversion v1.0.0
   190  
   191  replace (
   192  	example.com/unused => nonexistent.example.com/unused v1.0.0-whatever
   193  	example.com/version v1.0.0 => ./replacement-version
   194  	example.com/version v1.2.0 => nonexistent.example.com/version v1.2.0
   195  )
   196  -- $WORK/auto/tools.go --
   197  // +build tools
   198  
   199  package auto
   200  
   201  import _ "example.com/printversion"
   202  -- $WORK/auto/auto.go --
   203  package auto
   204  -- $WORK/auto/replacement-version/go.mod --
   205  module example.com/version
   206  -- $WORK/auto/replacement-version/version.go --
   207  package version
   208  
   209  const V = "v1.0.0-replaced"
   210  -- $WORK/modules-1.14.txt --
   211  # example.com/printversion v1.0.0
   212  ## explicit
   213  example.com/printversion
   214  # example.com/version v1.0.0 => ./replacement-version
   215  example.com/version
   216  # example.com/unused => nonexistent.example.com/unused v1.0.0-whatever
   217  # example.com/version v1.2.0 => nonexistent.example.com/version v1.2.0
   218  -- $WORK/modules-1.13.txt --
   219  # example.com/printversion v1.0.0
   220  example.com/printversion
   221  # example.com/version v1.0.0 => ./replacement-version
   222  example.com/version
   223  -- $WORK/modules-bad-1.13.txt --
   224  # example.com/printversion v1.1.0
   225  example.com/printversion
   226  # example.com/version v1.1.0
   227  example.com/version
   228  -- $WORK/auto/vendor/example.com/printversion/go.mod --
   229  module example.com/printversion
   230  
   231  require example.com/version v1.0.0
   232  replace example.com/version v1.0.0 => ../oops v0.0.0
   233  exclude example.com/version v1.0.1
   234  -- $WORK/auto/vendor/example.com/printversion/printversion.go --
   235  package main
   236  
   237  import (
   238  	"fmt"
   239  	"os"
   240  	"runtime/debug"
   241  
   242  	_ "example.com/version"
   243  )
   244  
   245  func main() {
   246  	info, _ := debug.ReadBuildInfo()
   247  	fmt.Fprintf(os.Stdout, "path is %s\n", info.Path)
   248  	fmt.Fprintf(os.Stdout, "main is %s %s\n", info.Main.Path, info.Main.Version)
   249  	for _, m := range info.Deps {
   250  		fmt.Fprintf(os.Stdout, "using %s %s\n", m.Path, m.Version)
   251  	}
   252  }
   253  -- $WORK/auto/vendor/example.com/version/version.go --
   254  package version
   255  
   256  const V = "v1.0.0-replaced"
   257  

View as plain text