[PATCH 2 of 4] run-tests: allow to put conditions and comments in expected output
Simon Heimberg
simohe at besonet.ch
Tue Feb 4 00:14:18 UTC 2014
# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1391470011 -3600
# Tue Feb 04 00:26:51 2014 +0100
# Branch stable
# Node ID 94c2bb6ad0656684bdc90bb52a1a205a5ad151e3
# Parent ab6f4d067f28326dfdd5c352491c92148f0ee160
run-tests: allow to put conditions and comments in expected output
Writing the condition in the output will reduce the copied output lines in
some tests (see next patch).
To see output containing comments or conditions, see near the changes in
test-run-tests.t.
Limitation: The return code must follow the last output line directly. So this
does not work:
$ echo output; false
#if true
output
#else
something else
#endif
[1]
It must be written like this:
$ echo output; false
#if true
output
[1]
#else
something else
[1]
#endif
diff -r ab6f4d067f28 -r 94c2bb6ad065 tests/run-tests.py
--- a/tests/run-tests.py Mon Feb 03 22:20:52 2014 +0100
+++ b/tests/run-tests.py Tue Feb 04 00:26:51 2014 +0100
@@ -655,14 +655,11 @@
# After we run the shell script, we re-unify the script output
# with non-active parts of the source, with synchronization by our
- # SALT line number markers. The after table contains the
- # non-active components, ordered by line number
- after = {}
+ # SALT line number markers. The alloutput table contains the
+ # non-active components and the expected output, ordered by line number
+ alloutput = {}
pos = prepos = -1
- # Expected shellscript output
- expected = {}
-
# We keep track of whether or not we're in a Python block so we
# can generate the surrounding doctest magic
inpython = False
@@ -685,10 +682,7 @@
return ret == 0
def add_output(pos, text, isexpected=False):
- if isexpected:
- expected.setdefault(pos, []).append(text)
- else:
- after.setdefault(pos, []).append(text)
+ alloutput.setdefault(pos, []).append((isexpected, text))
f = open(test)
t = f.readlines()
@@ -795,9 +789,12 @@
lout += ' (no-eol)\n'
# find the expected output at the current position
- el = None
- if pos in expected and expected[pos]:
- el = expected[pos].pop(0)
+ l = alloutput.get(pos, None)
+ while l:
+ isexpected, el = l.pop(0)
+ if isexpected:
+ break
+ postout.append(el) # add non-active component
r = linematch(el, lout)
if isinstance(r, str):
@@ -823,13 +820,17 @@
ret = int(lcmd.split()[1])
if ret != 0:
postout.append(" [%s]\n" % ret)
- if pos in after:
+ for isexpected, el in alloutput.get(pos, []):
# merge in non-active test bits
- postout += after.pop(pos)
+ if not isexpected:
+ postout.append(el)
+ alloutput[pos] = [] # clear, doctest comes here twice with same pos
pos = int(lcmd.split()[0])
- if pos in after:
- postout += after.pop(pos)
+ # add remaining non-active components
+ for isexpected, el in alloutput.get(pos, []):
+ if not isexpected:
+ postout.append(el)
return exitcode, postout
diff -r ab6f4d067f28 -r 94c2bb6ad065 tests/test-run-tests.t
--- a/tests/test-run-tests.t Mon Feb 03 22:20:52 2014 +0100
+++ b/tests/test-run-tests.t Tue Feb 04 00:26:51 2014 +0100
@@ -31,6 +31,7 @@
... print c
x
y
+comment in the output
z
>>> print
@@ -115,6 +116,14 @@
tested
#endif
+ $ printf a\\nB\\nc
+ a
+#if true
+ B
+#endif
+and some comment
+ c (no-eol)
+
Exit code:
$ (exit 1)
More information about the Mercurial-devel
mailing list