github.com/reiver/go@v0.0.0-20150109200633-1d0c7792f172/test/fixedbugs/bug345.go (about)

     1  // +build !nacl,!plan9,!windows
     2  // run
     3  
     4  // Copyright 2011 The Go Authors.  All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  package main
     9  
    10  import (
    11  	"fmt"
    12  	"go/build"
    13  	"os"
    14  	"os/exec"
    15  	"path/filepath"
    16  )
    17  
    18  func main() {
    19  	a, err := build.ArchChar(build.Default.GOARCH)
    20  	check(err)
    21  
    22  	// TODO: If we get rid of errchk, re-enable this test on Plan 9 and Windows.
    23  	errchk, err := filepath.Abs("errchk")
    24  	check(err)
    25  
    26  	err = os.Chdir(filepath.Join(".", "fixedbugs", "bug345.dir"))
    27  	check(err)
    28  
    29  	run("go", "tool", a+"g", "io.go")
    30  	run(errchk, "go", "tool", a+"g", "-e", "main.go")
    31  	os.Remove("io." + a)
    32  }
    33  
    34  func run(name string, args ...string) {
    35  	cmd := exec.Command(name, args...)
    36  	out, err := cmd.CombinedOutput()
    37  	if err != nil {
    38  		fmt.Println(string(out))
    39  		fmt.Println(err)
    40  		os.Exit(1)
    41  	}
    42  }
    43  
    44  func check(err error) {
    45  	if err != nil {
    46  		fmt.Println(err)
    47  		os.Exit(1)
    48  	}
    49  }