LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package build | 5 package build |
6 | 6 |
7 import ( | 7 import ( |
8 "os/exec" | 8 "os/exec" |
9 "path/filepath" | 9 "path/filepath" |
10 "reflect" | 10 "reflect" |
(...skipping 28 matching lines...) Expand all Loading... |
39 &DirInfo{ | 39 &DirInfo{ |
40 GoFiles: []string{"main.go"}, | 40 GoFiles: []string{"main.go"}, |
41 Package: "main", | 41 Package: "main", |
42 Imports: []string{"go/build/pkgtest"}, | 42 Imports: []string{"go/build/pkgtest"}, |
43 TestImports: []string{}, | 43 TestImports: []string{}, |
44 }, | 44 }, |
45 }, | 45 }, |
46 { | 46 { |
47 "go/build/cgotest", | 47 "go/build/cgotest", |
48 &DirInfo{ | 48 &DirInfo{ |
49 » » » CgoFiles: []string{"cgotest.go"}, | 49 » » » CgoFiles: ifCgo([]string{"cgotest.go"}), |
50 CFiles: []string{"cgotest.c"}, | 50 CFiles: []string{"cgotest.c"}, |
51 HFiles: []string{"cgotest.h"}, | 51 HFiles: []string{"cgotest.h"}, |
52 Imports: []string{"C", "unsafe"}, | 52 Imports: []string{"C", "unsafe"}, |
53 TestImports: []string{}, | 53 TestImports: []string{}, |
54 Package: "cgotest", | 54 Package: "cgotest", |
55 }, | 55 }, |
56 }, | 56 }, |
| 57 } |
| 58 |
| 59 func ifCgo(x []string) []string { |
| 60 if DefaultContext.CgoEnabled { |
| 61 return x |
| 62 } |
| 63 return nil |
57 } | 64 } |
58 | 65 |
59 const cmdtestOutput = "3" | 66 const cmdtestOutput = "3" |
60 | 67 |
61 func TestBuild(t *testing.T) { | 68 func TestBuild(t *testing.T) { |
62 for _, tt := range buildPkgs { | 69 for _, tt := range buildPkgs { |
63 tree := Path[0] // Goroot | 70 tree := Path[0] // Goroot |
64 dir := filepath.Join(tree.SrcDir(), tt.dir) | 71 dir := filepath.Join(tree.SrcDir(), tt.dir) |
65 info, err := ScanDir(dir) | 72 info, err := ScanDir(dir) |
66 if err != nil { | 73 if err != nil { |
67 t.Errorf("ScanDir(%#q): %v", tt.dir, err) | 74 t.Errorf("ScanDir(%#q): %v", tt.dir, err) |
68 continue | 75 continue |
69 } | 76 } |
70 if !reflect.DeepEqual(info, tt.info) { | 77 if !reflect.DeepEqual(info, tt.info) { |
71 t.Errorf("ScanDir(%#q) = %#v, want %#v\n", tt.dir, info,
tt.info) | 78 t.Errorf("ScanDir(%#q) = %#v, want %#v\n", tt.dir, info,
tt.info) |
| 79 continue |
| 80 } |
| 81 |
| 82 if tt.dir == "go/build/cgotest" && len(info.CgoFiles) == 0 { |
72 continue | 83 continue |
73 } | 84 } |
74 | 85 |
75 s, err := Build(tree, tt.dir, info) | 86 s, err := Build(tree, tt.dir, info) |
76 if err != nil { | 87 if err != nil { |
77 t.Errorf("Build(%#q): %v", tt.dir, err) | 88 t.Errorf("Build(%#q): %v", tt.dir, err) |
78 continue | 89 continue |
79 } | 90 } |
80 | 91 |
81 if err := s.Run(); err != nil { | 92 if err := s.Run(); err != nil { |
(...skipping 14 matching lines...) Expand all Loading... |
96 } | 107 } |
97 | 108 |
98 // Deferred because cmdtest depends on pkgtest. | 109 // Deferred because cmdtest depends on pkgtest. |
99 defer func(s *Script) { | 110 defer func(s *Script) { |
100 if err := s.Nuke(); err != nil { | 111 if err := s.Nuke(); err != nil { |
101 t.Errorf("nuking: %v", err) | 112 t.Errorf("nuking: %v", err) |
102 } | 113 } |
103 }(s) | 114 }(s) |
104 } | 115 } |
105 } | 116 } |
LEFT | RIGHT |