@@ -40,7 +40,7 @@ struct Test {
40
40
struct TestCtxt {
41
41
sess : session:: Session ,
42
42
path : RefCell < ~[ ast:: Ident ] > ,
43
- ext_cx : @ ExtCtxt ,
43
+ ext_cx : ExtCtxt ,
44
44
testfns : RefCell < ~[ Test ] > ,
45
45
is_extra : bool ,
46
46
config : ast:: CrateConfig ,
@@ -63,30 +63,30 @@ pub fn modify_for_testing(sess: session::Session,
63
63
}
64
64
65
65
struct TestHarnessGenerator {
66
- cx : @ TestCtxt ,
66
+ cx : TestCtxt ,
67
67
}
68
68
69
69
impl 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 {
71
71
let folded = fold:: noop_fold_crate ( c, self ) ;
72
72
73
73
// Add a special __test module to the crate that will contain code
74
74
// generated for the test harness
75
75
ast:: Crate {
76
- module : add_test_module ( self . cx , & folded. module ) ,
76
+ module : add_test_module ( & self . cx , & folded. module ) ,
77
77
.. folded
78
78
}
79
79
}
80
80
81
- fn fold_item ( & self , i : @ast:: item ) -> SmallVector < @ast:: item > {
81
+ fn fold_item ( & mut self , i : @ast:: item ) -> SmallVector < @ast:: item > {
82
82
{
83
83
let mut path = self . cx . path . borrow_mut ( ) ;
84
84
path. get ( ) . push ( i. ident ) ;
85
85
}
86
86
debug ! ( "current path: {}" ,
87
87
ast_util:: path_name_i( self . cx. path. get( ) ) ) ;
88
88
89
- if is_test_fn ( self . cx , i) || is_bench_fn ( i) {
89
+ if is_test_fn ( & self . cx , i) || is_bench_fn ( i) {
90
90
match i. node {
91
91
ast:: item_fn( _, purity, _, _, _)
92
92
if purity == ast:: unsafe_fn => {
@@ -101,7 +101,7 @@ impl fold::ast_fold for TestHarnessGenerator {
101
101
span : i. span ,
102
102
path : self . cx . path . get ( ) ,
103
103
bench : is_bench_fn ( i) ,
104
- ignore : is_ignored ( self . cx , i) ,
104
+ ignore : is_ignored ( & self . cx , i) ,
105
105
should_fail : should_fail ( i)
106
106
} ;
107
107
{
@@ -122,11 +122,11 @@ impl fold::ast_fold for TestHarnessGenerator {
122
122
res
123
123
}
124
124
125
- fn fold_mod ( & self , m : & ast:: _mod ) -> ast:: _mod {
125
+ fn fold_mod ( & mut self , m : & ast:: _mod ) -> ast:: _mod {
126
126
// Remove any #[main] from the AST so it doesn't clash with
127
127
// the one we're going to add. Only if compiling an executable.
128
128
129
- fn nomain ( cx : @ TestCtxt , item : @ast:: item ) -> @ast:: item {
129
+ fn nomain ( cx : & TestCtxt , item : @ast:: item ) -> @ast:: item {
130
130
if !cx. sess . building_library . get ( ) {
131
131
@ast:: item {
132
132
attrs : item. attrs . iter ( ) . filter_map ( |attr| {
@@ -145,7 +145,7 @@ impl fold::ast_fold for TestHarnessGenerator {
145
145
146
146
let mod_nomain = ast:: _mod {
147
147
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 ( ) ,
149
149
} ;
150
150
151
151
fold:: noop_fold_mod ( & mod_nomain, self )
@@ -154,7 +154,7 @@ impl fold::ast_fold for TestHarnessGenerator {
154
154
155
155
fn generate_test_harness ( sess : session:: Session , crate : ast:: Crate )
156
156
-> ast:: Crate {
157
- let cx: @ TestCtxt = @ TestCtxt {
157
+ let mut cx: TestCtxt = TestCtxt {
158
158
sess : sess,
159
159
ext_cx : ExtCtxt :: new ( sess. parse_sess , sess. opts . cfg . clone ( ) ) ,
160
160
path : RefCell :: new ( ~[ ] ) ,
@@ -163,8 +163,7 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
163
163
config : crate . config. clone ( ) ,
164
164
} ;
165
165
166
- let ext_cx = cx. ext_cx ;
167
- ext_cx. bt_push ( ExpnInfo {
166
+ cx. ext_cx . bt_push ( ExpnInfo {
168
167
call_site : dummy_sp ( ) ,
169
168
callee : NameAndSpan {
170
169
name : @"test",
@@ -173,11 +172,11 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
173
172
}
174
173
} ) ;
175
174
176
- let fold = TestHarnessGenerator {
175
+ let mut fold = TestHarnessGenerator {
177
176
cx : cx
178
177
} ;
179
178
let res = fold. fold_crate ( crate ) ;
180
- ext_cx. bt_pop ( ) ;
179
+ fold . cx . ext_cx . bt_pop ( ) ;
181
180
return res;
182
181
}
183
182
@@ -190,7 +189,7 @@ fn strip_test_functions(crate: ast::Crate) -> ast::Crate {
190
189
} )
191
190
}
192
191
193
- fn is_test_fn ( cx : @ TestCtxt , i : @ast:: item ) -> bool {
192
+ fn is_test_fn ( cx : & TestCtxt , i : @ast:: item ) -> bool {
194
193
let has_test_attr = attr:: contains_name ( i. attrs , "test" ) ;
195
194
196
195
fn has_test_signature ( i : @ast:: item ) -> bool {
@@ -243,7 +242,7 @@ fn is_bench_fn(i: @ast::item) -> bool {
243
242
return has_bench_attr && has_test_signature ( i) ;
244
243
}
245
244
246
- fn is_ignored ( cx : @ TestCtxt , i : @ast:: item ) -> bool {
245
+ fn is_ignored ( cx : & TestCtxt , i : @ast:: item ) -> bool {
247
246
i. attrs . iter ( ) . any ( |attr| {
248
247
// check ignore(cfg(foo, bar))
249
248
"ignore" == attr. name ( ) && match attr. meta_item_list ( ) {
@@ -313,7 +312,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item {
313
312
314
313
// The synthesized main function which will call the console test runner
315
314
// with our list of tests
316
- let mainfn = ( quote_item ! ( cx. ext_cx,
315
+ let mainfn = ( quote_item ! ( & cx. ext_cx,
317
316
pub fn main( ) {
318
317
#[ main] ;
319
318
extra:: test:: test_main_static( :: std:: os:: args( ) , TESTS ) ;
@@ -377,7 +376,7 @@ fn mk_tests(cx: &TestCtxt) -> @ast::item {
377
376
// The vector of test_descs for this crate
378
377
let test_descs = mk_test_descs ( cx) ;
379
378
380
- ( quote_item ! ( cx. ext_cx,
379
+ ( quote_item ! ( & cx. ext_cx,
381
380
pub static TESTS : & ' static [ self :: extra:: test:: TestDescAndFn ] =
382
381
$test_descs
383
382
;
@@ -438,24 +437,24 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr {
438
437
} ;
439
438
440
439
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) )
442
441
} 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) )
444
443
} ;
445
444
446
445
let ignore_expr = if test. ignore {
447
- quote_expr ! ( cx. ext_cx, true )
446
+ quote_expr ! ( & cx. ext_cx, true )
448
447
} else {
449
- quote_expr ! ( cx. ext_cx, false )
448
+ quote_expr ! ( & cx. ext_cx, false )
450
449
} ;
451
450
452
451
let fail_expr = if test. should_fail {
453
- quote_expr ! ( cx. ext_cx, true )
452
+ quote_expr ! ( & cx. ext_cx, true )
454
453
} else {
455
- quote_expr ! ( cx. ext_cx, false )
454
+ quote_expr ! ( & cx. ext_cx, false )
456
455
} ;
457
456
458
- let e = quote_expr ! ( cx. ext_cx,
457
+ let e = quote_expr ! ( & cx. ext_cx,
459
458
self :: extra:: test:: TestDescAndFn {
460
459
desc: self :: extra:: test:: TestDesc {
461
460
name: self :: extra:: test:: StaticTestName ( $name_expr) ,
0 commit comments