@@ -29,43 +29,6 @@ func TestMain(m *testing.M) {
29
29
os .Exit (m .Run ())
30
30
}
31
31
32
- // ----------------------------------------------------------------------------
33
- // The following three functions (Builder, HasGoBuild, MustHaveGoBuild) were
34
- // copied from $GOROOT/src/internal/testenv since that package is not available
35
- // in x/tools.
36
-
37
- // Builder reports the name of the builder running this test
38
- // (for example, "linux-amd64" or "windows-386-gce").
39
- // If the test is not running on the build infrastructure,
40
- // Builder returns the empty string.
41
- func Builder () string {
42
- return os .Getenv ("GO_BUILDER_NAME" )
43
- }
44
-
45
- // HasGoBuild reports whether the current system can build programs with ``go build''
46
- // and then run them with os.StartProcess or exec.Command.
47
- func HasGoBuild () bool {
48
- switch runtime .GOOS {
49
- case "android" , "nacl" :
50
- return false
51
- case "darwin" :
52
- if strings .HasPrefix (runtime .GOARCH , "arm" ) {
53
- return false
54
- }
55
- }
56
- return true
57
- }
58
-
59
- // MustHaveGoBuild checks that the current system can build programs with ``go build''
60
- // and then run them with os.StartProcess or exec.Command.
61
- // If not, MustHaveGoBuild calls t.Skip with an explanation.
62
- func MustHaveGoBuild (t * testing.T ) {
63
- testenv .NeedsTool (t , "go" )
64
- if ! HasGoBuild () {
65
- t .Skipf ("skipping test: 'go build' not available on %s/%s" , runtime .GOOS , runtime .GOARCH )
66
- }
67
- }
68
-
69
32
// ----------------------------------------------------------------------------
70
33
71
34
// skipSpecialPlatforms causes the test to be skipped for platforms where
@@ -82,10 +45,21 @@ func skipSpecialPlatforms(t *testing.T) {
82
45
}
83
46
}
84
47
48
+ func needsCompiler (t * testing.T , compiler string ) {
49
+ if runtime .Compiler == compiler {
50
+ return
51
+ }
52
+ switch compiler {
53
+ case "gc" :
54
+ t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
55
+ }
56
+ }
57
+
85
58
// compile runs the compiler on filename, with dirname as the working directory,
86
59
// and writes the output file to outdirname.
87
60
func compile (t * testing.T , dirname , filename , outdirname string ) string {
88
- /* testenv. */ MustHaveGoBuild (t )
61
+ testenv .NeedsGoBuild (t )
62
+
89
63
// filename must end with ".go"
90
64
if ! strings .HasSuffix (filename , ".go" ) {
91
65
t .Fatalf ("filename doesn't end in .go: %s" , filename )
@@ -159,10 +133,7 @@ func mktmpdir(t *testing.T) string {
159
133
const testfile = "exports.go"
160
134
161
135
func TestImportTestdata (t * testing.T ) {
162
- // This package only handles gc export data.
163
- if runtime .Compiler != "gc" {
164
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
165
- }
136
+ needsCompiler (t , "gc" )
166
137
167
138
tmpdir := mktmpdir (t )
168
139
defer os .RemoveAll (tmpdir )
@@ -194,9 +165,7 @@ func TestVersionHandling(t *testing.T) {
194
165
skipSpecialPlatforms (t ) // we really only need to exclude nacl platforms, but this is fine
195
166
196
167
// This package only handles gc export data.
197
- if runtime .Compiler != "gc" {
198
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
199
- }
168
+ needsCompiler (t , "gc" )
200
169
201
170
const dir = "./testdata/versions"
202
171
list , err := ioutil .ReadDir (dir )
@@ -275,12 +244,10 @@ func TestImportStdLib(t *testing.T) {
275
244
skipSpecialPlatforms (t )
276
245
277
246
// This package only handles gc export data.
278
- if runtime .Compiler != "gc" {
279
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
280
- }
247
+ needsCompiler (t , "gc" )
281
248
282
249
dt := maxTime
283
- if testing .Short () && /* testenv. */ Builder ( ) == "" {
250
+ if testing .Short () && os . Getenv ( "GO_BUILDER_NAME" ) == "" {
284
251
dt = 10 * time .Millisecond
285
252
}
286
253
nimports := testDir (t , "" , time .Now ().Add (dt )) // installed packages
@@ -316,9 +283,7 @@ func TestImportedTypes(t *testing.T) {
316
283
skipSpecialPlatforms (t )
317
284
318
285
// This package only handles gc export data.
319
- if runtime .Compiler != "gc" {
320
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
321
- }
286
+ needsCompiler (t , "gc" )
322
287
323
288
for _ , test := range importedObjectTests {
324
289
obj := importObject (t , test .name )
@@ -424,9 +389,7 @@ func TestIssue5815(t *testing.T) {
424
389
skipSpecialPlatforms (t )
425
390
426
391
// This package only handles gc export data.
427
- if runtime .Compiler != "gc" {
428
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
429
- }
392
+ needsCompiler (t , "gc" )
430
393
431
394
pkg := importPkg (t , "strings" , "." )
432
395
@@ -453,9 +416,7 @@ func TestCorrectMethodPackage(t *testing.T) {
453
416
skipSpecialPlatforms (t )
454
417
455
418
// This package only handles gc export data.
456
- if runtime .Compiler != "gc" {
457
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
458
- }
419
+ needsCompiler (t , "gc" )
459
420
460
421
imports := make (map [string ]* types.Package )
461
422
_ , err := Import (imports , "net/http" , "." , nil )
@@ -476,9 +437,7 @@ func TestIssue13566(t *testing.T) {
476
437
skipSpecialPlatforms (t )
477
438
478
439
// This package only handles gc export data.
479
- if runtime .Compiler != "gc" {
480
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
481
- }
440
+ needsCompiler (t , "gc" )
482
441
483
442
// On windows, we have to set the -D option for the compiler to avoid having a drive
484
443
// letter and an illegal ':' in the import path - just skip it (see also issue #3483).
@@ -515,9 +474,7 @@ func TestIssue13898(t *testing.T) {
515
474
skipSpecialPlatforms (t )
516
475
517
476
// This package only handles gc export data.
518
- if runtime .Compiler != "gc" {
519
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
520
- }
477
+ needsCompiler (t , "gc" )
521
478
522
479
// import go/internal/gcimporter which imports go/types partially
523
480
imports := make (map [string ]* types.Package )
@@ -561,9 +518,7 @@ func TestIssue15517(t *testing.T) {
561
518
skipSpecialPlatforms (t )
562
519
563
520
// This package only handles gc export data.
564
- if runtime .Compiler != "gc" {
565
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
566
- }
521
+ needsCompiler (t , "gc" )
567
522
568
523
// On windows, we have to set the -D option for the compiler to avoid having a drive
569
524
// letter and an illegal ':' in the import path - just skip it (see also issue #3483).
@@ -600,9 +555,7 @@ func TestIssue15920(t *testing.T) {
600
555
skipSpecialPlatforms (t )
601
556
602
557
// This package only handles gc export data.
603
- if runtime .Compiler != "gc" {
604
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
605
- }
558
+ needsCompiler (t , "gc" )
606
559
607
560
// On windows, we have to set the -D option for the compiler to avoid having a drive
608
561
// letter and an illegal ':' in the import path - just skip it (see also issue #3483).
@@ -617,9 +570,7 @@ func TestIssue20046(t *testing.T) {
617
570
skipSpecialPlatforms (t )
618
571
619
572
// This package only handles gc export data.
620
- if runtime .Compiler != "gc" {
621
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
622
- }
573
+ needsCompiler (t , "gc" )
623
574
624
575
// On windows, we have to set the -D option for the compiler to avoid having a drive
625
576
// letter and an illegal ':' in the import path - just skip it (see also issue #3483).
@@ -640,9 +591,7 @@ func TestIssue25301(t *testing.T) {
640
591
skipSpecialPlatforms (t )
641
592
642
593
// This package only handles gc export data.
643
- if runtime .Compiler != "gc" {
644
- t .Skipf ("gc-built packages not available (compiler = %s)" , runtime .Compiler )
645
- }
594
+ needsCompiler (t , "gc" )
646
595
647
596
// On windows, we have to set the -D option for the compiler to avoid having a drive
648
597
// letter and an illegal ':' in the import path - just skip it (see also issue #3483).
0 commit comments