testify
testify copied to clipboard
[BUG] assertions.go: CallerInfo() Not Get Actual File Path When Workdir Changed
https://github.com/stretchr/testify/blob/181cea6eab8b2de7071383eca4be32a424db38dd/assert/assertions.go#L144
Above link directs to the line to blame. This will remove the absolute path info retrieved from runtime.Caller(i).
parts := strings.Split(file, "/")
file = parts[len(parts)-1]
Reproduce:
- set workdir before test start
- call assert.True(t, false)
A simple fix would be like this:
parts := strings.Split(file, "/")
// file := parts[len(parts)-1]
filename := parts[len(parts)-1]
if len(parts) > 1 {
dir := parts[len(parts)-2]
//if (dir != "assert" && dir != "mock" && dir != "require") || file == "mock_test.go" {
if (dir != "assert" && dir != "mock" && dir != "require") || filename == "mock_test.go" {
//path, _ := filepath.Abs(file)
callers = append(callers, fmt.Sprintf("%s:%d", file, line))
}
}