@@ -419,6 +419,15 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
419
419
if testfile. is_dir ( ) {
420
420
return ;
421
421
}
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
+
422
431
let rdr = BufReader :: new ( File :: open ( testfile) . unwrap ( ) ) ;
423
432
for ln in rdr. lines ( ) {
424
433
// 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)) {
428
437
let ln = ln. trim ( ) ;
429
438
if ln. starts_with ( "fn" ) || ln. starts_with ( "mod" ) {
430
439
return ;
431
- } else if ln. starts_with ( "//[" ) {
440
+ } else if ln. starts_with ( & comment_with_brace ) {
432
441
// A comment like `//[foo]` is specific to revision `foo`
433
442
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] ;
435
445
let matches = match cfg {
436
446
Some ( s) => s == & lncfg[ ..] ,
437
447
None => false ,
@@ -440,11 +450,11 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
440
450
it ( ln[ ( close_brace + 1 ) ..] . trim_left ( ) ) ;
441
451
}
442
452
} else {
443
- panic ! ( "malformed condition directive: expected `//[ foo]`, found `{}`" ,
444
- ln)
453
+ panic ! ( "malformed condition directive: expected `{} foo]`, found `{}`" ,
454
+ comment_with_brace , ln)
445
455
}
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 ( ) ) ;
448
458
}
449
459
}
450
460
return ;
0 commit comments