Skip to content

Commit

Permalink
Use want helpers for callers_test (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantv authored Jan 14, 2025
1 parent efd4ee0 commit 3f570c1
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions callers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package faket

import (
"path/filepath"
"strings"
"testing"

"github.com/prashantv/faket/internal/want"
)

func TestGetCallers(t *testing.T) {
Expand All @@ -28,25 +29,17 @@ func TestGetCallers(t *testing.T) {
func TestGetCaller(t *testing.T) {
t.Run("skip all", func(t *testing.T) {
pc := getCaller(1000)
if pc != 0 {
t.Fatalf("expected empty pc, got %v", pc)
}
want.Equal(t, "pc", pc, 0)
})

t.Run("skip 0", func(t *testing.T) {
s := pcToFunction(getCallerCaller(0))
want := "faket.getCallerCaller"
if got := filepath.Base(s); got != want {
t.Fatalf("with no skip, got %v, want %v", got, want)
}
got := pcToFunction(getCallerCaller(0))
want.Equal(t, "caller function", filepath.Base(got), "faket.getCallerCaller")
})

t.Run("skip 1", func(t *testing.T) {
got := pcToFunction(getCallerCaller(1))
want := "TestGetCaller"
if !strings.Contains(got, want) {
t.Fatalf("with skip, got %v, want contains %v", got, want)
}
want.Contains(t, "caller function", got, "TestGetCaller")
})
}

Expand Down

0 comments on commit 3f570c1

Please sign in to comment.