Source file src/cmd/go/internal/modindex/syslist_test.go

     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  // This file is a lightly modified copy go/build/syslist_test.go.
     6  
     7  package modindex
     8  
     9  import (
    10  	"go/build"
    11  	"runtime"
    12  	"testing"
    13  )
    14  
    15  var (
    16  	thisOS    = runtime.GOOS
    17  	thisArch  = runtime.GOARCH
    18  	otherOS   = anotherOS()
    19  	otherArch = anotherArch()
    20  )
    21  
    22  func anotherOS() string {
    23  	if thisOS != "darwin" && thisOS != "ios" {
    24  		return "darwin"
    25  	}
    26  	return "linux"
    27  }
    28  
    29  func anotherArch() string {
    30  	if thisArch != "amd64" {
    31  		return "amd64"
    32  	}
    33  	return "386"
    34  }
    35  
    36  type GoodFileTest struct {
    37  	name   string
    38  	result bool
    39  }
    40  
    41  var tests = []GoodFileTest{
    42  	{"file.go", true},
    43  	{"file.c", true},
    44  	{"file_foo.go", true},
    45  	{"file_" + thisArch + ".go", true},
    46  	{"file_" + otherArch + ".go", false},
    47  	{"file_" + thisOS + ".go", true},
    48  	{"file_" + otherOS + ".go", false},
    49  	{"file_" + thisOS + "_" + thisArch + ".go", true},
    50  	{"file_" + otherOS + "_" + thisArch + ".go", false},
    51  	{"file_" + thisOS + "_" + otherArch + ".go", false},
    52  	{"file_" + otherOS + "_" + otherArch + ".go", false},
    53  	{"file_foo_" + thisArch + ".go", true},
    54  	{"file_foo_" + otherArch + ".go", false},
    55  	{"file_" + thisOS + ".c", true},
    56  	{"file_" + otherOS + ".c", false},
    57  }
    58  
    59  func TestGoodOSArch(t *testing.T) {
    60  	for _, test := range tests {
    61  		if (*Context)(&build.Default).goodOSArchFile(test.name, make(map[string]bool)) != test.result {
    62  			t.Fatalf("goodOSArchFile(%q) != %v", test.name, test.result)
    63  		}
    64  	}
    65  }
    66  

View as plain text