@@ -274,30 +274,43 @@ fn strip_test_functions(krate: ast::Crate) -> ast::Crate {
274
274
fn is_test_fn ( cx : & TestCtxt , i : & ast:: Item ) -> bool {
275
275
let has_test_attr = attr:: contains_name ( i. attrs . as_slice ( ) , "test" ) ;
276
276
277
- fn has_test_signature ( i : & ast:: Item ) -> bool {
277
+ #[ deriving( PartialEq ) ]
278
+ enum HasTestSignature {
279
+ Yes ,
280
+ No ,
281
+ NotEvenAFunction ,
282
+ }
283
+
284
+ fn has_test_signature ( i : & ast:: Item ) -> HasTestSignature {
278
285
match & i. node {
279
286
& ast:: ItemFn ( ref decl, _, _, ref generics, _) => {
280
287
let no_output = match decl. output . node {
281
288
ast:: TyNil => true ,
282
- _ => false
289
+ _ => false ,
283
290
} ;
284
- decl. inputs . is_empty ( )
285
- && no_output
286
- && !generics. is_parameterized ( )
291
+ if decl. inputs . is_empty ( )
292
+ && no_output
293
+ && !generics. is_parameterized ( ) {
294
+ Yes
295
+ } else {
296
+ No
297
+ }
287
298
}
288
- _ => false
299
+ _ => NotEvenAFunction ,
289
300
}
290
301
}
291
302
292
- if has_test_attr && ! has_test_signature ( i ) {
303
+ if has_test_attr {
293
304
let diag = cx. span_diagnostic ;
294
- diag. span_err (
295
- i. span ,
296
- "functions used as tests must have signature fn() -> ()."
297
- ) ;
305
+ match has_test_signature ( i) {
306
+ Yes => { } ,
307
+ No => diag. span_err ( i. span , "functions used as tests must have signature fn() -> ()" ) ,
308
+ NotEvenAFunction => diag. span_err ( i. span ,
309
+ "only functions may be used as tests" ) ,
310
+ }
298
311
}
299
312
300
- return has_test_attr && has_test_signature ( i) ;
313
+ return has_test_attr && has_test_signature ( i) == Yes ;
301
314
}
302
315
303
316
fn is_bench_fn ( cx : & TestCtxt , i : & ast:: Item ) -> bool {
0 commit comments