@@ -48,7 +48,6 @@ struct Test {
48
48
struct TestCtxt < ' a > {
49
49
sess : & ' a Session ,
50
50
path : Vec < ast:: Ident > ,
51
- reexports : Vec < Vec < ast:: Ident > > ,
52
51
ext_cx : ExtCtxt < ' a > ,
53
52
testfns : Vec < Test > ,
54
53
reexport_mod_ident : ast:: Ident ,
@@ -74,6 +73,8 @@ pub fn modify_for_testing(sess: &Session,
74
73
75
74
struct TestHarnessGenerator < ' a > {
76
75
cx : TestCtxt < ' a > ,
76
+ tests : Vec < ast:: Ident > ,
77
+ tested_submods : Vec < ast:: Ident > ,
77
78
}
78
79
79
80
impl < ' a > fold:: Folder for TestHarnessGenerator < ' a > {
@@ -111,7 +112,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
111
112
should_fail : should_fail ( i)
112
113
} ;
113
114
self . cx . testfns . push ( test) ;
114
- self . cx . reexports . push ( self . cx . path . clone ( ) ) ;
115
+ self . tests . push ( i . ident ) ;
115
116
// debug!("have {} test/bench functions",
116
117
// cx.testfns.len());
117
118
}
@@ -129,9 +130,11 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
129
130
}
130
131
131
132
fn fold_mod ( & mut self , m : & ast:: Mod ) -> ast:: Mod {
132
- let reexports = mem:: replace ( & mut self . cx . reexports , Vec :: new ( ) ) ;
133
+ let tests = mem:: replace ( & mut self . tests , Vec :: new ( ) ) ;
134
+ let tested_submods = mem:: replace ( & mut self . tested_submods , Vec :: new ( ) ) ;
133
135
let mut mod_folded = fold:: noop_fold_mod ( m, self ) ;
134
- let reexports = mem:: replace ( & mut self . cx . reexports , reexports) ;
136
+ let tests = mem:: replace ( & mut self . tests , tests) ;
137
+ let tested_submods = mem:: replace ( & mut self . tested_submods , tested_submods) ;
135
138
136
139
// Remove any #[main] from the AST so it doesn't clash with
137
140
// the one we're going to add. Only if compiling an executable.
@@ -152,20 +155,32 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
152
155
for i in mod_folded. items . mut_iter ( ) {
153
156
* i = nomain ( * i) ;
154
157
}
155
- if !reexports. is_empty ( ) {
156
- mod_folded. items . push ( mk_reexport_mod ( & mut self . cx , reexports) ) ;
157
- self . cx . reexports . push ( self . cx . path . clone ( ) ) ;
158
+ if !tests. is_empty ( ) || !tested_submods. is_empty ( ) {
159
+ mod_folded. items . push ( mk_reexport_mod ( & mut self . cx , tests,
160
+ tested_submods) ) ;
161
+ if !self . cx . path . is_empty ( ) {
162
+ self . tested_submods . push ( self . cx . path [ self . cx . path . len ( ) -1 ] ) ;
163
+ }
158
164
}
159
165
160
166
mod_folded
161
167
}
162
168
}
163
169
164
- fn mk_reexport_mod ( cx : & mut TestCtxt , reexports : Vec < Vec < ast:: Ident > > )
165
- -> Gc < ast:: Item > {
166
- let view_items = reexports. move_iter ( ) . map ( |r| {
167
- cx. ext_cx . view_use_simple ( DUMMY_SP , ast:: Public , cx. ext_cx . path ( DUMMY_SP , r) )
168
- } ) . collect ( ) ;
170
+ fn mk_reexport_mod ( cx : & mut TestCtxt , tests : Vec < ast:: Ident > ,
171
+ tested_submods : Vec < ast:: Ident > ) -> Gc < ast:: Item > {
172
+ let mut view_items = Vec :: new ( ) ;
173
+ let super_ = token:: str_to_ident ( "super" ) ;
174
+
175
+ view_items. extend ( tests. move_iter ( ) . map ( |r| {
176
+ cx. ext_cx . view_use_simple ( DUMMY_SP , ast:: Public ,
177
+ cx. ext_cx . path ( DUMMY_SP , vec ! [ super_, r] ) )
178
+ } ) ) ;
179
+ view_items. extend ( tested_submods. move_iter ( ) . map ( |r| {
180
+ let path = cx. ext_cx . path ( DUMMY_SP , vec ! [ super_, r, cx. reexport_mod_ident] ) ;
181
+ cx. ext_cx . view_use_simple_ ( DUMMY_SP , ast:: Public , r, path)
182
+ } ) ) ;
183
+
169
184
let reexport_mod = ast:: Mod {
170
185
inner : DUMMY_SP ,
171
186
view_items : view_items,
@@ -190,7 +205,6 @@ fn generate_test_harness(sess: &Session, krate: ast::Crate) -> ast::Crate {
190
205
crate_name : "test" . to_string ( ) ,
191
206
} ) ,
192
207
path : Vec :: new ( ) ,
193
- reexports : Vec :: new ( ) ,
194
208
testfns : Vec :: new ( ) ,
195
209
reexport_mod_ident : token:: str_to_ident ( "__test_reexports" ) ,
196
210
is_test_crate : is_test_crate ( & krate) ,
@@ -208,6 +222,8 @@ fn generate_test_harness(sess: &Session, krate: ast::Crate) -> ast::Crate {
208
222
209
223
let mut fold = TestHarnessGenerator {
210
224
cx : cx,
225
+ tests : Vec :: new ( ) ,
226
+ tested_submods : Vec :: new ( ) ,
211
227
} ;
212
228
let res = fold. fold_crate ( krate) ;
213
229
fold. cx . ext_cx . bt_pop ( ) ;
@@ -448,11 +464,8 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> Gc<ast::Expr> {
448
464
span : span
449
465
} ;
450
466
451
- let mut visible_path = Vec :: new ( ) ;
452
- for ident in path. move_iter ( ) {
453
- visible_path. push ( cx. reexport_mod_ident . clone ( ) ) ;
454
- visible_path. push ( ident) ;
455
- }
467
+ let mut visible_path = vec ! [ cx. reexport_mod_ident. clone( ) ] ;
468
+ visible_path. extend ( path. move_iter ( ) ) ;
456
469
let fn_path = cx. ext_cx . path_global ( DUMMY_SP , visible_path) ;
457
470
458
471
let fn_expr = box ( GC ) ast:: Expr {
0 commit comments