Skip to content

Commit

Permalink
Support test header directives in run-make mode too.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed May 3, 2018
1 parent d58ab3d commit fefed13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/tools/compiletest/src/header.rs
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/tools/compiletest/src/main.rs
Expand Up @@ -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.
Expand Down

0 comments on commit fefed13

Please sign in to comment.