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

login
register
mail settings
Submitter Simon Heimberg
Date Feb. 4, 2014, 12:14 a.m.
Message ID <ab6f4d067f28326dfdd5.1391472857@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/3453/
State Changes Requested
Headers show

Comments

Simon Heimberg - Feb. 4, 2014, 12:14 a.m.
# HG changeset patch
# User Simon Heimberg <simohe@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.
Pierre-Yves David - April 14, 2014, 4:41 a.m.
On 02/03/2014 07:14 PM, Simon Heimberg wrote:
> # HG changeset patch
> # User Simon Heimberg <simohe@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

Does a new version of this series ever made it to the repo (or the 
mailing list?)

Patch

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