[PATCH 2 of 2] tests/run-tests: use hghave.py
Mads Kiilerich
mads at kiilerich.com
Thu Jun 14 05:21:04 CDT 2012
On 13/06/12 18:27, Adrian Buehlmann wrote:
> # HG changeset patch
> # User Adrian Buehlmann <adrian at cadifra.com>
> # Date 1339600654 -7200
> # Node ID c5d405b7129df301e20053d555fdb0229bfc4669
> # Parent 0c7325fd7b4b793f1c9ea38cdb23a680f8fbd92a
> tests/run-tests: use hghave.py
>
> Eliminates the start of a subprocess for #if requirements checking.
FWIW: I would take this without the TestError stuff (and thus without
the hardcoded 127).
This is the test suite. If hghave throws exceptions then it is a bug in
hghave or in the test and then it is better to crash badly with a full
stacktrace so it can be fixed.
/Mads
> 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 f in features:
> + negate = f.startswith('no-')
> + if negate:
> + f = f[3:]
> +
> + if f not in checks:
> + raise TestError('unknown feature: ' + f)
> +
> + check, desc = checks[f]
> + try:
> + available = check()
> + except Exception, e:
> + raise TestError('hghave check failed: ' + f)
> +
> + 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 = '.'
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list