Skip to content

Commit

Permalink
Merge pull request go-quicktest#17 from lmb/add-helper-calls
Browse files Browse the repository at this point in the history
Call TB.Helper from Assert and Check
  • Loading branch information
frankban authored Mar 1, 2024
2 parents 144a5cf + 91a28b3 commit c6c8733
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions quicktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// Assert checks that the provided argument passes the given check and calls
// tb.Fatal otherwise, including any Comment arguments in the failure.
func Assert(t testing.TB, checker Checker, comments ...Comment) bool {
t.Helper()
return check(t, checkParams{
fail: t.Fatal,
checker: checker,
Expand All @@ -19,6 +20,7 @@ func Assert(t testing.TB, checker Checker, comments ...Comment) bool {
// Check checks that the provided argument passes the given check and calls
// tb.Error otherwise, including any Comment arguments in the failure.
func Check(t testing.TB, checker Checker, comments ...Comment) bool {
t.Helper()
return check(t, checkParams{
fail: t.Error,
checker: checker,
Expand Down
14 changes: 14 additions & 0 deletions quicktest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,20 @@ func TestCAssertCheck(t *testing.T) {
}
}

func TestHelperCalls(t *testing.T) {
tt := &testingT{}
qt.Assert(tt, qt.IsTrue(false))
if tt.helperCalls < 2 {
t.Error("Assert doesn't invoke TB.Helper()")
}

tt = &testingT{}
qt.Check(tt, qt.IsTrue(false))
if tt.helperCalls < 2 {
t.Error("Check doesn't invoke TB.Helper()")
}
}

func checkResult(t *testing.T, ok bool, got, want string) {
t.Helper()
if want != "" {
Expand Down

0 comments on commit c6c8733

Please sign in to comment.