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

View as plain text