diff --git a/assert/assertions.go b/assert/assertions.go index 6ab0ec347..81d9a2826 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -1879,6 +1879,7 @@ func (c *CollectT) Reset() { c.errors = nil } +// Deprecated: Copy should not be used. // Copy copies the collected errors to the supplied t. func (c *CollectT) Copy(t TestingT) { if tt, ok := t.(tHelper); ok { @@ -1921,13 +1922,22 @@ func EventuallyWithT(t TestingT, condition func(collect *CollectT), waitFor time ticker := time.NewTicker(tick) defer ticker.Stop() + var lastErrors []error + + copyErrors := func(t TestingT) { + for _, err := range lastErrors { + t.Errorf("%v", err) + } + } + for tick := ticker.C; ; { select { case <-timer.C: - collect.Copy(t) + copyErrors(t) return Fail(t, "Condition never satisfied", msgAndArgs...) case <-tick: tick = nil + lastErrors = collect.errors collect.Reset() go func() { condition(collect) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 162c71801..436e97d02 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -2763,8 +2763,13 @@ func TestEventuallyTrue(t *testing.T) { func TestEventuallyWithTFalse(t *testing.T) { mockT := new(CollectT) + var calledOnce bool condition := func(collect *CollectT) { + if calledOnce { + time.Sleep(time.Second) + } True(collect, false) + calledOnce = true } False(t, EventuallyWithT(mockT, condition, 100*time.Millisecond, 20*time.Millisecond))