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  
    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  #
    15  go version empty.txt
    16  ! stdout .
    17  ! stderr .
    18  go version empty.exe
    19  stderr 'could not read Go build info'
    20  go version empty.so
    21  stderr 'could not read Go build info'
    22  go version empty.dll
    23  stderr 'could not read Go build info'
    24  
    25  # Neither of the two flags above should be an issue via GOFLAGS.
    26  env GOFLAGS='-m -v'
    27  go version
    28  stdout '^go version'
    29  env GOFLAGS=
    30  
    31  env GO111MODULE=on
    32  
    33  # Check that very basic version lookup succeeds.
    34  go build empty.go
    35  go 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.
    43  go get rsc.io/fortune
    44  go build -o fortune.exe rsc.io/fortune
    45  go version fortune.exe
    46  stdout '^fortune.exe: .+'
    47  go version -m fortune.exe
    48  stdout -buildmode=exe
    49  stdout '^\tpath\trsc.io/fortune'
    50  stdout '^\tmod\trsc.io/fortune\tv1.0.0'
    51  
    52  # Check the build info of a binary built from $GOROOT/src/cmd
    53  go build -o test2json.exe cmd/test2json
    54  go version -m test2json.exe
    55  stdout -buildmode=exe
    56  stdout '^test2json.exe: .+'
    57  stdout '^\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
    63  go build -buildmode=pie -o external.exe rsc.io/fortune
    64  go version external.exe
    65  stdout '^external.exe: .+'
    66  go version -m external.exe
    67  stdout -buildmode=pie
    68  stdout '^\tpath\trsc.io/fortune'
    69  stdout '^\tmod\trsc.io/fortune\tv1.0.0'
    70  
    71  # Also test PIE with internal linking.
    72  [pielinkext] stop
    73  go build -buildmode=pie -ldflags=-linkmode=internal -o internal.exe rsc.io/fortune
    74  go version internal.exe
    75  stdout '^internal.exe: .+'
    76  go version -m internal.exe
    77  stdout -buildmode=pie
    78  stdout '^\tpath\trsc.io/fortune'
    79  stdout '^\tmod\trsc.io/fortune\tv1.0.0'
    80  
    81  -- go.mod --
    82  module m
    83  
    84  -- empty.go --
    85  package main
    86  func main(){}
    87  
    88  -- empty.txt --
    89  -- empty.exe --
    90  -- empty.so --
    91  -- empty.dll --
    92  

View as plain text