github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/testdata/script/mod_readonly.txt (about)

     1  env GO111MODULE=on
     2  [short] skip
     3  
     4  # -mod=readonly must not resolve missing modules nor update go.mod
     5  env GOFLAGS=-mod=readonly
     6  go mod edit -fmt
     7  cp go.mod go.mod.empty
     8  ! go list all
     9  stderr '^can''t load package: x.go:2:8: cannot find module providing package rsc\.io/quote: import lookup disabled by -mod=readonly'
    10  ! stderr '\(\)' # If we don't have a reason for -mod=readonly, don't log an empty one.
    11  cmp go.mod go.mod.empty
    12  
    13  # -mod=readonly should be set implicitly if the go.mod file is read-only
    14  chmod 0400 go.mod
    15  env GOFLAGS=
    16  ! go list all
    17  stderr '^can''t load package: x.go:2:8: cannot find module providing package rsc\.io/quote: import lookup disabled by -mod=readonly\n\t\(go.mod file is read-only\.\)$'
    18  
    19  chmod 0600 go.mod
    20  env GOFLAGS=-mod=readonly
    21  
    22  # update go.mod - go get allowed
    23  go get rsc.io/quote
    24  grep rsc.io/quote go.mod
    25  
    26  # update go.mod - go mod tidy allowed
    27  cp go.mod.empty go.mod
    28  go mod tidy
    29  cp go.mod go.mod.tidy
    30  
    31  # -mod=readonly must succeed once go.mod is up-to-date...
    32  go list all
    33  
    34  # ... even if it needs downloads
    35  go clean -modcache
    36  go list all
    37  
    38  # -mod=readonly must not cause 'go list -m' to fail.
    39  # (golang.org/issue/36478)
    40  go list -m all
    41  ! stderr 'cannot query module'
    42  
    43  # -mod=readonly should reject inconsistent go.mod files
    44  # (ones that would be rewritten).
    45  go mod edit -require rsc.io/sampler@v1.2.0
    46  cp go.mod go.mod.inconsistent
    47  ! go list
    48  stderr 'go: updates to go.mod needed, disabled by -mod=readonly'
    49  cmp go.mod go.mod.inconsistent
    50  
    51  # However, it should not reject files missing a 'go' directive,
    52  # since that was not always required.
    53  cp go.mod.nogo go.mod
    54  go list all
    55  
    56  # Nor should it reject files with redundant (not incorrect)
    57  # requirements.
    58  cp go.mod.redundant go.mod
    59  go list all
    60  
    61  cp go.mod.indirect go.mod
    62  go list all
    63  
    64  -- go.mod --
    65  module m
    66  
    67  go 1.20
    68  
    69  -- x.go --
    70  package x
    71  import _ "rsc.io/quote"
    72  -- go.mod.nogo --
    73  module m
    74  
    75  require (
    76  	rsc.io/quote v1.5.2
    77  	rsc.io/testonly v1.0.0 // indirect
    78  )
    79  -- go.mod.redundant --
    80  module m
    81  
    82  go 1.20
    83  
    84  require (
    85  	rsc.io/quote v1.5.2
    86  	rsc.io/sampler v1.3.0 // indirect
    87  	rsc.io/testonly v1.0.0 // indirect
    88  )
    89  -- go.mod.indirect --
    90  module m
    91  
    92  go 1.20
    93  
    94  require (
    95  	rsc.io/quote v1.5.2 // indirect
    96  	rsc.io/sampler v1.3.0 // indirect
    97  	rsc.io/testonly v1.0.0 // indirect
    98  )