...

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.
     2env GO111MODULE=auto
     3go install example.com/cmd/a@v1.0.0
     4exists $GOPATH/bin/a$GOEXE
     5rm $GOPATH/bin
     6
     7
     8# 'go install pkg@version' reports an error if modules are disabled.
     9env GO111MODULE=off
    10! go install example.com/cmd/a@v1.0.0
    11stderr '^go: modules disabled by GO111MODULE=off; see ''go help modules''$'
    12env GO111MODULE=auto
    13
    14
    15# 'go install pkg@version' ignores go.mod in current directory.
    16cd m
    17cp go.mod go.mod.orig
    18! go list -m all
    19stderr '^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$'
    20stderr '^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$'
    21go install example.com/cmd/a@latest
    22cmp go.mod go.mod.orig
    23exists $GOPATH/bin/a$GOEXE
    24go version -m $GOPATH/bin/a$GOEXE
    25stdout '^\tmod\texample.com/cmd\tv1.0.0\t' # "latest", not from go.mod
    26rm $GOPATH/bin/a
    27cd ..
    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.
    32cd m
    33env GOFLAGS=-modfile=go.mod
    34go install example.com/cmd/a@latest  # same as above
    35env GOFLAGS=
    36! go install -modfile=go.mod example.com/cmd/a@latest
    37stderr '^go: -modfile cannot be used with commands that ignore the current module$'
    38cd ..
    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.
    49go install rsc.io/fortune@v1.0.0
    50stderr '^go: found rsc.io/quote in rsc.io/quote v1.5.2$'
    51exists $GOPATH/bin/fortune$GOEXE
    52! exists $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0/go.mod # no go.mod file
    53go version -m $GOPATH/bin/fortune$GOEXE
    54stdout '^\tdep\trsc.io/quote\tv1.5.2\t' # latest version of fortune's dependency
    55rm $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.
    60env GO111MODULE=on
    61go mod download rsc.io/fortune@v1.0.0
    62! go install $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    63stderr '^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
    65stderr '^go: go\.mod file not found in current directory or any parent directory; see ''go help modules''$'
    66mkdir tmp
    67cd tmp
    68go mod init tmp
    69go mod edit -require=rsc.io/fortune@v1.0.0
    70! go install -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    71stderr '^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
    73stderr '^missing go\.sum entry for module providing package rsc\.io/fortune; to add:\n\tgo mod download rsc\.io/fortune$'
    74go get rsc.io/fortune@v1.0.0
    75go install -mod=readonly $GOPATH/pkg/mod/rsc.io/fortune@v1.0.0
    76exists $GOPATH/bin/fortune$GOEXE
    77cd ..
    78rm tmp
    79rm $GOPATH/bin
    80env 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
    85stderr '^go: std@v1.0.0: argument must be a package path, not a meta-package$'
    86! go install fmt@v1.0.0
    87stderr '^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
    89stderr '^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
    91stderr '^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
    93stderr '^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
    95stderr '^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.
    99go install example.com/cmd/a@v1.0.0 example.com/cmd/b@v1.0.0
   100exists $GOPATH/bin/a$GOEXE
   101exists $GOPATH/bin/b$GOEXE
   102rm $GOPATH/bin
   103
   104env GO111MODULE=on
   105go list -m example.com/cmd@latest
   106stdout '^example.com/cmd v1.0.0$'
   107env GO111MODULE=auto
   108
   109! go install example.com/cmd/a@v1.0.0 example.com/cmd/b@latest
   110stderr '^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
   116stderr '^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
   122stderr '^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.
   126mkdir tmp
   127cd tmp
   128go mod init m
   129go get example.com/cmd@v1.0.0
   130! go build example.com/cmd/...
   131stderr 'err[/\\]err.go:3:9: undefined: DoesNotCompile( .*)?$'
   132cd ..
   133
   134go install example.com/cmd/...@v1.0.0
   135exists $GOPATH/bin/a$GOEXE
   136exists $GOPATH/bin/b$GOEXE
   137rm $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
   141stderr '^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\.\.\.$'
   142go install example.com/cmd/a@v1.0.0 example.com/cmd/nomatch...@v1.0.0
   143stderr '^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.
   146go install example.com/cmd/err...@v1.0.0
   147stderr '^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.
   152go mod download example.com/cmd@v1.0.0-replace
   153! go install example.com/cmd/a@v1.0.0-replace
   154cmp stderr replace-err
   155
   156go mod download example.com/cmd@v1.0.0-exclude
   157! go install example.com/cmd/a@v1.0.0-exclude
   158cmp 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
   163stderr '^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.
   168env GO111MODULE=on
   169go list -m -versions example.com/cmd
   170! stdout v1.9.0
   171go list -m -versions -retracted example.com/cmd
   172stdout v1.9.0
   173go install example.com/cmd/a@latest
   174go version -m $GOPATH/bin/a$GOEXE
   175stdout '^\tmod\texample.com/cmd\tv1.0.0\t'
   176go install example.com/cmd/a@v1.9.0
   177go version -m $GOPATH/bin/a$GOEXE
   178stdout '^\tmod\texample.com/cmd\tv1.9.0\t'
   179env GO111MODULE=
   180
   181# 'go install pkg@version' succeeds when -mod=readonly is set explicitly.
   182# Verifies #43278.
   183go install -mod=readonly example.com/cmd/a@v1.0.0
   184
   185-- m/go.mod --
   186module m
   187
   188go 1.16
   189
   190require example.com/cmd v1.1.0-doesnotexist
   191-- x/x.go --
   192package main
   193
   194func main() {}
   195-- replace-err --
   196go: example.com/cmd/a@v1.0.0-replace (in example.com/cmd@v1.0.0-replace):
   197	The go.mod file for the module providing named packages contains one or
   198	more replace directives. It must not contain directives that would cause
   199	it to be interpreted differently than if it were the main module.
   200-- exclude-err --
   201go: example.com/cmd/a@v1.0.0-exclude (in example.com/cmd@v1.0.0-exclude):
   202	The go.mod file for the module providing named packages contains one or
   203	more exclude directives. It must not contain directives that would cause
   204	it to be interpreted differently than if it were the main module.

View as plain text