...
1[short] skip 'builds and runs go programs'
2[!symlink] skip 'uses symlinks to construct a GOROOT'
3
4env NEWGOROOT=$WORK${/}goroot
5env TOOLDIR=$GOROOT/pkg/tool/${GOOS}_${GOARCH}
6# Use ${/} in paths we'll check for in stdout below, so they contain '\' on Windows
7env NEWTOOLDIR=$NEWGOROOT${/}pkg${/}tool${/}${GOOS}_${GOARCH}
8mkdir $NEWGOROOT $NEWGOROOT/bin $NEWTOOLDIR
9[symlink] symlink $NEWGOROOT/src -> $GOROOT/src
10[symlink] symlink $NEWGOROOT/pkg/include -> $GOROOT/pkg/include
11[symlink] symlink $NEWGOROOT/bin/go -> $GOROOT/bin/go
12[symlink] symlink $NEWTOOLDIR/compile$GOEXE -> $TOOLDIR/compile$GOEXE
13[symlink] symlink $NEWTOOLDIR/cgo$GOEXE -> $TOOLDIR/cgo$GOEXE
14[symlink] symlink $NEWTOOLDIR/link$GOEXE -> $TOOLDIR/link$GOEXE
15[symlink] symlink $NEWTOOLDIR/asm$GOEXE -> $TOOLDIR/asm$GOEXE
16[symlink] symlink $NEWTOOLDIR/pack$GOEXE -> $TOOLDIR/pack$GOEXE
17env GOROOT=$NEWGOROOT
18env TOOLDIR=$NEWTOOLDIR
19
20# GOROOT without test2json tool builds and runs it as needed
21go env GOROOT
22! exists $TOOLDIR/test2json
23go tool test2json
24stdout '{"Action":"start"}'
25! exists $TOOLDIR/test2json$GOEXE
26go tool -n test2json
27! stdout $NEWTOOLDIR${/}test2json$GOEXE
28
29# GOROOT with test2json uses the test2json in the GOROOT
30go install cmd/test2json
31exists $TOOLDIR/test2json$GOEXE
32go tool test2json
33stdout '{"Action":"start"}'
34go tool -n test2json
35stdout $NEWTOOLDIR${/}test2json$GOEXE
36
37# Tool still runs properly even with wrong GOOS/GOARCH
38# Remove test2json from tooldir
39rm $TOOLDIR/test2json$GOEXE
40go tool -n test2json
41! stdout $NEWTOOLDIR${/}test2json$GOEXE
42# Set GOOS/GOARCH to different values than host GOOS/GOARCH.
43env GOOS=windows
44[GOOS:windows] env GOOS=linux
45env GOARCH=arm64
46[GOARCH:arm64] env GOARCH=amd64
47# Control case: go run shouldn't work because it respects
48# GOOS/GOARCH, and we can't execute non-native binary.
49! go run cmd/test2json -exec=''
50# But go tool should because it doesn't respect GOOS/GOARCH.
51go tool test2json
52stdout '{"Action":"start"}'
View as plain text