Skip to content

Commit a7e2eae

Browse files
Support test header directives in run-make mode too.
1 parent 6a667ef commit a7e2eae

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/tools/compiletest/src/header.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
412412
if testfile.is_dir() {
413413
return;
414414
}
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+
415424
let rdr = BufReader::new(File::open(testfile).unwrap());
416425
for ln in rdr.lines() {
417426
// 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)) {
421430
let ln = ln.trim();
422431
if ln.starts_with("fn") || ln.starts_with("mod") {
423432
return;
424-
} else if ln.starts_with("//[") {
433+
} else if ln.starts_with(&comment_with_brace) {
425434
// A comment like `//[foo]` is specific to revision `foo`
426435
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];
428438
let matches = match cfg {
429439
Some(s) => s == &lncfg[..],
430440
None => false,
@@ -433,11 +443,11 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
433443
it(ln[(close_brace + 1) ..].trim_left());
434444
}
435445
} else {
436-
panic!("malformed condition directive: expected `//[foo]`, found `{}`",
437-
ln)
446+
panic!("malformed condition directive: expected `{}foo]`, found `{}`",
447+
comment_with_brace, ln)
438448
}
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());
441451
}
442452
}
443453
return;

src/tools/compiletest/src/main.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,12 @@ pub fn is_test(file_name: &OsString) -> bool {
610610
}
611611

612612
pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn {
613-
let early_props = EarlyProps::from_file(config, &testpaths.file);
613+
614+
let early_props = if config.mode == Mode::RunMake {
615+
EarlyProps::from_file(config, &testpaths.file.join("Makefile"))
616+
} else {
617+
EarlyProps::from_file(config, &testpaths.file)
618+
};
614619

615620
// The `should-fail` annotation doesn't apply to pretty tests,
616621
// since we run the pretty printer across all tests by default.

0 commit comments

Comments
 (0)