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

     1  # Check that with -mod=readonly, when we load a package in a module that is
     2  # replaced but not required, we emit an error with the command to add the
     3  # requirement.
     4  # Verifies golang.org/issue/41416, golang.org/issue/41577.
     5  cp go.mod go.mod.orig
     6  
     7  # Replace all versions of a module without requiring it.
     8  # With -mod=mod, we'd add a requirement for a "zero" pseudo-version, but we
     9  # can't in readonly mode, since its go.mod may alter the build list.
    10  go mod edit -replace rsc.io/quote=./quote
    11  ! go list rsc.io/quote
    12  stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote$'
    13  go get rsc.io/quote
    14  cmp go.mod go.mod.latest
    15  go list rsc.io/quote
    16  cp go.mod.orig go.mod
    17  
    18  # Same test with a specific version.
    19  go mod edit -replace rsc.io/quote@v1.0.0-doesnotexist=./quote
    20  ! go list rsc.io/quote
    21  stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote@v1.0.0-doesnotexist$'
    22  go get rsc.io/quote@v1.0.0-doesnotexist
    23  cmp go.mod go.mod.specific
    24  go list rsc.io/quote
    25  cp go.mod.orig go.mod
    26  
    27  # If there are multiple versions, the highest is suggested.
    28  go mod edit -replace rsc.io/quote@v1.0.0-doesnotexist=./quote
    29  go mod edit -replace rsc.io/quote@v1.1.0-doesnotexist=./quote
    30  ! go list rsc.io/quote
    31  stderr '^module rsc.io/quote provides package rsc.io/quote and is replaced but not required; to add it:\n\tgo get rsc.io/quote@v1.1.0-doesnotexist$'
    32  
    33  -- go.mod --
    34  module m
    35  
    36  go 1.16
    37  -- go.mod.latest --
    38  module m
    39  
    40  go 1.16
    41  
    42  replace rsc.io/quote => ./quote
    43  
    44  require rsc.io/quote v1.5.2 // indirect
    45  -- go.mod.specific --
    46  module m
    47  
    48  go 1.16
    49  
    50  replace rsc.io/quote v1.0.0-doesnotexist => ./quote
    51  
    52  require rsc.io/quote v1.0.0-doesnotexist // indirect
    53  -- use.go --
    54  package use
    55  
    56  import _ "rsc.io/quote"
    57  -- quote/go.mod --
    58  module rsc.io/quote
    59  
    60  go 1.16
    61  -- quote/quote.go --
    62  package quote
    63  

View as plain text