| 1 |
// +build !nacl,!js,!windows,gc |
| 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 |
// Test that compiling with optimization turned on produces faster code. |
| 9 |
|
| 10 |
package main |
| 11 |
|
| 12 |
import ( |
| 13 |
"fmt" |
| 14 |
"io/ioutil" |
| 15 |
"os" |
| 16 |
"os/exec" |
| 17 |
"path/filepath" |
| 18 |
) |
| 19 |
|
| 20 |
func main() { |
| 21 |
err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir")) |
| 22 |
check(err) |
| 23 |
|
| 24 |
tmpDir, err := ioutil.TempDir("", "bug369") |
| 25 |
check(err) |
| 26 |
defer os.RemoveAll(tmpDir) |
| 27 |
|
| 28 |
tmp := func(name string) string { |
| 29 |
return filepath.Join(tmpDir, name) |
| 30 |
} |
| 31 |
|
| 32 |
run("go", "tool", "compile", "-N", "-o", tmp("slow.o"), "pkg.go") |
| 33 |
run("go", "tool", "compile", "-o", tmp("fast.o"), "pkg.go") |
| 34 |
run("go", "tool", "compile", "-D", tmpDir, "-o", tmp("main.o"), "main.go") |
| 35 |
run("go", "tool", "link", "-o", tmp("a.exe"), tmp("main.o")) |
| 36 |
run(tmp("a.exe")) |
| 37 |
} |
| 38 |
|
| 39 |
func run(name string, args ...string) { |
| 40 |
cmd := exec.Command(name, args...) |
| 41 |
out, err := cmd.CombinedOutput() |
| 42 |
if err != nil { |
| 43 |
fmt.Println(string(out)) |
| 44 |
fmt.Println(err) |
| 45 |
os.Exit(1) |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
func check(err error) { |
| 50 |
if err != nil { |
| 51 |
fmt.Println(err) |
| 52 |
os.Exit(1) |
| 53 |
} |
| 54 |
} |