Skip to content

Commit

Permalink
Make //@ mode configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 19, 2023
1 parent 8467c20 commit 91b1310
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ pub struct Config {
/// The default Rust edition
pub edition: Option<String>,

/// 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,
Expand Down Expand Up @@ -420,6 +425,7 @@ impl Default for Config {
llvm_cxxflags: "llvm-cxxflags".to_string(),
nodejs: None,
edition: None,
strict_headers: false,
}
}
}
14 changes: 11 additions & 3 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl EarlyProps {

iter_header(testfile,
None,
config,
&mut |ln| {
props.ignore =
props.ignore ||
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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());
}
}
Expand Down
1 change: 1 addition & 0 deletions test-project/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 91b1310

Please sign in to comment.