...

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

Documentation: cmd/go/testdata/script

     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
     5go tool bar
     6stdout 'my name is: bar'$GOEXE
     7! stdout 'a.out'
     8
     9# Second run: executable is cached. Make sure it
    10# has the right name.
    11go tool bar
    12stdout 'my name is: bar'$GOEXE
    13! stdout 'a.out'
    14
    15# Third run: with arguments
    16# https://go.dev/issue/70509
    17go tool bar --baz
    18stdout '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
    26stderr 'go: no such tool "v2"'
    27
    28# Use the second to last component as the short
    29# name of the tool.
    30go tool foo
    31stdout '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.
    37env GOCACHE=$WORK/cache2
    38go run example.com/foo/v2
    39stdout 'my name is: foo'$GOEXE
    40
    41# list aliases for tools
    42go tool
    43stdout '^bar \(example.com/foo/bar\)$'
    44! stdout '^example.com/foo/bar$'
    45stdout '^foo \(example.com/foo/v2\)$'
    46! stdout '^example.com/foo/v2$'
    47stdout '^example.com/foo/noalias$'
    48! stdout '^noalias \(example.com/foo/noalias\)$'
    49stdout '^example.com/foo/noalias/noalias$'
    50! stdout '^noalias \(example.com/foo/noalias\)$'
    51-- go.mod --
    52module example.com/foo
    53
    54go 1.24
    55
    56tool example.com/foo/bar
    57tool example.com/foo/v2
    58tool example.com/foo/noalias
    59tool example.com/foo/noalias/noalias
    60
    61require example.com/foo/v2 v2.0.0
    62
    63replace example.com/foo/v2 => ./v2
    64-- bar/bar.go --
    65package main
    66
    67import (
    68	"fmt"
    69	"os"
    70	"path/filepath"
    71)
    72
    73func main() {
    74	fmt.Println("my name is:", filepath.Base(os.Args[0]))
    75}
    76-- v2/go.mod --
    77module example.com/foo/v2
    78
    79go 1.24
    80-- v2/main.go --
    81package main
    82
    83import (
    84	"fmt"
    85	"os"
    86	"path/filepath"
    87)
    88
    89func main() {
    90	fmt.Println("my name is:", filepath.Base(os.Args[0]))
    91}
    92
    93-- noalias/noalias.go --
    94package main
    95
    96func main() {}
    97-- noalias/noalias/noalias.go --
    98pagckage main
    99func main() {}

View as plain text