Skip to content

Require an @ in front of all commands. #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
}
}
33 changes: 19 additions & 14 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,23 +443,20 @@ 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 ln.starts_with("//[") {
} else if let Some(ln) = ln.strip_prefix(header_prefix[1]) {
// A comment like `//[foo]` is specific to revision `foo`
if let Some(close_brace) = ln.find(']') {
let lncfg = &ln[3..close_brace];
let matches = match cfg {
Some(s) => s == &lncfg[..],
None => false,
};
if matches {
it(ln[(close_brace + 1) ..].trim_start());
if let Some((lncfg, ln)) = ln.split_once(']') {
if cfg == Some(lncfg) {
it(ln.trim_start());
}
} else {
panic!("malformed condition directive: expected `//[foo]`, found `{}`",
ln)
panic!(
"malformed condition directive: expected `//[foo]`, found `{}`",
ln
)
}
} else if ln.starts_with("//") {
it(ln[2..].trim_start());
} else if let Some(ln) = ln.strip_prefix(header_prefix[0]) {
it(ln.trim_start());
}
}
return;
Expand Down
6 changes: 3 additions & 3 deletions test-project/tests/assembly/panic.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// assembly-output: emit-asm
// compile-flags: --crate-type rlib
//@assembly-output: emit-asm
//@compile-flags: --crate-type rlib
#![no_std]

#[no_mangle]
fn panic_fun() -> u32 {
// CHECK-LABEL: panic_fun:
// CHECK: ud2
panic!();
}
}
4 changes: 2 additions & 2 deletions test-project/tests/nightly/2018-edition.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// edition:2018
// compile-pass
//@edition:2018
//@compile-pass

pub struct Foo;
impl Foo {
Expand Down
2 changes: 1 addition & 1 deletion test-project/tests/nightly/auxiliary/simple_proc_macro.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// no-prefer-dynamic
//@no-prefer-dynamic

#![crate_type = "proc-macro"]

Expand Down
4 changes: 2 additions & 2 deletions test-project/tests/nightly/some-proc-macro.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-pass
// aux-build:simple_proc_macro.rs
//@run-pass
//@aux-build:simple_proc_macro.rs

#![feature(proc_macro_hygiene)]

Expand Down
6 changes: 3 additions & 3 deletions test-project/tests/pretty/macro.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// pretty-compare-only
// pretty-mode:expanded
// pp-exact:macro.pp
//@pretty-compare-only
//@pretty-mode:expanded
//@pp-exact:macro.pp

macro_rules! square {
($x:expr) => {
Expand Down
2 changes: 1 addition & 1 deletion test-project/tests/run-fail/args-panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.


// error-pattern:meep
//@error-pattern:meep

#![allow(unknown_features)]
#![feature(box_syntax)]
Expand Down
2 changes: 1 addition & 1 deletion test-project/tests/run-fail/issue-20971.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// Regression test for Issue #20971.

// error-pattern:Hello, world!
//@error-pattern:Hello, world!

pub trait Parser {
type Input;
Expand Down
2 changes: 1 addition & 1 deletion test-project/tests/run-fail/match-wildcards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:squirrelcupcake
//@error-pattern:squirrelcupcake
fn cmp() -> int {
match (Some('a'), None::<char>) {
(Some(_), _) => { panic!("squirrelcupcake"); }
Expand Down
2 changes: 1 addition & 1 deletion test-project/tests/run-fail/mod-zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:attempted remainder with a divisor of zero
//@error-pattern:attempted remainder with a divisor of zero
fn main() {
let y = 0;
let _z = 1 % y;
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
2 changes: 1 addition & 1 deletion test-project/tests/ui/dyn-keyword.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix
//@run-rustfix

#![allow(unused_variables)]
#![deny(keyword_idents)]
Expand Down
2 changes: 1 addition & 1 deletion test-project/tests/ui/dyn-keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix
//@run-rustfix

#![allow(unused_variables)]
#![deny(keyword_idents)]
Expand Down