Skip to content

Commit 6bdc5d6

Browse files
committed
Auto merge of rust-lang#2348 - RalfJung:ui-test, r=RalfJung
ui_test: require colon after command Turns out we already use colons everywhere properly. Also rename ui_test::comments to parser. I think that better describes its contents. :)
2 parents 7a6a812 + 2850db9 commit 6bdc5d6

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

ui_test/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use std::sync::Mutex;
1010
pub use color_eyre;
1111
use color_eyre::eyre::Result;
1212
use colored::*;
13-
use comments::ErrorMatch;
13+
use parser::ErrorMatch;
1414
use regex::Regex;
1515
use rustc_stderr::{Level, Message};
1616

17-
use crate::comments::{Comments, Condition};
17+
use crate::parser::{Comments, Condition};
1818

19-
mod comments;
19+
mod parser;
2020
mod rustc_stderr;
2121
#[cfg(test)]
2222
mod tests;

ui_test/src/comments.rs renamed to ui_test/src/parser.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,8 @@ impl Comments {
117117
let next = args
118118
.next()
119119
.expect("the `position` above guarantees that there is at least one char");
120-
// FIXME: this replicates the existing flexibility in our syntax. Consider requiring the colon.
121-
let args = match next {
122-
':' | ' ' => args.as_str(),
123-
_ => bail!("expected space or `:`, got `{next}`"),
124-
};
125-
(command, args.trim())
120+
ensure!(next == ':', "test command must be followed by : (or end the line)");
121+
(command, args.as_str().trim())
126122
}
127123
};
128124

@@ -188,16 +184,19 @@ impl Comments {
188184
self.error_pattern = Some((args.trim().to_string(), l));
189185
}
190186
"stderr-per-bitwidth" => {
187+
// args are ignored (can be used as comment)
191188
ensure!(!self.stderr_per_bitwidth, "cannot specifiy stderr-per-bitwidth twice");
192189
self.stderr_per_bitwidth = true;
193190
}
194191
command => {
195192
if let Some(s) = command.strip_prefix("ignore-") {
193+
// args are ignored (can be sue as comment)
196194
self.ignore.push(Condition::parse(s));
197195
return Ok(());
198196
}
199197

200198
if let Some(s) = command.strip_prefix("only-") {
199+
// args are ignored (can be sue as comment)
201200
self.only.push(Condition::parse(s));
202201
return Ok(());
203202
}

ui_test/src/comments/tests.rs renamed to ui_test/src/parser/tests.rs

+14
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,17 @@ use std::mem;
5353
Err(_) => Ok(()),
5454
}
5555
}
56+
57+
#[test]
58+
fn missing_colon_fail() -> Result<()> {
59+
init();
60+
let s = r"
61+
//@stderr-per-bitwidth hello
62+
use std::mem;
63+
64+
";
65+
match Comments::parse(Path::new("<dummy>"), s) {
66+
Ok(_) => bail!("expected parsing to fail"),
67+
Err(_) => Ok(()),
68+
}
69+
}

0 commit comments

Comments
 (0)