|
@@ -65,7 +65,8 @@ func TestFrameFormat(t *testing.T) {
|
|
|
}, {
|
|
}, {
|
|
|
Frame(initpc),
|
|
Frame(initpc),
|
|
|
"%+s",
|
|
"%+s",
|
|
|
- "github.com/pkg/errors/stack_test.go",
|
|
|
|
|
|
|
+ "github.com/pkg/errors.init\n" +
|
|
|
|
|
+ "\t.+/github.com/pkg/errors/stack_test.go",
|
|
|
}, {
|
|
}, {
|
|
|
Frame(0),
|
|
Frame(0),
|
|
|
"%s",
|
|
"%s",
|
|
@@ -92,7 +93,7 @@ func TestFrameFormat(t *testing.T) {
|
|
|
return x.ptr()
|
|
return x.ptr()
|
|
|
}(),
|
|
}(),
|
|
|
"%n",
|
|
"%n",
|
|
|
- "(*X).ptr",
|
|
|
|
|
|
|
+ `\(\*X\).ptr`,
|
|
|
}, {
|
|
}, {
|
|
|
func() Frame {
|
|
func() Frame {
|
|
|
var x X
|
|
var x X
|
|
@@ -111,7 +112,8 @@ func TestFrameFormat(t *testing.T) {
|
|
|
}, {
|
|
}, {
|
|
|
Frame(initpc),
|
|
Frame(initpc),
|
|
|
"%+v",
|
|
"%+v",
|
|
|
- "github.com/pkg/errors/stack_test.go:9",
|
|
|
|
|
|
|
+ "github.com/pkg/errors.init\n" +
|
|
|
|
|
+ "\t.+/github.com/pkg/errors/stack_test.go:9",
|
|
|
}, {
|
|
}, {
|
|
|
Frame(0),
|
|
Frame(0),
|
|
|
"%v",
|
|
"%v",
|
|
@@ -119,11 +121,7 @@ func TestFrameFormat(t *testing.T) {
|
|
|
}}
|
|
}}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
for _, tt := range tests {
|
|
|
- got := fmt.Sprintf(tt.format, tt.Frame)
|
|
|
|
|
- want := tt.want
|
|
|
|
|
- if want != got {
|
|
|
|
|
- t.Errorf("%v %q: want: %q, got: %q", tt.Frame, tt.format, want, got)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ testFormatRegexp(t, tt.Frame, tt.format, tt.want)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -175,20 +173,25 @@ func TestStacktrace(t *testing.T) {
|
|
|
want []string
|
|
want []string
|
|
|
}{{
|
|
}{{
|
|
|
New("ooh"), []string{
|
|
New("ooh"), []string{
|
|
|
- "github.com/pkg/errors/stack_test.go:177",
|
|
|
|
|
|
|
+ "github.com/pkg/errors.TestStacktrace\n" +
|
|
|
|
|
+ "\t.+/github.com/pkg/errors/stack_test.go:175",
|
|
|
},
|
|
},
|
|
|
}, {
|
|
}, {
|
|
|
Wrap(New("ooh"), "ahh"), []string{
|
|
Wrap(New("ooh"), "ahh"), []string{
|
|
|
- "github.com/pkg/errors/stack_test.go:181", // this is the stack of Wrap, not New
|
|
|
|
|
|
|
+ "github.com/pkg/errors.TestStacktrace\n" +
|
|
|
|
|
+ "\t.+/github.com/pkg/errors/stack_test.go:180", // this is the stack of Wrap, not New
|
|
|
},
|
|
},
|
|
|
}, {
|
|
}, {
|
|
|
Cause(Wrap(New("ooh"), "ahh")), []string{
|
|
Cause(Wrap(New("ooh"), "ahh")), []string{
|
|
|
- "github.com/pkg/errors/stack_test.go:185", // this is the stack of New
|
|
|
|
|
|
|
+ "github.com/pkg/errors.TestStacktrace\n" +
|
|
|
|
|
+ "\t.+/github.com/pkg/errors/stack_test.go:185", // this is the stack of New
|
|
|
},
|
|
},
|
|
|
}, {
|
|
}, {
|
|
|
func() error { return New("ooh") }(), []string{
|
|
func() error { return New("ooh") }(), []string{
|
|
|
- "github.com/pkg/errors/stack_test.go:189", // this is the stack of New
|
|
|
|
|
- "github.com/pkg/errors/stack_test.go:189", // this is the stack of New's caller
|
|
|
|
|
|
|
+ `github.com/pkg/errors.(func·005|TestStacktrace.func1)` +
|
|
|
|
|
+ "\n\t.+/github.com/pkg/errors/stack_test.go:190", // this is the stack of New
|
|
|
|
|
+ "github.com/pkg/errors.TestStacktrace\n" +
|
|
|
|
|
+ "\t.+/github.com/pkg/errors/stack_test.go:190", // this is the stack of New's caller
|
|
|
},
|
|
},
|
|
|
}, {
|
|
}, {
|
|
|
Cause(func() error {
|
|
Cause(func() error {
|
|
@@ -196,12 +199,15 @@ func TestStacktrace(t *testing.T) {
|
|
|
return Errorf("hello %s", fmt.Sprintf("world"))
|
|
return Errorf("hello %s", fmt.Sprintf("world"))
|
|
|
}()
|
|
}()
|
|
|
}()), []string{
|
|
}()), []string{
|
|
|
- "github.com/pkg/errors/stack_test.go:196", // this is the stack of Errorf
|
|
|
|
|
- "github.com/pkg/errors/stack_test.go:197", // this is the stack of Errorf's caller
|
|
|
|
|
- "github.com/pkg/errors/stack_test.go:198", // this is the stack of Errorf's caller's caller
|
|
|
|
|
|
|
+ `github.com/pkg/errors.(func·006|TestStacktrace.func2.1)` +
|
|
|
|
|
+ "\n\t.+/github.com/pkg/errors/stack_test.go:199", // this is the stack of Errorf
|
|
|
|
|
+ `github.com/pkg/errors.(func·007|TestStacktrace.func2)` +
|
|
|
|
|
+ "\n\t.+/github.com/pkg/errors/stack_test.go:200", // this is the stack of Errorf's caller
|
|
|
|
|
+ "github.com/pkg/errors.TestStacktrace\n" +
|
|
|
|
|
+ "\t.+/github.com/pkg/errors/stack_test.go:201", // this is the stack of Errorf's caller's caller
|
|
|
},
|
|
},
|
|
|
}}
|
|
}}
|
|
|
- for i, tt := range tests {
|
|
|
|
|
|
|
+ for _, tt := range tests {
|
|
|
x, ok := tt.err.(interface {
|
|
x, ok := tt.err.(interface {
|
|
|
Stacktrace() Stacktrace
|
|
Stacktrace() Stacktrace
|
|
|
})
|
|
})
|
|
@@ -211,11 +217,7 @@ func TestStacktrace(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
st := x.Stacktrace()
|
|
st := x.Stacktrace()
|
|
|
for j, want := range tt.want {
|
|
for j, want := range tt.want {
|
|
|
- frame := st[j]
|
|
|
|
|
- got := fmt.Sprintf("%+v", frame)
|
|
|
|
|
- if got != want {
|
|
|
|
|
- t.Errorf("test %d: frame %d: got %q, want %q", i, j, got, want)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ testFormatRegexp(t, st[j], "%+v", want)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -236,57 +238,58 @@ func TestStacktraceFormat(t *testing.T) {
|
|
|
}{{
|
|
}{{
|
|
|
nil,
|
|
nil,
|
|
|
"%s",
|
|
"%s",
|
|
|
- "[]",
|
|
|
|
|
|
|
+ `\[\]`,
|
|
|
}, {
|
|
}, {
|
|
|
nil,
|
|
nil,
|
|
|
"%v",
|
|
"%v",
|
|
|
- "[]",
|
|
|
|
|
|
|
+ `\[\]`,
|
|
|
}, {
|
|
}, {
|
|
|
nil,
|
|
nil,
|
|
|
"%+v",
|
|
"%+v",
|
|
|
- "[]",
|
|
|
|
|
|
|
+ "",
|
|
|
}, {
|
|
}, {
|
|
|
nil,
|
|
nil,
|
|
|
"%#v",
|
|
"%#v",
|
|
|
- "[]errors.Frame(nil)",
|
|
|
|
|
|
|
+ `\[\]errors.Frame\(nil\)`,
|
|
|
}, {
|
|
}, {
|
|
|
make(Stacktrace, 0),
|
|
make(Stacktrace, 0),
|
|
|
"%s",
|
|
"%s",
|
|
|
- "[]",
|
|
|
|
|
|
|
+ `\[\]`,
|
|
|
}, {
|
|
}, {
|
|
|
make(Stacktrace, 0),
|
|
make(Stacktrace, 0),
|
|
|
"%v",
|
|
"%v",
|
|
|
- "[]",
|
|
|
|
|
|
|
+ `\[\]`,
|
|
|
}, {
|
|
}, {
|
|
|
make(Stacktrace, 0),
|
|
make(Stacktrace, 0),
|
|
|
"%+v",
|
|
"%+v",
|
|
|
- "[]",
|
|
|
|
|
|
|
+ "",
|
|
|
}, {
|
|
}, {
|
|
|
make(Stacktrace, 0),
|
|
make(Stacktrace, 0),
|
|
|
"%#v",
|
|
"%#v",
|
|
|
- "[]errors.Frame{}",
|
|
|
|
|
|
|
+ `\[\]errors.Frame{}`,
|
|
|
}, {
|
|
}, {
|
|
|
stacktrace()[:2],
|
|
stacktrace()[:2],
|
|
|
"%s",
|
|
"%s",
|
|
|
- "[stack_test.go stack_test.go]",
|
|
|
|
|
|
|
+ `\[stack_test.go stack_test.go\]`,
|
|
|
}, {
|
|
}, {
|
|
|
stacktrace()[:2],
|
|
stacktrace()[:2],
|
|
|
"%v",
|
|
"%v",
|
|
|
- "[stack_test.go:226 stack_test.go:273]",
|
|
|
|
|
|
|
+ `\[stack_test.go:228 stack_test.go:275\]`,
|
|
|
}, {
|
|
}, {
|
|
|
stacktrace()[:2],
|
|
stacktrace()[:2],
|
|
|
"%+v",
|
|
"%+v",
|
|
|
- "[github.com/pkg/errors/stack_test.go:226 github.com/pkg/errors/stack_test.go:277]",
|
|
|
|
|
|
|
+ "\n" +
|
|
|
|
|
+ "github.com/pkg/errors.stacktrace\n" +
|
|
|
|
|
+ "\t.+/github.com/pkg/errors/stack_test.go:228\n" +
|
|
|
|
|
+ "github.com/pkg/errors.TestStacktraceFormat\n" +
|
|
|
|
|
+ "\t.+/github.com/pkg/errors/stack_test.go:279",
|
|
|
}, {
|
|
}, {
|
|
|
stacktrace()[:2],
|
|
stacktrace()[:2],
|
|
|
"%#v",
|
|
"%#v",
|
|
|
- "[]errors.Frame{stack_test.go:226, stack_test.go:281}",
|
|
|
|
|
|
|
+ `\[\]errors.Frame{stack_test.go:228, stack_test.go:287}`,
|
|
|
}}
|
|
}}
|
|
|
|
|
|
|
|
- for i, tt := range tests {
|
|
|
|
|
- got := fmt.Sprintf(tt.format, tt.Stacktrace)
|
|
|
|
|
- if got != tt.want {
|
|
|
|
|
- t.Errorf("test %d: got: %q, want: %q", i+1, got, tt.want)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ for _, tt := range tests {
|
|
|
|
|
+ testFormatRegexp(t, tt.Stacktrace, tt.format, tt.want)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|