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

`require(nil).to(beNil())` will incorrectly fail & throw an error. #1125

Open younata opened 4 months ago

younata commented 4 months ago

This test fails, with the contradictory error "expected to be nil, got \<nil>":

func testRequireNil() throws {
    expect {
        try require(nil as Int?).to(beNil())
    }.toNot(throwError())
}

Which ultimately comes down to us being unable to unwrap nil (because... it's nil!) in (Sync|Async)Requirement.verify (highlighted is the sync variant, but the Async one has the same logic and therefore, same issue): https://github.com/Quick/Nimble/blob/v13.2.1/Sources/Nimble/Requirement.swift#L88-L95

So... that's fun and unexpected.