about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-04-20 11:10:32 +0200
committerGitHub <noreply@github.com>2024-04-20 11:10:32 +0200
commitf58ef084c9740ed917a2009dfe2035f33ceaeb55 (patch)
tree2831af5a4d3aa8e8176edf0c6c0affdbdec76d48
parentff9a0b19ff97711499b525ea281f380889274466 (diff)
parent282488c80871191718c1ba6d04dcb53e83ee6de5 (diff)
Rollup merge of #124137 - tgross35:testsuite-multi-rev-regex, r=jieyouxu
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 include `-`.
-rw-r--r--src/tools/compiletest/src/errors.rs5
-rw-r--r--src/tools/compiletest/src/errors/tests.rs12
2 files changed, 16 insertions, 1 deletions
diff --git a/src/tools/compiletest/src/errors.rs b/src/tools/compiletest/src/errors.rs
index 140c3aa0a64..3231f9fd3a4 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<Regex> =
-        Lazy::new(|| Regex::new(r"//(?:\[(?P<revs>[\w,]+)])?~(?P<adjust>\||\^*)").unwrap());
+        Lazy::new(|| Regex::new(r"//(?:\[(?P<revs>[\w\-,]+)])?~(?P<adjust>\||\^*)").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 00000000000..dfb001d8e39
--- /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());
+}