@@ -37,7 +37,7 @@ use rustc_trans::back::link;
3737use syntax:: ast;
3838use syntax:: codemap:: CodeMap ;
3939use syntax:: feature_gate:: UnstableFeatures ;
40- use syntax_pos:: { BytePos , DUMMY_SP , Pos } ;
40+ use syntax_pos:: { BytePos , DUMMY_SP , Pos , Span } ;
4141use errors;
4242use errors:: emitter:: ColorConfig ;
4343
@@ -97,15 +97,13 @@ pub fn run(input: &str,
9797 link:: find_crate_name ( None , & hir_forest. krate ( ) . attrs , & input)
9898 } ) ;
9999 let opts = scrape_test_config ( hir_forest. krate ( ) ) ;
100- let filename = input_path. to_str ( ) . unwrap_or ( "" ) . to_owned ( ) ;
101100 let mut collector = Collector :: new ( crate_name,
102101 cfgs,
103102 libs,
104103 externs,
105104 false ,
106105 opts,
107106 maybe_sysroot,
108- filename,
109107 Some ( codemap) ) ;
110108
111109 {
@@ -391,15 +389,14 @@ pub struct Collector {
391389 cratename : String ,
392390 opts : TestOptions ,
393391 maybe_sysroot : Option < PathBuf > ,
394- filename : String ,
395- start_line : usize ,
392+ position : Span ,
396393 codemap : Option < Rc < CodeMap > > ,
397394}
398395
399396impl Collector {
400397 pub fn new ( cratename : String , cfgs : Vec < String > , libs : SearchPaths , externs : Externs ,
401398 use_headers : bool , opts : TestOptions , maybe_sysroot : Option < PathBuf > ,
402- filename : String , codemap : Option < Rc < CodeMap > > ) -> Collector {
399+ codemap : Option < Rc < CodeMap > > ) -> Collector {
403400 Collector {
404401 tests : Vec :: new ( ) ,
405402 names : Vec :: new ( ) ,
@@ -412,17 +409,16 @@ impl Collector {
412409 cratename : cratename,
413410 opts : opts,
414411 maybe_sysroot : maybe_sysroot,
415- filename : filename,
416- start_line : 0 ,
412+ position : DUMMY_SP ,
417413 codemap : codemap,
418414 }
419415 }
420416
421417 pub fn add_test ( & mut self , test : String ,
422418 should_panic : bool , no_run : bool , should_ignore : bool ,
423419 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) ;
426422 self . cnt += 1 ;
427423 let cfgs = self . cfgs . clone ( ) ;
428424 let libs = self . libs . clone ( ) ;
@@ -467,16 +463,25 @@ impl Collector {
467463 }
468464
469465 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 ;
472469 if line > 0 { line - 1 } else { line }
473470 } else {
474- self . start_line
471+ 0
475472 }
476473 }
477474
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+ }
480485 }
481486
482487 pub fn register_header ( & mut self , name : & str , level : u32 ) {
@@ -520,7 +525,7 @@ impl<'a, 'hir> HirCollector<'a, 'hir> {
520525 if let Some ( doc) = attrs. doc_value ( ) {
521526 self . collector . cnt = 0 ;
522527 markdown:: find_testable_code ( doc, self . collector ,
523- attrs. span . unwrap_or ( DUMMY_SP ) . lo . to_usize ( ) ) ;
528+ attrs. span . unwrap_or ( DUMMY_SP ) ) ;
524529 }
525530
526531 nested ( self ) ;
0 commit comments