1runtime, crypto/x509: add -target flag. 2 3--- src/crypto/x509/x509_test.go 4+++ src/crypto/x509/x509_test.go 5@@ -19,6 +19,7 @@ import ( 6 "encoding/hex" 7 "encoding/pem" 8 "fmt" 9+ "flag" 10 "internal/testenv" 11 "math/big" 12 "net" 13@@ -28,6 +29,8 @@ import ( 14 "time" 15 ) 16 17+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 18+ 19 func TestParsePKCS1PrivateKey(t *testing.T) { 20 block, _ := pem.Decode([]byte(pemPrivateKey)) 21 priv, err := ParsePKCS1PrivateKey(block.Bytes) 22@@ -862,7 +865,13 @@ func TestParsePEMCRL(t *testing.T) { 23 func TestImports(t *testing.T) { 24 testenv.MustHaveGoRun(t) 25 26- if err := exec.Command("go", "run", "x509_test_import.go").Run(); err != nil { 27+ var cmd *exec.Cmd 28+ if *target == "" { 29+ cmd = exec.Command("go", "run", "x509_test_import.go") 30+ } else { 31+ cmd = exec.Command("go_"+*target, "run", "-exec", "go_"+*target+"_exec", "x509_test_import.go") 32+ } 33+ if err := cmd.Run(); err != nil { 34 t.Errorf("failed to run x509_test_import.go: %s", err) 35 } 36 } 37--- src/runtime/crash_test.go 38+++ src/runtime/crash_test.go 39@@ -5,6 +5,7 @@ 40 package runtime_test 41 42 import ( 43+ "flag" 44 "fmt" 45 "internal/testenv" 46 "io/ioutil" 47@@ -18,6 +19,25 @@ import ( 48 "testing" 49 ) 50 51+var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries") 52+ 53+func goCmd() string { 54+ if *target != "" { 55+ return "go_" + *target 56+ } 57+ return "go" 58+} 59+ 60+func goExecCmd(name string, arg ...string) *exec.Cmd { 61+ var cmd []string 62+ if *target != "" { 63+ cmd = append(cmd, "go_"+*target+"_exec") 64+ } 65+ cmd = append(cmd, name) 66+ cmd = append(cmd, arg...) 67+ return exec.Command(cmd[0], cmd[1:]...) 68+} 69+ 70 var toRemove []string 71 72 func TestMain(m *testing.M) { 73@@ -65,7 +85,7 @@ func runTestProg(t *testing.T, binary, name string) string { 74 if err != nil { 75 t.Fatal(err) 76 } 77- got, _ := testEnv(exec.Command(exe, name)).CombinedOutput() 78+ got, _ := testEnv(goExecCmd(exe, name)).CombinedOutput() 79 return string(got) 80 } 81 82@@ -92,7 +112,7 @@ func buildTestProg(t *testing.T, binary string) (string, error) { 83 } 84 85 exe := filepath.Join(testprog.dir, binary+".exe") 86- cmd := exec.Command("go", "build", "-o", exe) 87+ cmd := exec.Command(goCmd(), "build", "-o", exe) 88 cmd.Dir = "testdata/" + binary 89 out, err := testEnv(cmd).CombinedOutput() 90 if err != nil { 91--- src/runtime/crash_unix_test.go 92+++ src/runtime/crash_unix_test.go 93@@ -157,7 +157,7 @@ func TestSignalExitStatus(t *testing.T) { 94 if err != nil { 95 t.Fatal(err) 96 } 97- err = testEnv(exec.Command(exe, "SignalExitStatus")).Run() 98+ err = testEnv(goExecCmd(exe, "SignalExitStatus")).Run() 99 if err == nil { 100 t.Error("test program succeeded unexpectedly") 101 } else if ee, ok := err.(*exec.ExitError); !ok { 102