changeset 38554:f83600efa1ca

tests: don't allow reodering of glob/re lines across non-glob/re lines As shown in the test case added in the previous patch, it can be really hard to interpret diffs from the test runner if there are multiple lines that would match a given glob or regular expression. It looks like this has been the case since 1ad0ddf8cccc (run-tests: teach _processoutput to handle multiple lines of churn, 2016-03-17). It seems like the point of that was to preserve the "(glob)" annotation on lines even if they got moved. This patch tries to preserve that but only allows the lines to be moved past other glob/re lines. Differential Revision: https://phab.mercurial-scm.org/D3881
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 02 Jul 2018 11:14:13 -0700
parents 3fb46734508d
children f2f9bacf0587
files tests/run-tests.py tests/test-run-tests.py tests/test-run-tests.t
diffstat 3 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Fri Jun 29 11:29:03 2018 -0700
+++ b/tests/run-tests.py	Mon Jul 02 11:14:13 2018 -0700
@@ -1484,7 +1484,7 @@
                 for i, el in enumerate(els):
                     r = False
                     if el:
-                        r = self.linematch(el, lout)
+                        r, exact = self.linematch(el, lout)
                     if isinstance(r, str):
                         if r == '-glob':
                             lout = ''.join(el.rsplit(' (glob)', 1))
@@ -1508,6 +1508,11 @@
 
                                 if not self._iftest(conditions):
                                     optional.append(i)
+                        if exact:
+                            # Don't allow line to be matches against a later
+                            # line in the output
+                            els.pop(i)
+                            break
 
                 if r:
                     if r == "retry":
@@ -1608,7 +1613,7 @@
 
     def linematch(self, el, l):
         if el == l: # perfect match (fast)
-            return True
+            return True, True
         retry = False
         if el.endswith(b" (?)\n"):
             retry = "retry"
@@ -1629,19 +1634,19 @@
             else:
                 el = el[:-7].decode('string-escape') + '\n'
         if el == l or os.name == 'nt' and el[:-1] + b'\r\n' == l:
-            return True
+            return True, True
         if el.endswith(b" (re)\n"):
-            return TTest.rematch(el[:-6], l) or retry
+            return (TTest.rematch(el[:-6], l) or retry), False
         if el.endswith(b" (glob)\n"):
             # ignore '(glob)' added to l by 'replacements'
             if l.endswith(b" (glob)\n"):
                 l = l[:-8] + b"\n"
-            return TTest.globmatch(el[:-8], l) or retry
+            return (TTest.globmatch(el[:-8], l) or retry), False
         if os.altsep:
             _l = l.replace(b'\\', b'/')
             if el == _l or os.name == 'nt' and el[:-1] + b'\r\n' == _l:
-                return True
-        return retry
+                return True, True
+        return retry, True
 
     @staticmethod
     def parsehghaveoutput(lines):
--- a/tests/test-run-tests.py	Fri Jun 29 11:29:03 2018 -0700
+++ b/tests/test-run-tests.py	Mon Jul 02 11:14:13 2018 -0700
@@ -40,7 +40,7 @@
     assert not re.search(br'[^ \w\\/\r\n()*?]', expected + output), \
            b'single backslash or unknown char'
     test = run_tests.TTest(b'test-run-test.t', b'.', b'.')
-    match = test.linematch(expected, output)
+    match, exact = test.linematch(expected, output)
     if isinstance(match, str):
         return 'special: ' + match
     elif isinstance(match, bytes):
--- a/tests/test-run-tests.t	Fri Jun 29 11:29:03 2018 -0700
+++ b/tests/test-run-tests.t	Mon Jul 02 11:14:13 2018 -0700
@@ -142,21 +142,18 @@
   
   --- $TESTTMP/test-failure-globs.t
   +++ $TESTTMP/test-failure-globs.t.err
-  @@ -2,10 +2,10 @@
+  @@ -2,9 +2,9 @@
      context
      context
      key: 1
   -  value: a
-  +  value: * (glob)
+  +  value: not a
      key: 2
   -  value: b
-  +  value: * (glob)
+  +  value: not b
      key: 3
-  -  value: * (glob)
-  +  value: c
+     value: * (glob)
      key: 4
-  -  value: * (glob)
-  +  value: d
   
   ERROR: test-failure-globs.t output changed
   !