}
}
-func toolPath(name string) string {
- p := filepath.Join(os.Getenv("GOROOT"), "bin", "tool", name)
- if _, err := os.Stat(p); err != nil {
- log.Fatalf("didn't find binary at %s", p)
- }
- return p
-}
-
// goTool reports the path of the go tool to use to run the tests.
// If possible, use the same Go used to run run.go, otherwise
// fallback to the go version found in the PATH.
func goFiles(dir string) []string {
f, err := os.Open(dir)
- check(err)
+ if err != nil {
+ log.Fatal(err)
+ }
dirnames, err := f.Readdirnames(-1)
f.Close()
- check(err)
+ if err != nil {
+ log.Fatal(err)
+ }
names := []string{}
for _, name := range dirnames {
if !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go") && shardMatch(name) {
func (s skipError) Error() string { return string(s) }
-func check(err error) {
- if err != nil {
- log.Fatal(err)
- }
-}
-
// test holds the state of a test.
type test struct {
dir, gofile string
for _, file := range files {
name := file.Name()
pkgname, err := getPackageNameFromSource(filepath.Join(longdir, name))
- check(err)
+ if err != nil {
+ log.Fatal(err)
+ }
i, ok := m[pkgname]
if singlefilepkgs || !ok {
i = len(pkgs)
// skip first line
action = action[nl+1:]
}
- if strings.HasPrefix(action, "//") {
- action = action[2:]
- }
+ action = strings.TrimPrefix(action, "//")
// Check for build constraints only up to the actual code.
pkgPos := strings.Index(t.src, "\npackage")
}
err = ioutil.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0644)
- check(err)
+ if err != nil {
+ log.Fatal(err)
+ }
// A few tests (of things like the environment) require these to be set.
if os.Getenv("GOOS") == "" {
pflags = append(pflags, flags...)
if setpkgpaths {
fp := filepath.Join(longdir, gofiles[0])
- pkgname, serr := getPackageNameFromSource(fp)
- check(serr)
+ pkgname, err := getPackageNameFromSource(fp)
+ if err != nil {
+ log.Fatal(err)
+ }
pflags = append(pflags, "-p", pkgname)
}
_, err := compileInDir(runcmd, longdir, pflags, localImports, gofiles...)
longdirgofile := filepath.Join(filepath.Join(cwd, t.dir), t.gofile)
cmd = append(cmd, flags...)
cmd = append(cmd, longdirgofile)
- out, err := runcmd(cmd...)
+ _, err := runcmd(cmd...)
if err != nil {
t.err = err
return
}
cmd = []string{"./a.exe"}
- out, err = runcmd(append(cmd, args...)...)
+ out, err := runcmd(append(cmd, args...)...)
if err != nil {
t.err = err
return
func (t *test) makeTempDir() {
var err error
t.tempDir, err = ioutil.TempDir("", "")
- check(err)
+ if err != nil {
+ log.Fatal(err)
+ }
if *keep {
log.Printf("Temporary directory is %s", t.tempDir)
}