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