mattgallagher / CwlPreconditionTesting

A Mach exception handler that allows Swift precondition failures to be caught and tested.
ISC License
175 stars 46 forks source link

Add the assertion message to returned exception #1

Closed abbeycode closed 8 years ago

abbeycode commented 8 years ago

Is there a way to retrieve the message from the assertion failure, in order to validate it? I can't see it on the returned NSException. It would be great if it were available in the exception's userInfo or reason property.

mattgallagher commented 8 years ago

I've had a look at this. In Debug (-Onone), it is possible to walk through the stack frames to the message parameter passed to the underlying _assertionFailure function. It involves making some dirty assumptions about how many stack frames and the location within the stack frame but you can do it.

In Release build, it is not possible. The entire precondition (or other test function) is inlined into the caller and the message parameter is gone from the stack before the ud2 occurs.