From fefed137470ecba8ee662c93b19bf39edffcde7e Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 17 Apr 2018 13:37:43 +0200 Subject: [PATCH] Support test header directives in run-make mode too. --- src/tools/compiletest/src/header.rs | 22 ++++++++++++++++------ src/tools/compiletest/src/main.rs | 7 ++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 73dd079cf0cc..32a0b75b33dd 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -419,6 +419,15 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) { if testfile.is_dir() { return; } + + let comment = if testfile.to_string_lossy().ends_with(".rs") { + "//" + } else { + "#" + }; + + let comment_with_brace = comment.to_string() + "["; + let rdr = BufReader::new(File::open(testfile).unwrap()); for ln in rdr.lines() { // 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)) { let ln = ln.trim(); if ln.starts_with("fn") || ln.starts_with("mod") { return; - } else if ln.starts_with("//[") { + } else if ln.starts_with(&comment_with_brace) { // A comment like `//[foo]` is specific to revision `foo` if let Some(close_brace) = ln.find(']') { - let lncfg = &ln[3..close_brace]; + let open_brace = ln.find('[').unwrap(); + let lncfg = &ln[open_brace + 1 .. close_brace]; let matches = match cfg { Some(s) => s == &lncfg[..], None => false, @@ -440,11 +450,11 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) { it(ln[(close_brace + 1) ..].trim_left()); } } else { - panic!("malformed condition directive: expected `//[foo]`, found `{}`", - ln) + panic!("malformed condition directive: expected `{}foo]`, found `{}`", + comment_with_brace, ln) } - } else if ln.starts_with("//") { - it(ln[2..].trim_left()); + } else if ln.starts_with(comment) { + it(ln[comment.len() ..].trim_left()); } } return; diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 37f7af0abe8f..d65a8d6a7dbf 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -610,7 +610,12 @@ pub fn is_test(file_name: &OsString) -> bool { } pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn { - let early_props = EarlyProps::from_file(config, &testpaths.file); + + let early_props = if config.mode == Mode::RunMake { + EarlyProps::from_file(config, &testpaths.file.join("Makefile")) + } else { + EarlyProps::from_file(config, &testpaths.file) + }; // The `should-fail` annotation doesn't apply to pretty tests, // since we run the pretty printer across all tests by default.