浏览代码

Fix WrapPrefix skip.

Gabriel Falkenberg 8 年之前
父节点
当前提交
829d436ebb
共有 2 个文件被更改,包括 6 次插入2 次删除
  1. 1 1
      error.go
  2. 5 1
      error_test.go

+ 1 - 1
error.go

@@ -118,7 +118,7 @@ func Wrap(e interface{}, skip int) *Error {
 // 1 from its caller, etc.
 func WrapPrefix(e interface{}, prefix string, skip int) *Error {
 
-	err := Wrap(e, skip)
+	err := Wrap(e, 1+skip)
 
 	if err.prefix != "" {
 		err.prefix = fmt.Sprintf("%s: %s", prefix, err.prefix)

+ 5 - 1
error_test.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"io"
 	"runtime/debug"
+	"strings"
 	"testing"
 )
 
@@ -139,7 +140,6 @@ func TestWrapPrefixError(t *testing.T) {
 		return WrapPrefix("hi", "prefix", 1)
 	}()
 
-	fmt.Println(e.Error())
 	if e.Error() != "prefix: hi" {
 		t.Errorf("Constructor with a string failed")
 	}
@@ -158,6 +158,10 @@ func TestWrapPrefixError(t *testing.T) {
 	if WrapPrefix(nil, "prefix", 0).Error() != "prefix: <nil>" {
 		t.Errorf("Constructor with nil failed")
 	}
+
+	if !strings.HasSuffix(original.StackFrames()[0].File, "error_test.go") || strings.HasSuffix(original.StackFrames()[1].File, "error_test.go") {
+		t.Errorf("Skip failed")
+	}
 }
 
 func ExampleErrorf(x int) (int, error) {