...

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-- go.mod --
    42module example.com/foo
    43
    44go 1.24
    45
    46tool example.com/foo/bar
    47tool example.com/foo/v2
    48
    49require example.com/foo/v2 v2.0.0
    50
    51replace example.com/foo/v2 => ./v2
    52-- bar/bar.go --
    53package main
    54
    55import (
    56	"fmt"
    57	"os"
    58	"path/filepath"
    59)
    60
    61func main() {
    62	fmt.Println("my name is:", filepath.Base(os.Args[0]))
    63}
    64-- v2/go.mod --
    65module example.com/foo/v2
    66
    67go 1.24
    68-- v2/main.go --
    69package main
    70
    71import (
    72	"fmt"
    73	"os"
    74	"path/filepath"
    75)
    76
    77func main() {
    78	fmt.Println("my name is:", filepath.Base(os.Args[0]))
    79}

View as plain text