1
1
// Code that generates a test runner to run all the tests in a crate
2
2
3
3
import std:: option;
4
+ import std:: ivec;
4
5
import syntax:: ast;
5
6
import syntax:: fold;
6
7
7
8
export modify_for_testing;
8
9
9
10
type node_id_gen = @fn ( ) -> ast:: node_id ;
10
11
11
- type test_ctxt = rec ( node_id_gen next_node_id ) ;
12
+ type test_ctxt = rec ( node_id_gen next_node_id ,
13
+ mutable ast:: ident[ ] path) ;
12
14
13
15
// Traverse the crate, collecting all the test functions, eliding any
14
16
// existing main functions, and synthesizing a main test harness
@@ -26,9 +28,11 @@ fn modify_for_testing(@ast::crate crate) -> @ast::crate {
26
28
ret this_node_id;
27
29
} ( next_node_id) ;
28
30
29
- auto cx = rec ( next_node_id = next_node_id_fn) ;
31
+ auto cx = rec( next_node_id = next_node_id_fn,
32
+ mutable path = ~[ ] ) ;
30
33
31
- auto precursor = rec ( fold_crate = bind fold_crate ( cx, _, _)
34
+ auto precursor = rec( fold_crate = bind fold_crate ( cx , _, _) ,
35
+ fold_item = bind fold_item( cx, _, _)
32
36
with * fold:: default_ast_fold ( ) ) ;
33
37
34
38
auto fold = fold:: make_fold ( precursor) ;
@@ -94,6 +98,16 @@ fn mk_main(&test_ctxt cx) -> @ast::item {
94
98
ret @item;
95
99
}
96
100
101
+ fn fold_item ( & test_ctxt cx, & @ast:: item i,
102
+ fold:: ast_fold fld) -> @ast:: item {
103
+
104
+ cx. path += ~[ i. ident ] ;
105
+ log #fmt( "current path: %s" , ast:: path_name_i ( cx. path ) ) ;
106
+ auto res = fold:: noop_fold_item ( i, fld) ;
107
+ ivec:: pop ( cx. path ) ;
108
+ ret res;
109
+ }
110
+
97
111
// Local Variables:
98
112
// mode: rust
99
113
// fill-column: 78;
0 commit comments