[PATCH 2 of 3] hghave: move feature checking into hghave.py

Augie Fackler raf at durin42.com
Mon Aug 24 09:12:24 CDT 2015


On Sat, Aug 22, 2015 at 11:03:10AM -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1440264514 25200
> #      Sat Aug 22 10:28:34 2015 -0700
> # Node ID f80e33f600fd047bab33fa23b239f2eb58439228
> # Parent  6a83eafd8e2ccba4d9df7e869f42f93d9a4076b5
> hghave: move feature checking into hghave.py
>
> Upcoming patches will kill hghave (the script - not hghave.py) and
> will move to a model where requirements checking is performed as
> a function call.
>
> Start diminishing the utility of hghave by moving some code to
> hghave.py.
>
> diff --git a/tests/hghave b/tests/hghave
> --- a/tests/hghave
> +++ b/tests/hghave
> @@ -63,37 +63,5 @@ if __name__ == '__main__':
>
>      if options.test_features:
>          sys.exit(test_features())
>
> -    quiet = options.quiet
> -
> -    failures = 0
> -
> -    def error(msg):
> -        global failures
> -        if not quiet:
> -            sys.stderr.write(msg + '\n')
> -        failures += 1
> -
> -    for feature in args:
> -        negate = feature.startswith('no-')
> -        if negate:
> -            feature = feature[3:]
> -
> -        if feature not in checks:
> -            error('skipped: unknown feature: ' + feature)
> -            sys.exit(2)
> -
> -        check, desc = checks[feature]
> -        try:
> -            available = check()
> -        except Exception, e:
> -            error('hghave check failed: ' + feature)
> -            continue
> -
> -        if not negate and not available:
> -            error('skipped: missing feature: ' + desc)
> -        elif negate and available:
> -            error('skipped: system supports %s' % desc)
> -
> -    if failures != 0:
> -        sys.exit(1)
> +    hghave.require(args, options.quiet)
> diff --git a/tests/hghave.py b/tests/hghave.py
> --- a/tests/hghave.py
> +++ b/tests/hghave.py
> @@ -16,8 +16,56 @@ def check(name, desc):
>          checks[name] = (func, desc)
>          return func
>      return decorator
>
> +def checkfeatures(features):
> +    result = {
> +        'error': [],
> +        'missing': [],
> +        'skipped': [],
> +    }
> +
> +    for feature in features:
> +        negate = feature.startswith('no-')
> +        if negate:
> +            feature = feature[3:]
> +
> +        if feature not in checks:
> +            result['missing'].append(feature)
> +            continue
> +
> +        check, desc = checks[feature]
> +        try:
> +            available = check()
> +        except Exception, e:

check-code sends greetings ;)

> +            result['error'].append('hghave check failed: %s' % feature)
> +            continue
> +
> +        if not negate and not available:
> +            result['skipped'].append('missing feature: %s' % desc)
> +        elif negate and available:
> +            result['skipped'].append('system supports %s' % desc)
> +
> +    return result
> +
> +def require(features, quiet=False):
> +    """Require that features are available, exiting if not."""
> +    result = checkfeatures(features)
> +
> +    if not quiet:
> +        for missing in result['missing']:
> +            sys.stderr.write('skipped: unknown feature: %s\n' % missing)
> +        for msg in result['skipped']:
> +            sys.stderr.write('skipped: %s\n' % msg)
> +        for msg in result['error']:
> +            sys.stderr.write('%s\n' % msg)
> +
> +    if result['missing']:
> +        sys.exit(2)
> +
> +    if result['skipped'] or result['error']:
> +        sys.exit(1)
> +
>  def matchoutput(cmd, regexp, ignorestatus=False):
>      """Return True if cmd executes successfully and its output
>      is matched by the supplied regular expression.
>      """
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list