github.com/shijuvar/go@v0.0.0-20141209052335-e8f13700b70c/test/fixedbugs/bug302.go (about)

     1  // +build !nacl
     2  // run
     3  
     4  // Copyright 2010 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  	"runtime"
    17  )
    18  
    19  func main() {
    20  	a, err := build.ArchChar(runtime.GOARCH)
    21  	if err != nil {
    22  		fmt.Println("BUG:", err)
    23  		os.Exit(1)
    24  	}
    25  
    26  	run("go", "tool", a+"g", filepath.Join("fixedbugs", "bug302.dir", "p.go"))
    27  	run("go", "tool", "pack", "grc", "pp.a", "p."+a)
    28  	run("go", "tool", a+"g", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go"))
    29  	os.Remove("p."+a)
    30  	os.Remove("pp.a")
    31  	os.Remove("main."+a)
    32  }
    33  
    34  func run(cmd string, args ...string) {
    35  	out, err := exec.Command(cmd, args...).CombinedOutput()
    36  	if err != nil {
    37  		fmt.Println(string(out))
    38  		fmt.Println(err)
    39  		os.Exit(1)
    40  	}
    41  }