...
Run Format

Source file src/go/build/syslist_test.go

Documentation: go/build

     1  // Copyright 2011 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package build
     6  
     7  import (
     8  	"runtime"
     9  	"testing"
    10  )
    11  
    12  var (
    13  	thisOS    = runtime.GOOS
    14  	thisArch  = runtime.GOARCH
    15  	otherOS   = anotherOS()
    16  	otherArch = anotherArch()
    17  )
    18  
    19  func anotherOS() string {
    20  	if thisOS != "darwin" {
    21  		return "darwin"
    22  	}
    23  	return "linux"
    24  }
    25  
    26  func anotherArch() string {
    27  	if thisArch != "amd64" {
    28  		return "amd64"
    29  	}
    30  	return "386"
    31  }
    32  
    33  type GoodFileTest struct {
    34  	name   string
    35  	result bool
    36  }
    37  
    38  var tests = []GoodFileTest{
    39  	{"file.go", true},
    40  	{"file.c", true},
    41  	{"file_foo.go", true},
    42  	{"file_" + thisArch + ".go", true},
    43  	{"file_" + otherArch + ".go", false},
    44  	{"file_" + thisOS + ".go", true},
    45  	{"file_" + otherOS + ".go", false},
    46  	{"file_" + thisOS + "_" + thisArch + ".go", true},
    47  	{"file_" + otherOS + "_" + thisArch + ".go", false},
    48  	{"file_" + thisOS + "_" + otherArch + ".go", false},
    49  	{"file_" + otherOS + "_" + otherArch + ".go", false},
    50  	{"file_foo_" + thisArch + ".go", true},
    51  	{"file_foo_" + otherArch + ".go", false},
    52  	{"file_" + thisOS + ".c", true},
    53  	{"file_" + otherOS + ".c", false},
    54  }
    55  
    56  func TestGoodOSArch(t *testing.T) {
    57  	for _, test := range tests {
    58  		if Default.goodOSArchFile(test.name, make(map[string]bool)) != test.result {
    59  			t.Fatalf("goodOSArchFile(%q) != %v", test.name, test.result)
    60  		}
    61  	}
    62  }
    63  

View as plain text