OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [go/] [build/] [build_test.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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
        "path/filepath"
9
        "reflect"
10
        "runtime"
11
        "sort"
12
        "testing"
13
)
14
 
15
func sortstr(x []string) []string {
16
        sort.Strings(x)
17
        return x
18
}
19
 
20
var buildPkgs = []struct {
21
        dir  string
22
        info *DirInfo
23
}{
24
        {
25
                "go/build/pkgtest",
26
                &DirInfo{
27
                        GoFiles:      []string{"pkgtest.go"},
28
                        SFiles:       []string{"sqrt_" + runtime.GOARCH + ".s"},
29
                        Package:      "pkgtest",
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"},
34
                },
35
        },
36
        {
37
                "go/build/cmdtest",
38
                &DirInfo{
39
                        GoFiles:     []string{"main.go"},
40
                        Package:     "main",
41
                        Imports:     []string{"go/build/pkgtest"},
42
                        TestImports: []string{},
43
                },
44
        },
45
        {
46
                "go/build/cgotest",
47
                &DirInfo{
48
                        CgoFiles:    ifCgo([]string{"cgotest.go"}),
49
                        CFiles:      []string{"cgotest.c"},
50
                        HFiles:      []string{"cgotest.h"},
51
                        Imports:     []string{"C", "unsafe"},
52
                        TestImports: []string{},
53
                        Package:     "cgotest",
54
                },
55
        },
56
}
57
 
58
func ifCgo(x []string) []string {
59
        if DefaultContext.CgoEnabled {
60
                return x
61
        }
62
        return nil
63
}
64
 
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)
70
                if err != nil {
71
                        t.Errorf("ScanDir(%#q): %v", tt.dir, err)
72
                        continue
73
                }
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)
78
                        continue
79
                }
80
        }
81
}
82
 
83
func TestMatch(t *testing.T) {
84
        ctxt := DefaultContext
85
        what := "default"
86
        match := func(tag string) {
87
                if !ctxt.match(tag) {
88
                        t.Errorf("%s context should match %s, does not", what, tag)
89
                }
90
        }
91
        nomatch := func(tag string) {
92
                if ctxt.match(tag) {
93
                        t.Errorf("%s context should NOT match %s, does", what, tag)
94
                }
95
        }
96
 
97
        match(runtime.GOOS + "," + runtime.GOARCH)
98
        match(runtime.GOOS + "," + runtime.GOARCH + ",!foo")
99
        nomatch(runtime.GOOS + "," + runtime.GOARCH + ",foo")
100
 
101
        what = "modified"
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")
108
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.