From 6d6c2867cc353acbe875087ec0b72030a55cda9f Mon Sep 17 00:00:00 2001 From: TheDiveO <6920158+thediveo@users.noreply.github.com> Date: Tue, 26 Jul 2022 21:40:41 +0200 Subject: [PATCH] don't panic on Eventually(nil), fixing #555 --- internal/async_assertion.go | 2 +- internal/async_assertion_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/async_assertion.go b/internal/async_assertion.go index 6640ff15f..126bbcb3f 100644 --- a/internal/async_assertion.go +++ b/internal/async_assertion.go @@ -40,7 +40,7 @@ func NewAsyncAssertion(asyncType AsyncAssertionType, actualInput interface{}, g } switch actualType := reflect.TypeOf(actualInput); { - case actualType.Kind() != reflect.Func: + case actualInput == nil || actualType.Kind() != reflect.Func: out.actualValue = actualInput case actualType.NumIn() == 0 && actualType.NumOut() > 0: out.actualIsFunc = true diff --git a/internal/async_assertion_test.go b/internal/async_assertion_test.go index 3c67520b0..1bedfdf58 100644 --- a/internal/async_assertion_test.go +++ b/internal/async_assertion_test.go @@ -742,4 +742,22 @@ var _ = Describe("Asynchronous Assertions", func() { }) + Context("eventual nil-ism", func() { // issue #555 + + It("doesn't panic on nil actual", func() { + ig := NewInstrumentedGomega() + Expect(func() { + ig.G.Eventually(nil).Should(BeNil()) + }).NotTo(Panic()) + }) + + It("doesn't panic on function returning nil error", func() { + ig := NewInstrumentedGomega() + Expect(func() { + ig.G.Eventually(func() error { return nil }).Should(BeNil()) + }).NotTo(Panic()) + }) + + }) + })