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  # list aliases for tools
    42  go tool
    43  stdout '^bar \(example.com/foo/bar\)$'
    44  ! stdout '^example.com/foo/bar$'
    45  stdout '^foo \(example.com/foo/v2\)$'
    46  ! stdout '^example.com/foo/v2$'
    47  stdout '^example.com/foo/noalias$'
    48  ! stdout '^noalias \(example.com/foo/noalias\)$'
    49  stdout '^example.com/foo/noalias/noalias$'
    50  ! stdout '^noalias \(example.com/foo/noalias\)$'
    51  -- go.mod --
    52  module example.com/foo
    53  
    54  go 1.24
    55  
    56  tool example.com/foo/bar
    57  tool example.com/foo/v2
    58  tool example.com/foo/noalias
    59  tool example.com/foo/noalias/noalias
    60  
    61  require example.com/foo/v2 v2.0.0
    62  
    63  replace example.com/foo/v2 => ./v2
    64  -- bar/bar.go --
    65  package main
    66  
    67  import (
    68  	"fmt"
    69  	"os"
    70  	"path/filepath"
    71  )
    72  
    73  func main() {
    74  	fmt.Println("my name is:", filepath.Base(os.Args[0]))
    75  }
    76  -- v2/go.mod --
    77  module example.com/foo/v2
    78  
    79  go 1.24
    80  -- v2/main.go --
    81  package main
    82  
    83  import (
    84  	"fmt"
    85  	"os"
    86  	"path/filepath"
    87  )
    88  
    89  func main() {
    90  	fmt.Println("my name is:", filepath.Base(os.Args[0]))
    91  }
    92  
    93  -- noalias/noalias.go --
    94  package main
    95  
    96  func main() {}
    97  -- noalias/noalias/noalias.go --
    98  pagckage main
    99  func main() {}

View as plain text