...

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

Documentation: cmd/go/testdata/script

     1env GO111MODULE=on
     2
     3# Replacement should not use a vendor directory as the target.
     4! go mod vendor
     5stderr 'replacement path ./vendor/not-rsc.io/quote/v3 inside vendor directory'
     6
     7cp go.mod1 go.mod
     8rm -r vendor
     9
    10# Before vendoring, we expect to see the original directory.
    11go list -f '{{with .Module}}{{.Version}}{{end}} {{.Dir}}' rsc.io/quote/v3
    12stdout 'v3.0.0'
    13stdout '.*[/\\]not-rsc.io[/\\]quote[/\\]v3'
    14
    15# Since all dependencies are replaced, 'go mod vendor' should not
    16# have to download anything from the network.
    17go mod vendor
    18! stderr 'downloading'
    19! stderr 'finding'
    20
    21# After vendoring, we expect to see the replacement in the vendor directory,
    22# without attempting to look up the non-replaced version.
    23cmp vendor/rsc.io/quote/v3/quote.go local/not-rsc.io/quote/v3/quote.go
    24
    25go list -mod=vendor -f '{{with .Module}}{{.Version}}{{end}} {{.Dir}}' rsc.io/quote/v3
    26stdout 'v3.0.0'
    27stdout '.*[/\\]vendor[/\\]rsc.io[/\\]quote[/\\]v3'
    28! stderr 'finding'
    29! stderr 'lookup disabled'
    30
    31# 'go list' should provide the original replacement directory as the module's
    32# replacement path.
    33go list -mod=vendor -f '{{with .Module}}{{with .Replace}}{{.Path}}{{end}}{{end}}' rsc.io/quote/v3
    34stdout '.*[/\\]not-rsc.io[/\\]quote[/\\]v3'
    35
    36# The same module can't be used as two different paths.
    37cd multiple-paths
    38! go mod vendor
    39stderr 'rsc.io/quote/v3@v3.0.0 used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)'
    40
    41-- go.mod --
    42module example.com/replace
    43
    44require rsc.io/quote/v3 v3.0.0
    45replace rsc.io/quote/v3 => ./vendor/not-rsc.io/quote/v3
    46
    47-- go.mod1 --
    48module example.com/replace
    49
    50require rsc.io/quote/v3 v3.0.0
    51replace rsc.io/quote/v3 => ./local/not-rsc.io/quote/v3
    52
    53-- imports.go --
    54package replace
    55
    56import _ "rsc.io/quote/v3"
    57
    58-- local/not-rsc.io/quote/v3/go.mod --
    59module not-rsc.io/quote/v3
    60
    61-- local/not-rsc.io/quote/v3/quote.go --
    62package quote
    63
    64-- multiple-paths/main.go --
    65package main
    66import (
    67	"fmt"
    68	"rsc.io/quote/v3"
    69)
    70func main() {
    71	fmt.Println(quote.GoV3())
    72}
    73-- multiple-paths/go.mod --
    74module quoter
    75require (
    76	rsc.io/quote/v3 v3.0.0
    77	not-rsc.io/quote/v3 v3.0.0
    78)
    79replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0
    80-- multiple-paths/go.sum --
    81golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
    82rsc.io/quote/v3 v3.0.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
    83rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
    84
    85-- vendor/not-rsc.io/quote/v3/go.mod --
    86module not-rsc.io/quote/v3
    87
    88-- vendor/not-rsc.io/quote/v3/quote.go --
    89package quote

View as plain text