...

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

Documentation: cmd/go/testdata/script

     1# Without arguments, we just print Go's own version.
     2go version
     3stdout '^go version'
     4
     5# Flags without files, or paths to missing files, should error.
     6! go version missing.exe
     7! go version -m
     8stderr 'with arguments'
     9! go version -v
    10stderr 'with arguments'
    11
    12# Check that 'go version' succeed even when it does not contain Go build info.
    13# It should print an error if the file has a known Go binary extension.
    14#
    15go version empty.txt
    16! stdout .
    17! stderr .
    18go version empty.exe
    19stderr 'could not read Go build info'
    20go version empty.so
    21stderr 'could not read Go build info'
    22go version empty.dll
    23stderr 'could not read Go build info'
    24
    25# Neither of the two flags above should be an issue via GOFLAGS.
    26env GOFLAGS='-m -v'
    27go version
    28stdout '^go version'
    29env GOFLAGS=
    30
    31env GO111MODULE=on
    32
    33# Check that very basic version lookup succeeds.
    34go build empty.go
    35go version empty$GOEXE
    36[cgo] go build -ldflags=-linkmode=external empty.go
    37[cgo] go version empty$GOEXE
    38
    39# Skip the remaining builds if we are running in short mode.
    40[short] skip
    41
    42# Check that 'go version' and 'go version -m' work on a binary built in module mode.
    43go get rsc.io/fortune
    44go build -o fortune.exe rsc.io/fortune
    45go version fortune.exe
    46stdout '^fortune.exe: .+'
    47go version -m fortune.exe
    48stdout -buildmode=exe
    49stdout '^\tpath\trsc.io/fortune'
    50stdout '^\tmod\trsc.io/fortune\tv1.0.0'
    51
    52# Check the build info of a binary built from $GOROOT/src/cmd
    53go build -o test2json.exe cmd/test2json
    54go version -m test2json.exe
    55stdout -buildmode=exe
    56stdout '^test2json.exe: .+'
    57stdout '^\tpath\tcmd/test2json$'
    58! stdout 'mod[^e]'
    59
    60# Repeat the test with -buildmode=pie.
    61[!buildmode:pie] stop
    62go build -buildmode=pie -o external.exe rsc.io/fortune
    63go version external.exe
    64stdout '^external.exe: .+'
    65go version -m external.exe
    66stdout -buildmode=pie
    67stdout '^\tpath\trsc.io/fortune'
    68stdout '^\tmod\trsc.io/fortune\tv1.0.0'
    69
    70# Also test PIE with internal linking.
    71# currently only supported on linux/amd64, linux/arm64 and windows/amd64.
    72[!GOOS:linux] [!GOOS:windows] stop
    73[!GOARCH:amd64] [!GOARCH:arm64] stop
    74go build -buildmode=pie -ldflags=-linkmode=internal -o internal.exe rsc.io/fortune
    75go version internal.exe
    76stdout '^internal.exe: .+'
    77go version -m internal.exe
    78stdout -buildmode=pie
    79stdout '^\tpath\trsc.io/fortune'
    80stdout '^\tmod\trsc.io/fortune\tv1.0.0'
    81
    82-- go.mod --
    83module m
    84
    85-- empty.go --
    86package main
    87func main(){}
    88
    89-- empty.txt --
    90-- empty.exe --
    91-- empty.so --
    92-- empty.dll --

View as plain text