Skip to content

Commit 91b1310

Browse files
committed
Make //@ mode configurable
1 parent 8467c20 commit 91b1310

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ pub struct Config {
229229
/// The default Rust edition
230230
pub edition: Option<String>,
231231

232+
/// Whether parsing of headers uses `//@` and errors on malformed headers or
233+
/// just allows any comment to have headers and silently ignores things that don't parse
234+
/// as a header.
235+
pub strict_headers: bool,
236+
232237
// Configuration for various run-make tests frobbing things like C compilers
233238
// or querying about various LLVM component information.
234239
pub cc: String,
@@ -420,6 +425,7 @@ impl Default for Config {
420425
llvm_cxxflags: "llvm-cxxflags".to_string(),
421426
nodejs: None,
422427
edition: None,
428+
strict_headers: false,
423429
}
424430
}
425431
}

src/header.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl EarlyProps {
3838

3939
iter_header(testfile,
4040
None,
41+
config,
4142
&mut |ln| {
4243
props.ignore =
4344
props.ignore ||
@@ -300,6 +301,7 @@ impl TestProps {
300301
let mut has_edition = false;
301302
iter_header(testfile,
302303
cfg,
304+
config,
303305
&mut |ln| {
304306
if let Some(ep) = config.parse_error_pattern(ln) {
305307
self.error_patterns.push(ep);
@@ -422,10 +424,16 @@ impl TestProps {
422424
}
423425
}
424426

425-
fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
427+
const HEADER_PREFIXES: [[&str; 2]; 2] = [
428+
["//", "//["],
429+
["//@", "//@["],
430+
];
431+
432+
fn iter_header(testfile: &Path, cfg: Option<&str>, config: &Config, it: &mut dyn FnMut(&str)) {
426433
if testfile.is_dir() {
427434
return;
428435
}
436+
let header_prefix = HEADER_PREFIXES[config.strict_headers as usize];
429437
let rdr = BufReader::new(File::open(testfile).unwrap());
430438
for ln in rdr.lines() {
431439
// 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)) {
435443
let ln = ln.trim();
436444
if ln.starts_with("fn") || ln.starts_with("mod") {
437445
return;
438-
} else if let Some(ln) = ln.strip_prefix("//@[") {
446+
} else if let Some(ln) = ln.strip_prefix(header_prefix[1]) {
439447
// A comment like `//[foo]` is specific to revision `foo`
440448
if let Some((lncfg, ln)) = ln.split_once(']') {
441449
if cfg == Some(lncfg) {
@@ -447,7 +455,7 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
447455
ln
448456
)
449457
}
450-
} else if let Some(ln) = ln.strip_prefix("//@") {
458+
} else if let Some(ln) = ln.strip_prefix(header_prefix[0]) {
451459
it(ln.trim_start());
452460
}
453461
}

test-project/tests/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fn run_mode(mode: &'static str, custom_dir: Option<&'static str>) {
1818
.into(),
1919
);
2020
config.clean_rmeta();
21+
config.strict_headers = true;
2122

2223
compiletest::run_tests(&config);
2324
}

0 commit comments

Comments
 (0)