From fdffaf740bf15dbcedd630b0ac6bd81293202bc8 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 8 Jul 2022 17:17:44 -0400 Subject: [PATCH] ui_test: require colon after command --- ui_test/src/comments.rs | 11 +++++------ ui_test/src/comments/tests.rs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ui_test/src/comments.rs b/ui_test/src/comments.rs index 4046a9fc0ddf..12f0864d9ab8 100644 --- a/ui_test/src/comments.rs +++ b/ui_test/src/comments.rs @@ -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(()); } diff --git a/ui_test/src/comments/tests.rs b/ui_test/src/comments/tests.rs index 15a0aae247b1..096cc8eab965 100644 --- a/ui_test/src/comments/tests.rs +++ b/ui_test/src/comments/tests.rs @@ -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(""), s) { + Ok(_) => bail!("expected parsing to fail"), + Err(_) => Ok(()), + } +}