ui_test: require colon after command

This commit is contained in:
Ralf Jung 2022-07-08 17:17:44 -04:00
parent 7a6a812794
commit fdffaf740b
2 changed files with 19 additions and 6 deletions

View file

@ -117,12 +117,8 @@ impl Comments {
let next = args
.next()
.expect("the `position` above guarantees that there is at least one char");
// FIXME: this replicates the existing flexibility in our syntax. Consider requiring the colon.
let args = match next {
':' | ' ' => args.as_str(),
_ => bail!("expected space or `:`, got `{next}`"),
};
(command, args.trim())
ensure!(next == ':', "test command must be followed by : (or end the line)");
(command, args.as_str().trim())
}
};
@ -188,16 +184,19 @@ impl Comments {
self.error_pattern = Some((args.trim().to_string(), l));
}
"stderr-per-bitwidth" => {
// args are ignored (can be sue as comment)
ensure!(!self.stderr_per_bitwidth, "cannot specifiy stderr-per-bitwidth twice");
self.stderr_per_bitwidth = true;
}
command => {
if let Some(s) = command.strip_prefix("ignore-") {
// args are ignored (can be sue as comment)
self.ignore.push(Condition::parse(s));
return Ok(());
}
if let Some(s) = command.strip_prefix("only-") {
// args are ignored (can be sue as comment)
self.only.push(Condition::parse(s));
return Ok(());
}

View file

@ -53,3 +53,17 @@ use std::mem;
Err(_) => Ok(()),
}
}
#[test]
fn missing_colon_fail() -> Result<()> {
init();
let s = r"
//@stderr-per-bitwidth hello
use std::mem;
";
match Comments::parse(Path::new("<dummy>"), s) {
Ok(_) => bail!("expected parsing to fail"),
Err(_) => Ok(()),
}
}