@@ -419,6 +419,15 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
419419 if testfile. is_dir ( ) {
420420 return ;
421421 }
422+
423+ let comment = if testfile. to_string_lossy ( ) . ends_with ( ".rs" ) {
424+ "//"
425+ } else {
426+ "#"
427+ } ;
428+
429+ let comment_with_brace = comment. to_string ( ) + "[" ;
430+
422431 let rdr = BufReader :: new ( File :: open ( testfile) . unwrap ( ) ) ;
423432 for ln in rdr. lines ( ) {
424433 // Assume that any directives will be found before the first
@@ -428,10 +437,11 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
428437 let ln = ln. trim ( ) ;
429438 if ln. starts_with ( "fn" ) || ln. starts_with ( "mod" ) {
430439 return ;
431- } else if ln. starts_with ( "//[" ) {
440+ } else if ln. starts_with ( & comment_with_brace ) {
432441 // A comment like `//[foo]` is specific to revision `foo`
433442 if let Some ( close_brace) = ln. find ( ']' ) {
434- let lncfg = & ln[ 3 ..close_brace] ;
443+ let open_brace = ln. find ( '[' ) . unwrap ( ) ;
444+ let lncfg = & ln[ open_brace + 1 .. close_brace] ;
435445 let matches = match cfg {
436446 Some ( s) => s == & lncfg[ ..] ,
437447 None => false ,
@@ -440,11 +450,11 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
440450 it ( ln[ ( close_brace + 1 ) ..] . trim_left ( ) ) ;
441451 }
442452 } else {
443- panic ! ( "malformed condition directive: expected `//[ foo]`, found `{}`" ,
444- ln)
453+ panic ! ( "malformed condition directive: expected `{} foo]`, found `{}`" ,
454+ comment_with_brace , ln)
445455 }
446- } else if ln. starts_with ( "//" ) {
447- it ( ln[ 2 ..] . trim_left ( ) ) ;
456+ } else if ln. starts_with ( comment ) {
457+ it ( ln[ comment . len ( ) ..] . trim_left ( ) ) ;
448458 }
449459 }
450460 return ;
0 commit comments