LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package build | 5 package build |
6 | 6 |
7 import ( | 7 import ( |
8 "os" | 8 "os" |
9 "path/filepath" | 9 "path/filepath" |
10 "runtime" | 10 "runtime" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 | 69 |
70 p, err := ImportDir(cwd, 0) | 70 p, err := ImportDir(cwd, 0) |
71 if err != nil { | 71 if err != nil { |
72 t.Fatal(err) | 72 t.Fatal(err) |
73 } | 73 } |
74 if p.ImportPath != "go/build" { | 74 if p.ImportPath != "go/build" { |
75 t.Fatalf("ImportPath=%q, want %q", p.ImportPath, "go/build") | 75 t.Fatalf("ImportPath=%q, want %q", p.ImportPath, "go/build") |
76 } | 76 } |
77 } | 77 } |
| 78 |
| 79 func TestShouldBuild(t *testing.T) { |
| 80 const file1 = "// +build tag1\n\n" + |
| 81 "package main\n" |
| 82 |
| 83 const file2 = "// +build cgo\n\n" + |
| 84 "// This package implements parsing of tags like\n" + |
| 85 "// +build tag1\n" + |
| 86 "package build" |
| 87 |
| 88 const file3 = "// Copyright The Go Authors.\n\n" + |
| 89 "package build\n\n" + |
| 90 "// shouldBuild checks tags given by lines of the form\n" + |
| 91 "// +build tag\n" + |
| 92 "func shouldBuild(content []byte)\n" |
| 93 |
| 94 ctx := &Context{BuildTags: []string{"tag1"}} |
| 95 if !ctx.shouldBuild([]byte(file1)) { |
| 96 t.Errorf("should not build file1, expected the contrary") |
| 97 } |
| 98 if ctx.shouldBuild([]byte(file2)) { |
| 99 t.Errorf("should build file2, expected the contrary") |
| 100 } |
| 101 |
| 102 ctx = &Context{BuildTags: nil} |
| 103 if !ctx.shouldBuild([]byte(file3)) { |
| 104 t.Errorf("should not build file3, expected the contrary") |
| 105 } |
| 106 } |
LEFT | RIGHT |