[PATCH 2 of 2 RFC] tests/run-tests: use hghave.py
Adrian Buehlmann
adrian at cadifra.com
Tue Jun 12 06:17:19 CDT 2012
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1339495296 -7200
# Node ID 7284bfac8225399e3f16c06bdb6d6d9ab88be5eb
# Parent a52c543f0523f83d0c313b934646e9692fae254a
tests/run-tests: use hghave.py
diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -272,3 +272,32 @@
"windows": (has_windows, "Windows"),
"msys": (has_msys, "Windows with MSYS"),
}
+
+class TestError(Exception):
+ def __init__(self, msg):
+ self.msg = msg
+ def __str__(self):
+ return self.msg
+
+def testfeatures(features):
+
+ for feature in features:
+ negate = feature.startswith('no-')
+ if negate:
+ feature = feature[3:]
+
+ if feature not in checks:
+ raise TestError('unknown feature: ' + feature)
+
+ check, desc = checks[feature]
+ try:
+ available = check()
+ except Exception, e:
+ raise TestError('hghave check failed: ' + featur)
+
+ if not negate and not available:
+ return False
+ elif negate and available:
+ return False
+
+ return True
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -54,6 +54,7 @@
import time
import re
import threading
+import hghave
processlock = threading.Lock()
@@ -597,17 +598,6 @@
# True or False when in a true or false conditional section
skipping = None
- def hghave(reqs):
- # TODO: do something smarter when all other uses of hghave is gone
- tdir = TESTDIR.replace('\\', '/')
- proc = Popen4('%s -c "%s/hghave %s"' %
- (options.shell, tdir, ' '.join(reqs)), wd, 0)
- proc.communicate()
- ret = proc.wait()
- if wifexited(ret):
- ret = os.WEXITSTATUS(ret)
- return ret == 0
-
f = open(test)
t = f.readlines()
f.close()
@@ -623,7 +613,7 @@
if l.startswith('#if'):
if skipping is not None:
after.setdefault(pos, []).append(' !!! nested #if\n')
- skipping = not hghave(l.split()[1:])
+ skipping = not hghave.testfeatures(l.split()[1:])
after.setdefault(pos, []).append(l)
elif l.startswith('#else'):
if skipping is None:
@@ -932,7 +922,11 @@
replacements.append((re.escape(testtmp), '$TESTTMP'))
os.mkdir(testtmp)
- ret, out = runner(testpath, testtmp, options, replacements)
+ try:
+ ret, out = runner(testpath, testtmp, options, replacements)
+ except hghave.TestError, e:
+ ret = 127
+ out = [str(e)]
vlog("# Ret was:", ret)
mark = '.'
More information about the Mercurial-devel
mailing list