[PATCH] tests: add (?) flag for optional lines

Matt Mackall mpm at selenic.com
Mon Jun 1 17:11:54 UTC 2015


# HG changeset patch
# User Matt Mackall <mpm at selenic.com>
# Date 1433109574 18000
#      Sun May 31 16:59:34 2015 -0500
# Node ID 9eda7a4d8e3c3efc72095e64080a00abdd45b916
# Parent  4cc3fb23881d9abc7745501ef0d777e5976ddb52
tests: add (?) flag for optional lines

When the test engine fails to match output on a line marked with (?),
it will simply continue to the next expected line and try again. This
allows simplifying tests that have either version-specific or
non-fixed behavior, for instance:

  $ coin-flip
  heads (?)
  tails (?)

(There's no form of back-tracking attempted, so optional matches
should be specific.)

diff -r 4cc3fb23881d -r 9eda7a4d8e3c tests/run-tests.py
--- a/tests/run-tests.py	Sat May 30 12:46:30 2015 +0900
+++ b/tests/run-tests.py	Sun May 31 16:59:34 2015 -0500
@@ -1043,7 +1043,7 @@
             if salt in l:
                 lout, lcmd = l.split(salt, 1)
 
-            if lout:
+            while lout:
                 if not lout.endswith(b'\n'):
                     lout += b' (no-eol)\n'
 
@@ -1060,6 +1060,9 @@
                     elif r == '-glob':
                         lout = ''.join(el.rsplit(' (glob)', 1))
                         r = '' # Warn only this line.
+                    elif r == "retry":
+                        postout.append(b'  ' + el)
+                        continue
                     else:
                         log('\ninfo, unknown linematch result: %r\n' % r)
                         r = False
@@ -1074,6 +1077,15 @@
                         warnonly = 3 # for sure not
                     elif warnonly == 1: # Is "not yet" and line is warn only.
                         warnonly = 2 # Yes do warn.
+                break
+
+            # clean up any optional leftovers
+            while expected.get(pos, None):
+                el = expected[pos].pop(0)
+                if not el.endswith(" (?)\n"):
+                    expected[pos].insert(0, el)
+                    break
+                postout.append(b'  ' + el)
 
             if lcmd:
                 # Add on last return code.
@@ -1136,9 +1148,13 @@
 
     @staticmethod
     def linematch(el, l):
+        retry = False
         if el == l: # perfect match (fast)
             return True
         if el:
+            if el.endswith(" (?)\n"):
+                retry = "retry"
+                el = el[:-5] + "\n"
             if el.endswith(b" (esc)\n"):
                 if PYTHON3:
                     el = el[:-7].decode('unicode_escape') + '\n'
@@ -1148,7 +1164,7 @@
             if el == l or os.name == 'nt' and el[:-1] + b'\r\n' == l:
                 return True
             if el.endswith(b" (re)\n"):
-                return TTest.rematch(el[:-6], l)
+                return TTest.rematch(el[:-6], l) or retry
             if el.endswith(b" (glob)\n"):
                 # ignore '(glob)' added to l by 'replacements'
                 if l.endswith(b" (glob)\n"):
@@ -1156,7 +1172,7 @@
                 return TTest.globmatch(el[:-8], l)
             if os.altsep and l.replace(b'\\', b'/') == el:
                 return b'+glob'
-        return False
+        return retry
 
     @staticmethod
     def parsehghaveoutput(lines):
diff -r 4cc3fb23881d -r 9eda7a4d8e3c tests/test-run-tests.t
--- a/tests/test-run-tests.t	Sat May 30 12:46:30 2015 +0900
+++ b/tests/test-run-tests.t	Sun May 31 16:59:34 2015 -0500
@@ -21,7 +21,9 @@
   >   $ echo babar
   >   babar
   >   $ echo xyzzy
+  >   never happens (?)
   >   xyzzy
+  >   nor this (?)
   > EOF
 
   $ $TESTDIR/run-tests.py --with-hg=`which hg`
@@ -237,8 +239,8 @@
   *SALT* 2 0 (glob)
   + echo xyzzy
   xyzzy
-  + echo *SALT* 4 0 (glob)
-  *SALT* 4 0 (glob)
+  + echo *SALT* 6 0 (glob)
+  *SALT* 6 0 (glob)
   .
   # Ran 2 tests, 0 skipped, 0 warned, 0 failed.
 


More information about the Mercurial-devel mailing list