...

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 and default linking.
    61[!buildmode:pie] stop
    62[pielinkext] [!cgo] stop
    63go build -buildmode=pie -o external.exe rsc.io/fortune
    64go version external.exe
    65stdout '^external.exe: .+'
    66go version -m external.exe
    67stdout -buildmode=pie
    68stdout '^\tpath\trsc.io/fortune'
    69stdout '^\tmod\trsc.io/fortune\tv1.0.0'
    70
    71# Also test PIE with internal linking.
    72[pielinkext] stop
    73go build -buildmode=pie -ldflags=-linkmode=internal -o internal.exe rsc.io/fortune
    74go version internal.exe
    75stdout '^internal.exe: .+'
    76go version -m internal.exe
    77stdout -buildmode=pie
    78stdout '^\tpath\trsc.io/fortune'
    79stdout '^\tmod\trsc.io/fortune\tv1.0.0'
    80
    81-- go.mod --
    82module m
    83
    84-- empty.go --
    85package main
    86func main(){}
    87
    88-- empty.txt --
    89-- empty.exe --
    90-- empty.so --
    91-- empty.dll --

View as plain text