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.
15 func sortstr(x []string) []string {
20 var buildPkgs = []struct {
27 GoFiles: []string{"pkgtest.go"},
28 SFiles: []string{"sqrt_" + runtime.GOARCH + ".s"},
30 Imports: []string{"bytes"},
31 TestImports: []string{"fmt", "pkgtest"},
32 TestGoFiles: sortstr([]string{"sqrt_test.go", "sqrt_" + runtime.GOARCH + "_test.go"}),
33 XTestGoFiles: []string{"xsqrt_test.go"},
39 GoFiles: []string{"main.go"},
41 Imports: []string{"go/build/pkgtest"},
42 TestImports: []string{},
48 CgoFiles: ifCgo([]string{"cgotest.go"}),
49 CFiles: []string{"cgotest.c"},
50 HFiles: []string{"cgotest.h"},
51 Imports: []string{"C", "unsafe"},
52 TestImports: []string{},
58 func ifCgo(x []string) []string {
59 if DefaultContext.CgoEnabled {
65 func TestBuild(t *testing.T) {
66 for _, tt := range buildPkgs {
67 tree := Path[0] // Goroot
68 dir := filepath.Join(tree.SrcDir(), tt.dir)
69 info, err := ScanDir(dir)
71 t.Errorf("ScanDir(%#q): %v", tt.dir, err)
74 // Don't bother testing import positions.
75 tt.info.ImportPos, tt.info.TestImportPos = info.ImportPos, info.TestImportPos
76 if !reflect.DeepEqual(info, tt.info) {
77 t.Errorf("ScanDir(%#q) = %#v, want %#v\n", tt.dir, info, tt.info)
83 func TestMatch(t *testing.T) {
84 ctxt := DefaultContext
86 match := func(tag string) {
88 t.Errorf("%s context should match %s, does not", what, tag)
91 nomatch := func(tag string) {
93 t.Errorf("%s context should NOT match %s, does", what, tag)
97 match(runtime.GOOS + "," + runtime.GOARCH)
98 match(runtime.GOOS + "," + runtime.GOARCH + ",!foo")
99 nomatch(runtime.GOOS + "," + runtime.GOARCH + ",foo")
102 ctxt.BuildTags = []string{"foo"}
103 match(runtime.GOOS + "," + runtime.GOARCH)
104 match(runtime.GOOS + "," + runtime.GOARCH + ",foo")
105 nomatch(runtime.GOOS + "," + runtime.GOARCH + ",!foo")
106 match(runtime.GOOS + "," + runtime.GOARCH + ",!bar")
107 nomatch(runtime.GOOS + "," + runtime.GOARCH + ",bar")