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.
14 func TestMatch(t *testing.T) {
17 match := func(tag string) {
19 t.Errorf("%s context should match %s, does not", what, tag)
22 nomatch := func(tag string) {
24 t.Errorf("%s context should NOT match %s, does", what, tag)
28 match(runtime.GOOS + "," + runtime.GOARCH)
29 match(runtime.GOOS + "," + runtime.GOARCH + ",!foo")
30 nomatch(runtime.GOOS + "," + runtime.GOARCH + ",foo")
33 ctxt.BuildTags = []string{"foo"}
34 match(runtime.GOOS + "," + runtime.GOARCH)
35 match(runtime.GOOS + "," + runtime.GOARCH + ",foo")
36 nomatch(runtime.GOOS + "," + runtime.GOARCH + ",!foo")
37 match(runtime.GOOS + "," + runtime.GOARCH + ",!bar")
38 nomatch(runtime.GOOS + "," + runtime.GOARCH + ",bar")
42 func TestDotSlashImport(t *testing.T) {
43 p, err := ImportDir("testdata/other", 0)
47 if len(p.Imports) != 1 || p.Imports[0] != "./file" {
48 t.Fatalf("testdata/other: Imports=%v, want [./file]", p.Imports)
51 p1, err := Import("./file", "testdata/other", 0)
55 if p1.Name != "file" {
56 t.Fatalf("./file: Name=%q, want %q", p1.Name, "file")
58 dir := filepath.Clean("testdata/other/file") // Clean to use \ on Windows
60 t.Fatalf("./file: Dir=%q, want %q", p1.Name, dir)
64 func TestLocalDirectory(t *testing.T) {
65 cwd, err := os.Getwd()
70 p, err := ImportDir(cwd, 0)
74 if p.ImportPath != "go/build" {
75 t.Fatalf("ImportPath=%q, want %q", p.ImportPath, "go/build")