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

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

View as plain text