"bytes"
"flag"
"fmt"
+ "io/ioutil"
"os"
"os/exec"
+ "path/filepath"
"regexp"
"runtime"
"strings"
onlyTest(flag.Args()...)
}
+ tmpdir, err := ioutil.TempDir("", "go-progs")
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ os.Exit(1)
+ }
+
// ratec limits the number of tests running concurrently.
// None of the tests are intensive, so don't bother
// trying to manually adjust for slow builders.
tt := tt
ratec <- true
go func() {
- errc <- test(tt.file, tt.want)
+ errc <- test(tmpdir, tt.file, tt.want)
<-ratec
}()
}
rc = 1
}
}
+ os.Remove(tmpdir)
os.Exit(rc)
}
// test builds the test in the given file.
// If want is non-empty, test also runs the test
// and checks that the output matches the regexp want.
-func test(file, want string) error {
+func test(tmpdir, file, want string) error {
// Build the program.
- cmd := exec.Command("go", "build", file+".go")
+ prog := filepath.Join(tmpdir, file)
+ cmd := exec.Command("go", "build", "-o", prog, file+".go")
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("go build %s.go failed: %v\nOutput:\n%s", file, err, out)
}
- defer os.Remove(file)
+ defer os.Remove(prog)
// Only run the test if we have output to check.
if want == "" {
return nil
}
- cmd = exec.Command("./" + file)
+ cmd = exec.Command(prog)
out, err = cmd.CombinedOutput()
if err != nil {
- return fmt.Errorf("./%s failed: %v\nOutput:\n%s", file, err, out)
+ return fmt.Errorf("%s failed: %v\nOutput:\n%s", file, err, out)
}
// Canonicalize output.