@@ -7,6 +7,7 @@ import syntax::ast_util::*;
7
7
import syntax:: fold;
8
8
import syntax:: print:: pprust;
9
9
import syntax:: codemap:: span;
10
+ import driver:: session;
10
11
import front:: attr;
11
12
12
13
export modify_for_testing;
@@ -16,13 +17,15 @@ type node_id_gen = fn() -> ast::node_id;
16
17
type test = { span : span , path: [ ast:: ident ] , ignore : bool } ;
17
18
18
19
type test_ctxt =
19
- @{ next_node_id : node_id_gen ,
20
+ @{ sess : session:: session ,
21
+ next_node_id : node_id_gen ,
20
22
mutable path: [ ast:: ident ] ,
21
23
mutable testfns: [ test ] } ;
22
24
23
25
// Traverse the crate, collecting all the test functions, eliding any
24
26
// existing main functions, and synthesizing a main test harness
25
- fn modify_for_testing ( crate : @ast:: crate ) -> @ast:: crate {
27
+ fn modify_for_testing ( sess : session:: session ,
28
+ crate : @ast:: crate ) -> @ast:: crate {
26
29
27
30
// FIXME: This hackasaurus assumes that 200000 is a safe number to start
28
31
// generating node_ids at (which is totally not the case). pauls is going
@@ -37,7 +40,8 @@ fn modify_for_testing(crate: @ast::crate) -> @ast::crate {
37
40
} ( next_node_id) ;
38
41
39
42
let cx: test_ctxt =
40
- @{ next_node_id: next_node_id_fn,
43
+ @{ sess: sess,
44
+ next_node_id: next_node_id_fn,
41
45
mutable path: [ ] ,
42
46
mutable testfns: [ ] } ;
43
47
@@ -90,10 +94,19 @@ fn fold_item(cx: test_ctxt, &&i: @ast::item, fld: fold::ast_fold) ->
90
94
log #fmt[ "current path: %s" , ast_util:: path_name_i ( cx. path ) ] ;
91
95
92
96
if is_test_fn ( i) {
93
- log "this is a test function" ;
94
- let test = { span: i. span , path: cx. path , ignore: is_ignored ( i) } ;
95
- cx. testfns += [ test] ;
96
- log #fmt[ "have %u test functions" , vec:: len ( cx. testfns ) ] ;
97
+ alt i. node {
98
+ ast:: item_fn ( f, _) when f. decl . purity == ast:: unsafe_fn {
99
+ cx. sess . span_fatal (
100
+ i. span ,
101
+ "unsafe functions cannot be used for tests" ) ;
102
+ }
103
+ _ {
104
+ log "this is a test function" ;
105
+ let test = { span: i. span , path: cx. path , ignore: is_ignored ( i) } ;
106
+ cx. testfns += [ test] ;
107
+ log #fmt[ "have %u test functions" , vec:: len ( cx. testfns ) ] ;
108
+ }
109
+ }
97
110
}
98
111
99
112
let res = fold:: noop_fold_item ( i, fld) ;
0 commit comments