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

     1  cp go.mod go.mod.orig
     2  
     3  env oldGOPROXY=$GOPROXY
     4  
     5  # If a wildcard replacement exists for an otherwise-nonexistent module,
     6  # 'go get' should resolve it to the minimum valid pseudo-version.
     7  
     8  go mod edit -replace=example.com/x=./x
     9  go get example.com/x
    10  
    11  go list -m example.com/x
    12  stdout '^example.com/x v0.0.0-00010101000000-000000000000 '
    13  
    14  # If specific-version replacements exist, the highest matching version should be used.
    15  go mod edit -replace=example.com/x@v0.1.0=./x
    16  go mod edit -replace=example.com/x@v0.2.0=./x
    17  
    18  go get example.com/x
    19  go list -m example.com/x
    20  stdout '^example.com/x v0.2.0 '
    21  
    22  go get example.com/x@<v0.2.0
    23  go list -m example.com/x
    24  stdout '^example.com/x v0.1.0 '
    25  
    26  
    27  # The same should work with GOPROXY=off.
    28  
    29  env GOPROXY=off
    30  cp go.mod.orig go.mod
    31  
    32  go mod edit -replace=example.com/x=./x
    33  go get example.com/x
    34  
    35  go list -m example.com/x
    36  stdout '^example.com/x v0.0.0-00010101000000-000000000000 '
    37  
    38  # If specific-version replacements exist, the highest matching version should be used.
    39  go mod edit -replace=example.com/x@v0.1.0=./x
    40  go mod edit -replace=example.com/x@v0.2.0=./x
    41  
    42  go get example.com/x
    43  go list -m example.com/x
    44  stdout '^example.com/x v0.2.0 '
    45  
    46  go get example.com/x@<v0.2.0
    47  go list -m example.com/x
    48  stdout '^example.com/x v0.1.0 '
    49  
    50  
    51  # Replacements should also be listed as known versions, and 'go get' should sort
    52  # them in with ordinary versions.
    53  
    54  env GOPROXY=$oldGOPROXY
    55  
    56  cp go.mod.orig go.mod
    57  go list -versions -m rsc.io/quote
    58  stdout 'v1.3.0 v1.4.0'
    59  
    60  go get rsc.io/quote@v1.3
    61  go list -m rsc.io/quote
    62  stdout '^rsc.io/quote v1.3.0'
    63  
    64  go mod edit -replace rsc.io/quote@v1.3.1=rsc.io/quote@v1.4.0
    65  
    66  go list -versions -m rsc.io/quote
    67  stdout 'v1.3.0 v1.3.1 v1.4.0'
    68  
    69  go get rsc.io/quote@v1.3
    70  go list -m rsc.io/quote
    71  stdout '^rsc.io/quote v1.3.1 '
    72  
    73  go get rsc.io/quote@>v1.3.1
    74  go list -m rsc.io/quote
    75  stdout '^rsc.io/quote v1.4.0'
    76  
    77  
    78  # Replacements should allow 'go get' to work even with dotless module paths.
    79  
    80  cp go.mod.orig go.mod
    81  
    82  ! go list example
    83  stderr '^package example is not in GOROOT \(.*\)$'
    84  ! go get example
    85  stderr '^go: malformed module path "example": missing dot in first path element$'
    86  
    87  go mod edit -replace example@v0.1.0=./example
    88  
    89  ! go list example
    90  stderr '^module example provides package example and is replaced but not required; to add it:\n\tgo get example@v0.1.0$'
    91  
    92  go get example
    93  go list -m example
    94  stdout '^example v0.1.0 '
    95  
    96  
    97  -- go.mod --
    98  module example.com
    99  
   100  go 1.16
   101  -- x/go.mod --
   102  module example.com/x
   103  
   104  go 1.16
   105  -- x/x.go --
   106  package x
   107  -- example/go.mod --
   108  module example
   109  go 1.16
   110  -- example/example.go --
   111  package example
   112  

View as plain text