mockingbird icon indicating copy to clipboard operation
mockingbird copied to clipboard

Mocks crashing when using NSUserActivity as parameter passed with any()

Open mauronate opened this issue 3 years ago • 2 comments

New Issue Checklist

Overview

When using verify to check if a mocked function has been called, if such function accepts a NSUserActivity as a parameter passed , and it has been passed as any(), the unit tests project crashes raising on the current latest version (0.19.2) a Thread 1: EXC_BAD_ACCESS.

On 0.18.x the error is also present, but is handled so that the project does not crash resulting into a failing test with a provided description and highlighting the specific line where the exception is raised: -[NSProxy methodSignatureForSelector:] called! (NSInvalidArgumentException)

On the 0.17.0 version the tests proceed without any issue.

Example

Protocol Function example: func scene(_ scene: UIScene, continue userActivity: NSUserActivity)

Code that raises the exception/error: verify(mockBranchClient.scene(any(), continue: any())).wasNeverCalled() verify(mockBranchClient.scene(any(), continue: any())).wasCalled()

Expected Behavior

The test should either succeed or fail by check if the verified function has been called or not with the passed parameters.

Environment

  • Xcode 13.2 Swift 5.5.2
  • Mockingbird set up using pods and using the CLI bundled with it.
  • Using Quick and Nimble

mauronate avatar Jan 21 '22 11:01 mauronate

Thanks for reporting. Unfortunately I wasn’t able to repro this crash (see the changes under Examples/CocoaPodsExample): https://github.com/andrewchang-bird/mockingbird/tree/repro-issue-276

Could you provide additional context or a minimal repro project for this?

andrewchang-bird avatar Jan 21 '22 16:01 andrewchang-bird

@andrewchang-bird I also stumbled on the same issue in 0.20.0 trying to mock a protocol which references NSDecimalNumber.

I reproduced the crash with a basic example in a fresh Carthage project.

// App target
protocol NSProtocol {
  func calculateSomething(from: NSDecimalNumber) -> String
}

// In test
let m = mock(NSProtocol.self)
given(m.calculateSomething(from: any())) ~> "test" // any() crashes

karlpuusepp avatar Feb 18 '22 15:02 karlpuusepp