...

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

Documentation: cmd/go/testdata/script

     1# Regression test for golang.org/issue/34822: the 'go' command should prefer not
     2# to update the go.mod file if the changes only affect formatting, and should only
     3# remove redundant requirements in 'go mod tidy'.
     4
     5env GO111MODULE=on
     6[short] skip
     7
     8# Control case: verify that go.mod.tidy is actually tidy.
     9cp go.mod.tidy go.mod
    10go list -mod=mod all
    11cmp go.mod go.mod.tidy
    12
    13
    14# If the only difference in the go.mod file is the line endings,
    15# it should not be overwritten automatically.
    16cp go.mod.crlf go.mod
    17go list all
    18cmp go.mod go.mod.crlf
    19
    20# However, 'go mod tidy' should fix whitespace even if there are no other changes.
    21go mod tidy
    22cmp go.mod go.mod.tidy
    23
    24
    25# Out-of-order requirements should not be overwritten automatically...
    26cp go.mod.unsorted go.mod
    27go list all
    28cmp go.mod go.mod.unsorted
    29
    30# ...but 'go mod edit -fmt' should sort them.
    31go mod edit -fmt
    32cmp go.mod go.mod.tidy
    33
    34
    35# "// indirect" comments should be removed if direct dependencies are seen.
    36# changes.
    37cp go.mod.indirect go.mod
    38go list -mod=mod all
    39cmp go.mod go.mod.tidy
    40
    41# "// indirect" comments should be added if appropriate.
    42# TODO(#42504): add case for 'go list -mod=mod -tags=any all' when -tags=any
    43# is supported. Only a command that loads "all" without build constraints
    44# (except "ignore") has enough information to add "// indirect" comments.
    45# 'go mod tidy' and 'go mod vendor' are the only commands that do that,
    46# but 'go mod vendor' cannot write go.mod.
    47cp go.mod.toodirect go.mod
    48go list all
    49cmp go.mod go.mod.toodirect
    50
    51
    52# Redundant requirements should be preserved...
    53cp go.mod.redundant go.mod
    54go list all
    55cmp go.mod go.mod.redundant
    56go mod vendor
    57cmp go.mod go.mod.redundant
    58rm -r vendor
    59
    60# ...except by 'go mod tidy'.
    61go mod tidy
    62cmp go.mod go.mod.tidy
    63
    64
    65# A missing "go" version directive should be added.
    66# However, that should not remove other redundant requirements.
    67# In fact, it may *add* redundant requirements due to activating lazy loading.
    68cp go.mod.nogo go.mod
    69go list -mod=mod all
    70cmpenv go.mod go.mod.addedgo
    71
    72
    73-- go.mod.tidy --
    74module m
    75
    76go 1.14
    77
    78require (
    79	rsc.io/quote v1.5.2
    80	rsc.io/testonly v1.0.0 // indirect
    81)
    82-- x.go --
    83package x
    84import _ "rsc.io/quote"
    85-- go.mod.crlf --
    86module m
    87
    88go 1.14
    89
    90require (
    91	rsc.io/quote v1.5.2
    92	rsc.io/testonly v1.0.0 // indirect
    93)
    94-- go.mod.unsorted --
    95module m
    96
    97go 1.14
    98
    99require (
   100	rsc.io/testonly v1.0.0 // indirect
   101	rsc.io/quote v1.5.2
   102)
   103-- go.mod.indirect --
   104module m
   105
   106go 1.14
   107
   108require (
   109	rsc.io/quote v1.5.2 // indirect
   110	rsc.io/testonly v1.0.0 // indirect
   111)
   112-- go.mod.toodirect --
   113module m
   114
   115go 1.14
   116
   117require (
   118	rsc.io/quote v1.5.2
   119	rsc.io/testonly v1.0.0
   120)
   121-- go.mod.redundant --
   122module m
   123
   124go 1.14
   125
   126require (
   127	rsc.io/quote v1.5.2
   128	rsc.io/sampler v1.3.0 // indirect
   129	rsc.io/testonly v1.0.0 // indirect
   130)
   131-- go.mod.nogo --
   132module m
   133
   134require (
   135	rsc.io/quote v1.5.2
   136	rsc.io/sampler v1.3.0 // indirect
   137	rsc.io/testonly v1.0.0 // indirect
   138)
   139-- go.mod.addedgo --
   140module m
   141
   142go $goversion
   143
   144require rsc.io/quote v1.5.2
   145
   146require (
   147	golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
   148	rsc.io/sampler v1.3.0 // indirect
   149	rsc.io/testonly v1.0.0 // indirect
   150)

View as plain text