@@ -28,7 +28,7 @@ use errors;
28
28
use errors:: snippet:: { SnippetData } ;
29
29
use config;
30
30
use entry:: { self , EntryPointType } ;
31
- use ext:: base:: { ExtCtxt , DummyResolver } ;
31
+ use ext:: base:: { ExtCtxt , Resolver } ;
32
32
use ext:: build:: AstBuilder ;
33
33
use ext:: expand:: ExpansionConfig ;
34
34
use fold:: Folder ;
@@ -70,6 +70,7 @@ struct TestCtxt<'a> {
70
70
// Traverse the crate, collecting all the test functions, eliding any
71
71
// existing main functions, and synthesizing a main test harness
72
72
pub fn modify_for_testing ( sess : & ParseSess ,
73
+ resolver : & mut Resolver ,
73
74
should_test : bool ,
74
75
krate : ast:: Crate ,
75
76
span_diagnostic : & errors:: Handler ) -> ast:: Crate {
@@ -82,7 +83,7 @@ pub fn modify_for_testing(sess: &ParseSess,
82
83
"reexport_test_harness_main" ) ;
83
84
84
85
if should_test {
85
- generate_test_harness ( sess, reexport_test_harness_main, krate, span_diagnostic)
86
+ generate_test_harness ( sess, resolver , reexport_test_harness_main, krate, span_diagnostic)
86
87
} else {
87
88
krate
88
89
}
@@ -248,41 +249,39 @@ fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec<ast::Ident>,
248
249
} ) . chain ( tested_submods. into_iter ( ) . map ( |( r, sym) | {
249
250
let path = cx. ext_cx . path ( DUMMY_SP , vec ! [ super_, r, sym] ) ;
250
251
cx. ext_cx . item_use_simple_ ( DUMMY_SP , ast:: Visibility :: Public , r, path)
251
- } ) ) ;
252
+ } ) ) . collect ( ) ;
252
253
253
254
let reexport_mod = ast:: Mod {
254
255
inner : DUMMY_SP ,
255
- items : items. collect ( ) ,
256
+ items : items,
256
257
} ;
257
258
258
259
let sym = token:: gensym_ident ( "__test_reexports" ) ;
259
- let it = P ( ast:: Item {
260
+ let it = cx . ext_cx . expander ( ) . fold_item ( P ( ast:: Item {
260
261
ident : sym. clone ( ) ,
261
262
attrs : Vec :: new ( ) ,
262
263
id : ast:: DUMMY_NODE_ID ,
263
264
node : ast:: ItemKind :: Mod ( reexport_mod) ,
264
265
vis : ast:: Visibility :: Public ,
265
266
span : DUMMY_SP ,
266
- } ) ;
267
+ } ) ) . pop ( ) . unwrap ( ) ;
267
268
268
269
( it, sym)
269
270
}
270
271
271
272
fn generate_test_harness ( sess : & ParseSess ,
273
+ resolver : & mut Resolver ,
272
274
reexport_test_harness_main : Option < InternedString > ,
273
275
krate : ast:: Crate ,
274
276
sd : & errors:: Handler ) -> ast:: Crate {
275
277
// Remove the entry points
276
278
let mut cleaner = EntryPointCleaner { depth : 0 } ;
277
279
let krate = cleaner. fold_crate ( krate) ;
278
280
279
- let mut resolver = DummyResolver ;
280
281
let mut cx: TestCtxt = TestCtxt {
281
282
sess : sess,
282
283
span_diagnostic : sd,
283
- ext_cx : ExtCtxt :: new ( sess, vec ! [ ] ,
284
- ExpansionConfig :: default ( "test" . to_string ( ) ) ,
285
- & mut resolver) ,
284
+ ext_cx : ExtCtxt :: new ( sess, vec ! [ ] , ExpansionConfig :: default ( "test" . to_string ( ) ) , resolver) ,
286
285
path : Vec :: new ( ) ,
287
286
testfns : Vec :: new ( ) ,
288
287
reexport_test_harness_main : reexport_test_harness_main,
@@ -511,16 +510,17 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P<ast::Item>, Option<P<ast::Item>>) {
511
510
items : vec ! [ import, mainfn, tests] ,
512
511
} ;
513
512
let item_ = ast:: ItemKind :: Mod ( testmod) ;
514
-
515
513
let mod_ident = token:: gensym_ident ( "__test" ) ;
516
- let item = P ( ast:: Item {
514
+
515
+ let mut expander = cx. ext_cx . expander ( ) ;
516
+ let item = expander. fold_item ( P ( ast:: Item {
517
517
id : ast:: DUMMY_NODE_ID ,
518
518
ident : mod_ident,
519
519
attrs : vec ! [ ] ,
520
520
node : item_,
521
521
vis : ast:: Visibility :: Public ,
522
522
span : DUMMY_SP ,
523
- } ) ;
523
+ } ) ) . pop ( ) . unwrap ( ) ;
524
524
let reexport = cx. reexport_test_harness_main . as_ref ( ) . map ( |s| {
525
525
// building `use <ident> = __test::main`
526
526
let reexport_ident = token:: str_to_ident ( & s) ;
@@ -529,14 +529,14 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P<ast::Item>, Option<P<ast::Item>>) {
529
529
nospan ( ast:: ViewPathSimple ( reexport_ident,
530
530
path_node ( vec ! [ mod_ident, token:: str_to_ident( "main" ) ] ) ) ) ;
531
531
532
- P ( ast:: Item {
532
+ expander . fold_item ( P ( ast:: Item {
533
533
id : ast:: DUMMY_NODE_ID ,
534
534
ident : keywords:: Invalid . ident ( ) ,
535
535
attrs : vec ! [ ] ,
536
536
node : ast:: ItemKind :: Use ( P ( use_path) ) ,
537
537
vis : ast:: Visibility :: Inherited ,
538
538
span : DUMMY_SP
539
- } )
539
+ } ) ) . pop ( ) . unwrap ( )
540
540
} ) ;
541
541
542
542
debug ! ( "Synthetic test module:\n {}\n " , pprust:: item_to_string( & item) ) ;
0 commit comments