[PATCH] tests: introduce conditional sections in .t tests
Mads Kiilerich
mads at kiilerich.com
Fri Jun 1 00:28:01 UTC 2012
# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1338510312 -7200
# Node ID 61e232a608328f5dadf0edcccadaca9c5e4ab54e
# Parent f694ab54b66097ce96a9fa22c0869abcca3182cc
tests: introduce conditional sections in .t tests
This proof of concept use a syntax everybody can agree to dislike, for example:
$$hghave windows
$ date
$$hghad
$$hghave no-windows
$ date
$$hghad
where only one of sections will be executed and the other copied literally.
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -593,6 +593,8 @@
# We keep track of whether or not we're in a Python block so we
# can generate the surrounding doctest magic
inpython = False
+ # True or False when in a true or false conditional section
+ skipping = None
f = open(test)
t = f.readlines()
@@ -606,7 +608,26 @@
for n, l in enumerate(t):
if not l.endswith('\n'):
l += '\n'
- if l.startswith(' >>> '): # python inlines
+ if l.startswith(' $$hghave '):
+ if skipping is not None:
+ after.setdefault(pos, []).append(' !!! missing hghad\n')
+ hghavecmd = l[4:].strip()
+ proc = Popen4('%s -c "%s/%s"' %
+ (options.shell, TESTDIR, hghavecmd), TESTDIR, 0)
+ proc.communicate()
+ ret = proc.wait()
+ if wifexited(ret):
+ ret = os.WEXITSTATUS(ret)
+ skipping = ret != 0
+ after.setdefault(pos, []).append(l)
+ elif l.startswith(' $$hghad'):
+ if skipping is None:
+ after.setdefault(pos, []).append(' !!! missing hghave\n')
+ skipping = None
+ after.setdefault(pos, []).append(l)
+ elif skipping:
+ after.setdefault(pos, []).append(l)
+ elif l.startswith(' >>> '): # python inlines
after.setdefault(pos, []).append(l)
prepos = pos
pos = n
@@ -617,7 +638,7 @@
script.append('%s -m heredoctest <<EOF\n' % PYTHON)
addsalt(n, True)
script.append(l[2:])
- if l.startswith(' ... '): # python inlines
+ elif l.startswith(' ... '): # python inlines
after.setdefault(prepos, []).append(l)
script.append(l[2:])
elif l.startswith(' $ '): # commands
@@ -644,6 +665,8 @@
if inpython:
script.append("EOF\n")
+ if skipping is not None:
+ after.setdefault(pos, []).append(' !!! missing hghad\n')
addsalt(n + 1, False)
# Write out the script and execute it
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -1,5 +1,3 @@
- $ "$TESTDIR/hghave" symlink || exit 80
-
commit date test
$ hg init test
@@ -75,10 +73,14 @@
$ hg commit -m commit-14 does-not-exist
abort: does-not-exist: * (glob)
[255]
+
+ $$hghave symlink
$ ln -s foo baz
$ hg commit -m commit-15 baz
abort: baz: file not tracked!
[255]
+ $$hghad
+
$ touch quux
$ hg commit -m commit-16 quux
abort: quux: file not tracked!
More information about the Mercurial-devel
mailing list