@@ -32,37 +32,37 @@ impl fmt::Display for MallocEncoding {
32
32
33
33
#[ derive( Debug , PartialEq , Eq , Hash ) ]
34
34
enum Inner {
35
- MethodNotFound ( Sel ) ,
36
- MismatchedReturn ( Sel , MallocEncoding , Encoding < ' static > ) ,
37
- MismatchedArgumentsCount ( Sel , usize , usize ) ,
38
- MismatchedArgument ( Sel , usize , MallocEncoding , Encoding < ' static > ) ,
35
+ MethodNotFound ,
36
+ MismatchedReturn ( MallocEncoding , Encoding < ' static > ) ,
37
+ MismatchedArgumentsCount ( usize , usize ) ,
38
+ MismatchedArgument ( usize , MallocEncoding , Encoding < ' static > ) ,
39
39
}
40
40
41
41
impl fmt:: Display for Inner {
42
42
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
43
43
match self {
44
- Self :: MethodNotFound ( sel ) => {
45
- write ! ( f, "Method {:?} not found on class" , sel )
44
+ Self :: MethodNotFound => {
45
+ write ! ( f, "method not found" )
46
46
}
47
- Self :: MismatchedReturn ( sel , expected, actual) => {
47
+ Self :: MismatchedReturn ( expected, actual) => {
48
48
write ! (
49
49
f,
50
- "Return type code {} does not match expected {} for method {:? }" ,
51
- actual , expected, sel
50
+ "expected return to have type code {}, but found { }" ,
51
+ expected, actual
52
52
)
53
53
}
54
- Self :: MismatchedArgumentsCount ( sel , expected, actual) => {
54
+ Self :: MismatchedArgumentsCount ( expected, actual) => {
55
55
write ! (
56
56
f,
57
- "Method {:?} accepts {} arguments, but {} were given" ,
58
- sel , expected, actual
57
+ "expected {} arguments, but {} were given" ,
58
+ expected, actual
59
59
)
60
60
}
61
- Self :: MismatchedArgument ( sel , i, expected, actual) => {
61
+ Self :: MismatchedArgument ( i, expected, actual) => {
62
62
write ! (
63
63
f,
64
- "Method {:?} expected argument at index {} with type code {} but was given {}" ,
65
- sel , i, expected, actual
64
+ "expected argument at index {} to have type code {}, but found {}" ,
65
+ i, expected, actual
66
66
)
67
67
}
68
68
}
@@ -101,13 +101,13 @@ where
101
101
{
102
102
let method = match cls. instance_method ( sel) {
103
103
Some ( method) => method,
104
- None => return Err ( Inner :: MethodNotFound ( sel ) . into ( ) ) ,
104
+ None => return Err ( Inner :: MethodNotFound . into ( ) ) ,
105
105
} ;
106
106
107
107
let actual = R :: ENCODING ;
108
108
let expected = method. return_type ( ) ;
109
109
if !actual. equivalent_to_str ( & * expected) {
110
- return Err ( Inner :: MismatchedReturn ( sel , MallocEncoding ( expected) , actual) . into ( ) ) ;
110
+ return Err ( Inner :: MismatchedReturn ( MallocEncoding ( expected) , actual) . into ( ) ) ;
111
111
}
112
112
113
113
let self_and_cmd = [ <* mut Object >:: ENCODING , Sel :: ENCODING ] ;
@@ -116,13 +116,13 @@ where
116
116
let actual = self_and_cmd. len ( ) + args. len ( ) ;
117
117
let expected = method. arguments_count ( ) ;
118
118
if actual != expected {
119
- return Err ( Inner :: MismatchedArgumentsCount ( sel , expected, actual) . into ( ) ) ;
119
+ return Err ( Inner :: MismatchedArgumentsCount ( expected, actual) . into ( ) ) ;
120
120
}
121
121
122
122
for ( i, actual) in self_and_cmd. iter ( ) . chain ( args) . copied ( ) . enumerate ( ) {
123
123
let expected = method. argument_type ( i) . unwrap ( ) ;
124
124
if !actual. equivalent_to_str ( & * expected) {
125
- return Err ( Inner :: MismatchedArgument ( sel , i, MallocEncoding ( expected) , actual) . into ( ) ) ;
125
+ return Err ( Inner :: MismatchedArgument ( i, MallocEncoding ( expected) , actual) . into ( ) ) ;
126
126
}
127
127
}
128
128
@@ -154,42 +154,51 @@ mod tests {
154
154
155
155
// Unimplemented selector (missing colon)
156
156
let err = cls. verify_sel :: < ( ) , ( ) > ( sel ! ( setFoo) ) . unwrap_err ( ) ;
157
- assert_eq ! ( err. to_string( ) , "Method setFoo not found on class " ) ;
157
+ assert_eq ! ( err. to_string( ) , "method not found" ) ;
158
158
159
159
// Incorrect return type
160
160
let err = cls. verify_sel :: < ( u32 , ) , u64 > ( sel ! ( setFoo: ) ) . unwrap_err ( ) ;
161
161
assert_eq ! (
162
162
err. to_string( ) ,
163
- "Return type code Q does not match expected v for method setFoo: "
163
+ "expected return to have type code v, but found Q "
164
164
) ;
165
165
166
166
// Too many arguments
167
167
let err = cls. verify_sel :: < ( u32 , i8 ) , ( ) > ( sel ! ( setFoo: ) ) . unwrap_err ( ) ;
168
- assert_eq ! (
169
- err. to_string( ) ,
170
- "Method setFoo: accepts 3 arguments, but 4 were given"
171
- ) ;
168
+ assert_eq ! ( err. to_string( ) , "expected 3 arguments, but 4 were given" ) ;
172
169
173
170
// Too few arguments
174
171
let err = cls. verify_sel :: < ( ) , ( ) > ( sel ! ( setFoo: ) ) . unwrap_err ( ) ;
175
- assert_eq ! (
176
- err. to_string( ) ,
177
- "Method setFoo: accepts 3 arguments, but 2 were given"
178
- ) ;
172
+ assert_eq ! ( err. to_string( ) , "expected 3 arguments, but 2 were given" ) ;
179
173
180
174
// Incorrect argument type
181
175
let err = cls. verify_sel :: < ( Sel , ) , ( ) > ( sel ! ( setFoo: ) ) . unwrap_err ( ) ;
182
176
assert_eq ! (
183
177
err. to_string( ) ,
184
- "Method setFoo: expected argument at index 2 with type code I but was given :"
178
+ "expected argument at index 2 to have type code I, but found :"
185
179
) ;
180
+
181
+ // Metaclass
182
+ let metaclass = cls. metaclass ( ) ;
183
+ let err = metaclass
184
+ . verify_sel :: < ( i32 , i32 , i32 ) , i32 > ( sel ! ( addNumber: toNumber: ) )
185
+ . unwrap_err ( ) ;
186
+ assert_eq ! ( err. to_string( ) , "expected 4 arguments, but 5 were given" ) ;
186
187
}
187
188
188
189
#[ test]
189
190
#[ cfg( feature = "verify_message" ) ]
190
- #[ should_panic = "Return type code i does not match expected I for method foo " ]
191
+ #[ should_panic = "invalid message send to -[CustomObject foo]: expected return to have type code I, but found i " ]
191
192
fn test_send_message_verified ( ) {
192
193
let obj = test_utils:: custom_object ( ) ;
193
194
let _: i32 = unsafe { msg_send ! [ & obj, foo] } ;
194
195
}
196
+
197
+ #[ test]
198
+ #[ cfg( feature = "verify_message" ) ]
199
+ #[ should_panic = "invalid message send to +[CustomObject abcDef]: method not found" ]
200
+ fn test_send_message_verified_to_class ( ) {
201
+ let cls = test_utils:: custom_class ( ) ;
202
+ let _: i32 = unsafe { msg_send ! [ cls, abcDef] } ;
203
+ }
195
204
}
0 commit comments