Skip to content

Commit b43a394

Browse files
authored
Merge pull request #261 from oli-obk/@
Require an `@` in front of all commands.
2 parents 655228a + 91b1310 commit b43a394

File tree

14 files changed

+43
-31
lines changed

14 files changed

+43
-31
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: 19 additions & 14 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,23 +443,20 @@ 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 ln.starts_with("//[") {
446+
} else if let Some(ln) = ln.strip_prefix(header_prefix[1]) {
439447
// A comment like `//[foo]` is specific to revision `foo`
440-
if let Some(close_brace) = ln.find(']') {
441-
let lncfg = &ln[3..close_brace];
442-
let matches = match cfg {
443-
Some(s) => s == &lncfg[..],
444-
None => false,
445-
};
446-
if matches {
447-
it(ln[(close_brace + 1) ..].trim_start());
448+
if let Some((lncfg, ln)) = ln.split_once(']') {
449+
if cfg == Some(lncfg) {
450+
it(ln.trim_start());
448451
}
449452
} else {
450-
panic!("malformed condition directive: expected `//[foo]`, found `{}`",
451-
ln)
453+
panic!(
454+
"malformed condition directive: expected `//[foo]`, found `{}`",
455+
ln
456+
)
452457
}
453-
} else if ln.starts_with("//") {
454-
it(ln[2..].trim_start());
458+
} else if let Some(ln) = ln.strip_prefix(header_prefix[0]) {
459+
it(ln.trim_start());
455460
}
456461
}
457462
return;

test-project/tests/assembly/panic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// assembly-output: emit-asm
2-
// compile-flags: --crate-type rlib
1+
//@assembly-output: emit-asm
2+
//@compile-flags: --crate-type rlib
33
#![no_std]
44

55
#[no_mangle]
66
fn panic_fun() -> u32 {
77
// CHECK-LABEL: panic_fun:
88
// CHECK: ud2
99
panic!();
10-
}
10+
}

test-project/tests/nightly/2018-edition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// edition:2018
2-
// compile-pass
1+
//@edition:2018
2+
//@compile-pass
33

44
pub struct Foo;
55
impl Foo {

test-project/tests/nightly/auxiliary/simple_proc_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// no-prefer-dynamic
1+
//@no-prefer-dynamic
22

33
#![crate_type = "proc-macro"]
44

test-project/tests/nightly/some-proc-macro.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// run-pass
2-
// aux-build:simple_proc_macro.rs
1+
//@run-pass
2+
//@aux-build:simple_proc_macro.rs
33

44
#![feature(proc_macro_hygiene)]
55

test-project/tests/pretty/macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// pretty-compare-only
2-
// pretty-mode:expanded
3-
// pp-exact:macro.pp
1+
//@pretty-compare-only
2+
//@pretty-mode:expanded
3+
//@pp-exact:macro.pp
44

55
macro_rules! square {
66
($x:expr) => {

test-project/tests/run-fail/args-panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111

12-
// error-pattern:meep
12+
//@error-pattern:meep
1313

1414
#![allow(unknown_features)]
1515
#![feature(box_syntax)]

test-project/tests/run-fail/issue-20971.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// Regression test for Issue #20971.
1212

13-
// error-pattern:Hello, world!
13+
//@error-pattern:Hello, world!
1414

1515
pub trait Parser {
1616
type Input;

test-project/tests/run-fail/match-wildcards.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:squirrelcupcake
11+
//@error-pattern:squirrelcupcake
1212
fn cmp() -> int {
1313
match (Some('a'), None::<char>) {
1414
(Some(_), _) => { panic!("squirrelcupcake"); }

0 commit comments

Comments
 (0)