1diff --git test/fixedbugs/bug302.go test/fixedbugs/bug302.go 2index c763b87786..470841f676 100644 3--- test/fixedbugs/bug302.go 4+++ test/fixedbugs/bug302.go 5@@ -1,5 +1,5 @@ 6 // +build !nacl,!js 7-// run 8+// runtarget 9 10 // Copyright 2010 The Go Authors. All rights reserved. 11 // Use of this source code is governed by a BSD-style 12@@ -8,16 +8,28 @@ 13 package main 14 15 import ( 16+ "flag" 17 "fmt" 18 "os" 19 "os/exec" 20 "path/filepath" 21 ) 22 23+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 24+ 25+func goCmd() string { 26+ if *target != "" { 27+ return "go_" + *target 28+ } 29+ return "go" 30+} 31+ 32+ 33 func main() { 34- run("go", "tool", "compile", filepath.Join("fixedbugs", "bug302.dir", "p.go")) 35- run("go", "tool", "pack", "grc", "pp.a", "p.o") 36- run("go", "tool", "compile", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go")) 37+ flag.Parse() 38+ run(goCmd(), "tool", "compile", filepath.Join("fixedbugs", "bug302.dir", "p.go")) 39+ run(goCmd(), "tool", "pack", "grc", "pp.a", "p.o") 40+ run(goCmd(), "tool", "compile", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go")) 41 os.Remove("p.o") 42 os.Remove("pp.a") 43 os.Remove("main.o") 44diff --git test/fixedbugs/bug369.go test/fixedbugs/bug369.go 45index e2a1147735..769364d503 100644 46--- test/fixedbugs/bug369.go 47+++ test/fixedbugs/bug369.go 48@@ -1,5 +1,5 @@ 49 // +build !nacl,!js,!windows 50-// run 51+// runtarget 52 53 // Copyright 2011 The Go Authors. All rights reserved. 54 // Use of this source code is governed by a BSD-style 55@@ -10,21 +10,40 @@ 56 package main 57 58 import ( 59+ "flag" 60 "fmt" 61 "os" 62 "os/exec" 63 "path/filepath" 64 ) 65 66+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 67+ 68+func goCmd() string { 69+ if *target != "" { 70+ return "go_" + *target 71+ } 72+ return "go" 73+} 74+ 75+func goRun(cmd ...string) { 76+ if *target == "" { 77+ run(cmd[0], cmd[1:]...) 78+ } else { 79+ run("go_"+*target+"_exec", cmd...) 80+ } 81+} 82+ 83 func main() { 84+ flag.Parse() 85 err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir")) 86 check(err) 87 88- run("go", "tool", "compile", "-N", "-o", "slow.o", "pkg.go") 89- run("go", "tool", "compile", "-o", "fast.o", "pkg.go") 90- run("go", "tool", "compile", "-o", "main.o", "main.go") 91- run("go", "tool", "link", "-o", "a.exe", "main.o") 92- run("." + string(filepath.Separator) + "a.exe") 93+ run(goCmd(), "tool", "compile", "-N", "-o", "slow.o", "pkg.go") 94+ run(goCmd(), "tool", "compile", "-o", "fast.o", "pkg.go") 95+ run(goCmd(), "tool", "compile", "-o", "main.o", "main.go") 96+ run(goCmd(), "tool", "link", "-o", "a.exe", "main.o") 97+ goRun("." + string(filepath.Separator) + "a.exe") 98 99 os.Remove("slow.o") 100 os.Remove("fast.o") 101diff --git test/fixedbugs/bug429_run.go test/fixedbugs/bug429_run.go 102index c6a02aae5e..30298de97b 100644 103--- test/fixedbugs/bug429_run.go 104+++ test/fixedbugs/bug429_run.go 105@@ -1,5 +1,5 @@ 106 // +build !nacl,!js 107-// run 108+// runtarget 109 110 // Copyright 2014 The Go Authors. All rights reserved. 111 // Use of this source code is governed by a BSD-style 112@@ -10,6 +10,7 @@ 113 package main 114 115 import ( 116+ "flag" 117 "fmt" 118 "os" 119 "os/exec" 120@@ -17,8 +18,27 @@ import ( 121 "strings" 122 ) 123 124+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 125+ 126+func goCmd() string { 127+ if *target != "" { 128+ return "go_" + *target 129+ } 130+ return "go" 131+} 132+ 133+func goRun(args ...string) *exec.Cmd { 134+ cmd := []string{"run"} 135+ if *target != "" { 136+ cmd = append(cmd, "-exec", "go_"+*target+"_exec") 137+ } 138+ cmd = append(cmd, args...) 139+ return exec.Command(goCmd(), cmd...) 140+} 141+ 142 func main() { 143- cmd := exec.Command("go", "run", filepath.Join("fixedbugs", "bug429.go")) 144+ flag.Parse() 145+ cmd := goRun(filepath.Join("fixedbugs", "bug429.go")) 146 out, err := cmd.CombinedOutput() 147 if err == nil { 148 fmt.Println("expected deadlock") 149diff --git test/fixedbugs/issue10607.go test/fixedbugs/issue10607.go 150index 9ee6c72bc6..e819a3085a 100644 151--- test/fixedbugs/issue10607.go 152+++ test/fixedbugs/issue10607.go 153@@ -1,5 +1,5 @@ 154 // +build linux,!ppc64 android 155-// run 156+// runtarget 157 158 // Copyright 2015 The Go Authors. All rights reserved. 159 // Use of this source code is governed by a BSD-style 160@@ -11,19 +11,39 @@ 161 package main 162 163 import ( 164+ "flag" 165 "fmt" 166 "os" 167 "os/exec" 168 "path/filepath" 169 ) 170 171+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 172+ 173+func goCmd() string { 174+ if *target != "" { 175+ return "go_" + *target 176+ } 177+ return "go" 178+} 179+ 180+func goRun(args ...string) *exec.Cmd { 181+ cmd := []string{"run"} 182+ if *target != "" { 183+ cmd = append(cmd, "-exec", "go_"+*target+"_exec") 184+ } 185+ cmd = append(cmd, args...) 186+ return exec.Command(goCmd(), cmd...) 187+} 188+ 189 func main() { 190- test("internal") 191+ flag.Parse() 192+ //test("internal") 193 test("external") 194 } 195 196 func test(linkmode string) { 197- out, err := exec.Command("go", "run", "-ldflags", "-B=0x12345678 -linkmode="+linkmode, filepath.Join("fixedbugs", "issue10607a.go")).CombinedOutput() 198+ out, err := goRun("-ldflags", "-B=0x12345678 -linkmode="+linkmode, filepath.Join("fixedbugs", "issue10607a.go")).CombinedOutput() 199 if err != nil { 200 fmt.Printf("BUG: linkmode=%s %v\n%s\n", linkmode, err, out) 201 os.Exit(1) 202diff --git test/fixedbugs/issue11771.go test/fixedbugs/issue11771.go 203index 99d7060d44..777cb7b9c4 100644 204--- test/fixedbugs/issue11771.go 205+++ test/fixedbugs/issue11771.go 206@@ -1,5 +1,5 @@ 207 // +build !nacl,!js 208-// run 209+// runtarget 210 211 // Copyright 2015 The Go Authors. All rights reserved. 212 // Use of this source code is governed by a BSD-style 213@@ -11,6 +11,7 @@ package main 214 215 import ( 216 "bytes" 217+ "flag" 218 "fmt" 219 "io/ioutil" 220 "log" 221@@ -19,8 +20,17 @@ import ( 222 "path/filepath" 223 "runtime" 224 ) 225+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 226+ 227+func goCmd() string { 228+ if *target != "" { 229+ return "go_" + *target 230+ } 231+ return "go" 232+} 233 234 func main() { 235+ flag.Parse() 236 if runtime.Compiler != "gc" { 237 return 238 } 239@@ -52,7 +62,7 @@ func x() { 240 log.Fatal(err) 241 } 242 243- cmd := exec.Command("go", "tool", "compile", "x.go") 244+ cmd := exec.Command(goCmd(), "tool", "compile", "x.go") 245 cmd.Dir = dir 246 output, err := cmd.CombinedOutput() 247 if err == nil { 248diff --git test/fixedbugs/issue9355.go test/fixedbugs/issue9355.go 249index 9657e64491..bad099f440 100644 250--- test/fixedbugs/issue9355.go 251+++ test/fixedbugs/issue9355.go 252@@ -1,4 +1,4 @@ 253-// run 254+// runtarget 255 256 // Copyright 2014 The Go Authors. All rights reserved. 257 // Use of this source code is governed by a BSD-style 258@@ -7,6 +7,7 @@ 259 package main 260 261 import ( 262+ "flag" 263 "fmt" 264 "os" 265 "os/exec" 266@@ -15,7 +16,17 @@ import ( 267 "runtime" 268 ) 269 270+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 271+ 272+func goCmd() string { 273+ if *target != "" { 274+ return "go_" + *target 275+ } 276+ return "go" 277+} 278+ 279 func main() { 280+ flag.Parse() 281 if runtime.Compiler != "gc" || runtime.GOOS == "nacl" || runtime.GOOS == "js" { 282 return 283 } 284@@ -23,7 +34,7 @@ func main() { 285 err := os.Chdir(filepath.Join("fixedbugs", "issue9355.dir")) 286 check(err) 287 288- out := run("go", "tool", "compile", "-S", "a.go") 289+ out := run(goCmd(), "tool", "compile", "-S", "a.go") 290 os.Remove("a.o") 291 292 // 6g/8g print the offset as dec, but 5g/9g print the offset as hex. 293diff --git test/fixedbugs/issue9862_run.go test/fixedbugs/issue9862_run.go 294index 299e809545..02b8ea83c2 100644 295--- test/fixedbugs/issue9862_run.go 296+++ test/fixedbugs/issue9862_run.go 297@@ -1,5 +1,5 @@ 298 // +build !nacl,!js 299-// run 300+// runtarget 301 302 // Copyright 2015 The Go Authors. All rights reserved. 303 // Use of this source code is governed by a BSD-style 304@@ -10,12 +10,32 @@ 305 package main 306 307 import ( 308+ "flag" 309 "os/exec" 310 "strings" 311 ) 312 313+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 314+ 315+func goCmd() string { 316+ if *target != "" { 317+ return "go_" + *target 318+ } 319+ return "go" 320+} 321+ 322+func goRun(args ...string) *exec.Cmd { 323+ cmd := []string{"run"} 324+ if *target != "" { 325+ cmd = append(cmd, "-exec", "go_"+*target+"_exec") 326+ } 327+ cmd = append(cmd, args...) 328+ return exec.Command(goCmd(), cmd...) 329+} 330+ 331 func main() { 332- out, err := exec.Command("go", "run", "fixedbugs/issue9862.go").CombinedOutput() 333+ flag.Parse() 334+ out, err := goRun("fixedbugs/issue9862.go").CombinedOutput() 335 outstr := string(out) 336 if err == nil { 337 println("go run issue9862.go succeeded, should have failed\n", outstr) 338diff --git test/linkmain_run.go test/linkmain_run.go 339index 68d53e8cad..0aa5e0fe2d 100644 340--- test/linkmain_run.go 341+++ test/linkmain_run.go 342@@ -1,5 +1,5 @@ 343 // +build !nacl,!js 344-// run 345+// runtarget 346 347 // Copyright 2014 The Go Authors. All rights reserved. 348 // Use of this source code is governed by a BSD-style 349@@ -10,12 +10,22 @@ 350 package main 351 352 import ( 353+ "flag" 354 "fmt" 355 "os" 356 "os/exec" 357 "strings" 358 ) 359 360+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 361+ 362+func goCmd() string { 363+ if *target != "" { 364+ return "go_" + *target 365+ } 366+ return "go" 367+} 368+ 369 func cleanup() { 370 os.Remove("linkmain.o") 371 os.Remove("linkmain.a") 372@@ -51,16 +61,18 @@ func runFail(cmdline string) { 373 } 374 375 func main() { 376+ flag.Parse() 377+ 378 // helloworld.go is package main 379- run("go tool compile -o linkmain.o helloworld.go") 380- run("go tool compile -pack -o linkmain.a helloworld.go") 381- run("go tool link -o linkmain.exe linkmain.o") 382- run("go tool link -o linkmain.exe linkmain.a") 383+ run(goCmd() + " tool compile -o linkmain.o helloworld.go") 384+ run(goCmd() + " tool compile -pack -o linkmain.a helloworld.go") 385+ run(goCmd() + " tool link -o linkmain.exe linkmain.o") 386+ run(goCmd() + " tool link -o linkmain.exe linkmain.a") 387 388 // linkmain.go is not 389- run("go tool compile -o linkmain1.o linkmain.go") 390- run("go tool compile -pack -o linkmain1.a linkmain.go") 391- runFail("go tool link -o linkmain.exe linkmain1.o") 392- runFail("go tool link -o linkmain.exe linkmain1.a") 393+ run(goCmd() + " tool compile -o linkmain1.o linkmain.go") 394+ run(goCmd() + " tool compile -pack -o linkmain1.a linkmain.go") 395+ runFail(goCmd() + " tool link -o linkmain.exe linkmain1.o") 396+ runFail(goCmd() + " tool link -o linkmain.exe linkmain1.a") 397 cleanup() 398 } 399diff --git test/linkobj.go test/linkobj.go 400index 2902d23f4b..c17dfd3da9 100644 401--- test/linkobj.go 402+++ test/linkobj.go 403@@ -1,5 +1,5 @@ 404 // +build !nacl,!js 405-// run 406+// runtarget 407 408 // Copyright 2016 The Go Authors. All rights reserved. 409 // Use of this source code is governed by a BSD-style 410@@ -10,6 +10,7 @@ 411 package main 412 413 import ( 414+ "flag" 415 "fmt" 416 "io/ioutil" 417 "log" 418@@ -18,9 +19,27 @@ import ( 419 "strings" 420 ) 421 422+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 423+ 424+func goCmd() string { 425+ if *target != "" { 426+ return "go_" + *target 427+ } 428+ return "go" 429+} 430+ 431+func goRun(cmd ...string) string { 432+ if *target == "" { 433+ return run(cmd...) 434+ } else { 435+ return run(append([]string{"go_"+*target+"_exec"}, cmd...)...) 436+ } 437+} 438+ 439 var pwd, tmpdir string 440 441 func main() { 442+ flag.Parse() 443 dir, err := ioutil.TempDir("", "go-test-linkobj-") 444 if err != nil { 445 log.Fatal(err) 446@@ -37,28 +56,28 @@ func main() { 447 448 writeFile("p1.go", ` 449 package p1 450- 451+ 452 func F() { 453 println("hello from p1") 454 } 455 `) 456 writeFile("p2.go", ` 457 package p2 458- 459+ 460 import "./p1" 461 462 func F() { 463 p1.F() 464 println("hello from p2") 465 } 466- 467+ 468 func main() {} 469 `) 470 writeFile("p3.go", ` 471 package main 472 473 import "./p2" 474- 475+ 476 func main() { 477 p2.F() 478 println("hello from main") 479@@ -76,9 +95,9 @@ func main() { 480 } 481 482 // inlining is disabled to make sure that the link objects contain needed code. 483- run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p1."+o, "-linkobj", "p1.lo", "p1.go") 484- run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p2."+o, "-linkobj", "p2.lo", "p2.go") 485- run("go", "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p3."+o, "-linkobj", "p3.lo", "p3.go") 486+ run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p1."+o, "-linkobj", "p1.lo", "p1.go") 487+ run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p2."+o, "-linkobj", "p2.lo", "p2.go") 488+ run(goCmd(), "tool", "compile", pkg, "-D", ".", "-I", ".", "-l", "-o", "p3."+o, "-linkobj", "p3.lo", "p3.go") 489 490 cp("p1."+o, "p1.oo") 491 cp("p2."+o, "p2.oo") 492@@ -86,13 +105,13 @@ func main() { 493 cp("p1.lo", "p1."+o) 494 cp("p2.lo", "p2."+o) 495 cp("p3.lo", "p3."+o) 496- out := runFail("go", "tool", "link", "p2."+o) 497+ out := runFail(goCmd(), "tool", "link", "p2."+o) 498 if !strings.Contains(out, "not package main") { 499 fatalf("link p2.o failed but not for package main:\n%s", out) 500 } 501 502- run("go", "tool", "link", "-L", ".", "-o", "a.out.exe", "p3."+o) 503- out = run("./a.out.exe") 504+ run(goCmd(), "tool", "link", "-L", ".", "-o", "a.out.exe", "p3."+o) 505+ out = goRun("./a.out.exe") 506 if !strings.Contains(out, "hello from p1\nhello from p2\nhello from main\n") { 507 fatalf("running main, incorrect output:\n%s", out) 508 } 509diff --git test/linkx_run.go test/linkx_run.go 510index ca9d31612a..631b95ee67 100644 511--- test/linkx_run.go 512+++ test/linkx_run.go 513@@ -1,5 +1,5 @@ 514 // +build !nacl,!js 515-// run 516+// runtarget 517 518 // Copyright 2014 The Go Authors. All rights reserved. 519 // Use of this source code is governed by a BSD-style 520@@ -11,20 +11,40 @@ package main 521 522 import ( 523 "bytes" 524+ "flag" 525 "fmt" 526 "os" 527 "os/exec" 528 "strings" 529 ) 530 531+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 532+ 533+func goCmd() string { 534+ if *target != "" { 535+ return "go_" + *target 536+ } 537+ return "go" 538+} 539+ 540+func goRun(args ...string) *exec.Cmd { 541+ cmd := []string{"run"} 542+ if *target != "" { 543+ cmd = append(cmd, "-exec", "go_"+*target+"_exec") 544+ } 545+ cmd = append(cmd, args...) 546+ return exec.Command(goCmd(), cmd...) 547+} 548+ 549 func main() { 550+ flag.Parse() 551 // test(" ") // old deprecated & removed syntax 552 test("=") // new syntax 553 } 554 555 func test(sep string) { 556 // Successful run 557- cmd := exec.Command("go", "run", "-ldflags=-X main.tbd"+sep+"hello -X main.overwrite"+sep+"trumped -X main.nosuchsymbol"+sep+"neverseen", "linkx.go") 558+ cmd := goRun("-ldflags=-X main.tbd"+sep+"hello -X main.overwrite"+sep+"trumped -X main.nosuchsymbol"+sep+"neverseen", "linkx.go") 559 var out, errbuf bytes.Buffer 560 cmd.Stdout = &out 561 cmd.Stderr = &errbuf 562@@ -44,7 +64,7 @@ func test(sep string) { 563 } 564 565 // Issue 8810 566- cmd = exec.Command("go", "run", "-ldflags=-X main.tbd", "linkx.go") 567+ cmd = goRun("-ldflags=-X main.tbd", "linkx.go") 568 _, err = cmd.CombinedOutput() 569 if err == nil { 570 fmt.Println("-X linker flag should not accept keys without values") 571@@ -52,7 +72,7 @@ func test(sep string) { 572 } 573 574 // Issue 9621 575- cmd = exec.Command("go", "run", "-ldflags=-X main.b=false -X main.x=42", "linkx.go") 576+ cmd = goRun("-ldflags=-X main.b=false -X main.x=42", "linkx.go") 577 outx, err := cmd.CombinedOutput() 578 if err == nil { 579 fmt.Println("-X linker flag should not overwrite non-strings") 580diff --git test/nosplit.go test/nosplit.go 581index e6cd04e563..baeea80e37 100644 582--- test/nosplit.go 583+++ test/nosplit.go 584@@ -1,5 +1,5 @@ 585 // +build !nacl,!js 586-// run 587+// runtarget 588 589 // Copyright 2014 The Go Authors. All rights reserved. 590 // Use of this source code is governed by a BSD-style 591@@ -9,6 +9,7 @@ package main 592 593 import ( 594 "bytes" 595+ "flag" 596 "fmt" 597 "io/ioutil" 598 "log" 599@@ -21,6 +22,24 @@ import ( 600 "strings" 601 ) 602 603+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 604+ 605+func goCmd() string { 606+ if *target != "" { 607+ return "go_" + *target 608+ } 609+ return "go" 610+} 611+ 612+func goArch() string { 613+ goarch, err := exec.Command(goCmd(), "env", "GOARCH").Output() 614+ if err != nil { 615+ bug() 616+ fmt.Printf("running go env GOARCH: %v\n", err) 617+ } 618+ return strings.TrimSpace(string(goarch)) 619+} 620+ 621 var tests = ` 622 # These are test cases for the linker analysis that detects chains of 623 # nosplit functions that would cause a stack overflow. 624@@ -194,12 +213,13 @@ var ( 625 ) 626 627 func main() { 628- goarch := os.Getenv("GOARCH") 629+ flag.Parse() 630+ goarch := goArch() 631 if goarch == "" { 632- goarch = runtime.GOARCH 633+ return 634 } 635 636- version, err := exec.Command("go", "tool", "compile", "-V").Output() 637+ version, err := exec.Command(goCmd(), "tool", "compile", "-V").Output() 638 if err != nil { 639 bug() 640 fmt.Printf("running go tool compile -V: %v\n", err) 641@@ -345,7 +365,7 @@ TestCases: 642 log.Fatal(err) 643 } 644 645- cmd := exec.Command("go", "build") 646+ cmd := exec.Command(goCmd(), "build") 647 cmd.Dir = dir 648 output, err := cmd.CombinedOutput() 649 if err == nil { 650diff --git test/run.go test/run.go 651index 2af3ee43ba..28c87c3583 100644 652--- test/run.go 653+++ test/run.go 654@@ -246,6 +246,16 @@ func goRun(runcmd runCmd, flags []string, goname string, args ...string) (out [] 655 } 656 657 658+func goRunTarget(runcmd runCmd, goname string, args ...string) (out []byte, err error) { 659+ cmd := []string{"go_local", "run"} 660+ cmd = append(cmd, goname) 661+ if *target != "" { 662+ cmd = append(cmd, "-target", *target) 663+ } 664+ cmd = append(cmd, args...) 665+ return runcmd(cmd...) 666+} 667+ 668 // skipError describes why a test was skipped. 669 type skipError string 670 671@@ -505,7 +515,7 @@ func (t *test) run() { 672 673 // TODO: Clean up/simplify this switch statement. 674 switch action { 675- case "compile", "compiledir", "build", "builddir", "buildrundir", "run", "buildrun", "runoutput", "rundir", "asmcheck": 676+ case "compile", "compiledir", "build", "builddir", "buildrundir", "run", "runtarget", "buildrun", "runoutput", "rundir", "asmcheck": 677 // nothing to do 678 case "errorcheckandrundir": 679 wantError = false // should be no error if also will run 680@@ -894,6 +904,17 @@ func (t *test) run() { 681 t.err = fmt.Errorf("incorrect output\n%s", out) 682 } 683 684+ case "runtarget": 685+ useTmp = false 686+ out, err := goRunTarget(runcmd, t.goFileName(), args...) 687+ if err != nil { 688+ t.err = err 689+ return 690+ } 691+ if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() { 692+ t.err = fmt.Errorf("incorrect output\n%s", out) 693+ } 694+ 695 case "runoutput": 696 // Run Go file and write its output into temporary Go file. 697 // Run generated Go file and verify its output. 698diff --git test/sinit_run.go test/sinit_run.go 699index fdd19c492f..0b3cb76083 100644 700--- test/sinit_run.go 701+++ test/sinit_run.go 702@@ -1,5 +1,5 @@ 703 // +build !nacl,!js 704-// run 705+// runtarget 706 707 // Copyright 2014 The Go Authors. All rights reserved. 708 // Use of this source code is governed by a BSD-style 709@@ -11,11 +11,21 @@ package main 710 711 import ( 712 "bytes" 713+ "flag" 714 "fmt" 715 "os" 716 "os/exec" 717 ) 718 719+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 720+ 721+func goCmd() string { 722+ if *target != "" { 723+ return "go_" + *target 724+ } 725+ return "go" 726+} 727+ 728 func main() { 729 cmd := exec.Command("go", "tool", "compile", "-S", "sinit.go") 730 out, err := cmd.CombinedOutput() 731