Skip to content

Commit

Permalink
Add additional exception test
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Sep 7, 2023
1 parent 391134a commit a8f8536
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions crates/objc2/src/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ pub unsafe fn catch<R>(
mod tests {
use alloc::format;
use alloc::string::ToString;
use core::panic::AssertUnwindSafe;

use super::*;
use crate::msg_send_id;
use crate::runtime::NSObject;

#[test]
Expand Down Expand Up @@ -332,6 +334,28 @@ mod tests {
assert!(result.unwrap_err().is_none());
}

#[test]
#[cfg_attr(
feature = "catch-all",
ignore = "Panics inside `catch` when catch-all is enabled"
)]
fn test_catch_unknown_selector() {
let obj = NSObject::new();
let result = unsafe {
let obj = AssertUnwindSafe(&obj);
catch(|| {
let obj = obj;
let _: Id<NSObject> = msg_send_id![obj.0, copy];
})
};
let err = result.unwrap_err().unwrap();

assert_eq!(
format!("{err}"),
format!("-[NSObject copyWithZone:]: unrecognized selector sent to instance {obj:p}"),
);
}

#[test]
fn test_throw_catch_object() {
let obj = NSObject::new();
Expand Down

0 comments on commit a8f8536

Please sign in to comment.