Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impr: CallerInfo should print full paths to the terminal #1201

Merged
merged 2 commits into from Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion assert/assertions.go
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"math"
"os"
"path/filepath"
"reflect"
"regexp"
"runtime"
Expand Down Expand Up @@ -144,7 +145,8 @@ func CallerInfo() []string {
if len(parts) > 1 {
dir := parts[len(parts)-2]
if (dir != "assert" && dir != "mock" && dir != "require") || file == "mock_test.go" {
callers = append(callers, fmt.Sprintf("%s:%d", file, line))
path, _ := filepath.Abs(file)
callers = append(callers, fmt.Sprintf("%s:%d", path, line))
}
}

Expand Down
12 changes: 6 additions & 6 deletions mock/mock_test.go
Expand Up @@ -151,7 +151,7 @@ func Test_Mock_Chained_On(t *testing.T) {
var mockedService = new(TestExampleImplementation)

// determine our current line number so we can assert the expected calls callerInfo properly
_, _, line, _ := runtime.Caller(0)
_, filename, line, _ := runtime.Caller(0)
mockedService.
On("TheExampleMethod", 1, 2, 3).
Return(0).
Expand All @@ -164,14 +164,14 @@ func Test_Mock_Chained_On(t *testing.T) {
Method: "TheExampleMethod",
Arguments: []interface{}{1, 2, 3},
ReturnArguments: []interface{}{0},
callerInfo: []string{fmt.Sprintf("mock_test.go:%d", line+2)},
callerInfo: []string{fmt.Sprintf("%s:%d", filename, line+2)},
},
{
Parent: &mockedService.Mock,
Method: "TheExampleMethod3",
Arguments: []interface{}{AnythingOfType("*mock.ExampleType")},
ReturnArguments: []interface{}{nil},
callerInfo: []string{fmt.Sprintf("mock_test.go:%d", line+4)},
callerInfo: []string{fmt.Sprintf("%s:%d", filename, line+4)},
},
}
assert.Equal(t, expectedCalls, mockedService.ExpectedCalls)
Expand Down Expand Up @@ -521,7 +521,7 @@ func Test_Mock_Chained_UnsetOnlyUnsetsLastCall(t *testing.T) {
var mockedService = new(TestExampleImplementation)

// determine our current line number so we can assert the expected calls callerInfo properly
_, _, line, _ := runtime.Caller(0)
_, filename, line, _ := runtime.Caller(0)
mockedService.
On("TheExampleMethod1", 1, 1).
Return(0).
Expand All @@ -536,14 +536,14 @@ func Test_Mock_Chained_UnsetOnlyUnsetsLastCall(t *testing.T) {
Method: "TheExampleMethod1",
Arguments: []interface{}{1, 1},
ReturnArguments: []interface{}{0},
callerInfo: []string{fmt.Sprintf("mock_test.go:%d", line+2)},
callerInfo: []string{fmt.Sprintf("%s:%d", filename, line+2)},
},
{
Parent: &mockedService.Mock,
Method: "TheExampleMethod2",
Arguments: []interface{}{2, 2},
ReturnArguments: []interface{}{},
callerInfo: []string{fmt.Sprintf("mock_test.go:%d", line+4)},
callerInfo: []string{fmt.Sprintf("%s:%d", filename, line+4)},
},
}
assert.Equal(t, 2, len(expectedCalls))
Expand Down