|
|
@@ -10,6 +10,26 @@ import (
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
|
+func BenchmarkStackFormat(b *testing.B) {
|
|
|
+ b.ReportAllocs()
|
|
|
+
|
|
|
+ for i := 0; i < b.N; i++ {
|
|
|
+ func() {
|
|
|
+ defer func() {
|
|
|
+ err := recover()
|
|
|
+ if err != 'a' {
|
|
|
+ b.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ e := Errorf("hi")
|
|
|
+ _ = string(e.Stack())
|
|
|
+ }()
|
|
|
+
|
|
|
+ a()
|
|
|
+ }()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestStackFormat(t *testing.T) {
|
|
|
|
|
|
defer func() {
|
|
|
@@ -247,7 +267,7 @@ func c() {
|
|
|
|
|
|
// compareStacks will compare a stack created using the errors package (actual)
|
|
|
// with a reference stack created with the callers function (expected). The
|
|
|
-// first entry is compared inexact since the actual and expected stacks cannot
|
|
|
+// first entry is not compared since the actual and expected stacks cannot
|
|
|
// be created at the exact same program counter position so the first entry
|
|
|
// will always differ somewhat. Returns nil if the stacks are equal enough and
|
|
|
// an error containing a detailed error message otherwise.
|
|
|
@@ -256,12 +276,7 @@ func compareStacks(actual, expected []uintptr) error {
|
|
|
return stackCompareError("Stacks does not have equal length", actual, expected)
|
|
|
}
|
|
|
for i, pc := range actual {
|
|
|
- if i == 0 {
|
|
|
- firstEntryDiff := (int)(expected[i]) - (int)(pc)
|
|
|
- if firstEntryDiff < -27 || firstEntryDiff > 27 {
|
|
|
- return stackCompareError(fmt.Sprintf("First entry PC diff to large (%d)", firstEntryDiff), actual, expected)
|
|
|
- }
|
|
|
- } else if pc != expected[i] {
|
|
|
+ if i != 0 && pc != expected[i] {
|
|
|
return stackCompareError(fmt.Sprintf("Stacks does not match entry %d (and maybe others)", i), actual, expected)
|
|
|
}
|
|
|
}
|