changeset 35155:6d5718e39657

run-tests: make "| foo (re)" not match everything We make "foo (re)" match the entire line by adding a \Z to the regular expression before matching. However, that doesn't help when the regular expression is something like "| foo", because that gets translated to "| foo\Z", where the "|" has lower precedence and it thus matches the empty string, which is of course a prefix of every string. Fix by wrapping expression in a group before adding the \Z to the end. Differential Revision: https://phab.mercurial-scm.org/D1546
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 29 Nov 2017 10:34:49 -0800
parents 4c04fd032af6
children 9f44d44626a0
files tests/run-tests.py tests/test-run-tests.t
diffstat 2 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Wed Nov 29 10:58:32 2017 -0800
+++ b/tests/run-tests.py	Wed Nov 29 10:34:49 2017 -0800
@@ -1527,6 +1527,7 @@
     @staticmethod
     def rematch(el, l):
         try:
+            el = b'(?:' + el + b')'
             # use \Z to ensure that the regex matches to the end of the string
             if os.name == 'nt':
                 return re.match(el + br'\r?\n\Z', l)
--- a/tests/test-run-tests.t	Wed Nov 29 10:58:32 2017 -0800
+++ b/tests/test-run-tests.t	Wed Nov 29 10:34:49 2017 -0800
@@ -98,19 +98,22 @@
 
 test churn with globs
   $ cat > test-failure.t <<EOF
-  >   $ echo "bar-baz"; echo "bar-bad"
+  >   $ echo "bar-baz"; echo "bar-bad"; echo foo
   >   bar*bad (glob)
   >   bar*baz (glob)
+  >   | fo (re)
   > EOF
   $ rt test-failure.t
   
   --- $TESTTMP/test-failure.t
   +++ $TESTTMP/test-failure.t.err
-  @@ -1,3 +1,3 @@
-     $ echo "bar-baz"; echo "bar-bad"
+  @@ -1,4 +1,4 @@
+     $ echo "bar-baz"; echo "bar-bad"; echo foo
   +  bar*baz (glob)
      bar*bad (glob)
   -  bar*baz (glob)
+  -  | fo (re)
+  +  foo
   
   ERROR: test-failure.t output changed
   !
@@ -126,11 +129,13 @@
   
   \x1b[38;5;124m--- $TESTTMP/test-failure.t\x1b[39m (esc)
   \x1b[38;5;34m+++ $TESTTMP/test-failure.t.err\x1b[39m (esc)
-  \x1b[38;5;90;01m@@ -1,3 +1,3 @@\x1b[39;00m (esc)
-     $ echo "bar-baz"; echo "bar-bad"
+  \x1b[38;5;90;01m@@ -1,4 +1,4 @@\x1b[39;00m (esc)
+     $ echo "bar-baz"; echo "bar-bad"; echo foo
   \x1b[38;5;34m+  bar*baz (glob)\x1b[39m (esc)
      bar*bad (glob)
   \x1b[38;5;124m-  bar*baz (glob)\x1b[39m (esc)
+  \x1b[38;5;124m-  | fo (re)\x1b[39m (esc)
+  \x1b[38;5;34m+  foo\x1b[39m (esc)
   
   \x1b[38;5;88mERROR: \x1b[39m\x1b[38;5;9mtest-failure.t\x1b[39m\x1b[38;5;88m output changed\x1b[39m (esc)
   !
@@ -145,11 +150,13 @@
   
   --- $TESTTMP/test-failure.t
   +++ $TESTTMP/test-failure.t.err
-  @@ -1,3 +1,3 @@
-     $ echo "bar-baz"; echo "bar-bad"
+  @@ -1,4 +1,4 @@
+     $ echo "bar-baz"; echo "bar-bad"; echo foo
   +  bar*baz (glob)
      bar*bad (glob)
   -  bar*baz (glob)
+  -  | fo (re)
+  +  foo
   
   ERROR: test-failure.t output changed
   !