From a8f85367db8d1eb16849e47c2fdee3ed68d90930 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 7 Sep 2023 04:19:35 +0200 Subject: [PATCH] Add additional exception test --- crates/objc2/src/exception.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/objc2/src/exception.rs b/crates/objc2/src/exception.rs index d3e399f91..aea37dad2 100644 --- a/crates/objc2/src/exception.rs +++ b/crates/objc2/src/exception.rs @@ -298,8 +298,10 @@ pub unsafe fn catch( 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] @@ -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 = 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();