...
1[!GOOS:windows] [short] stop 'this test only applies to Windows'
2env GO111MODULE=off
3
4go build run_go.go
5exec ./run_go$GOEXE $GOPATH $GOPATH/src/vend/hello
6stdout 'hello, world'
7
8-- run_go.go --
9package main
10
11import (
12 "fmt"
13 "os"
14 "os/exec"
15 "path/filepath"
16 "strings"
17)
18
19func changeVolume(s string, f func(s string) string) string {
20 vol := filepath.VolumeName(s)
21 return f(vol) + s[len(vol):]
22}
23
24func main() {
25 gopath := changeVolume(os.Args[1], strings.ToLower)
26 dir := changeVolume(os.Args[2], strings.ToUpper)
27 cmd := exec.Command("go", "run", "hello.go")
28 cmd.Dir = dir
29 cmd.Env = append(os.Environ(), "GOPATH="+gopath)
30 cmd.Stdout = os.Stdout
31 cmd.Stderr = os.Stderr
32 if err := cmd.Run(); err != nil {
33 fmt.Fprintln(os.Stderr, err)
34 os.Exit(1)
35 }
36}
37
38-- vend/hello/hello.go --
39package main
40
41import (
42 "fmt"
43 "strings" // really ../vendor/strings
44)
45
46func main() {
47 fmt.Printf("%s\n", strings.Msg)
48}
49-- vend/vendor/strings/msg.go --
50package strings
51
52var Msg = "hello, world"
View as plain text