Black Lives Matter. Support the Equal Justice Initiative.

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

Documentation: cmd/go/testdata/script

     1  # Tests the behavior of the -modfile flag in commands that support it.
     2  # The go.mod file exists but should not be read or written.
     3  # Same with go.sum.
     4  
     5  env GOFLAGS=-modfile=go.alt.mod
     6  cp go.mod go.mod.orig
     7  cp go.sum go.sum.orig
     8  
     9  
    10  # go mod init should create a new file, even though go.mod already exists.
    11  go mod init example.com/m
    12  grep example.com/m go.alt.mod
    13  
    14  # 'go env GOMOD' should print the path to the real file.
    15  # 'go env' does not recognize the '-modfile' flag.
    16  go env GOMOD
    17  stdout '^\$WORK[/\\]gopath[/\\]src[/\\]go.mod$'
    18  
    19  # 'go list -m' should print the effective go.mod file as GoMod though.
    20  go list -m -f '{{.GoMod}}'
    21  stdout '^go.alt.mod$'
    22  
    23  # go mod edit should operate on the alternate file
    24  go mod edit -require rsc.io/quote@v1.5.2
    25  grep rsc.io/quote go.alt.mod
    26  
    27  # other 'go mod' commands should work. 'go mod vendor' is tested later.
    28  go mod download rsc.io/quote
    29  go mod graph
    30  stdout rsc.io/quote
    31  go mod tidy
    32  grep rsc.io/quote go.alt.sum
    33  go mod verify
    34  go mod why rsc.io/quote
    35  
    36  
    37  # 'go list' and other commands with build flags should work.
    38  # They should update the alternate go.mod when a dependency is missing.
    39  go mod edit -droprequire rsc.io/quote
    40  go list -mod=mod .
    41  grep rsc.io/quote go.alt.mod
    42  go build -n -mod=mod .
    43  go test -n -mod=mod .
    44  go get -d rsc.io/quote
    45  
    46  
    47  # 'go mod vendor' should work.
    48  go mod vendor
    49  exists vendor
    50  
    51  # Automatic vendoring should be broken by editing an explicit requirement
    52  # in the alternate go.mod file.
    53  go mod edit -require rsc.io/quote@v1.5.1
    54  ! go list .
    55  go list -mod=mod
    56  rm vendor
    57  
    58  
    59  # 'go generate' should use the alternate file when resolving packages.
    60  # Recursive go commands started with 'go generate' should not get an explicitly
    61  # passed -modfile, but they should see arguments from GOFLAGS.
    62  cp go.alt.mod go.gen.mod
    63  env OLD_GOFLAGS=$GOFLAGS
    64  env GOFLAGS=-modfile=go.gen.mod
    65  go generate -modfile=go.alt.mod .
    66  env GOFLAGS=$OLD_GOFLAGS
    67  grep example.com/exclude go.gen.mod
    68  ! grep example.com/exclude go.alt.mod
    69  
    70  
    71  # The original files should not have been modified.
    72  cmp go.mod go.mod.orig
    73  cmp go.sum go.sum.orig
    74  
    75  
    76  # If the altnernate mod file does not have a ".mod" suffix, an error
    77  # should be reported.
    78  cp go.alt.mod goaltmod
    79  ! go mod tidy -modfile=goaltmod
    80  stderr '-modfile=goaltmod: file does not have .mod extension'
    81  
    82  -- go.mod --
    83  ʕ◔ϖ◔ʔ
    84  -- go.sum --
    85  ʕ◔ϖ◔ʔ
    86  -- use.go --
    87  package main
    88  
    89  import _ "rsc.io/quote"
    90  -- gen.go --
    91  //go:generate go mod edit -exclude example.com/exclude@v1.0.0
    92  
    93  package main
    94  

View as plain text