Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit 5776abf

Browse files
committed
Remove deprecated Stack() []uintptr interface (#45)
* Remove deprecated Stack() []uintptr interface * move TestStack to TestStacktrace
1 parent 89edb63 commit 5776abf

File tree

3 files changed

+55
-58
lines changed

3 files changed

+55
-58
lines changed

errors_test.go

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -197,61 +197,6 @@ func TestErrorf(t *testing.T) {
197197
}
198198
}
199199

200-
func TestStack(t *testing.T) {
201-
type fileline struct {
202-
file string
203-
line int
204-
}
205-
tests := []struct {
206-
err error
207-
want []fileline
208-
}{{
209-
New("ooh"), []fileline{
210-
{"github.com/pkg/errors/errors_test.go", 209},
211-
},
212-
}, {
213-
Wrap(New("ooh"), "ahh"), []fileline{
214-
{"github.com/pkg/errors/errors_test.go", 213}, // this is the stack of Wrap, not New
215-
},
216-
}, {
217-
Cause(Wrap(New("ooh"), "ahh")), []fileline{
218-
{"github.com/pkg/errors/errors_test.go", 217}, // this is the stack of New
219-
},
220-
}, {
221-
func() error { return New("ooh") }(), []fileline{
222-
{"github.com/pkg/errors/errors_test.go", 221}, // this is the stack of New
223-
{"github.com/pkg/errors/errors_test.go", 221}, // this is the stack of New's caller
224-
},
225-
}, {
226-
Cause(func() error {
227-
return func() error {
228-
return Errorf("hello %s", fmt.Sprintf("world"))
229-
}()
230-
}()), []fileline{
231-
{"github.com/pkg/errors/errors_test.go", 228}, // this is the stack of Errorf
232-
{"github.com/pkg/errors/errors_test.go", 229}, // this is the stack of Errorf's caller
233-
{"github.com/pkg/errors/errors_test.go", 230}, // this is the stack of Errorf's caller's caller
234-
},
235-
}}
236-
for _, tt := range tests {
237-
x, ok := tt.err.(interface {
238-
Stack() []uintptr
239-
})
240-
if !ok {
241-
t.Errorf("expected %#v to implement Stack()", tt.err)
242-
continue
243-
}
244-
st := x.Stack()
245-
for i, want := range tt.want {
246-
frame := Frame(st[i])
247-
file, line := fmt.Sprintf("%+s", frame), frame.line()
248-
if file != want.file || line != want.line {
249-
t.Errorf("frame %d: expected %s:%d, got %s:%d", i, want.file, want.line, file, line)
250-
}
251-
}
252-
}
253-
}
254-
255200
// errors.New, etc values are not expected to be compared by value
256201
// but the change in errors#27 made them incomparable. Assert that
257202
// various kinds of errors have a functional equality operator, even

stack.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ func (f Frame) Format(s fmt.State, verb rune) {
7979
// stack represents a stack of program counters.
8080
type stack []uintptr
8181

82-
// Deprecated: use Stacktrace()
83-
func (s *stack) Stack() []uintptr { return *s }
84-
8582
func (s *stack) Stacktrace() []Frame {
8683
f := make([]Frame, len(*s))
8784
for i := 0; i < len(f); i++ {

stack_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,58 @@ func TestTrimGOPATH(t *testing.T) {
168168
}
169169
}
170170
}
171+
172+
func TestStacktrace(t *testing.T) {
173+
type fileline struct {
174+
file string
175+
line int
176+
}
177+
tests := []struct {
178+
err error
179+
want []fileline
180+
}{{
181+
New("ooh"), []fileline{
182+
{"github.com/pkg/errors/stack_test.go", 181},
183+
},
184+
}, {
185+
Wrap(New("ooh"), "ahh"), []fileline{
186+
{"github.com/pkg/errors/stack_test.go", 185}, // this is the stack of Wrap, not New
187+
},
188+
}, {
189+
Cause(Wrap(New("ooh"), "ahh")), []fileline{
190+
{"github.com/pkg/errors/stack_test.go", 189}, // this is the stack of New
191+
},
192+
}, {
193+
func() error { return New("ooh") }(), []fileline{
194+
{"github.com/pkg/errors/stack_test.go", 193}, // this is the stack of New
195+
{"github.com/pkg/errors/stack_test.go", 193}, // this is the stack of New's caller
196+
},
197+
}, {
198+
Cause(func() error {
199+
return func() error {
200+
return Errorf("hello %s", fmt.Sprintf("world"))
201+
}()
202+
}()), []fileline{
203+
{"github.com/pkg/errors/stack_test.go", 200}, // this is the stack of Errorf
204+
{"github.com/pkg/errors/stack_test.go", 201}, // this is the stack of Errorf's caller
205+
{"github.com/pkg/errors/stack_test.go", 202}, // this is the stack of Errorf's caller's caller
206+
},
207+
}}
208+
for _, tt := range tests {
209+
x, ok := tt.err.(interface {
210+
Stacktrace() []Frame
211+
})
212+
if !ok {
213+
t.Errorf("expected %#v to implement Stacktrace() []Frame", tt.err)
214+
continue
215+
}
216+
st := x.Stacktrace()
217+
for i, want := range tt.want {
218+
frame := st[i]
219+
file, line := fmt.Sprintf("%+s", frame), frame.line()
220+
if file != want.file || line != want.line {
221+
t.Errorf("frame %d: expected %s:%d, got %s:%d", i, want.file, want.line, file, line)
222+
}
223+
}
224+
}
225+
}

0 commit comments

Comments
 (0)