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
58
59
60
61
|
// 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 (
"exec"
"path/filepath"
"testing"
)
var buildPkgs = []string{
"go/build/pkgtest",
"go/build/cmdtest",
"go/build/cgotest",
}
const cmdtestOutput = "3"
func TestBuild(t *testing.T) {
for _, pkg := range buildPkgs {
tree := Path[0] // Goroot
dir := filepath.Join(tree.SrcDir(), pkg)
info, err := ScanDir(dir, true)
if err != nil {
t.Error("ScanDir:", err)
continue
}
s, err := Build(tree, pkg, info)
if err != nil {
t.Error("Build:", err)
continue
}
if err := s.Run(); err != nil {
t.Error("Run:", err)
continue
}
if pkg == "go/build/cmdtest" {
bin := s.Output[0]
b, err := exec.Command(bin).CombinedOutput()
if err != nil {
t.Errorf("exec: %s: %v", bin, err)
continue
}
if string(b) != cmdtestOutput {
t.Errorf("cmdtest output: %s want: %s", b, cmdtestOutput)
}
}
defer func(s *Script) {
if err := s.Nuke(); err != nil {
t.Errorf("nuking: %v", err)
}
}(s)
}
}
|