Skip to content

Commit

Permalink
fix cropFilename bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nikandfor committed Nov 12, 2023
1 parent da59c9b commit 484188d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions location.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ func CallersFill(skip int, tr PCs) PCs {
func cropFilename(fn, tp string) string {
p := strings.LastIndexByte(tp, '/')
pp := strings.IndexByte(tp[p+1:], '.')
tp = tp[:p+pp]
tp = tp[:p+pp] // cut type and func name

for {
if p = strings.Index(fn, tp); p != -1 {
if p = strings.LastIndex(fn, tp); p != -1 {
return fn[p:]
}

Expand Down
2 changes: 2 additions & 0 deletions location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func TestLocationCropFileName(t *testing.T) {
assert.Equal(t, "root.go", cropFilename("/path/to/src/root.go", "tlog.method"))
assert.Equal(t, "subpkg/file.go", cropFilename("/path/to/src/subpkg/file.go", "subpkg.method"))
assert.Equal(t, "subpkg/file.go", cropFilename("/path/to/src/subpkg/file.go", "github.com/nikandfor/tlog/subpkg.(*type).method"))
assert.Equal(t, "errors/fmt_test.go",
cropFilename("/home/runner/work/errors/errors/fmt_test.go", "tlog.app/go/error.TestErrorFormatCaller"))
}

func TestCaller(t *testing.T) {
Expand Down

0 comments on commit 484188d

Please sign in to comment.