summaryrefslogtreecommitdiff
path: root/src/pkg/go/build/build_test.go
blob: c543eddbda79a2fd49e2963f3b55bf99be0b2c76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2011 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package build

import (
	"os"
	"path/filepath"
	"runtime"
	"strings"
	"testing"
)

var buildDirs = []string{
	"pkg/path",
	"cmd/gofix",
	"pkg/big",
	"pkg/go/build/cgotest",
}

func TestBuild(t *testing.T) {
	out, err := filepath.Abs("_test/out")
	if err != nil {
		t.Fatal(err)
	}
	for _, d := range buildDirs {
		if runtime.GOARCH == "arm" && strings.Contains(d, "/cgo") {
			// no cgo for arm, yet.
			continue
		}
		dir := filepath.Join(runtime.GOROOT(), "src", d)
		testBuild(t, dir, out)
	}
}

func testBuild(t *testing.T, dir, targ string) {
	d, err := ScanDir(dir, true)
	if err != nil {
		t.Error(err)
		return
	}
	defer os.Remove(targ)
	cmds, err := d.Build(targ)
	if err != nil {
		t.Error(err)
		return
	}
	for _, c := range cmds {
		t.Log("Run:", c)
		err = c.Run(dir)
		if err != nil {
			t.Error(c, err)
			return
		}
	}
}