Quick / Nimble

A Matcher Framework for Swift and Objective-C
https://quick.github.io/Nimble/documentation/nimble/
Apache License 2.0
4.79k stars 595 forks source link

`expect(nil).toAlways(equal(0))` incorrectly succeeds #1120

Closed defagos closed 4 months ago

defagos commented 4 months ago

What did you do?

Consider the following expectation:

func testExpectNilToAlwaysEqualZero() {
    expect(nil).toAlways(equal(0))
}

You would expect a test failure but the test actually succeeds.

The issue is likely associated with polling since the following expectation fails as expected:

func testExpectNilToEqualZero() {
    expect(nil).to(equal(0))
}

What did you expect to happen?

The expectation in testExpectNilToAlwaysEqualZero() above must fail.

What actually happened instead?

The expectation in testExpectNilToAlwaysEqualZero() above incorrectly succeeds.

Environment

younata commented 4 months ago

Thanks for identifying this!

younata commented 4 months ago

After looking into this more, this type of issue also applies to toNever. Lovely.

defagos commented 4 months ago

Thanks for your answer.

As a temporary workaround it is possible to force-unwrap potentially nullable values in related expectations so that mismatches at least do not get unnoticed:

expect(somePotentiallyNilValue!).toAlways(equal(1234))
younata commented 4 months ago

This is now fixed in Nimble 13.2.1.

defagos commented 4 months ago

Thank you very much for the quick fix, really appreciated!