@@ -37,7 +37,7 @@ use rustc_trans::back::link;
37
37
use syntax:: ast;
38
38
use syntax:: codemap:: CodeMap ;
39
39
use syntax:: feature_gate:: UnstableFeatures ;
40
- use syntax_pos:: { BytePos , DUMMY_SP , Pos } ;
40
+ use syntax_pos:: { BytePos , DUMMY_SP , Pos , Span } ;
41
41
use errors;
42
42
use errors:: emitter:: ColorConfig ;
43
43
@@ -97,15 +97,13 @@ pub fn run(input: &str,
97
97
link:: find_crate_name ( None , & hir_forest. krate ( ) . attrs , & input)
98
98
} ) ;
99
99
let opts = scrape_test_config ( hir_forest. krate ( ) ) ;
100
- let filename = input_path. to_str ( ) . unwrap_or ( "" ) . to_owned ( ) ;
101
100
let mut collector = Collector :: new ( crate_name,
102
101
cfgs,
103
102
libs,
104
103
externs,
105
104
false ,
106
105
opts,
107
106
maybe_sysroot,
108
- filename,
109
107
Some ( codemap) ) ;
110
108
111
109
{
@@ -391,15 +389,14 @@ pub struct Collector {
391
389
cratename : String ,
392
390
opts : TestOptions ,
393
391
maybe_sysroot : Option < PathBuf > ,
394
- filename : String ,
395
- start_line : usize ,
392
+ position : Span ,
396
393
codemap : Option < Rc < CodeMap > > ,
397
394
}
398
395
399
396
impl Collector {
400
397
pub fn new ( cratename : String , cfgs : Vec < String > , libs : SearchPaths , externs : Externs ,
401
398
use_headers : bool , opts : TestOptions , maybe_sysroot : Option < PathBuf > ,
402
- filename : String , codemap : Option < Rc < CodeMap > > ) -> Collector {
399
+ codemap : Option < Rc < CodeMap > > ) -> Collector {
403
400
Collector {
404
401
tests : Vec :: new ( ) ,
405
402
names : Vec :: new ( ) ,
@@ -412,17 +409,16 @@ impl Collector {
412
409
cratename : cratename,
413
410
opts : opts,
414
411
maybe_sysroot : maybe_sysroot,
415
- filename : filename,
416
- start_line : 0 ,
412
+ position : DUMMY_SP ,
417
413
codemap : codemap,
418
414
}
419
415
}
420
416
421
417
pub fn add_test ( & mut self , test : String ,
422
418
should_panic : bool , no_run : bool , should_ignore : bool ,
423
419
as_test_harness : bool , compile_fail : bool , error_codes : Vec < String > ,
424
- line : usize ) {
425
- let name = format ! ( "{} - line {}" , self . filename, line) ;
420
+ line : usize , filename : String ) {
421
+ let name = format ! ( "{} - line {}" , filename, line) ;
426
422
self . cnt += 1 ;
427
423
let cfgs = self . cfgs . clone ( ) ;
428
424
let libs = self . libs . clone ( ) ;
@@ -467,16 +463,25 @@ impl Collector {
467
463
}
468
464
469
465
pub fn get_line ( & self ) -> usize {
470
- if let Some ( ref codemap) = self . codemap {
471
- let line = codemap. lookup_char_pos ( BytePos ( self . start_line as u32 ) ) . line ;
466
+ if let Some ( ref codemap) = self . codemap {
467
+ let line = self . position . lo . to_usize ( ) ;
468
+ let line = codemap. lookup_char_pos ( BytePos ( line as u32 ) ) . line ;
472
469
if line > 0 { line - 1 } else { line }
473
470
} else {
474
- self . start_line
471
+ 0
475
472
}
476
473
}
477
474
478
- pub fn set_line ( & mut self , start_line : usize ) {
479
- self . start_line = start_line;
475
+ pub fn set_position ( & mut self , position : Span ) {
476
+ self . position = position;
477
+ }
478
+
479
+ pub fn get_filename ( & self ) -> String {
480
+ if let Some ( ref codemap) = self . codemap {
481
+ codemap. span_to_filename ( self . position )
482
+ } else {
483
+ "<input>" . to_owned ( )
484
+ }
480
485
}
481
486
482
487
pub fn register_header ( & mut self , name : & str , level : u32 ) {
@@ -520,7 +525,7 @@ impl<'a, 'hir> HirCollector<'a, 'hir> {
520
525
if let Some ( doc) = attrs. doc_value ( ) {
521
526
self . collector . cnt = 0 ;
522
527
markdown:: find_testable_code ( doc, self . collector ,
523
- attrs. span . unwrap_or ( DUMMY_SP ) . lo . to_usize ( ) ) ;
528
+ attrs. span . unwrap_or ( DUMMY_SP ) ) ;
524
529
}
525
530
526
531
nested ( self ) ;
0 commit comments