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

     1  [short] skip 'runs go build'
     2  
     3  # First run: executable for bar is not cached.
     4  # Make sure it's not called a.out
     5  go tool bar
     6  stdout 'my name is: bar'$GOEXE
     7  ! stdout 'a.out'
     8  
     9  # Second run: executable is cached. Make sure it
    10  # has the right name.
    11  go tool bar
    12  stdout 'my name is: bar'$GOEXE
    13  ! stdout 'a.out'
    14  
    15  # Third run: with arguments
    16  # https://go.dev/issue/70509
    17  go tool bar --baz
    18  stdout 'my name is: bar'$GOEXE
    19  ! stdout 'a.out'
    20  
    21  # Test tool package paths that end in v2
    22  # to ensure we use the second to last component.
    23  
    24  # Don't use v2 as the short name of the tool.
    25  ! go tool v2
    26  stderr 'go: no such tool "v2"'
    27  
    28  # Use the second to last component as the short
    29  # name of the tool.
    30  go tool foo
    31  stdout 'my name is: foo'$GOEXE
    32  
    33  # go run should use the same name for the tool
    34  # We need to use a fresh cache, or we'd end up with an executable cache hit
    35  # from when we ran built the tool to run go tool above, and we'd just
    36  # reuse the name from the test case above.
    37  env GOCACHE=$WORK/cache2
    38  go run example.com/foo/v2
    39  stdout 'my name is: foo'$GOEXE
    40  
    41  -- go.mod --
    42  module example.com/foo
    43  
    44  go 1.24
    45  
    46  tool example.com/foo/bar
    47  tool example.com/foo/v2
    48  
    49  require example.com/foo/v2 v2.0.0
    50  
    51  replace example.com/foo/v2 => ./v2
    52  -- bar/bar.go --
    53  package main
    54  
    55  import (
    56  	"fmt"
    57  	"os"
    58  	"path/filepath"
    59  )
    60  
    61  func main() {
    62  	fmt.Println("my name is:", filepath.Base(os.Args[0]))
    63  }
    64  -- v2/go.mod --
    65  module example.com/foo/v2
    66  
    67  go 1.24
    68  -- v2/main.go --
    69  package main
    70  
    71  import (
    72  	"fmt"
    73  	"os"
    74  	"path/filepath"
    75  )
    76  
    77  func main() {
    78  	fmt.Println("my name is:", filepath.Base(os.Args[0]))
    79  }
    80  

View as plain text