Home | History | Annotate | Download | only in patch
      1 test: add -target flag.
      2 
      3 --- test/run.go
      4 +++ test/run.go
      5 @@ -37,9 +37,9 @@ var (
      6  	numParallel    = flag.Int("n", runtime.NumCPU(), "number of parallel tests to run")
      7  	summary        = flag.Bool("summary", false, "show summary of results")
      8  	showSkips      = flag.Bool("show_skips", false, "show skipped tests")
      9 -	linkshared     = flag.Bool("linkshared", false, "")
     10  	updateErrors   = flag.Bool("update_errors", false, "update error messages in test file based on compiler output")
     11  	runoutputLimit = flag.Int("l", defaultRunOutputLimit(), "number of parallel runoutput tests to run")
     12 +	target         = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
     13  
     14  	shard  = flag.Int("shard", 0, "shard index to run. Only applicable if -shards is non-zero.")
     15  	shards = flag.Int("shards", 0, "number of shards. If 0, all tests are run. This is used by the continuous build.")
     16 @@ -192,19 +192,11 @@ func goFiles(dir string) []string {
     17  type runCmd func(...string) ([]byte, error)
     18  
     19  func compileFile(runcmd runCmd, longname string) (out []byte, err error) {
     20 -	cmd := []string{"go", "tool", "compile", "-e"}
     21 -	if *linkshared {
     22 -		cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
     23 -	}
     24 -	cmd = append(cmd, longname)
     25 -	return runcmd(cmd...)
     26 +	return runcmd(findGoCmd(), "tool", "compile", "-e", longname)
     27  }
     28  
     29  func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err error) {
     30 -	cmd := []string{"go", "tool", "compile", "-e", "-D", ".", "-I", "."}
     31 -	if *linkshared {
     32 -		cmd = append(cmd, "-dynlink", "-installsuffix=dynlink")
     33 -	}
     34 +	cmd := []string{findGoCmd(), "tool", "compile", "-e", "-D", ".", "-I", "."}
     35  	for _, name := range names {
     36  		cmd = append(cmd, filepath.Join(dir, name))
     37  	}
     38 @@ -213,15 +205,21 @@ func compileInDir(runcmd runCmd, dir string, names ...string) (out []byte, err e
     39  
     40  func linkFile(runcmd runCmd, goname string) (err error) {
     41  	pfile := strings.Replace(goname, ".go", ".o", -1)
     42 -	cmd := []string{"go", "tool", "link", "-w", "-o", "a.exe", "-L", "."}
     43 -	if *linkshared {
     44 -		cmd = append(cmd, "-linkshared", "-installsuffix=dynlink")
     45 -	}
     46 -	cmd = append(cmd, pfile)
     47 -	_, err = runcmd(cmd...)
     48 +	_, err = runcmd(findGoCmd(), "tool", "link", "-w", "-o", "a.exe", "-L", ".", pfile)
     49  	return
     50  }
     51  
     52 +func goRun(runcmd runCmd, goname string, args ...string) (out []byte, err error) {
     53 +	cmd := []string{findGoCmd(), "run"}
     54 +	if len(findExecCmd()) > 0 {
     55 +		cmd = append(cmd, "-exec")
     56 +		cmd = append(cmd, findExecCmd()...)
     57 +	}
     58 +	cmd = append(cmd, goname)
     59 +	cmd = append(cmd, args...)
     60 +	return runcmd(cmd...)
     61 +}
     62 +
     63  // skipError describes why a test was skipped.
     64  type skipError string
     65  
     66 @@ -530,8 +528,7 @@ func (t *test) run() {
     67  		t.err = fmt.Errorf("unimplemented action %q", action)
     68  
     69  	case "errorcheck":
     70 -		cmdline := []string{"go", "tool", "compile", "-e", "-o", "a.o"}
     71 -		// No need to add -dynlink even if linkshared if we're just checking for errors...
     72 +		cmdline := []string{findGoCmd(), "tool", "compile", "-e", "-o", "a.o"}
     73  		cmdline = append(cmdline, flags...)
     74  		cmdline = append(cmdline, long)
     75  		out, err := runcmd(cmdline...)
     76 @@ -640,19 +637,14 @@ func (t *test) run() {
     77  		}
     78  
     79  	case "build":
     80 -		_, err := runcmd("go", "build", "-o", "a.exe", long)
     81 +		_, err := runcmd(findGoCmd(), "build", "-o", "a.exe", long)
     82  		if err != nil {
     83  			t.err = err
     84  		}
     85  
     86  	case "run":
     87  		useTmp = false
     88 -		cmd := []string{"go", "run"}
     89 -		if *linkshared {
     90 -			cmd = append(cmd, "-linkshared")
     91 -		}
     92 -		cmd = append(cmd, t.goFileName())
     93 -		out, err := runcmd(append(cmd, args...)...)
     94 +		out, err := goRun(runcmd, t.goFileName(), args...)
     95  		if err != nil {
     96  			t.err = err
     97  			return
     98 @@ -667,12 +659,7 @@ func (t *test) run() {
     99  			<-rungatec
    100  		}()
    101  		useTmp = false
    102 -		cmd := []string{"go", "run"}
    103 -		if *linkshared {
    104 -			cmd = append(cmd, "-linkshared")
    105 -		}
    106 -		cmd = append(cmd, t.goFileName())
    107 -		out, err := runcmd(append(cmd, args...)...)
    108 +		out, err := goRun(runcmd, t.goFileName(), args...)
    109  		if err != nil {
    110  			t.err = err
    111  			return
    112 @@ -682,12 +669,7 @@ func (t *test) run() {
    113  			t.err = fmt.Errorf("write tempfile:%s", err)
    114  			return
    115  		}
    116 -		cmd = []string{"go", "run"}
    117 -		if *linkshared {
    118 -			cmd = append(cmd, "-linkshared")
    119 -		}
    120 -		cmd = append(cmd, tfile)
    121 -		out, err = runcmd(cmd...)
    122 +		out, err = goRun(runcmd, tfile)
    123  		if err != nil {
    124  			t.err = err
    125  			return
    126 @@ -698,12 +680,7 @@ func (t *test) run() {
    127  
    128  	case "errorcheckoutput":
    129  		useTmp = false
    130 -		cmd := []string{"go", "run"}
    131 -		if *linkshared {
    132 -			cmd = append(cmd, "-linkshared")
    133 -		}
    134 -		cmd = append(cmd, t.goFileName())
    135 -		out, err := runcmd(append(cmd, args...)...)
    136 +		out, err := goRun(runcmd, t.goFileName(), args...)
    137  		if err != nil {
    138  			t.err = err
    139  			return
    140 @@ -714,7 +691,7 @@ func (t *test) run() {
    141  			t.err = fmt.Errorf("write tempfile:%s", err)
    142  			return
    143  		}
    144 -		cmdline := []string{"go", "tool", "compile", "-e", "-o", "a.o"}
    145 +		cmdline := []string{findGoCmd(), "tool", "compile", "-e", "-o", "a.o"}
    146  		cmdline = append(cmdline, flags...)
    147  		cmdline = append(cmdline, tfile)
    148  		out, err = runcmd(cmdline...)
    149 @@ -741,6 +718,10 @@ func findExecCmd() []string {
    150  		return execCmd
    151  	}
    152  	execCmd = []string{} // avoid work the second time
    153 +	if *target != "" {
    154 +		execCmd = []string{"go_" + *target + "_exec"}
    155 +		return execCmd
    156 +	}
    157  	if goos == runtime.GOOS && goarch == runtime.GOARCH {
    158  		return execCmd
    159  	}
    160 @@ -751,6 +732,13 @@ func findExecCmd() []string {
    161  	return execCmd
    162  }
    163  
    164 +func findGoCmd() string {
    165 +	if *target != "" {
    166 +		return "go_" + *target
    167 +	}
    168 +	return "go"
    169 +}
    170 +
    171  func (t *test) String() string {
    172  	return filepath.Join(t.dir, t.gofile)
    173  }
    174