[PATCH V4] run-tests: use hghave.py
Adrian Buehlmann
adrian at cadifra.com
Tue Jun 19 11:45:43 UTC 2012
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1340041060 -7200
# Node ID 60e6c72cc6df5e3c1e8abd88c6949a6382e31411
# Parent 79902f7e27df0eeae96d4d47d5c8a12fae2a0bb7
run-tests: use hghave.py
Eliminates the start of a subprocess for #if requirements checking.
The has_xxx functions in hghave.py now get the path where they should do their
check in.
diff --git a/tests/hghave b/tests/hghave
--- a/tests/hghave
+++ b/tests/hghave
@@ -19,7 +19,7 @@
for name, feature in checks.iteritems():
check, _ = feature
try:
- check()
+ check(".")
except Exception, e:
print "feature %s failed: %s" % (name, e)
failed += 1
@@ -63,7 +63,7 @@
check, desc = checks[feature]
try:
- available = check()
+ available = check(".")
except Exception, e:
error('hghave check failed: ' + feature)
continue
diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -19,17 +19,17 @@
ret = 1
return (ignorestatus or ret is None) and r.search(s)
-def has_baz():
+def has_baz(wd):
return matchoutput('baz --version 2>&1', r'baz Bazaar version')
-def has_bzr():
+def has_bzr(wd):
try:
import bzrlib
return bzrlib.__doc__ is not None
except ImportError:
return False
-def has_bzr114():
+def has_bzr114(wd):
try:
import bzrlib
return (bzrlib.__doc__ is not None
@@ -37,30 +37,30 @@
except ImportError:
return False
-def has_cvs():
+def has_cvs(wd):
re = r'Concurrent Versions System.*?server'
- return matchoutput('cvs --version 2>&1', re) and not has_msys()
+ return matchoutput('cvs --version 2>&1', re) and not has_msys(wd)
-def has_darcs():
+def has_darcs(wd):
return matchoutput('darcs --version', r'2\.[2-9]', True)
-def has_mtn():
+def has_mtn(wd):
return matchoutput('mtn --version', r'monotone', True) and not matchoutput(
'mtn --version', r'monotone 0\.', True)
-def has_eol_in_paths():
+def has_eol_in_paths(wd):
try:
- fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r')
+ fd, path = tempfile.mkstemp(dir=wd, prefix=tempprefix, suffix='\n\r')
os.close(fd)
os.remove(path)
return True
except (IOError, OSError):
return False
-def has_executablebit():
+def has_executablebit(wd):
try:
EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
- fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
+ fh, fn = tempfile.mkstemp(dir=wd, prefix=tempprefix)
try:
os.close(fh)
m = os.stat(fn).st_mode & 0777
@@ -74,9 +74,9 @@
return False
return not (new_file_has_exec or exec_flags_cannot_flip)
-def has_icasefs():
+def has_icasefs(wd):
# Stolen from mercurial.util
- fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
+ fd, path = tempfile.mkstemp(dir=wd, prefix=tempprefix)
os.close(fd)
try:
s1 = os.stat(path)
@@ -92,12 +92,12 @@
finally:
os.remove(path)
-def has_inotify():
+def has_inotify(wd):
try:
import hgext.inotify.linux.watcher
except ImportError:
return False
- name = tempfile.mktemp(dir='.', prefix=tempprefix)
+ name = tempfile.mktemp(dir=wd, prefix=tempprefix)
sock = socket.socket(socket.AF_UNIX)
try:
sock.bind(name)
@@ -107,10 +107,10 @@
os.unlink(name)
return True
-def has_fifo():
+def has_fifo(wd):
if getattr(os, "mkfifo", None) is None:
return False
- name = tempfile.mktemp(dir='.', prefix=tempprefix)
+ name = tempfile.mktemp(dir=wd, prefix=tempprefix)
try:
os.mkfifo(name)
os.unlink(name)
@@ -118,30 +118,30 @@
except OSError:
return False
-def has_cacheable_fs():
+def has_cacheable_fs(wd):
from mercurial import util
- fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
+ fd, path = tempfile.mkstemp(dir=wd, prefix=tempprefix)
os.close(fd)
try:
return util.cachestat(path).cacheable()
finally:
os.remove(path)
-def has_lsprof():
+def has_lsprof(wd):
try:
import _lsprof
return True
except ImportError:
return False
-def has_gettext():
+def has_gettext(wd):
return matchoutput('msgfmt --version', 'GNU gettext-tools')
-def has_git():
+def has_git(wd):
return matchoutput('git --version 2>&1', r'^git version')
-def has_docutils():
+def has_docutils(wd):
try:
from docutils.core import publish_cmdline
return True
@@ -154,17 +154,17 @@
return (0, 0)
return (int(m.group(1)), int(m.group(2)))
-def has_svn15():
+def has_svn15(wd):
return getsvnversion() >= (1, 5)
-def has_svn13():
+def has_svn13(wd):
return getsvnversion() >= (1, 3)
-def has_svn():
+def has_svn(wd):
return matchoutput('svn --version 2>&1', r'^svn, version') and \
matchoutput('svnadmin --version 2>&1', r'^svnadmin, version')
-def has_svn_bindings():
+def has_svn_bindings(wd):
try:
import svn.core
version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
@@ -174,26 +174,26 @@
except ImportError:
return False
-def has_p4():
+def has_p4(wd):
return (matchoutput('p4 -V', r'Rev\. P4/') and
matchoutput('p4d -V', r'Rev\. P4D/'))
-def has_symlink():
+def has_symlink(wd):
if getattr(os, "symlink", None) is None:
return False
- name = tempfile.mktemp(dir='.', prefix=tempprefix)
+ name = tempfile.mktemp(dir=wd, prefix=tempprefix)
try:
- os.symlink(".", name)
+ os.symlink(wd, name)
os.unlink(name)
return True
except (OSError, AttributeError):
return False
-def has_hardlink():
+def has_hardlink(wd):
from mercurial import util
- fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
+ fh, fn = tempfile.mkstemp(dir=wd, prefix=tempprefix)
os.close(fh)
- name = tempfile.mktemp(dir='.', prefix=tempprefix)
+ name = tempfile.mktemp(dir=wd, prefix=tempprefix)
try:
try:
util.oslink(fn, name)
@@ -204,14 +204,14 @@
finally:
os.unlink(fn)
-def has_tla():
+def has_tla(wd):
return matchoutput('tla --version 2>&1', r'The GNU Arch Revision')
-def has_gpg():
+def has_gpg(wd):
return matchoutput('gpg --version 2>&1', r'GnuPG')
-def has_unix_permissions():
- d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
+def has_unix_permissions(wd):
+ d = tempfile.mkdtemp(dir=wd, prefix=tempprefix)
try:
fname = os.path.join(d, 'foo')
for umask in (077, 007, 022):
@@ -226,22 +226,22 @@
finally:
os.rmdir(d)
-def has_pyflakes():
+def has_pyflakes(wd):
return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"",
r"<stdin>:1: 're' imported but unused",
True)
-def has_pygments():
+def has_pygments(wd):
try:
import pygments
return True
except ImportError:
return False
-def has_outer_repo():
+def has_outer_repo(wd):
return matchoutput('hg root 2>&1', r'')
-def has_ssl():
+def has_ssl(wd):
try:
import ssl
import OpenSSL
@@ -250,24 +250,24 @@
except ImportError:
return False
-def has_windows():
+def has_windows(wd):
return os.name == 'nt'
-def has_system_sh():
+def has_system_sh(wd):
return os.name != 'nt'
-def has_serve():
+def has_serve(wd):
return os.name != 'nt' # gross approximation
-def has_tic():
+def has_tic(wd):
return matchoutput('test -x "`which tic`"', '')
-def has_msys():
+def has_msys(wd):
return os.getenv('MSYSTEM')
checks = {
- "true": (lambda: True, "yak shaving"),
- "false": (lambda: False, "nail clipper"),
+ "true": (lambda x: True, "yak shaving"),
+ "false": (lambda x: False, "nail clipper"),
"baz": (has_baz, "GNU Arch baz client"),
"bzr": (has_bzr, "Canonical's Bazaar client"),
"bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"),
@@ -304,3 +304,23 @@
"windows": (has_windows, "Windows"),
"msys": (has_msys, "Windows with MSYS"),
}
+
+def testfeatures(features, wd=None):
+
+ if wd is None:
+ wd = "."
+
+ for f in features:
+ negate = f.startswith('no-')
+ if negate:
+ f = f[3:]
+
+ check, t = checks[f]
+ available = check(wd)
+
+ 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,8 +613,13 @@
if l.startswith('#if'):
if skipping is not None:
after.setdefault(pos, []).append(' !!! nested #if\n')
- skipping = not hghave(l.split()[1:])
after.setdefault(pos, []).append(l)
+ try:
+ skipping = not hghave.testfeatures(l.split()[1:], wd)
+ except KeyError, e:
+ after.setdefault(pos, []).append(
+ ' !!! unknown feature: %s\n' % e)
+ skipping = True
elif l.startswith('#else'):
if skipping is None:
after.setdefault(pos, []).append(' !!! missing #if\n')
@@ -1306,6 +1301,11 @@
COVERAGE_FILE = os.path.join(TESTDIR, ".coverage")
+ # insert root in sys.path, so mercurial can be imported in hghave
+ rootdir = os.path.realpath(os.path.join(TESTDIR, ".."))
+ if rootdir not in sys.path:
+ sys.path.insert(1, rootdir)
+
vlog("# Using TESTDIR", TESTDIR)
vlog("# Using HGTMP", HGTMP)
vlog("# Using PATH", os.environ["PATH"])
More information about the Mercurial-devel
mailing list