From patchwork Tue Feb 4 00:14:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 4] run-tests: add helper function for appending expected and text output From: Simon Heimberg X-Patchwork-Id: 3453 Message-Id: To: Mercurial-devel Date: Tue, 04 Feb 2014 01:14:17 +0100 # HG changeset patch # User Simon Heimberg # 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