@@ -48,7 +48,6 @@ struct Test {
4848struct TestCtxt < ' a > {
4949 sess : & ' a Session ,
5050 path : Vec < ast:: Ident > ,
51- reexports : Vec < Vec < ast:: Ident > > ,
5251 ext_cx : ExtCtxt < ' a > ,
5352 testfns : Vec < Test > ,
5453 reexport_mod_ident : ast:: Ident ,
@@ -74,6 +73,8 @@ pub fn modify_for_testing(sess: &Session,
7473
7574struct TestHarnessGenerator < ' a > {
7675 cx : TestCtxt < ' a > ,
76+ tests : Vec < ast:: Ident > ,
77+ tested_submods : Vec < ast:: Ident > ,
7778}
7879
7980impl < ' a > fold:: Folder for TestHarnessGenerator < ' a > {
@@ -111,7 +112,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
111112 should_fail : should_fail ( i)
112113 } ;
113114 self . cx . testfns . push ( test) ;
114- self . cx . reexports . push ( self . cx . path . clone ( ) ) ;
115+ self . tests . push ( i . ident ) ;
115116 // debug!("have {} test/bench functions",
116117 // cx.testfns.len());
117118 }
@@ -129,9 +130,11 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
129130 }
130131
131132 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 ( ) ) ;
133135 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) ;
135138
136139 // Remove any #[main] from the AST so it doesn't clash with
137140 // the one we're going to add. Only if compiling an executable.
@@ -152,20 +155,32 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
152155 for i in mod_folded. items . mut_iter ( ) {
153156 * i = nomain ( * i) ;
154157 }
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+ }
158164 }
159165
160166 mod_folded
161167 }
162168}
163169
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+
169184 let reexport_mod = ast:: Mod {
170185 inner : DUMMY_SP ,
171186 view_items : view_items,
@@ -190,7 +205,6 @@ fn generate_test_harness(sess: &Session, krate: ast::Crate) -> ast::Crate {
190205 crate_name : "test" . to_string ( ) ,
191206 } ) ,
192207 path : Vec :: new ( ) ,
193- reexports : Vec :: new ( ) ,
194208 testfns : Vec :: new ( ) ,
195209 reexport_mod_ident : token:: str_to_ident ( "__test_reexports" ) ,
196210 is_test_crate : is_test_crate ( & krate) ,
@@ -208,6 +222,8 @@ fn generate_test_harness(sess: &Session, krate: ast::Crate) -> ast::Crate {
208222
209223 let mut fold = TestHarnessGenerator {
210224 cx : cx,
225+ tests : Vec :: new ( ) ,
226+ tested_submods : Vec :: new ( ) ,
211227 } ;
212228 let res = fold. fold_crate ( krate) ;
213229 fold. cx . ext_cx . bt_pop ( ) ;
@@ -448,11 +464,8 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> Gc<ast::Expr> {
448464 span : span
449465 } ;
450466
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 ( ) ) ;
456469 let fn_path = cx. ext_cx . path_global ( DUMMY_SP , visible_path) ;
457470
458471 let fn_expr = box ( GC ) ast:: Expr {
0 commit comments