1
+ use core:: fmt;
1
2
use core:: hint:: unreachable_unchecked;
2
3
use core:: panic:: { RefUnwindSafe , UnwindSafe } ;
3
4
@@ -8,7 +9,7 @@ use objc2::{msg_send, msg_send_id, sel};
8
9
9
10
use crate :: { NSCopying , NSDictionary , NSObject , NSString } ;
10
11
11
- object ! {
12
+ extern_class ! {
12
13
/// A special condition that interrupts the normal flow of program
13
14
/// execution.
14
15
///
@@ -18,6 +19,7 @@ object! {
18
19
/// See also [Apple's documentation][doc].
19
20
///
20
21
/// [doc]: https://developer.apple.com/documentation/foundation/nsexception?language=objc
22
+ #[ derive( PartialEq , Eq , Hash ) ]
21
23
unsafe pub struct NSException : NSObject ;
22
24
}
23
25
@@ -120,7 +122,18 @@ impl alloc::borrow::ToOwned for NSException {
120
122
}
121
123
}
122
124
123
- // TODO: Better Debug impl
125
+ impl fmt:: Debug for NSException {
126
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
127
+ let obj: & Object = self . as_ref ( ) ;
128
+ write ! ( f, "{:?} '{}'" , obj, self . name( ) ) ?;
129
+ if let Some ( reason) = self . reason ( ) {
130
+ write ! ( f, " reason:{}" , reason) ?;
131
+ } else {
132
+ write ! ( f, " reason:(NULL)" ) ?;
133
+ }
134
+ Ok ( ( ) )
135
+ }
136
+ }
124
137
125
138
#[ cfg( test) ]
126
139
mod tests {
@@ -148,15 +161,13 @@ mod tests {
148
161
} ;
149
162
150
163
assert_eq ! ( exc. description( ) , NSString :: from_str( & description) ) ;
151
- assert_eq ! ( format!( "{:?}" , exc) , format!( "\" {}\" " , description) ) ;
164
+
165
+ let debug = format ! ( "<NSException: {:p}> 'abc' reason:def" , exc) ;
166
+ assert_eq ! ( format!( "{:?}" , exc) , debug) ;
152
167
}
153
168
154
169
#[ test]
155
- #[ cfg_attr(
156
- feature = "apple" ,
157
- should_panic = "called `Result::unwrap()` on an `Err` value: \" def\" "
158
- ) ]
159
- #[ cfg_attr( feature = "gnustep-1-7" , should_panic = "> NAME:abc REASON:def" ) ]
170
+ #[ should_panic = "'abc' reason:def" ]
160
171
fn unwrap ( ) {
161
172
let exc = NSException :: new (
162
173
& NSString :: from_str ( "abc" ) ,
0 commit comments