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

View as plain text