...

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! go version -json
    12stderr 'with arguments'
    13
    14# Check that 'go version' succeed even when it does not contain Go build info.
    15# It should print an error if the file has a known Go binary extension.
    16#
    17go version empty.txt
    18! stdout .
    19! stderr .
    20go version empty.exe
    21stderr 'could not read Go build info'
    22go version empty.so
    23stderr 'could not read Go build info'
    24go version empty.dll
    25stderr 'could not read Go build info'
    26
    27# Neither of the three flags above should be an issue via GOFLAGS.
    28env GOFLAGS='-m -v -json'
    29go version
    30stdout '^go version'
    31env GOFLAGS=
    32
    33env GO111MODULE=on
    34
    35# Check that very basic version lookup succeeds.
    36go build empty.go
    37go version empty$GOEXE
    38[cgo] go build -ldflags=-linkmode=external empty.go
    39[cgo] go version empty$GOEXE
    40
    41# Skip the remaining builds if we are running in short mode.
    42[short] skip
    43
    44# Check that 'go version' and 'go version -m' work on a binary built in module mode.
    45go get rsc.io/fortune
    46go build -o fortune.exe rsc.io/fortune
    47go version fortune.exe
    48stdout '^fortune.exe: .+'
    49go version -m fortune.exe
    50stdout -buildmode=exe
    51stdout '^\tpath\trsc.io/fortune'
    52stdout '^\tmod\trsc.io/fortune\tv1.0.0'
    53
    54# Check the build info of a binary built from $GOROOT/src/cmd
    55go build -o test2json.exe cmd/test2json
    56go version -m test2json.exe
    57stdout -buildmode=exe
    58stdout '^test2json.exe: .+'
    59stdout '^\tpath\tcmd/test2json$'
    60! stdout 'mod[^e]'
    61
    62# Check -json flag
    63go build -o test2json.exe cmd/test2json
    64go version -m -json test2json.exe
    65stdout '"Path": "cmd/test2json"'
    66! stdout 'null'
    67
    68# Check -json flag output with multiple binaries
    69go build -o test2json.exe cmd/test2json
    70go version -m -json test2json.exe test2json.exe
    71stdout -count=2 '"Path": "cmd/test2json"'
    72
    73# Check -json flag without -m
    74go build -o test2json.exe cmd/test2json
    75! go version -json test2json.exe
    76! stdout '"Path": "cmd/test2json"'
    77stderr 'with -json flag requires -m flag'
    78
    79# Repeat the test with -buildmode=pie and default linking.
    80[!buildmode:pie] stop
    81[pielinkext] [!cgo] stop
    82go build -buildmode=pie -o external.exe rsc.io/fortune
    83go version external.exe
    84stdout '^external.exe: .+'
    85go version -m external.exe
    86stdout -buildmode=pie
    87stdout '^\tpath\trsc.io/fortune'
    88stdout '^\tmod\trsc.io/fortune\tv1.0.0'
    89
    90# Also test PIE with internal linking.
    91[pielinkext] stop
    92go build -buildmode=pie -ldflags=-linkmode=internal -o internal.exe rsc.io/fortune
    93go version internal.exe
    94stdout '^internal.exe: .+'
    95go version -m internal.exe
    96stdout -buildmode=pie
    97stdout '^\tpath\trsc.io/fortune'
    98stdout '^\tmod\trsc.io/fortune\tv1.0.0'
    99
   100-- go.mod --
   101module m
   102
   103-- empty.go --
   104package main
   105func main(){}
   106
   107-- empty.txt --
   108-- empty.exe --
   109-- empty.so --
   110-- empty.dll --

View as plain text