Source file src/cmd/cover/testdata/toolexec.go
1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // The toolexec program is a helper program for cmd/cover tests. 6 // It is used so that the go tool will call the newly built version 7 // of the cover program, rather than the installed one. 8 // 9 // The tests arrange to run the go tool with the argument 10 // -toolexec="/path/to/toolexec /path/to/testcover" 11 // The go tool will invoke this program (compiled into /path/to/toolexec) 12 // with the arguments shown above followed by the command to run. 13 // This program will check whether it is expected to run the cover 14 // program, and if so replace it with /path/to/testcover. 15 package main 16 17 import ( 18 exec "internal/execabs" 19 "os" 20 "strings" 21 ) 22 23 func main() { 24 if strings.HasSuffix(strings.TrimSuffix(os.Args[2], ".exe"), "cover") { 25 os.Args[2] = os.Args[1] 26 } 27 cmd := exec.Command(os.Args[2], os.Args[3:]...) 28 cmd.Stdout = os.Stdout 29 cmd.Stderr = os.Stderr 30 if err := cmd.Run(); err != nil { 31 os.Exit(1) 32 } 33 } 34