[PATCH 1 of 4] run-tests: add helper function for appending expected and text output

Simon Heimberg simohe at besonet.ch
Mon Feb 3 18:14:17 CST 2014


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1391462452 -3600
#      Mon Feb 03 22:20:52 2014 +0100
# Branch stable
# Node ID ab6f4d067f28326dfdd5c352491c92148f0ee160
# Parent  bf8664a21657a57df9bc7ed1e9476cf2f67c1b9d
run-tests: add helper function for appending expected and text output

This abstraction makes the following changes smaller.

diff -r bf8664a21657 -r ab6f4d067f28 tests/run-tests.py
--- a/tests/run-tests.py	Wed Jan 29 16:58:00 2014 +0100
+++ b/tests/run-tests.py	Mon Feb 03 22:20:52 2014 +0100
@@ -684,6 +684,12 @@
             sys.exit(1)
         return ret == 0
 
+    def add_output(pos, text, isexpected=False):
+        if isexpected:
+            expected.setdefault(pos, []).append(text)
+        else:
+            after.setdefault(pos, []).append(text)
+
     f = open(test)
     t = f.readlines()
     f.close()
@@ -699,23 +705,23 @@
             l += '\n'
         if l.startswith('#if'):
             if skipping is not None:
-                after.setdefault(pos, []).append('  !!! nested #if\n')
+                add_output(pos, '  !!! nested #if\n')
             skipping = not hghave(l.split()[1:])
-            after.setdefault(pos, []).append(l)
+            add_output(pos, l)
         elif l.startswith('#else'):
             if skipping is None:
-                after.setdefault(pos, []).append('  !!! missing #if\n')
+                add_output(pos, '  !!! missing #if\n')
             skipping = not skipping
-            after.setdefault(pos, []).append(l)
+            add_output(pos, l)
         elif l.startswith('#endif'):
             if skipping is None:
-                after.setdefault(pos, []).append('  !!! missing #if\n')
+                add_output(pos, '  !!! missing #if\n')
             skipping = None
-            after.setdefault(pos, []).append(l)
+            add_output(pos, l)
         elif skipping:
-            after.setdefault(pos, []).append(l)
+            add_output(pos, l)
         elif l.startswith('  >>> '): # python inlines
-            after.setdefault(pos, []).append(l)
+            add_output(pos, l)
             prepos = pos
             pos = n
             if not inpython:
@@ -726,13 +732,13 @@
             addsalt(n, True)
             script.append(l[2:])
         elif l.startswith('  ... '): # python inlines
-            after.setdefault(prepos, []).append(l)
+            add_output(prepos, l)
             script.append(l[2:])
         elif l.startswith('  $ '): # commands
             if inpython:
                 script.append("EOF\n")
                 inpython = False
-            after.setdefault(pos, []).append(l)
+            add_output(pos, l)
             prepos = pos
             pos = n
             addsalt(n, False)
@@ -741,22 +747,22 @@
                 l = '  $ cd %s || exit 1\n' % cmd[1]
             script.append(l[4:])
         elif l.startswith('  > '): # continuations
-            after.setdefault(prepos, []).append(l)
+            add_output(prepos, l)
             script.append(l[4:])
         elif l.startswith('  '): # results
             # queue up a list of expected results
-            expected.setdefault(pos, []).append(l[2:])
+            add_output(pos, l[2:], isexpected=True)
         else:
             if inpython:
                 script.append("EOF\n")
                 inpython = False
             # non-command/result - queue up for merged output
-            after.setdefault(pos, []).append(l)
+            add_output(pos, l)
 
     if inpython:
         script.append("EOF\n")
     if skipping is not None:
-        after.setdefault(pos, []).append('  !!! missing #endif\n')
+        add_output(pos, '  !!! missing #endif\n')
     addsalt(n + 1, False)
 
     # Write out the script and execute it


More information about the Mercurial-devel mailing list