@@ -208,13 +208,16 @@ mod __test {
208
208
*/
209
209
210
210
fn mk_test_module ( cx : test_ctxt ) -> @ast:: item {
211
+ // Link to std
212
+ let std = mk_std ( cx) ;
213
+ let view_items = if is_std ( cx) { ~[ ] } else { ~[ std] } ;
211
214
// A function that generates a vector of test descriptors to feed to the
212
215
// test runner
213
216
let testsfn = mk_tests ( cx) ;
214
217
// The synthesized main function which will call the console test runner
215
218
// with our list of tests
216
219
let mainfn = mk_main ( cx) ;
217
- let testmod: ast:: _mod = { view_items: ~ [ ] , items: ~[ mainfn, testsfn] } ;
220
+ let testmod: ast:: _mod = { view_items: view_items , items: ~[ mainfn, testsfn] } ;
218
221
let item_ = ast:: item_mod ( testmod) ;
219
222
// This attribute tells resolve to let us call unexported functions
220
223
let resolve_unexported_attr =
@@ -245,6 +248,24 @@ fn path_node_global(ids: ~[ast::ident]) -> @ast::path {
245
248
@{ span: dummy_sp ( ) , global: true , idents: ids, rp: None , types: ~[ ] }
246
249
}
247
250
251
+ fn mk_std( cx : test_ctxt ) -> @ast:: view_item {
252
+ let vers = ast:: lit_str ( @~"0.6 ") ;
253
+ let vers = nospan ( vers) ;
254
+ let mi = ast:: meta_name_value ( ~"vers", vers) ;
255
+ let mi = nospan ( mi) ;
256
+ let vi = ast:: view_item_use ( cx. sess . ident_of ( ~"std") ,
257
+ ~[ @mi] ,
258
+ cx. sess . next_node_id ( ) ) ;
259
+ let vi = {
260
+ node: vi,
261
+ attrs: ~[ ] ,
262
+ vis: ast:: private,
263
+ span: dummy_sp ( )
264
+ } ;
265
+
266
+ return @vi;
267
+ }
268
+
248
269
fn mk_tests( cx : test_ctxt ) -> @ast:: item {
249
270
let ret_ty = mk_test_desc_vec_ty ( cx) ;
250
271
@@ -271,25 +292,34 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
271
292
return @item;
272
293
}
273
294
274
- fn mk_path ( cx : test_ctxt , path : ~[ ast:: ident ] ) -> ~[ ast:: ident ] {
275
- // For tests that are inside of std we don't want to prefix
276
- // the paths with std::
295
+ fn is_std ( cx : test_ctxt ) -> bool {
277
296
let is_std = {
278
297
let items = attr:: find_linkage_metas ( cx. crate . node . attrs ) ;
279
298
match attr:: last_meta_item_value_str_by_name ( items, ~"name") {
280
299
Some ( ~"std") => true ,
281
300
_ => false
282
301
}
283
302
} ;
284
- if is_std { path }
285
- else { vec:: append ( ~[ cx. sess . ident_of ( ~"std") ] , path) }
303
+ return is_std;
304
+ }
305
+
306
+ fn mk_path ( cx : test_ctxt , path : ~[ ast:: ident ] ) -> @ast:: path {
307
+ // For tests that are inside of std we don't want to prefix
308
+ // the paths with std::
309
+ if is_std ( cx) { path_node_global ( path) }
310
+ else {
311
+ path_node (
312
+ ~[ cx. sess . ident_of ( ~"self ") ,
313
+ cx. sess . ident_of ( ~"std") ]
314
+ + path)
315
+ }
286
316
}
287
317
288
318
// The ast::Ty of ~[std::test::test_desc]
289
319
fn mk_test_desc_vec_ty ( cx : test_ctxt ) -> @ast:: Ty {
290
320
let test_desc_ty_path =
291
- path_node_global ( mk_path ( cx, ~[ cx. sess . ident_of ( ~"test") ,
292
- cx. sess . ident_of ( ~"TestDesc ") ] ) ) ;
321
+ mk_path ( cx, ~[ cx. sess . ident_of ( ~"test") ,
322
+ cx. sess . ident_of ( ~"TestDesc ") ] ) ;
293
323
294
324
let test_desc_ty: ast:: Ty =
295
325
{ id: cx. sess . next_node_id ( ) ,
@@ -501,9 +531,9 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
501
531
node: test_call_expr_, span: dummy_sp ( ) } ;
502
532
503
533
// Call std::test::test_main
504
- let test_main_path = path_node_global (
534
+ let test_main_path =
505
535
mk_path ( cx, ~[ cx. sess . ident_of ( ~"test") ,
506
- cx. sess . ident_of ( ~"test_main") ] ) ) ;
536
+ cx. sess . ident_of ( ~"test_main") ] ) ;
507
537
508
538
let test_main_path_expr_: ast:: expr_ = ast:: expr_path ( test_main_path) ;
509
539
0 commit comments