Skip to content

Commit f98d933

Browse files
authored
Merge pull request #18 from launchdarkly/eb/sc-166183/set-t-helper
call t.Helper() so our helpers don't mess up the stacktrace
2 parents f090ea3 + c534ff5 commit f98d933

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

channels.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ func TryReceive[V any](ch <-chan V, timeout time.Duration) (V, bool, bool) {
2929
// RequireValue returns the next value from the channel, or forces an immediate test failure
3030
// and exit if the timeout expires first.
3131
func RequireValue[V any](t require.TestingT, ch <-chan V, timeout time.Duration, customMessageAndArgs ...any) V {
32+
if t, ok := t.(interface{ Helper() }); ok {
33+
t.Helper()
34+
}
3235
v, ok, closed := TryReceive(ch, timeout)
3336
if ok {
3437
return v
@@ -53,6 +56,9 @@ func AssertNoMoreValues[V any](
5356
timeout time.Duration,
5457
customMessageAndArgs ...any,
5558
) bool {
59+
if t, ok := t.(interface{ Helper() }); ok {
60+
t.Helper()
61+
}
5662
v, ok, closed := TryReceive(ch, timeout)
5763
if ok {
5864
failWithMessageAndArgs(t, customMessageAndArgs,
@@ -73,6 +79,9 @@ func AssertChannelClosed[V any](
7379
timeout time.Duration,
7480
customMessageAndArgs ...any,
7581
) bool {
82+
if t, ok := t.(interface{ Helper() }); ok {
83+
t.Helper()
84+
}
7685
v, ok, closed := TryReceive(ch, timeout)
7786
if ok {
7887
failWithMessageAndArgs(t, customMessageAndArgs,
@@ -95,6 +104,9 @@ func AssertChannelNotClosed[V any](
95104
timeout time.Duration,
96105
customMessageAndArgs ...any,
97106
) bool {
107+
if t, ok := t.(interface{ Helper() }); ok {
108+
t.Helper()
109+
}
98110
deadline := time.NewTimer(timeout)
99111
defer deadline.Stop()
100112
for {

jsonhelpers/assertions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414
// The two values may either be pre-parsed JValue instances, or if they are not, they are
1515
// converted using the same rules as JValueOf.
1616
func AssertEqual(t assert.TestingT, expected, actual any) bool {
17+
if t, ok := t.(interface{ Helper() }); ok {
18+
t.Helper()
19+
}
1720
ev, av := JValueOf(expected), JValueOf(actual)
1821
if ev.err != nil {
1922
t.Errorf("invalid expected value (%s): %s", ev.err, ev)

testbox/sandbox.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ func (m *mockTestingT) runSafely(action func(TestingT)) {
154154
// ShouldFail is a shortcut for running some action against a testbox.TestingT and
155155
// asserting that it failed.
156156
func ShouldFail(t assert.TestingT, action func(TestingT)) bool {
157+
if t, ok := t.(interface{ Helper() }); ok {
158+
t.Helper()
159+
}
157160
shouldGetHere := make(chan struct{}, 1)
158161
result := SandboxTest(func(t1 TestingT) {
159162
action(t1)
@@ -173,6 +176,9 @@ func ShouldFail(t assert.TestingT, action func(TestingT)) bool {
173176
// ShouldFailAndExitEarly is the same as ShouldFail, except that it also asserts that
174177
// the test was terminated early with FailNow.
175178
func ShouldFailAndExitEarly(t assert.TestingT, action func(TestingT)) bool {
179+
if t, ok := t.(interface{ Helper() }); ok {
180+
t.Helper()
181+
}
176182
shouldNotGetHere := make(chan struct{}, 1)
177183
result := SandboxTest(func(t1 TestingT) {
178184
action(t1)

0 commit comments

Comments
 (0)