...

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

Documentation: cmd/go/testdata/script

     1# Regression test for 'go install' locations in GOPATH mode.
     2env GO111MODULE=off
     3[short] skip
     4
     5# Without $GOBIN set, binaries should be installed into the GOPATH bin directory.
     6env GOBIN=
     7rm $GOPATH/bin/go-cmd-test$GOEXE
     8go install go-cmd-test
     9exists $GOPATH/bin/go-cmd-test$GOEXE
    10
    11# With $GOBIN set, binaries should be installed to $GOBIN.
    12env GOBIN=$WORK/bin1
    13mkdir -p $GOBIN
    14go install go-cmd-test
    15exists $GOBIN/go-cmd-test$GOEXE
    16
    17# Issue 11065: installing to the current directory should create an executable.
    18cd go-cmd-test
    19env GOBIN=$PWD
    20go install
    21exists ./go-cmd-test$GOEXE
    22cd ..
    23
    24# Without $GOBIN set, installing a program outside $GOPATH should fail
    25# (there is nowhere to install it).
    26env GOPATH= # reset to default ($HOME/go, which does not exist)
    27env GOBIN=
    28! go install go-cmd-test/helloworld.go
    29stderr '^go: no install location for \.go files listed on command line \(GOBIN not set\)$'
    30
    31# With $GOBIN set, should install there.
    32env GOBIN=$WORK/bin1
    33go install go-cmd-test/helloworld.go
    34exists $GOBIN/helloworld$GOEXE
    35
    36# We can't assume that we can write to GOROOT, because it may not be writable.
    37# However, we can check its install location using 'go list'.
    38# cmd/fix should be installed to GOROOT/pkg, not GOPATH/bin.
    39env GOPATH=$PWD
    40go list -f '{{.Target}}' cmd/fix
    41stdout $GOROOT'[/\\]pkg[/\\]tool[/\\]'$GOOS'_'$GOARCH'[/\\]fix'$GOEXE'$'
    42
    43# GOBIN should not affect toolchain install locations.
    44env GOBIN=$WORK/bin1
    45go list -f '{{.Target}}' cmd/fix
    46stdout $GOROOT'[/\\]pkg[/\\]tool[/\\]'$GOOS'_'$GOARCH'[/\\]fix'$GOEXE'$'
    47
    48-- go-cmd-test/helloworld.go --
    49package main
    50
    51func main() {
    52	println("hello world")
    53}

View as plain text