1
0
mirror of https://github.com/golang/go synced 2024-11-12 07:40:23 -07:00

gotest: fix a bug in error handling.

If the command couldn't be found, argv[0] would be wiped.
Also, fix a print statement not to refer to make - it was a vestige of a prior form.

R=rsc, gri
CC=golang-dev
https://golang.org/cl/4360048
This commit is contained in:
Rob Pike 2011-04-05 12:51:10 -07:00
parent 906b2e7679
commit 88a8ac08b9

View File

@ -254,7 +254,8 @@ func doRun(argv []string, returnStdout bool) string {
if xFlag {
fmt.Printf("gotest: %s\n", strings.Join(argv, " "))
}
if runtime.GOOS == "windows" && argv[0] == "gomake" {
command := argv[0]
if runtime.GOOS == "windows" && command == "gomake" {
// gomake is a shell script and it cannot be executed directly on Windows.
cmd := ""
for i, v := range argv {
@ -266,9 +267,9 @@ func doRun(argv []string, returnStdout bool) string {
argv = []string{"cmd", "/c", "sh", "-c", cmd}
}
var err os.Error
argv[0], err = exec.LookPath(argv[0])
argv[0], err = exec.LookPath(command)
if err != nil {
Fatalf("can't find %s: %s", argv[0], err)
Fatalf("can't find %s: %s", command, err)
}
procAttr := &os.ProcAttr{
Env: env,
@ -288,7 +289,7 @@ func doRun(argv []string, returnStdout bool) string {
}
proc, err := os.StartProcess(argv[0], argv, procAttr)
if err != nil {
Fatalf("make failed to start: %s", err)
Fatalf("%s failed to start: %s", command, err)
}
if returnStdout {
defer r.Close()
@ -296,7 +297,7 @@ func doRun(argv []string, returnStdout bool) string {
}
waitMsg, err := proc.Wait(0)
if err != nil || waitMsg == nil {
Fatalf("%s failed: %s", argv[0], err)
Fatalf("%s failed: %s", command, err)
}
if !waitMsg.Exited() || waitMsg.ExitStatus() != 0 {
Fatalf("%q failed: %s", strings.Join(argv, " "), waitMsg)