@@ -119,7 +119,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
119
119
}
120
120
debug ! ( "current path: {}" , path_name_i( & self . cx. path) ) ;
121
121
122
- let i = if is_test_fn ( & self . cx , & i) || is_bench_fn ( & self . cx , & i) {
122
+ if is_test_fn ( & self . cx , & i) || is_bench_fn ( & self . cx , & i) {
123
123
match i. node {
124
124
ast:: ItemKind :: Fn ( _, ast:: Unsafety :: Unsafe , _, _, _, _) => {
125
125
let diag = self . cx . span_diagnostic ;
@@ -136,54 +136,37 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
136
136
} ;
137
137
self . cx . testfns . push ( test) ;
138
138
self . tests . push ( i. ident ) ;
139
- // debug!("have {} test/bench functions",
140
- // cx.testfns.len());
141
-
142
- // Make all tests public so we can call them from outside
143
- // the module (note that the tests are re-exported and must
144
- // be made public themselves to avoid privacy errors).
145
- i. map ( |mut i| {
146
- i. vis = ast:: Visibility :: Public ;
147
- i
148
- } )
149
139
}
150
140
}
151
- } else {
152
- i
153
- } ;
141
+ }
154
142
143
+ let mut item = i. unwrap ( ) ;
155
144
// We don't want to recurse into anything other than mods, since
156
145
// mods or tests inside of functions will break things
157
- let res = match i. node {
158
- ast:: ItemKind :: Mod ( ..) => fold:: noop_fold_item ( i, self ) ,
159
- _ => SmallVector :: one ( i) ,
160
- } ;
146
+ if let ast:: ItemKind :: Mod ( module) = item. node {
147
+ let tests = mem:: replace ( & mut self . tests , Vec :: new ( ) ) ;
148
+ let tested_submods = mem:: replace ( & mut self . tested_submods , Vec :: new ( ) ) ;
149
+ let mut mod_folded = fold:: noop_fold_mod ( module, self ) ;
150
+ let tests = mem:: replace ( & mut self . tests , tests) ;
151
+ let tested_submods = mem:: replace ( & mut self . tested_submods , tested_submods) ;
152
+
153
+ if !tests. is_empty ( ) || !tested_submods. is_empty ( ) {
154
+ let ( it, sym) = mk_reexport_mod ( & mut self . cx , item. id , tests, tested_submods) ;
155
+ mod_folded. items . push ( it) ;
156
+
157
+ if !self . cx . path . is_empty ( ) {
158
+ self . tested_submods . push ( ( self . cx . path [ self . cx . path . len ( ) -1 ] , sym) ) ;
159
+ } else {
160
+ debug ! ( "pushing nothing, sym: {:?}" , sym) ;
161
+ self . cx . toplevel_reexport = Some ( sym) ;
162
+ }
163
+ }
164
+ item. node = ast:: ItemKind :: Mod ( mod_folded) ;
165
+ }
161
166
if ident. name != keywords:: Invalid . name ( ) {
162
167
self . cx . path . pop ( ) ;
163
168
}
164
- res
165
- }
166
-
167
- fn fold_mod ( & mut self , m : ast:: Mod ) -> ast:: Mod {
168
- let tests = mem:: replace ( & mut self . tests , Vec :: new ( ) ) ;
169
- let tested_submods = mem:: replace ( & mut self . tested_submods , Vec :: new ( ) ) ;
170
- let mut mod_folded = fold:: noop_fold_mod ( m, self ) ;
171
- let tests = mem:: replace ( & mut self . tests , tests) ;
172
- let tested_submods = mem:: replace ( & mut self . tested_submods , tested_submods) ;
173
-
174
- if !tests. is_empty ( ) || !tested_submods. is_empty ( ) {
175
- let ( it, sym) = mk_reexport_mod ( & mut self . cx , tests, tested_submods) ;
176
- mod_folded. items . push ( it) ;
177
-
178
- if !self . cx . path . is_empty ( ) {
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) ;
183
- }
184
- }
185
-
186
- mod_folded
169
+ SmallVector :: one ( P ( item) )
187
170
}
188
171
189
172
fn fold_mac ( & mut self , mac : ast:: Mac ) -> ast:: Mac { mac }
@@ -239,7 +222,7 @@ impl fold::Folder for EntryPointCleaner {
239
222
fn fold_mac ( & mut self , mac : ast:: Mac ) -> ast:: Mac { mac }
240
223
}
241
224
242
- fn mk_reexport_mod ( cx : & mut TestCtxt , tests : Vec < ast:: Ident > ,
225
+ fn mk_reexport_mod ( cx : & mut TestCtxt , parent : ast :: NodeId , tests : Vec < ast:: Ident > ,
243
226
tested_submods : Vec < ( ast:: Ident , ast:: Ident ) > ) -> ( P < ast:: Item > , ast:: Ident ) {
244
227
let super_ = token:: str_to_ident ( "super" ) ;
245
228
@@ -257,6 +240,8 @@ fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec<ast::Ident>,
257
240
} ;
258
241
259
242
let sym = token:: gensym_ident ( "__test_reexports" ) ;
243
+ let parent = if parent == ast:: DUMMY_NODE_ID { ast:: CRATE_NODE_ID } else { parent } ;
244
+ cx. ext_cx . current_expansion . mark = cx. ext_cx . resolver . get_module_scope ( parent) ;
260
245
let it = cx. ext_cx . monotonic_expander ( ) . fold_item ( P ( ast:: Item {
261
246
ident : sym. clone ( ) ,
262
247
attrs : Vec :: new ( ) ,
0 commit comments