Skip to content

Commit 7030050

Browse files
committed
Add additional exception test
1 parent 391134a commit 7030050

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

crates/objc2/src/exception.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,10 @@ pub unsafe fn catch<R>(
298298
mod tests {
299299
use alloc::format;
300300
use alloc::string::ToString;
301+
use core::panic::AssertUnwindSafe;
301302

302303
use super::*;
304+
use crate::msg_send_id;
303305
use crate::runtime::NSObject;
304306

305307
#[test]
@@ -332,6 +334,27 @@ mod tests {
332334
assert!(result.unwrap_err().is_none());
333335
}
334336

337+
#[test]
338+
#[cfg_attr(
339+
feature = "catch-all",
340+
ignore = "Panics inside `catch` when catch-all is enabled"
341+
)]
342+
fn test_catch_unknown_selector() {
343+
let obj = AssertUnwindSafe(NSObject::new());
344+
let ptr = Id::as_ptr(&obj);
345+
let result = unsafe {
346+
catch(|| {
347+
let _: Id<NSObject> = msg_send_id![&*obj, copy];
348+
})
349+
};
350+
let err = result.unwrap_err().unwrap();
351+
352+
assert_eq!(
353+
format!("{err}"),
354+
format!("-[NSObject copyWithZone:]: unrecognized selector sent to instance {ptr:?}"),
355+
);
356+
}
357+
335358
#[test]
336359
fn test_throw_catch_object() {
337360
let obj = NSObject::new();

0 commit comments

Comments
 (0)