diff --git a/src/common.rs b/src/common.rs index 17eaa54..332e9a6 100644 --- a/src/common.rs +++ b/src/common.rs @@ -229,6 +229,11 @@ pub struct Config { /// The default Rust edition pub edition: Option, + /// Whether parsing of headers uses `//@` and errors on malformed headers or + /// just allows any comment to have headers and silently ignores things that don't parse + /// as a header. + pub strict_headers: bool, + // Configuration for various run-make tests frobbing things like C compilers // or querying about various LLVM component information. pub cc: String, @@ -420,6 +425,7 @@ impl Default for Config { llvm_cxxflags: "llvm-cxxflags".to_string(), nodejs: None, edition: None, + strict_headers: false, } } } diff --git a/src/header.rs b/src/header.rs index 6aea9bb..9652b18 100644 --- a/src/header.rs +++ b/src/header.rs @@ -38,6 +38,7 @@ impl EarlyProps { iter_header(testfile, None, + config, &mut |ln| { props.ignore = props.ignore || @@ -300,6 +301,7 @@ impl TestProps { let mut has_edition = false; iter_header(testfile, cfg, + config, &mut |ln| { if let Some(ep) = config.parse_error_pattern(ln) { self.error_patterns.push(ep); @@ -422,10 +424,16 @@ impl TestProps { } } -fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) { +const HEADER_PREFIXES: [[&str; 2]; 2] = [ + ["//", "//["], + ["//@", "//@["], +]; + +fn iter_header(testfile: &Path, cfg: Option<&str>, config: &Config, it: &mut dyn FnMut(&str)) { if testfile.is_dir() { return; } + let header_prefix = HEADER_PREFIXES[config.strict_headers as usize]; let rdr = BufReader::new(File::open(testfile).unwrap()); for ln in rdr.lines() { // Assume that any directives will be found before the first @@ -435,7 +443,7 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) { let ln = ln.trim(); if ln.starts_with("fn") || ln.starts_with("mod") { return; - } else if let Some(ln) = ln.strip_prefix("//@[") { + } else if let Some(ln) = ln.strip_prefix(header_prefix[1]) { // A comment like `//[foo]` is specific to revision `foo` if let Some((lncfg, ln)) = ln.split_once(']') { if cfg == Some(lncfg) { @@ -447,7 +455,7 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) { ln ) } - } else if let Some(ln) = ln.strip_prefix("//@") { + } else if let Some(ln) = ln.strip_prefix(header_prefix[0]) { it(ln.trim_start()); } } diff --git a/test-project/tests/tests.rs b/test-project/tests/tests.rs index c46710c..52466dc 100644 --- a/test-project/tests/tests.rs +++ b/test-project/tests/tests.rs @@ -18,6 +18,7 @@ fn run_mode(mode: &'static str, custom_dir: Option<&'static str>) { .into(), ); config.clean_rmeta(); + config.strict_headers = true; compiletest::run_tests(&config); }