# HG changeset patch # User Martin von Zweigbergk # Date 2017-11-29 18:34:49 # Node ID 6d5718e3965711c64aa79dd10bff4431fba6c8bc # Parent 4c04fd032af683e56c54ec98d869d12b162790e0 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 diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -1527,6 +1527,7 @@ class TTest(Test): @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) diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t --- a/tests/test-run-tests.t +++ b/tests/test-run-tests.t @@ -98,19 +98,22 @@ failing test test churn with globs $ cat > test-failure.t < $ 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 @@ test diff colorisation \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 @@ test diff colorisation --- $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 !