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

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

View as plain text