From d1e754f011821f166578fd75f36049304751f7d4 Mon Sep 17 00:00:00 2001 From: Victor Farazdagi Date: Mon, 13 Jul 2020 20:20:18 +0300 Subject: [PATCH] Fixes display issue in testutils/assert (#6585) * fixes minor display issue in testutils/assert --- shared/testutil/assertions.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/shared/testutil/assertions.go b/shared/testutil/assertions.go index 83ffd5de0..7ddd1288f 100644 --- a/shared/testutil/assertions.go +++ b/shared/testutil/assertions.go @@ -20,8 +20,8 @@ type assertionLoggerFn func(string, ...interface{}) func Equal(loggerFn assertionLoggerFn, expected, actual interface{}, msg ...string) { errMsg := parseMsg("Values are not equal", msg...) if expected != actual { - _, file, line, _ := runtime.Caller(1) - loggerFn("%s:%d %s, got: %v, want: %v", file, line, errMsg, actual, expected) + _, file, line, _ := runtime.Caller(2) + loggerFn("%s:%d %s, got: %v, want: %v", filepath.Base(file), line, errMsg, actual, expected) } } @@ -29,8 +29,8 @@ func Equal(loggerFn assertionLoggerFn, expected, actual interface{}, msg ...stri func DeepEqual(loggerFn assertionLoggerFn, expected, actual interface{}, msg ...string) { errMsg := parseMsg("Values are not equal", msg...) if !reflect.DeepEqual(expected, actual) { - _, file, line, _ := runtime.Caller(1) - loggerFn("%s:%d %s, got: %v, want: %v", file, line, errMsg, actual, expected) + _, file, line, _ := runtime.Caller(2) + loggerFn("%s:%d %s, got: %v, want: %v", filepath.Base(file), line, errMsg, actual, expected) } } @@ -38,7 +38,7 @@ func DeepEqual(loggerFn assertionLoggerFn, expected, actual interface{}, msg ... func NoError(loggerFn assertionLoggerFn, err error, msg ...string) { errMsg := parseMsg("Unexpected error", msg...) if err != nil { - _, file, line, _ := runtime.Caller(1) + _, file, line, _ := runtime.Caller(2) loggerFn("%s:%d %s: %v", filepath.Base(file), line, errMsg, err) } } @@ -47,7 +47,7 @@ func NoError(loggerFn assertionLoggerFn, err error, msg ...string) { func ErrorContains(loggerFn assertionLoggerFn, want string, err error, msg ...string) { errMsg := parseMsg("Expected error not returned", msg...) if err == nil || !strings.Contains(err.Error(), want) { - _, file, line, _ := runtime.Caller(1) + _, file, line, _ := runtime.Caller(2) loggerFn("%s:%d %s, got: %v, want: %s", filepath.Base(file), line, errMsg, err, want) } } @@ -56,7 +56,7 @@ func ErrorContains(loggerFn assertionLoggerFn, want string, err error, msg ...st func NotNil(loggerFn assertionLoggerFn, obj interface{}, msg ...string) { errMsg := parseMsg("Unexpected nil value", msg...) if obj == nil { - _, file, line, _ := runtime.Caller(1) + _, file, line, _ := runtime.Caller(2) loggerFn("%s:%d %s", filepath.Base(file), line, errMsg) } }