From 282488c80871191718c1ba6d04dcb53e83ee6de5 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Thu, 18 Apr 2024 17:17:47 -0400 Subject: [PATCH] Match hyphen in multi-revision comment matchers Currently, the matcher `//[rev-foo,rev-bar]~` does not get selected by the regex. Change the matcher to also match strings that contain a `-`.h --- src/tools/compiletest/src/errors.rs | 5 ++++- src/tools/compiletest/src/errors/tests.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/tools/compiletest/src/errors/tests.rs diff --git a/src/tools/compiletest/src/errors.rs b/src/tools/compiletest/src/errors.rs index 140c3aa0a64ec..3231f9fd3a4b9 100644 --- a/src/tools/compiletest/src/errors.rs +++ b/src/tools/compiletest/src/errors.rs @@ -118,7 +118,7 @@ fn parse_expected( // //[rev1]~ // //[rev1,rev2]~^^ static RE: Lazy = - Lazy::new(|| Regex::new(r"//(?:\[(?P[\w,]+)])?~(?P\||\^*)").unwrap()); + Lazy::new(|| Regex::new(r"//(?:\[(?P[\w\-,]+)])?~(?P\||\^*)").unwrap()); let captures = RE.captures(line)?; @@ -178,3 +178,6 @@ fn parse_expected( ); Some((which, Error { line_num, kind, msg })) } + +#[cfg(test)] +mod tests; diff --git a/src/tools/compiletest/src/errors/tests.rs b/src/tools/compiletest/src/errors/tests.rs new file mode 100644 index 0000000000000..dfb001d8e397f --- /dev/null +++ b/src/tools/compiletest/src/errors/tests.rs @@ -0,0 +1,12 @@ +use super::*; + +#[test] +fn test_parse_expected_matching() { + // Ensure that we correctly extract expected revisions + let d1 = "//[rev1,rev2]~^ ERROR foo"; + let d2 = "//[rev1,rev2-foo]~^ ERROR foo"; + assert!(parse_expected(None, 1, d1, Some("rev1")).is_some()); + assert!(parse_expected(None, 1, d1, Some("rev2")).is_some()); + assert!(parse_expected(None, 1, d2, Some("rev1")).is_some()); + assert!(parse_expected(None, 1, d2, Some("rev2-foo")).is_some()); +}