...

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

Documentation: cmd/go/testdata/script

     1env GO111MODULE=on
     2env GOFLAGS=-mod=mod
     3[short] skip
     4
     5# golang.org/issue/30166: 'go mod tidy' should not crash if a replaced module is
     6# involved in a cycle.
     7cd cycle
     8env GOTRACEBACK=off
     9go mod tidy
    10cd ..
    11
    12# From inside the module, 'go list -m all' should NOT include transitive
    13# requirements of modules that have been replaced.
    14go list -m all
    15stdout 'rsc.io/quote/v3 v3.0.0'
    16! stdout 'rsc.io/sampler'
    17! stdout 'golang.org/x/text'
    18
    19# From outside the module, 'go list -m all' should include them.
    20cd outside
    21go list -m all
    22stdout 'rsc.io/quote/v3 v3.0.0'
    23stdout 'rsc.io/sampler v1.3.0'
    24stdout 'golang.org/x/text'
    25cd ..
    26
    27# 'go list all' should add indirect requirements to satisfy the packages
    28# imported from replacement modules.
    29! grep 'rsc.io/sampler' go.mod
    30! grep 'golang.org/x/text' go.mod
    31go list all
    32grep 'rsc.io/sampler' go.mod
    33grep 'golang.org/x/text' go.mod
    34
    35# 'go get' and 'go mod tidy' should follow the requirements of the replacements,
    36# not the originals, even if that results in a set of versions that are
    37# misleading or redundant without those replacements.
    38go get rsc.io/sampler@v1.2.0
    39go mod tidy
    40go list -m all
    41stdout 'rsc.io/quote/v3 v3.0.0'
    42stdout 'rsc.io/sampler v1.2.0'
    43stdout 'golang.org/x/text'
    44
    45# The requirements seen from outside may be higher (or lower)
    46# than those seen from within the module.
    47grep 'rsc.io/sampler v1.2.0' go.mod
    48cd outside
    49go list -m all
    50stdout 'rsc.io/sampler v1.3.0'
    51cd ..
    52
    53# The same module can't be used as two different paths.
    54cd multiple-paths
    55! go mod tidy
    56stderr 'rsc.io/quote/v3@v3.0.0 used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)'
    57
    58-- go.mod --
    59module example.com/tidy
    60
    61require rsc.io/quote/v3 v3.0.0
    62replace rsc.io/quote/v3 => ./not-rsc.io/quote/v3
    63
    64-- imports.go --
    65package tidy
    66
    67import _ "rsc.io/quote/v3"
    68
    69-- outside/go.mod --
    70module example.com/tidy/outside
    71
    72require example.com/tidy v0.0.0
    73replace example.com/tidy => ./..
    74
    75-- not-rsc.io/quote/v3/go.mod --
    76module not-rsc.io/quote/v3
    77
    78// No requirements specified!
    79
    80-- not-rsc.io/quote/v3/quote.go --
    81package quote
    82
    83import (
    84	_ "rsc.io/sampler"
    85	_ "golang.org/x/text/language"
    86)
    87
    88-- cycle/go.mod --
    89module golang.org/issue/30166
    90
    91require (
    92	golang.org/issue/30166/a v0.0.0
    93	golang.org/issue/30166/b v0.0.0
    94)
    95
    96replace (
    97	golang.org/issue/30166/a => ./a
    98	golang.org/issue/30166/b => ./b
    99)
   100-- cycle/cycle.go --
   101package cycle
   102
   103import (
   104	_ "golang.org/issue/30166/a"
   105	_ "golang.org/issue/30166/b"
   106)
   107-- cycle/a/a.go --
   108package a
   109-- cycle/a/go.mod --
   110module golang.org/issue/30166/a
   111
   112require golang.org/issue/30166/b v0.0.0
   113-- cycle/b/b.go --
   114package b
   115-- cycle/b/go.mod --
   116module golang.org/issue/30166/b
   117
   118require golang.org/issue/30166/a v0.0.0
   119-- multiple-paths/main.go --
   120package main
   121
   122import (
   123	"fmt"
   124	"rsc.io/quote/v3"
   125)
   126
   127func main() {
   128	fmt.Println(quote.GoV3())
   129}
   130-- multiple-paths/go.mod --
   131module quoter
   132
   133require (
   134	rsc.io/quote/v3 v3.0.0
   135	not-rsc.io/quote/v3 v3.0.0
   136)
   137
   138replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0
   139-- multiple-paths/use.go --
   140package quoter
   141
   142import (
   143	_ "not-rsc.io/quote/v3"
   144	_ "rsc.io/quote/v3"
   145)

View as plain text