@@ -412,6 +412,15 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
412
412
if testfile. is_dir ( ) {
413
413
return ;
414
414
}
415
+
416
+ let comment = if testfile. to_string_lossy ( ) . ends_with ( ".rs" ) {
417
+ "//"
418
+ } else {
419
+ "#"
420
+ } ;
421
+
422
+ let comment_with_brace = comment. to_string ( ) + "[" ;
423
+
415
424
let rdr = BufReader :: new ( File :: open ( testfile) . unwrap ( ) ) ;
416
425
for ln in rdr. lines ( ) {
417
426
// Assume that any directives will be found before the first
@@ -421,10 +430,11 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
421
430
let ln = ln. trim ( ) ;
422
431
if ln. starts_with ( "fn" ) || ln. starts_with ( "mod" ) {
423
432
return ;
424
- } else if ln. starts_with ( "//[" ) {
433
+ } else if ln. starts_with ( & comment_with_brace ) {
425
434
// A comment like `//[foo]` is specific to revision `foo`
426
435
if let Some ( close_brace) = ln. find ( ']' ) {
427
- let lncfg = & ln[ 3 ..close_brace] ;
436
+ let open_brace = ln. find ( '[' ) . unwrap ( ) ;
437
+ let lncfg = & ln[ open_brace + 1 .. close_brace] ;
428
438
let matches = match cfg {
429
439
Some ( s) => s == & lncfg[ ..] ,
430
440
None => false ,
@@ -433,11 +443,11 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
433
443
it ( ln[ ( close_brace + 1 ) ..] . trim_left ( ) ) ;
434
444
}
435
445
} else {
436
- panic ! ( "malformed condition directive: expected `//[ foo]`, found `{}`" ,
437
- ln)
446
+ panic ! ( "malformed condition directive: expected `{} foo]`, found `{}`" ,
447
+ comment_with_brace , ln)
438
448
}
439
- } else if ln. starts_with ( "//" ) {
440
- it ( ln[ 2 ..] . trim_left ( ) ) ;
449
+ } else if ln. starts_with ( comment ) {
450
+ it ( ln[ comment . len ( ) ..] . trim_left ( ) ) ;
441
451
}
442
452
}
443
453
return ;
0 commit comments