...

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

Documentation: cmd/go/testdata/script

     1# https://go.dev/issue/68005: 'go run' should run the program with its own GOROOT/bin
     2# at the beginning of $PATH.
     3
     4[short] skip
     5
     6[!GOOS:plan9] env PATH=
     7[GOOS:plan9] env path=
     8go run .
     9
    10[!GOOS:plan9] env PATH=$WORK${/}bin
    11[GOOS:plan9] env path=$WORK${/}bin
    12go run .
    13
    14-- go.mod --
    15module example
    16
    17go 1.19
    18-- main.go --
    19package main
    20
    21import (
    22	"fmt"
    23	"os"
    24	"os/exec"
    25	"path/filepath"
    26)
    27
    28func main() {
    29	got, err := exec.LookPath("go")
    30	if err != nil {
    31		fmt.Println(err)
    32		os.Exit(1)
    33	}
    34
    35	want := filepath.Join(os.Getenv("GOROOT"), "bin", "go" + os.Getenv("GOEXE"))
    36	if got != want {
    37		fmt.Printf(`exec.LookPath("go") = %q; want %q\n`, got, want)
    38		os.Exit(1)
    39	}
    40}
    41-- $WORK/bin/README.txt --
    42This directory contains no executables.

View as plain text