fix(deps) transitive dependency was missing
programmer error License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Nov 15, 2014 at 00:46 UTC
9f798e86b294b76a0059b5240c9580134f291db4
7 files changed
+334
-3
Godeps/Godeps.json
+5
-1
@@ -1,6 +1,6 @@
1
{
2
"ImportPath": "github.com/jbenet/go-ipfs",
3
- "GoVersion": "go1.3",
3
+ "GoVersion": "go1.3.3",
4
"Packages": [
5
"./..."
6
],
@@ -60,6 +60,10 @@
60
"ImportPath": "github.com/coreos/go-semver/semver",
61
"Rev": "6fe83ccda8fb9b7549c9ab4ba47f47858bc950aa"
62
},
63
+ {
64
+ "ImportPath": "github.com/facebookgo/stack",
65
+ "Rev": "4da6d991fc3c389efa512151354d643eb5fae4e2"
66
+ },
67
{
68
"ImportPath": "github.com/facebookgo/stackerr",
69
"Rev": "060fbf9364c89acd41bf710e9e92915a90e7a5b5"
Godeps/_workspace/src/github.com/facebookgo/stack/.travis.yml
new
+24
@@ -0,0 +1,24 @@
1
+language: go
2
+
3
+go:
4
+ - 1.2
5
+ - 1.3
6
+
7
+matrix:
8
+ fast_finish: true
9
+
10
+before_install:
11
+ - go get -v code.google.com/p/go.tools/cmd/vet
12
+ - go get -v github.com/golang/lint/golint
13
+ - go get -v code.google.com/p/go.tools/cmd/cover
14
+
15
+install:
16
+ - go install -race -v std
17
+ - go get -race -t -v ./...
18
+ - go install -race -v ./...
19
+
20
+script:
21
+ - go vet ./...
22
+ - $HOME/gopath/bin/golint .
23
+ - go test -cpu=2 -race -v ./...
24
+ - go test -cpu=2 -covermode=atomic ./...
Godeps/_workspace/src/github.com/facebookgo/stack/readme.md
new
+4
@@ -0,0 +1,4 @@
1
+stack [](http://travis-ci.org/facebookgo/stack)
2
+=====
3
+
4
+Documentation: https://godoc.org/github.com/facebookgo/stack
Godeps/_workspace/src/github.com/facebookgo/stack/stack.go
new
+197
@@ -0,0 +1,197 @@
1
+// Package stack provides utilities to capture and pass around stack traces.
2
+//
3
+// This is useful for building errors that know where they originated from, to
4
+// track where a certain log event occured and so on.
5
+package stack
6
+
7
+import (
8
+ "bytes"
9
+ "fmt"
10
+ "os"
11
+ "path/filepath"
12
+ "runtime"
13
+ "strings"
14
+)
15
+
16
+const maxStackSize = 32
17
+
18
+// Frame identifies a file, line & function name in the stack.
19
+type Frame struct {
20
+ File string
21
+ Line int
22
+ Name string
23
+}
24
+
25
+// String provides the standard file:line representation.
26
+func (f Frame) String() string {
27
+ return fmt.Sprintf("%s:%d %s", f.File, f.Line, f.Name)
28
+}
29
+
30
+// Stack represents an ordered set of Frames.
31
+type Stack []Frame
32
+
33
+// String provides the standard multi-line stack trace.
34
+func (s Stack) String() string {
35
+ var b bytes.Buffer
36
+ writeStack(&b, s)
37
+ return b.String()
38
+}
39
+
40
+// Multi represents a number of Stacks. This is useful to allow tracking a
41
+// value as it travels thru code.
42
+type Multi struct {
43
+ stacks []Stack
44
+}
45
+
46
+// Stacks returns the tracked Stacks.
47
+func (m *Multi) Stacks() []Stack {
48
+ return m.stacks
49
+}
50
+
51
+// Add the given Stack to this Multi.
52
+func (m *Multi) Add(s Stack) {
53
+ m.stacks = append(m.stacks, s)
54
+}
55
+
56
+// AddCallers adds the Callers Stack to this Multi. The argument skip is
57
+// the number of stack frames to ascend, with 0 identifying the caller of
58
+// Callers.
59
+func (m *Multi) AddCallers(skip int) {
60
+ m.Add(Callers(skip + 1))
61
+}
62
+
63
+// String provides a human readable multi-line stack trace.
64
+func (m *Multi) String() string {
65
+ var b bytes.Buffer
66
+ for i, s := range m.stacks {
67
+ if i != 0 {
68
+ fmt.Fprintf(&b, "\n(Stack %d)\n", i+1)
69
+ }
70
+ writeStack(&b, s)
71
+ }
72
+ return b.String()
73
+}
74
+
75
+// Caller returns a single Frame for the caller. The argument skip is the
76
+// number of stack frames to ascend, with 0 identifying the caller of Callers.
77
+func Caller(skip int) Frame {
78
+ pc, file, line, _ := runtime.Caller(skip + 1)
79
+ fun := runtime.FuncForPC(pc)
80
+ return Frame{
81
+ File: StripGOPATH(file),
82
+ Line: line,
83
+ Name: StripPackage(fun.Name()),
84
+ }
85
+}
86
+
87
+// Callers returns a Stack of Frames for the callers. The argument skip is the
88
+// number of stack frames to ascend, with 0 identifying the caller of Callers.
89
+func Callers(skip int) Stack {
90
+ pcs := make([]uintptr, maxStackSize)
91
+ num := runtime.Callers(skip+2, pcs)
92
+ stack := make(Stack, num)
93
+ for i, pc := range pcs[:num] {
94
+ fun := runtime.FuncForPC(pc)
95
+ file, line := fun.FileLine(pc)
96
+ stack[i].File = StripGOPATH(file)
97
+ stack[i].Line = line
98
+ stack[i].Name = StripPackage(fun.Name())
99
+ }
100
+ return stack
101
+}
102
+
103
+// CallersMulti returns a Multi which includes one Stack for the
104
+// current callers. The argument skip is the number of stack frames to ascend,
105
+// with 0 identifying the caller of CallersMulti.
106
+func CallersMulti(skip int) *Multi {
107
+ m := new(Multi)
108
+ m.AddCallers(skip + 1)
109
+ return m
110
+}
111
+
112
+func writeStack(b *bytes.Buffer, s Stack) {
113
+ var width int
114
+ for _, f := range s {
115
+ if l := len(f.File) + numDigits(f.Line) + 1; l > width {
116
+ width = l
117
+ }
118
+ }
119
+ last := len(s) - 1
120
+ for i, f := range s {
121
+ b.WriteString(f.File)
122
+ b.WriteRune(rune(':'))
123
+ n, _ := fmt.Fprintf(b, "%d", f.Line)
124
+ for i := width - len(f.File) - n; i != 0; i-- {
125
+ b.WriteRune(rune(' '))
126
+ }
127
+ b.WriteString(f.Name)
128
+ if i != last {
129
+ b.WriteRune(rune('\n'))
130
+ }
131
+ }
132
+}
133
+
134
+func numDigits(i int) int {
135
+ var n int
136
+ for {
137
+ n++
138
+ i = i / 10
139
+ if i == 0 {
140
+ return n
141
+ }
142
+ }
143
+}
144
+
145
+// This can be set by a build script. It will be the colon separated equivalent
146
+// of the environment variable.
147
+var gopath string
148
+
149
+// This is the processed version based on either the above variable set by the
150
+// build or from the GOPATH environment variable.
151
+var gopaths []string
152
+
153
+func init() {
154
+ // prefer the variable set at build time, otherwise fallback to the
155
+ // environment variable.
156
+ if gopath == "" {
157
+ gopath = os.Getenv("GOPATH")
158
+ }
159
+
160
+ for _, p := range strings.Split(gopath, ":") {
161
+ if p != "" {
162
+ gopaths = append(gopaths, filepath.Join(p, "src")+"/")
163
+ }
164
+ }
165
+
166
+ // Also strip GOROOT for maximum cleanliness
167
+ gopaths = append(gopaths, filepath.Join(runtime.GOROOT(), "src", "pkg")+"/")
168
+}
169
+
170
+// StripGOPATH strips the GOPATH prefix from the file path f.
171
+// In development, this will be done using the GOPATH environment variable.
172
+// For production builds, where the GOPATH environment will not be set, the
173
+// GOPATH can be included in the binary by passing ldflags, for example:
174
+//
175
+// GO_LDFLAGS="$GO_LDFLAGS -X github.com/facebookgo/stack.gopath $GOPATH"
176
+// go install "-ldflags=$GO_LDFLAGS" my/pkg
177
+func StripGOPATH(f string) string {
178
+ for _, p := range gopaths {
179
+ if strings.HasPrefix(f, p) {
180
+ return f[len(p):]
181
+ }
182
+ }
183
+ return f
184
+}
185
+
186
+// StripPackage strips the package name from the given Func.Name.
187
+func StripPackage(n string) string {
188
+ slashI := strings.LastIndex(n, "/")
189
+ if slashI == -1 {
190
+ slashI = 0 // for built-in packages
191
+ }
192
+ dotI := strings.Index(n[slashI:], ".")
193
+ if dotI == -1 {
194
+ return n
195
+ }
196
+ return n[slashI+dotI+1:]
197
+}
Godeps/_workspace/src/github.com/facebookgo/stack/stack_test.go
new
+102
@@ -0,0 +1,102 @@
1
+package stack_test
2
+
3
+import (
4
+ "regexp"
5
+ "strings"
6
+ "testing"
7
+
8
+ "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/facebookgo/stack"
9
+)
10
+
11
+func indirect1() stack.Stack {
12
+ return stack.Callers(0)
13
+}
14
+
15
+func indirect2() stack.Stack {
16
+ return indirect1()
17
+}
18
+
19
+func indirect3() stack.Stack {
20
+ return indirect2()
21
+}
22
+
23
+func TestCallers(t *testing.T) {
24
+ s := indirect3()
25
+ matches := []string{
26
+ "^github.com/facebookgo/stack/stack_test.go:12 +indirect1$",
27
+ "^github.com/facebookgo/stack/stack_test.go:16 +indirect2$",
28
+ "^github.com/facebookgo/stack/stack_test.go:20 +indirect3$",
29
+ "^github.com/facebookgo/stack/stack_test.go:24 +TestCallers$",
30
+ }
31
+ match(t, s.String(), matches)
32
+}
33
+
34
+func TestCallersMulti(t *testing.T) {
35
+ m := stack.CallersMulti(0)
36
+ const expected = "github.com/facebookgo/stack/stack_test.go:35 TestCallersMulti"
37
+ first := m.Stacks()[0][0].String()
38
+ if first != expected {
39
+ t.Fatalf(`expected "%s" got "%s"`, expected, first)
40
+ }
41
+}
42
+
43
+func TestCallersMultiWithTwo(t *testing.T) {
44
+ m := stack.CallersMulti(0)
45
+ m.AddCallers(0)
46
+ matches := []string{
47
+ "^github.com/facebookgo/stack/stack_test.go:44 +TestCallersMultiWithTwo$",
48
+ "",
49
+ "",
50
+ `^\(Stack 2\)$`,
51
+ "^github.com/facebookgo/stack/stack_test.go:46 +TestCallersMultiWithTwo$",
52
+ }
53
+ match(t, m.String(), matches)
54
+}
55
+
56
+type typ struct{}
57
+
58
+func (m typ) indirect1() stack.Stack {
59
+ return stack.Callers(0)
60
+}
61
+
62
+func (m typ) indirect2() stack.Stack {
63
+ return m.indirect1()
64
+}
65
+
66
+func (m typ) indirect3() stack.Stack {
67
+ return m.indirect2()
68
+}
69
+
70
+func TestCallersWithStruct(t *testing.T) {
71
+ var m typ
72
+ s := m.indirect3()
73
+ matches := []string{
74
+ "^github.com/facebookgo/stack/stack_test.go:59 +typ.indirect1$",
75
+ "^github.com/facebookgo/stack/stack_test.go:63 +typ.indirect2$",
76
+ "^github.com/facebookgo/stack/stack_test.go:67 +typ.indirect3$",
77
+ "^github.com/facebookgo/stack/stack_test.go:72 +TestCallersWithStruct$",
78
+ }
79
+ match(t, s.String(), matches)
80
+}
81
+
82
+func TestCaller(t *testing.T) {
83
+ f := stack.Caller(0)
84
+ const expected = "github.com/facebookgo/stack/stack_test.go:83 TestCaller"
85
+ if f.String() != expected {
86
+ t.Fatalf(`expected "%s" got "%s"`, expected, f)
87
+ }
88
+}
89
+
90
+func match(t testing.TB, s string, matches []string) {
91
+ lines := strings.Split(s, "\n")
92
+ for i, m := range matches {
93
+ if !regexp.MustCompile(m).MatchString(lines[i]) {
94
+ t.Fatalf(
95
+ "did not find expected match \"%s\" on line %d in:\n%s",
96
+ m,
97
+ i,
98
+ s,
99
+ )
100
+ }
101
+ }
102
+}
Godeps/_workspace/src/github.com/facebookgo/stackerr/stackerr.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"errors"
7
"fmt"
8
9
- "github.com/facebookgo/stack"
9
+ "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/facebookgo/stack"
10
)
11
12
// Error provides the wrapper that adds multiple Stacks to an error. Each Stack
Godeps/_workspace/src/github.com/facebookgo/stackerr/stackerr_test.go
+1
-1
@@ -7,7 +7,7 @@ import (
7
"strings"
8
"testing"
9
10
- "github.com/facebookgo/stackerr"
10
+ "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/facebookgo/stackerr"
11
)
12
13
func TestNew(t *testing.T) {