@@ -40,7 +40,7 @@ struct Test {
4040struct TestCtxt {
4141 sess : session:: Session ,
4242 path : RefCell < ~[ ast:: Ident ] > ,
43- ext_cx : @ ExtCtxt ,
43+ ext_cx : ExtCtxt ,
4444 testfns : RefCell < ~[ Test ] > ,
4545 is_extra : bool ,
4646 config : ast:: CrateConfig ,
@@ -63,30 +63,30 @@ pub fn modify_for_testing(sess: session::Session,
6363}
6464
6565struct TestHarnessGenerator {
66- cx : @ TestCtxt ,
66+ cx : TestCtxt ,
6767}
6868
6969impl fold:: ast_fold for TestHarnessGenerator {
70- fn fold_crate ( & self , c : ast:: Crate ) -> ast:: Crate {
70+ fn fold_crate ( & mut self , c : ast:: Crate ) -> ast:: Crate {
7171 let folded = fold:: noop_fold_crate ( c, self ) ;
7272
7373 // Add a special __test module to the crate that will contain code
7474 // generated for the test harness
7575 ast:: Crate {
76- module : add_test_module ( self . cx , & folded. module ) ,
76+ module : add_test_module ( & self . cx , & folded. module ) ,
7777 .. folded
7878 }
7979 }
8080
81- fn fold_item ( & self , i : @ast:: item ) -> SmallVector < @ast:: item > {
81+ fn fold_item ( & mut self , i : @ast:: item ) -> SmallVector < @ast:: item > {
8282 {
8383 let mut path = self . cx . path . borrow_mut ( ) ;
8484 path. get ( ) . push ( i. ident ) ;
8585 }
8686 debug ! ( "current path: {}" ,
8787 ast_util:: path_name_i( self . cx. path. get( ) ) ) ;
8888
89- if is_test_fn ( self . cx , i) || is_bench_fn ( i) {
89+ if is_test_fn ( & self . cx , i) || is_bench_fn ( i) {
9090 match i. node {
9191 ast:: item_fn( _, purity, _, _, _)
9292 if purity == ast:: unsafe_fn => {
@@ -101,7 +101,7 @@ impl fold::ast_fold for TestHarnessGenerator {
101101 span : i. span ,
102102 path : self . cx . path . get ( ) ,
103103 bench : is_bench_fn ( i) ,
104- ignore : is_ignored ( self . cx , i) ,
104+ ignore : is_ignored ( & self . cx , i) ,
105105 should_fail : should_fail ( i)
106106 } ;
107107 {
@@ -122,11 +122,11 @@ impl fold::ast_fold for TestHarnessGenerator {
122122 res
123123 }
124124
125- fn fold_mod ( & self , m : & ast:: _mod ) -> ast:: _mod {
125+ fn fold_mod ( & mut self , m : & ast:: _mod ) -> ast:: _mod {
126126 // Remove any #[main] from the AST so it doesn't clash with
127127 // the one we're going to add. Only if compiling an executable.
128128
129- fn nomain ( cx : @ TestCtxt , item : @ast:: item ) -> @ast:: item {
129+ fn nomain ( cx : & TestCtxt , item : @ast:: item ) -> @ast:: item {
130130 if !cx. sess . building_library . get ( ) {
131131 @ast:: item {
132132 attrs : item. attrs . iter ( ) . filter_map ( |attr| {
@@ -145,7 +145,7 @@ impl fold::ast_fold for TestHarnessGenerator {
145145
146146 let mod_nomain = ast:: _mod {
147147 view_items : m. view_items . clone ( ) ,
148- items : m. items . iter ( ) . map ( |i| nomain ( self . cx , * i) ) . collect ( ) ,
148+ items : m. items . iter ( ) . map ( |i| nomain ( & self . cx , * i) ) . collect ( ) ,
149149 } ;
150150
151151 fold:: noop_fold_mod ( & mod_nomain, self )
@@ -154,7 +154,7 @@ impl fold::ast_fold for TestHarnessGenerator {
154154
155155fn generate_test_harness ( sess : session:: Session , crate : ast:: Crate )
156156 -> ast:: Crate {
157- let cx: @ TestCtxt = @ TestCtxt {
157+ let mut cx: TestCtxt = TestCtxt {
158158 sess : sess,
159159 ext_cx : ExtCtxt :: new ( sess. parse_sess , sess. opts . cfg . clone ( ) ) ,
160160 path : RefCell :: new ( ~[ ] ) ,
@@ -163,8 +163,7 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
163163 config : crate . config. clone ( ) ,
164164 } ;
165165
166- let ext_cx = cx. ext_cx ;
167- ext_cx. bt_push ( ExpnInfo {
166+ cx. ext_cx . bt_push ( ExpnInfo {
168167 call_site : dummy_sp ( ) ,
169168 callee : NameAndSpan {
170169 name : @"test",
@@ -173,11 +172,11 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
173172 }
174173 } ) ;
175174
176- let fold = TestHarnessGenerator {
175+ let mut fold = TestHarnessGenerator {
177176 cx : cx
178177 } ;
179178 let res = fold. fold_crate ( crate ) ;
180- ext_cx. bt_pop ( ) ;
179+ fold . cx . ext_cx . bt_pop ( ) ;
181180 return res;
182181}
183182
@@ -190,7 +189,7 @@ fn strip_test_functions(crate: ast::Crate) -> ast::Crate {
190189 } )
191190}
192191
193- fn is_test_fn ( cx : @ TestCtxt , i : @ast:: item ) -> bool {
192+ fn is_test_fn ( cx : & TestCtxt , i : @ast:: item ) -> bool {
194193 let has_test_attr = attr:: contains_name ( i. attrs , "test" ) ;
195194
196195 fn has_test_signature ( i : @ast:: item ) -> bool {
@@ -243,7 +242,7 @@ fn is_bench_fn(i: @ast::item) -> bool {
243242 return has_bench_attr && has_test_signature ( i) ;
244243}
245244
246- fn is_ignored ( cx : @ TestCtxt , i : @ast:: item ) -> bool {
245+ fn is_ignored ( cx : & TestCtxt , i : @ast:: item ) -> bool {
247246 i. attrs . iter ( ) . any ( |attr| {
248247 // check ignore(cfg(foo, bar))
249248 "ignore" == attr. name ( ) && match attr. meta_item_list ( ) {
@@ -313,7 +312,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item {
313312
314313 // The synthesized main function which will call the console test runner
315314 // with our list of tests
316- let mainfn = ( quote_item ! ( cx. ext_cx,
315+ let mainfn = ( quote_item ! ( & cx. ext_cx,
317316 pub fn main( ) {
318317 #[ main] ;
319318 extra:: test:: test_main_static( :: std:: os:: args( ) , TESTS ) ;
@@ -377,7 +376,7 @@ fn mk_tests(cx: &TestCtxt) -> @ast::item {
377376 // The vector of test_descs for this crate
378377 let test_descs = mk_test_descs ( cx) ;
379378
380- ( quote_item ! ( cx. ext_cx,
379+ ( quote_item ! ( & cx. ext_cx,
381380 pub static TESTS : & ' static [ self :: extra:: test:: TestDescAndFn ] =
382381 $test_descs
383382 ;
@@ -438,24 +437,24 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr {
438437 } ;
439438
440439 let t_expr = if test. bench {
441- quote_expr ! ( cx. ext_cx, self :: extra:: test:: StaticBenchFn ( $fn_expr) )
440+ quote_expr ! ( & cx. ext_cx, self :: extra:: test:: StaticBenchFn ( $fn_expr) )
442441 } else {
443- quote_expr ! ( cx. ext_cx, self :: extra:: test:: StaticTestFn ( $fn_expr) )
442+ quote_expr ! ( & cx. ext_cx, self :: extra:: test:: StaticTestFn ( $fn_expr) )
444443 } ;
445444
446445 let ignore_expr = if test. ignore {
447- quote_expr ! ( cx. ext_cx, true )
446+ quote_expr ! ( & cx. ext_cx, true )
448447 } else {
449- quote_expr ! ( cx. ext_cx, false )
448+ quote_expr ! ( & cx. ext_cx, false )
450449 } ;
451450
452451 let fail_expr = if test. should_fail {
453- quote_expr ! ( cx. ext_cx, true )
452+ quote_expr ! ( & cx. ext_cx, true )
454453 } else {
455- quote_expr ! ( cx. ext_cx, false )
454+ quote_expr ! ( & cx. ext_cx, false )
456455 } ;
457456
458- let e = quote_expr ! ( cx. ext_cx,
457+ let e = quote_expr ! ( & cx. ext_cx,
459458 self :: extra:: test:: TestDescAndFn {
460459 desc: self :: extra:: test:: TestDesc {
461460 name: self :: extra:: test:: StaticTestName ( $name_expr) ,
0 commit comments