~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to src/pkg/go/build/build_test.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
package build
6
6
 
7
7
import (
8
 
        "os"
 
8
        "exec"
9
9
        "path/filepath"
10
 
        "runtime"
11
 
        "strings"
12
10
        "testing"
13
11
)
14
12
 
15
 
var buildDirs = []string{
16
 
        "pkg/path",
17
 
        "cmd/gofix",
18
 
        "pkg/big",
19
 
        "pkg/go/build/cgotest",
 
13
var buildPkgs = []string{
 
14
        "go/build/pkgtest",
 
15
        "go/build/cmdtest",
 
16
        "go/build/cgotest",
20
17
}
21
18
 
 
19
const cmdtestOutput = "3"
 
20
 
22
21
func TestBuild(t *testing.T) {
23
 
        out, err := filepath.Abs("_test/out")
24
 
        if err != nil {
25
 
                t.Fatal(err)
26
 
        }
27
 
        for _, d := range buildDirs {
28
 
                if runtime.GOARCH == "arm" && strings.Contains(d, "/cgo") {
29
 
                        // no cgo for arm, yet.
30
 
                        continue
31
 
                }
32
 
                dir := filepath.Join(runtime.GOROOT(), "src", d)
33
 
                testBuild(t, dir, out)
34
 
        }
35
 
}
36
 
 
37
 
func testBuild(t *testing.T, dir, targ string) {
38
 
        d, err := ScanDir(dir, true)
39
 
        if err != nil {
40
 
                t.Error(err)
41
 
                return
42
 
        }
43
 
        defer os.Remove(targ)
44
 
        cmds, err := d.Build(targ)
45
 
        if err != nil {
46
 
                t.Error(err)
47
 
                return
48
 
        }
49
 
        for _, c := range cmds {
50
 
                t.Log("Run:", c)
51
 
                err = c.Run(dir)
52
 
                if err != nil {
53
 
                        t.Error(c, err)
54
 
                        return
55
 
                }
 
22
        for _, pkg := range buildPkgs {
 
23
                tree := Path[0] // Goroot
 
24
                dir := filepath.Join(tree.SrcDir(), pkg)
 
25
 
 
26
                info, err := ScanDir(dir, true)
 
27
                if err != nil {
 
28
                        t.Error("ScanDir:", err)
 
29
                        continue
 
30
                }
 
31
 
 
32
                s, err := Build(tree, pkg, info)
 
33
                if err != nil {
 
34
                        t.Error("Build:", err)
 
35
                        continue
 
36
                }
 
37
 
 
38
                if err := s.Run(); err != nil {
 
39
                        t.Error("Run:", err)
 
40
                        continue
 
41
                }
 
42
 
 
43
                if pkg == "go/build/cmdtest" {
 
44
                        bin := s.Output[0]
 
45
                        b, err := exec.Command(bin).CombinedOutput()
 
46
                        if err != nil {
 
47
                                t.Errorf("exec: %s: %v", bin, err)
 
48
                                continue
 
49
                        }
 
50
                        if string(b) != cmdtestOutput {
 
51
                                t.Errorf("cmdtest output: %s want: %s", b, cmdtestOutput)
 
52
                        }
 
53
                }
 
54
 
 
55
                defer func(s *Script) {
 
56
                        if err := s.Nuke(); err != nil {
 
57
                                t.Errorf("nuking: %v", err)
 
58
                        }
 
59
                }(s)
56
60
        }
57
61
}