summaryrefslogtreecommitdiff
path: root/src/pkg/go/build/build_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/go/build/build_test.go')
-rw-r--r--src/pkg/go/build/build_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/pkg/go/build/build_test.go b/src/pkg/go/build/build_test.go
new file mode 100644
index 000000000..e59d87672
--- /dev/null
+++ b/src/pkg/go/build/build_test.go
@@ -0,0 +1,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)
+ }
+}