@@ -50,10 +50,12 @@ struct TestCtxt<'a> {
50
50
path : Vec < ast:: Ident > ,
51
51
ext_cx : ExtCtxt < ' a > ,
52
52
testfns : Vec < Test > ,
53
- reexport_mod_ident : ast:: Ident ,
54
53
reexport_test_harness_main : Option < InternedString > ,
55
54
is_test_crate : bool ,
56
55
config : ast:: CrateConfig ,
56
+
57
+ // top-level re-export submodule, filled out after folding is finished
58
+ toplevel_reexport : Option < ast:: Ident > ,
57
59
}
58
60
59
61
// Traverse the crate, collecting all the test functions, eliding any
@@ -83,7 +85,9 @@ pub fn modify_for_testing(sess: &Session,
83
85
struct TestHarnessGenerator < ' a > {
84
86
cx : TestCtxt < ' a > ,
85
87
tests : Vec < ast:: Ident > ,
86
- tested_submods : Vec < ast:: Ident > ,
88
+
89
+ // submodule name, gensym'd identifier for re-exports
90
+ tested_submods : Vec < ( ast:: Ident , ast:: Ident ) > ,
87
91
}
88
92
89
93
impl < ' a > fold:: Folder for TestHarnessGenerator < ' a > {
@@ -168,10 +172,14 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
168
172
* i = nomain ( * i) ;
169
173
}
170
174
if !tests. is_empty ( ) || !tested_submods. is_empty ( ) {
171
- mod_folded. items . push ( mk_reexport_mod ( & mut self . cx , tests,
172
- tested_submods) ) ;
175
+ let ( it, sym) = mk_reexport_mod ( & mut self . cx , tests, tested_submods) ;
176
+ mod_folded. items . push ( it) ;
177
+
173
178
if !self . cx . path . is_empty ( ) {
174
- self . tested_submods . push ( self . cx . path [ self . cx . path . len ( ) -1 ] ) ;
179
+ self . tested_submods . push ( ( self . cx . path [ self . cx . path . len ( ) -1 ] , sym) ) ;
180
+ } else {
181
+ debug ! ( "pushing nothing, sym: {}" , sym) ;
182
+ self . cx . toplevel_reexport = Some ( sym) ;
175
183
}
176
184
}
177
185
@@ -180,16 +188,16 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
180
188
}
181
189
182
190
fn mk_reexport_mod ( cx : & mut TestCtxt , tests : Vec < ast:: Ident > ,
183
- tested_submods : Vec < ast:: Ident > ) -> Gc < ast:: Item > {
191
+ tested_submods : Vec < ( ast:: Ident , ast :: Ident ) > ) -> ( Gc < ast:: Item > , ast :: Ident ) {
184
192
let mut view_items = Vec :: new ( ) ;
185
193
let super_ = token:: str_to_ident ( "super" ) ;
186
194
187
195
view_items. extend ( tests. move_iter ( ) . map ( |r| {
188
196
cx. ext_cx . view_use_simple ( DUMMY_SP , ast:: Public ,
189
197
cx. ext_cx . path ( DUMMY_SP , vec ! [ super_, r] ) )
190
198
} ) ) ;
191
- view_items. extend ( tested_submods. move_iter ( ) . map ( |r | {
192
- let path = cx. ext_cx . path ( DUMMY_SP , vec ! [ super_, r, cx . reexport_mod_ident ] ) ;
199
+ view_items. extend ( tested_submods. move_iter ( ) . map ( |( r , sym ) | {
200
+ let path = cx. ext_cx . path ( DUMMY_SP , vec ! [ super_, r, sym ] ) ;
193
201
cx. ext_cx . view_use_simple_ ( DUMMY_SP , ast:: Public , r, path)
194
202
} ) ) ;
195
203
@@ -198,14 +206,18 @@ fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec<ast::Ident>,
198
206
view_items : view_items,
199
207
items : Vec :: new ( ) ,
200
208
} ;
201
- box ( GC ) ast:: Item {
202
- ident : cx. reexport_mod_ident . clone ( ) ,
209
+
210
+ let sym = token:: gensym_ident ( "__test_reexports" ) ;
211
+ let it = box ( GC ) ast:: Item {
212
+ ident : sym. clone ( ) ,
203
213
attrs : Vec :: new ( ) ,
204
214
id : ast:: DUMMY_NODE_ID ,
205
215
node : ast:: ItemMod ( reexport_mod) ,
206
216
vis : ast:: Public ,
207
217
span : DUMMY_SP ,
208
- }
218
+ } ;
219
+
220
+ ( it, sym)
209
221
}
210
222
211
223
fn generate_test_harness ( sess : & Session ,
@@ -220,10 +232,10 @@ fn generate_test_harness(sess: &Session,
220
232
} ) ,
221
233
path : Vec :: new ( ) ,
222
234
testfns : Vec :: new ( ) ,
223
- reexport_mod_ident : token:: gensym_ident ( "__test_reexports" ) ,
224
235
reexport_test_harness_main : reexport_test_harness_main,
225
236
is_test_crate : is_test_crate ( & krate) ,
226
237
config : krate. config . clone ( ) ,
238
+ toplevel_reexport : None ,
227
239
} ;
228
240
229
241
cx. ext_cx . bt_push ( ExpnInfo {
@@ -530,7 +542,14 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> Gc<ast::Expr> {
530
542
field( "should_fail" , fail_expr) ] ) ;
531
543
532
544
533
- let mut visible_path = vec ! [ cx. reexport_mod_ident. clone( ) ] ;
545
+ let mut visible_path = match cx. toplevel_reexport {
546
+ Some ( id) => vec ! [ id] ,
547
+ None => {
548
+ cx. sess . bug (
549
+ "expected to find top-level re-export name, but found None"
550
+ ) ;
551
+ }
552
+ } ;
534
553
visible_path. extend ( path. move_iter ( ) ) ;
535
554
536
555
let fn_expr = ecx. expr_path ( ecx. path_global ( span, visible_path) ) ;
0 commit comments