-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexamples_test.go
213 lines (163 loc) · 3.79 KB
/
examples_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package cove
// Copyright 2015 MediaMath <http://www.mediamath.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
func ExampleGet() {
if err := Get("text/scanner"); err != nil {
fmt.Println(err)
}
if err := Get("not/a/package"); err != nil {
fmt.Println("Got error")
}
//Output:
//Got error
}
func ExamplePackageExists() {
if PackageExists("os/exec") {
fmt.Println("os/exec exists")
}
if !PackageExists("boogey/woogey/bugleboy") {
fmt.Println("boogey/woogey/bugleboy does not exist")
}
//Output:
//os/exec exists
//boogey/woogey/bugleboy does not exist
}
func ExampleCoverageProfile() {
testdir, temperr := ioutil.TempDir("", "coverage-profile")
if temperr != nil {
fmt.Printf("%v", temperr)
}
defer os.RemoveAll(testdir)
profile, profileErr := CoverageProfile(false, "count", testdir, "text/scanner")
if profileErr != nil {
fmt.Printf("%v", profileErr)
}
fmt.Println(filepath.Base(profile))
//Output:
//text.scanner.out
}
func ExampleCoverageProfile_short() {
testdir, _ := ioutil.TempDir("", "coverage-profile")
defer os.RemoveAll(testdir)
profile, _ := CoverageProfile(true, "set", testdir, "text/scanner")
fmt.Println(filepath.Base(profile))
//Output:
//text.scanner.out
}
func ExamplePackages_single() {
packs, _ := Packages("text/template")
for _, pack := range packs {
fmt.Println(pack)
}
//Output:
//text/template
}
func ExamplePackages_wildcard() {
packs, _ := Packages("text/...")
for _, pack := range packs {
fmt.Println(pack)
}
//Output:
//text/scanner
//text/tabwriter
//text/template
//text/template/parse
}
func ExamplePackages_multiples() {
packs, _ := Packages("text/...", "os/exec")
for _, pack := range packs {
fmt.Println(pack)
}
//Output:
//os/exec
//text/scanner
//text/tabwriter
//text/template
//text/template/parse
}
func ExamplePackages_relative() {
//duplicates are filtered
packs, _ := Packages(".")
for _, pack := range packs {
fmt.Println(pack)
}
//Output:
//github.com/MediaMath/cove
}
func ExamplePackages_unknown() {
packs, err := Packages("foo/manchu", "text/...", "moo/...")
for _, pack := range packs {
fmt.Println(pack)
}
if err != nil {
fmt.Println("Had errors.")
}
//Output:
//text/scanner
//text/tabwriter
//text/template
//text/template/parse
//Had errors.
}
func ExamplePackages_unknown2() {
packs, err := Packages("foo/manchu")
for _, pack := range packs {
fmt.Println(pack)
}
if err != nil {
fmt.Println("Had errors.")
}
//Output:
//Had errors.
}
func ExamplePackageJSON() {
var info struct {
ImportPath string
Name string
Incomplete bool
}
PackageJSON("os/exec", &info)
fmt.Printf("%s %s %v", info.ImportPath, info.Name, info.Incomplete)
//Output:
//os/exec exec false
}
func ExamplePackageJSON_wildcard() {
type JSONresponse struct {
ImportPath string
Name string
Incomplete bool
}
var resp []JSONresponse
if err := PackageJSON("os/...", &resp); err != nil {
fmt.Printf("'go list -json os/...' returns an invalid json in the multiple return case.")
}
//Output:
//'go list -json os/...' returns an invalid json in the multiple return case.
}
func ExamplePackageJSON_unknown() {
var info struct {
ImportPath string
Name string
Incomplete bool
}
if err := PackageJSON("moo/boo", &info); err != nil {
fmt.Printf("%v", err)
}
//Output:
//Cannot get json for 'moo/boo' as it is not a go package. Original error: EOF
}
func ExampleMissingDependencies_unknown() {
_, err := MissingDependencies("moo/boo")
if err != nil {
fmt.Printf("%v", err)
}
//Output:
//Could not determine missing dependencies for moo/boo: Cannot get json for 'moo/boo' as it is not a go package. Original error: EOF
}