Black Lives Matter. Support the Equal Justice Initiative.

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

Documentation: cmd/go/testdata/script

     1  # 'go install pkg@version' works outside a module.
     2  env GO111MODULE=auto
     3  go install example.com/cmd/a@v1.0.0
     4  exists $GOPATH/bin/a$GOEXE
     5  rm $GOPATH/bin
     6  
     7  
     8  # 'go install pkg@version' reports an error if modules are disabled.
     9  env GO111MODULE=off
    10  ! go install example.com/cmd/a@v1.0.0
    11  stderr '^go: modules disabled by GO111MODULE=off; see ''go help modules''$'
    12  env GO111MODULE=auto
    13  
    14  
    15  # 'go install pkg@version' ignores go.mod in current directory.
    16  cd m
    17  cp go.mod go.mod.orig
    18  ! go list -m all
    19  stderr '^go list -m: example.com/cmd@v1.1.0-doesnotexist: missing go.sum entry; to add it:\n\tgo mod download example.com/cmd$'
    20  go install example.com/cmd/a@latest
    21  cmp go.mod go.mod.orig
    22  exists $GOPATH/bin/a$GOEXE
    23  go version -m $GOPATH/bin/a$GOEXE
    24  stdout '^\tmod\texample.com/cmd\tv1.0.0\t' # "latest", not from go.mod
    25  rm $GOPATH/bin/a
    26  cd ..
    27  
    28  
    29  # 'go install -modfile=x.mod pkg@version' reports an error, but only if
    30  # -modfile is specified explicitly on the command line.
    31  cd m
    32  env GOFLAGS=-modfile=go.mod
    33  go install example.com/cmd/a@latest  # same as above
    34  env GOFLAGS=
    35  ! go install -modfile=go.mod example.com/cmd/a@latest
    36  stderr '^go: -modfile cannot be used with commands that ignore the current module$'
    37  cd ..
    38  
    39  
    40  # Every test case requires linking, so we only cover the most important cases
    41  # when -short is set.
    42  [short] stop
    43  
    44  
    45  # 'go install pkg@version' works on a module that doesn't have a go.mod file
    46  # and with a module whose go.mod file has missing requirements.
    47  # With a proxy, the two cases are indistinguishable.
    48  go install rsc.io/fortune@v1.0.0
    49  stderr '^go: found rsc.io/quote in rsc.io/quote v1.5.2$'
    50  exists $GOPATH/bin/fortune$GOEXE
    51  ! exists $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0/go.mod # no go.mod file
    52  go version -m $GOPATH/bin/fortune$GOEXE
    53  stdout '^\tdep\trsc.io/quote\tv1.5.2\t' # latest version of fortune's dependency
    54  rm $GOPATH/bin
    55  
    56  
    57  # 'go install dir@version' works like a normal 'go install' command if
    58  # dir is a relative or absolute path.
    59  env GO111MODULE=on
    60  go mod download rsc.io/fortune@v1.0.0
    61  ! go install $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    62  stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$'
    63  ! go install ../pkg/mod/rsc.io/fortune@v1.0.0
    64  stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$'
    65  mkdir tmp
    66  cd tmp
    67  go mod init tmp
    68  go mod edit -require=rsc.io/fortune@v1.0.0
    69  ! go install -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    70  stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$'
    71  ! go install -mod=readonly ../../pkg/mod/rsc.io/fortune@v1.0.0
    72  stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$'
    73  go get -d rsc.io/fortune@v1.0.0
    74  go install -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    75  exists $GOPATH/bin/fortune$GOEXE
    76  cd ..
    77  rm tmp
    78  rm $GOPATH/bin
    79  env GO111MODULE=auto
    80  
    81  # 'go install pkg@version' reports errors for meta packages, std packages,
    82  # and directories.
    83  ! go install std@v1.0.0
    84  stderr '^go install: std@v1.0.0: argument must be a package path, not a meta-package$'
    85  ! go install fmt@v1.0.0
    86  stderr '^go install: fmt@v1.0.0: argument must not be a package in the standard library$'
    87  ! go install example.com//cmd/a@v1.0.0
    88  stderr '^go install: example.com//cmd/a@v1.0.0: argument must be a clean package path$'
    89  ! go install example.com/cmd/a@v1.0.0 ./x@v1.0.0
    90  stderr '^go install: ./x@v1.0.0: argument must be a package path, not a relative path$'
    91  ! go install example.com/cmd/a@v1.0.0 $GOPATH/src/x@v1.0.0
    92  stderr '^go install: '$WORK'[/\\]gopath/src/x@v1.0.0: argument must be a package path, not an absolute path$'
    93  ! go install example.com/cmd/a@v1.0.0 cmd/...@v1.0.0
    94  stderr '^package cmd/go not provided by module example.com/cmd@v1.0.0$'
    95  
    96  # 'go install pkg@version' should accept multiple arguments but report an error
    97  # if the version suffixes are different, even if they refer to the same version.
    98  go install example.com/cmd/a@v1.0.0 example.com/cmd/b@v1.0.0
    99  exists $GOPATH/bin/a$GOEXE
   100  exists $GOPATH/bin/b$GOEXE
   101  rm $GOPATH/bin
   102  
   103  env GO111MODULE=on
   104  go list -m example.com/cmd@latest
   105  stdout '^example.com/cmd v1.0.0$'
   106  env GO111MODULE=auto
   107  
   108  ! go install example.com/cmd/a@v1.0.0 example.com/cmd/b@latest
   109  stderr '^go install: example.com/cmd/b@latest: all arguments must have the same version \(@v1.0.0\)$'
   110  
   111  
   112  # 'go install pkg@version' should report an error if the arguments are in
   113  # different modules.
   114  ! go install example.com/cmd/a@v1.0.0 rsc.io/fortune@v1.0.0
   115  stderr '^package rsc.io/fortune provided by module rsc.io/fortune@v1.0.0\n\tAll packages must be provided by the same module \(example.com/cmd@v1.0.0\).$'
   116  
   117  
   118  # 'go install pkg@version' should report an error if an argument is not
   119  # a main package.
   120  ! go install example.com/cmd/a@v1.0.0 example.com/cmd/err@v1.0.0
   121  stderr '^package example.com/cmd/err is not a main package$'
   122  
   123  # Wildcards should match only main packages. This module has a non-main package
   124  # with an error, so we'll know if that gets built.
   125  mkdir tmp
   126  cd tmp
   127  go mod init m
   128  go get -d example.com/cmd@v1.0.0
   129  ! go build example.com/cmd/...
   130  stderr 'err[/\\]err.go:3:9: undefined: DoesNotCompile$'
   131  cd ..
   132  
   133  go install example.com/cmd/...@v1.0.0
   134  exists $GOPATH/bin/a$GOEXE
   135  exists $GOPATH/bin/b$GOEXE
   136  rm $GOPATH/bin
   137  
   138  # If a wildcard matches no packages, we should see a warning.
   139  ! go install example.com/cmd/nomatch...@v1.0.0
   140  stderr '^go install: example.com/cmd/nomatch\.\.\.@v1.0.0: module example.com/cmd@v1.0.0 found, but does not contain packages matching example.com/cmd/nomatch\.\.\.$'
   141  go install example.com/cmd/a@v1.0.0 example.com/cmd/nomatch...@v1.0.0
   142  stderr '^go: warning: "example.com/cmd/nomatch\.\.\." matched no packages$'
   143  
   144  # If a wildcard matches only non-main packges, we should see a different warning.
   145  go install example.com/cmd/err...@v1.0.0
   146  stderr '^go: warning: "example.com/cmd/err\.\.\." matched only non-main packages$'
   147  
   148  
   149  # 'go install pkg@version' should report errors if the module contains
   150  # replace or exclude directives.
   151  go mod download example.com/cmd@v1.0.0-replace
   152  ! go install example.com/cmd/a@v1.0.0-replace
   153  cmp stderr replace-err
   154  
   155  go mod download example.com/cmd@v1.0.0-exclude
   156  ! go install example.com/cmd/a@v1.0.0-exclude
   157  cmp stderr exclude-err
   158  
   159  # 'go install pkg@version' should report an error if the module requires a
   160  # higher version of itself.
   161  ! go install example.com/cmd/a@v1.0.0-newerself
   162  stderr '^go install: example.com/cmd/a@v1.0.0-newerself: version constraints conflict:\n\texample.com/cmd@v1.0.0-newerself requires example.com/cmd@v1.0.0, but example.com/cmd@v1.0.0-newerself is requested$'
   163  
   164  
   165  # 'go install pkg@version' will only match a retracted version if it's
   166  # explicitly requested.
   167  env GO111MODULE=on
   168  go list -m -versions example.com/cmd
   169  ! stdout v1.9.0
   170  go list -m -versions -retracted example.com/cmd
   171  stdout v1.9.0
   172  go install example.com/cmd/a@latest
   173  go version -m $GOPATH/bin/a$GOEXE
   174  stdout '^\tmod\texample.com/cmd\tv1.0.0\t'
   175  go install example.com/cmd/a@v1.9.0
   176  go version -m $GOPATH/bin/a$GOEXE
   177  stdout '^\tmod\texample.com/cmd\tv1.9.0\t'
   178  env GO111MODULE=
   179  
   180  # 'go install pkg@version' succeeds when -mod=readonly is set explicitly.
   181  # Verifies #43278.
   182  go install -mod=readonly example.com/cmd/a@v1.0.0
   183  
   184  -- m/go.mod --
   185  module m
   186  
   187  go 1.16
   188  
   189  require example.com/cmd v1.1.0-doesnotexist
   190  -- x/x.go --
   191  package main
   192  
   193  func main() {}
   194  -- replace-err --
   195  go install: example.com/cmd/a@v1.0.0-replace (in example.com/cmd@v1.0.0-replace):
   196  	The go.mod file for the module providing named packages contains one or
   197  	more replace directives. It must not contain directives that would cause
   198  	it to be interpreted differently than if it were the main module.
   199  -- exclude-err --
   200  go install: example.com/cmd/a@v1.0.0-exclude (in example.com/cmd@v1.0.0-exclude):
   201  	The go.mod file for the module providing named packages contains one or
   202  	more exclude directives. It must not contain directives that would cause
   203  	it to be interpreted differently than if it were the main module.
   204  

View as plain text