tests/hghave.py
author Durham Goode <durham@fb.com>
Tue, 05 Jan 2016 17:08:14 -0800
changeset 27643 62ce86fcfd06
parent 27298 e1f55b50edcb
child 27702 39122c2442cd
permissions -rw-r--r--
verify: move checkentry() to be a class function This is part of making verify more modular so extensions can hook into it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27298
e1f55b50edcb tests: use absolute_import in hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27114
diff changeset
     1
from __future__ import absolute_import
e1f55b50edcb tests: use absolute_import in hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27114
diff changeset
     2
26137
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
     3
import errno
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
     4
import os
5252
c0281c6b40b0 hghave: wrap command output matching
Patrick Mezard <pmezard@gmail.com>
parents: 5218
diff changeset
     5
import re
22994
840be5ca03e1 cmdserver: add service that listens on unix domain socket and forks process
Yuya Nishihara <yuya@tcha.org>
parents: 22579
diff changeset
     6
import socket
26137
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
     7
import stat
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
     8
import subprocess
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     9
import sys
5072
7e2385a31933 hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents: 5070
diff changeset
    10
import tempfile
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    11
5090
bf60e4bd6672 hghave: prefix temporary files with "hg-hghave-"
Patrick Mezard <pmezard@gmail.com>
parents: 5084
diff changeset
    12
tempprefix = 'hg-hghave-'
bf60e4bd6672 hghave: prefix temporary files with "hg-hghave-"
Patrick Mezard <pmezard@gmail.com>
parents: 5084
diff changeset
    13
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    14
checks = {
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    15
    "true": (lambda: True, "yak shaving"),
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    16
    "false": (lambda: False, "nail clipper"),
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    17
}
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    18
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    19
def check(name, desc):
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    20
    def decorator(func):
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    21
        checks[name] = (func, desc)
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    22
        return func
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    23
    return decorator
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    24
26067
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    25
def checkfeatures(features):
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    26
    result = {
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    27
        'error': [],
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    28
        'missing': [],
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    29
        'skipped': [],
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    30
    }
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    31
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    32
    for feature in features:
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    33
        negate = feature.startswith('no-')
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    34
        if negate:
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    35
            feature = feature[3:]
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    36
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    37
        if feature not in checks:
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    38
            result['missing'].append(feature)
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    39
            continue
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    40
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    41
        check, desc = checks[feature]
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    42
        try:
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    43
            available = check()
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    44
        except Exception:
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    45
            result['error'].append('hghave check failed: %s' % feature)
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    46
            continue
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    47
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    48
        if not negate and not available:
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    49
            result['skipped'].append('missing feature: %s' % desc)
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    50
        elif negate and available:
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    51
            result['skipped'].append('system supports %s' % desc)
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    52
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    53
    return result
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    54
26068
05e7f57c74ac hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26067
diff changeset
    55
def require(features):
26067
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    56
    """Require that features are available, exiting if not."""
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    57
    result = checkfeatures(features)
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    58
26068
05e7f57c74ac hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26067
diff changeset
    59
    for missing in result['missing']:
05e7f57c74ac hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26067
diff changeset
    60
        sys.stderr.write('skipped: unknown feature: %s\n' % missing)
05e7f57c74ac hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26067
diff changeset
    61
    for msg in result['skipped']:
05e7f57c74ac hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26067
diff changeset
    62
        sys.stderr.write('skipped: %s\n' % msg)
05e7f57c74ac hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26067
diff changeset
    63
    for msg in result['error']:
05e7f57c74ac hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26067
diff changeset
    64
        sys.stderr.write('%s\n' % msg)
26067
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    65
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    66
    if result['missing']:
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    67
        sys.exit(2)
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    68
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    69
    if result['skipped'] or result['error']:
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    70
        sys.exit(1)
8107c308ff22 hghave: move feature checking into hghave.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25859
diff changeset
    71
5302
961876838de0 hghave: detect cvs and cvsps availability
Patrick Mezard <pmezard@gmail.com>
parents: 5252
diff changeset
    72
def matchoutput(cmd, regexp, ignorestatus=False):
27114
a636a46f5094 hghave.py: fix matchoutput documentation
timeless <timeless@mozdev.org>
parents: 26842
diff changeset
    73
    """Return the match object if cmd executes successfully and its output
5252
c0281c6b40b0 hghave: wrap command output matching
Patrick Mezard <pmezard@gmail.com>
parents: 5218
diff changeset
    74
    is matched by the supplied regular expression.
c0281c6b40b0 hghave: wrap command output matching
Patrick Mezard <pmezard@gmail.com>
parents: 5218
diff changeset
    75
    """
c0281c6b40b0 hghave: wrap command output matching
Patrick Mezard <pmezard@gmail.com>
parents: 5218
diff changeset
    76
    r = re.compile(regexp)
8213
ac9c4049fd29 hghave: handle Windows raising on popen() failure
Patrick Mezard <pmezard@gmail.com>
parents: 8127
diff changeset
    77
    try:
26137
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
    78
        p = subprocess.Popen(
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
    79
            cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
    80
    except OSError as e:
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
    81
        if e.errno != errno.ENOENT:
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
    82
            raise
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
    83
        ret = -1
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
    84
    ret = p.wait()
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
    85
    s = p.stdout.read()
99e8a9ff1f5f hghave: use subprocess instead of os.popen
Augie Fackler <augie@google.com>
parents: 26111
diff changeset
    86
    return (ignorestatus or not ret) and r.search(s)
5252
c0281c6b40b0 hghave: wrap command output matching
Patrick Mezard <pmezard@gmail.com>
parents: 5218
diff changeset
    87
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    88
@check("baz", "GNU Arch baz client")
6078
ebc23d34102f convert: added gnu arch (baz) tests
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6063
diff changeset
    89
def has_baz():
ebc23d34102f convert: added gnu arch (baz) tests
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6063
diff changeset
    90
    return matchoutput('baz --version 2>&1', r'baz Bazaar version')
ebc23d34102f convert: added gnu arch (baz) tests
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6063
diff changeset
    91
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
    92
@check("bzr", "Canonical's Bazaar client")
7053
209ef5f3534c convert: add bzr source
Marek Kubica <marek@xivilization.net>
parents: 6998
diff changeset
    93
def has_bzr():
7061
8b874f8cd29f tests: check for bzr support by importing bzrlib
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7053
diff changeset
    94
    try:
8b874f8cd29f tests: check for bzr support by importing bzrlib
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7053
diff changeset
    95
        import bzrlib
16684
e617876fe82d cleanup: "x != None" -> "x is not None"
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
    96
        return bzrlib.__doc__ is not None
7061
8b874f8cd29f tests: check for bzr support by importing bzrlib
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7053
diff changeset
    97
    except ImportError:
8b874f8cd29f tests: check for bzr support by importing bzrlib
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7053
diff changeset
    98
        return False
7053
209ef5f3534c convert: add bzr source
Marek Kubica <marek@xivilization.net>
parents: 6998
diff changeset
    99
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   100
@check("bzr114", "Canonical's Bazaar client >= 1.14")
8126
13b36eb14324 convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents: 7823
diff changeset
   101
def has_bzr114():
13b36eb14324 convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents: 7823
diff changeset
   102
    try:
13b36eb14324 convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents: 7823
diff changeset
   103
        import bzrlib
16684
e617876fe82d cleanup: "x != None" -> "x is not None"
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
   104
        return (bzrlib.__doc__ is not None
9244
3f52a70959ce tests/hghave: bzr114 checks for bzr >= 1.14
Mads Kiilerich <mads@kiilerich.com>
parents: 8809
diff changeset
   105
                and bzrlib.version_info[:2] >= (1, 14))
8126
13b36eb14324 convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents: 7823
diff changeset
   106
    except ImportError:
13b36eb14324 convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents: 7823
diff changeset
   107
        return False
13b36eb14324 convert/bzr: handle files replaced by directories (issue1623)
Patrick Mezard <pmezard@gmail.com>
parents: 7823
diff changeset
   108
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   109
@check("cvs", "cvs client/server")
5302
961876838de0 hghave: detect cvs and cvsps availability
Patrick Mezard <pmezard@gmail.com>
parents: 5252
diff changeset
   110
def has_cvs():
6626
59f7b804352f tests: don't run test-convert-cvs if there's no cvs server
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6384
diff changeset
   111
    re = r'Concurrent Versions System.*?server'
15568
08635f4e44be tests: skip cvs tests with msys on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 15567
diff changeset
   112
    return matchoutput('cvs --version 2>&1', re) and not has_msys()
5302
961876838de0 hghave: detect cvs and cvsps availability
Patrick Mezard <pmezard@gmail.com>
parents: 5252
diff changeset
   113
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   114
@check("cvs112", "cvs client/server >= 1.12")
18285
9589227657bc hghave: introduce a test (unused) for cvs >= 1.12
Bryan O'Sullivan <bryano@fb.com>
parents: 17707
diff changeset
   115
def has_cvs112():
9589227657bc hghave: introduce a test (unused) for cvs >= 1.12
Bryan O'Sullivan <bryano@fb.com>
parents: 17707
diff changeset
   116
    re = r'Concurrent Versions System \(CVS\) 1.12.*?server'
9589227657bc hghave: introduce a test (unused) for cvs >= 1.12
Bryan O'Sullivan <bryano@fb.com>
parents: 17707
diff changeset
   117
    return matchoutput('cvs --version 2>&1', re) and not has_msys()
9589227657bc hghave: introduce a test (unused) for cvs >= 1.12
Bryan O'Sullivan <bryano@fb.com>
parents: 17707
diff changeset
   118
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   119
@check("darcs", "darcs client")
5410
2daecf3d2582 hghave: detect darcs client
Patrick Mezard <pmezard@gmail.com>
parents: 5409
diff changeset
   120
def has_darcs():
9326
b236f34ec1e9 Fix failing darcs test
Bryan O'Sullivan <bos@serpentine.com>
parents: 9244
diff changeset
   121
    return matchoutput('darcs --version', r'2\.[2-9]', True)
5410
2daecf3d2582 hghave: detect darcs client
Patrick Mezard <pmezard@gmail.com>
parents: 5409
diff changeset
   122
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   123
@check("mtn", "monotone client (>= 1.0)")
6372
8f79820443a4 Add a test for monotone conversion
Patrick Mezard <pmezard@gmail.com>
parents: 6355
diff changeset
   124
def has_mtn():
6384
8bc876e03143 Skip older monotone versions for tests.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6372
diff changeset
   125
    return matchoutput('mtn --version', r'monotone', True) and not matchoutput(
14550
2425a3536396 tests: fix updated monotone version requirement
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14432
diff changeset
   126
        'mtn --version', r'monotone 0\.', True)
6372
8f79820443a4 Add a test for monotone conversion
Patrick Mezard <pmezard@gmail.com>
parents: 6355
diff changeset
   127
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   128
@check("eol-in-paths", "end-of-lines in paths")
5409
190c234c8fa0 hghave: reorder check functions and entries
Patrick Mezard <pmezard@gmail.com>
parents: 5308
diff changeset
   129
def has_eol_in_paths():
190c234c8fa0 hghave: reorder check functions and entries
Patrick Mezard <pmezard@gmail.com>
parents: 5308
diff changeset
   130
    try:
16968
456f457e376d tests/hghave: consistently use dir='.', prefix=tempprefix for tempfiles
Mads Kiilerich <mads@kiilerich.com>
parents: 16966
diff changeset
   131
        fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r')
5409
190c234c8fa0 hghave: reorder check functions and entries
Patrick Mezard <pmezard@gmail.com>
parents: 5308
diff changeset
   132
        os.close(fd)
190c234c8fa0 hghave: reorder check functions and entries
Patrick Mezard <pmezard@gmail.com>
parents: 5308
diff changeset
   133
        os.remove(path)
190c234c8fa0 hghave: reorder check functions and entries
Patrick Mezard <pmezard@gmail.com>
parents: 5308
diff changeset
   134
        return True
16688
cfb6682961b8 cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents: 16685
diff changeset
   135
    except (IOError, OSError):
5409
190c234c8fa0 hghave: reorder check functions and entries
Patrick Mezard <pmezard@gmail.com>
parents: 5308
diff changeset
   136
        return False
190c234c8fa0 hghave: reorder check functions and entries
Patrick Mezard <pmezard@gmail.com>
parents: 5308
diff changeset
   137
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   138
@check("execbit", "executable bit")
5072
7e2385a31933 hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents: 5070
diff changeset
   139
def has_executablebit():
7e2385a31933 hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents: 5070
diff changeset
   140
    try:
16320
e11ab387e89c tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 16319
diff changeset
   141
        EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
16968
456f457e376d tests/hghave: consistently use dir='.', prefix=tempprefix for tempfiles
Mads Kiilerich <mads@kiilerich.com>
parents: 16966
diff changeset
   142
        fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
16320
e11ab387e89c tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 16319
diff changeset
   143
        try:
e11ab387e89c tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 16319
diff changeset
   144
            os.close(fh)
25658
e93036747902 global: mass rewrite to use modern octal syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25413
diff changeset
   145
            m = os.stat(fn).st_mode & 0o777
16320
e11ab387e89c tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 16319
diff changeset
   146
            new_file_has_exec = m & EXECFLAGS
e11ab387e89c tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 16319
diff changeset
   147
            os.chmod(fn, m ^ EXECFLAGS)
25658
e93036747902 global: mass rewrite to use modern octal syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25413
diff changeset
   148
            exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0o777) == m)
16320
e11ab387e89c tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 16319
diff changeset
   149
        finally:
e11ab387e89c tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 16319
diff changeset
   150
            os.unlink(fn)
e11ab387e89c tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 16319
diff changeset
   151
    except (IOError, OSError):
e11ab387e89c tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 16319
diff changeset
   152
        # we don't care, the user probably won't be able to commit anyway
e11ab387e89c tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 16319
diff changeset
   153
        return False
e11ab387e89c tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 16319
diff changeset
   154
    return not (new_file_has_exec or exec_flags_cannot_flip)
5072
7e2385a31933 hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents: 5070
diff changeset
   155
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   156
@check("icasefs", "case insensitive file system")
6806
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   157
def has_icasefs():
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   158
    # Stolen from mercurial.util
16968
456f457e376d tests/hghave: consistently use dir='.', prefix=tempprefix for tempfiles
Mads Kiilerich <mads@kiilerich.com>
parents: 16966
diff changeset
   159
    fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
6806
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   160
    os.close(fd)
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   161
    try:
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   162
        s1 = os.stat(path)
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   163
        d, b = os.path.split(path)
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   164
        p2 = os.path.join(d, b.upper())
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   165
        if path == p2:
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   166
            p2 = os.path.join(d, b.lower())
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   167
        try:
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   168
            s2 = os.stat(p2)
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   169
            return s2 == s1
16688
cfb6682961b8 cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents: 16685
diff changeset
   170
        except OSError:
6806
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   171
            return False
2134d6c09432 Add test for case folding issues
Patrick Mezard <pmezard@gmail.com>
parents: 6626
diff changeset
   172
    finally:
6998
ddfcefab8b97 merge with -stable
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6806 6996
diff changeset
   173
        os.remove(path)
ddfcefab8b97 merge with -stable
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6806 6996
diff changeset
   174
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   175
@check("fifo", "named pipes")
5409
190c234c8fa0 hghave: reorder check functions and entries
Patrick Mezard <pmezard@gmail.com>
parents: 5308
diff changeset
   176
def has_fifo():
16969
6d1673107143 tests/hghave: test that a fifo actually can be created on the filesystem
Mads Kiilerich <mads@kiilerich.com>
parents: 16968
diff changeset
   177
    if getattr(os, "mkfifo", None) is None:
6d1673107143 tests/hghave: test that a fifo actually can be created on the filesystem
Mads Kiilerich <mads@kiilerich.com>
parents: 16968
diff changeset
   178
        return False
6d1673107143 tests/hghave: test that a fifo actually can be created on the filesystem
Mads Kiilerich <mads@kiilerich.com>
parents: 16968
diff changeset
   179
    name = tempfile.mktemp(dir='.', prefix=tempprefix)
6d1673107143 tests/hghave: test that a fifo actually can be created on the filesystem
Mads Kiilerich <mads@kiilerich.com>
parents: 16968
diff changeset
   180
    try:
6d1673107143 tests/hghave: test that a fifo actually can be created on the filesystem
Mads Kiilerich <mads@kiilerich.com>
parents: 16968
diff changeset
   181
        os.mkfifo(name)
6d1673107143 tests/hghave: test that a fifo actually can be created on the filesystem
Mads Kiilerich <mads@kiilerich.com>
parents: 16968
diff changeset
   182
        os.unlink(name)
6d1673107143 tests/hghave: test that a fifo actually can be created on the filesystem
Mads Kiilerich <mads@kiilerich.com>
parents: 16968
diff changeset
   183
        return True
6d1673107143 tests/hghave: test that a fifo actually can be created on the filesystem
Mads Kiilerich <mads@kiilerich.com>
parents: 16968
diff changeset
   184
    except OSError:
6d1673107143 tests/hghave: test that a fifo actually can be created on the filesystem
Mads Kiilerich <mads@kiilerich.com>
parents: 16968
diff changeset
   185
        return False
5074
e86788af599a hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents: 5072
diff changeset
   186
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   187
@check("killdaemons", 'killdaemons.py support')
17467
448d0c452140 test-http-branchmap: enable on Windows
Patrick Mezard <patrick@mezard.eu>
parents: 17016
diff changeset
   188
def has_killdaemons():
448d0c452140 test-http-branchmap: enable on Windows
Patrick Mezard <patrick@mezard.eu>
parents: 17016
diff changeset
   189
    return True
448d0c452140 test-http-branchmap: enable on Windows
Patrick Mezard <patrick@mezard.eu>
parents: 17016
diff changeset
   190
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   191
@check("cacheable", "cacheable filesystem")
14927
2aa3e07b2f07 posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents: 14550
diff changeset
   192
def has_cacheable_fs():
2aa3e07b2f07 posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents: 14550
diff changeset
   193
    from mercurial import util
2aa3e07b2f07 posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents: 14550
diff changeset
   194
16968
456f457e376d tests/hghave: consistently use dir='.', prefix=tempprefix for tempfiles
Mads Kiilerich <mads@kiilerich.com>
parents: 16966
diff changeset
   195
    fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
14927
2aa3e07b2f07 posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents: 14550
diff changeset
   196
    os.close(fd)
2aa3e07b2f07 posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents: 14550
diff changeset
   197
    try:
2aa3e07b2f07 posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents: 14550
diff changeset
   198
        return util.cachestat(path).cacheable()
2aa3e07b2f07 posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents: 14550
diff changeset
   199
    finally:
2aa3e07b2f07 posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents: 14550
diff changeset
   200
        os.remove(path)
2aa3e07b2f07 posix, windows: introduce cachestat
Idan Kamara <idankk86@gmail.com>
parents: 14550
diff changeset
   201
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   202
@check("lsprof", "python lsprof module")
5099
105d4cf7ec24 Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents: 5092
diff changeset
   203
def has_lsprof():
105d4cf7ec24 Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents: 5092
diff changeset
   204
    try:
105d4cf7ec24 Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents: 5092
diff changeset
   205
        import _lsprof
22198
77142de48ae4 cleanup: make sure we always access members of imported modules
Mads Kiilerich <madski@unity3d.com>
parents: 22093
diff changeset
   206
        _lsprof.Profiler # silence unused import warning
5099
105d4cf7ec24 Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents: 5092
diff changeset
   207
        return True
105d4cf7ec24 Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents: 5092
diff changeset
   208
    except ImportError:
105d4cf7ec24 Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents: 5092
diff changeset
   209
        return False
105d4cf7ec24 Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents: 5092
diff changeset
   210
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   211
@check("gettext", "GNU Gettext (msgfmt)")
13442
bb107a31820e test-i18n: make test conditional on msgfmt availability
Martin Geisler <mg@lazybytes.net>
parents: 13418
diff changeset
   212
def has_gettext():
bb107a31820e test-i18n: make test conditional on msgfmt availability
Martin Geisler <mg@lazybytes.net>
parents: 13418
diff changeset
   213
    return matchoutput('msgfmt --version', 'GNU gettext-tools')
bb107a31820e test-i18n: make test conditional on msgfmt availability
Martin Geisler <mg@lazybytes.net>
parents: 13418
diff changeset
   214
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   215
@check("git", "git command line client")
5218
4fa0f2dff643 hghave: detect git availability
Patrick Mezard <pmezard@gmail.com>
parents: 5103
diff changeset
   216
def has_git():
5252
c0281c6b40b0 hghave: wrap command output matching
Patrick Mezard <pmezard@gmail.com>
parents: 5218
diff changeset
   217
    return matchoutput('git --version 2>&1', r'^git version')
5218
4fa0f2dff643 hghave: detect git availability
Patrick Mezard <pmezard@gmail.com>
parents: 5103
diff changeset
   218
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   219
@check("docutils", "Docutils text processing library")
10971
cbe400a8e217 doc: add generic frontend to rst2man and rst2html
Martin Geisler <mg@aragost.com>
parents: 9819
diff changeset
   220
def has_docutils():
cbe400a8e217 doc: add generic frontend to rst2man and rst2html
Martin Geisler <mg@aragost.com>
parents: 9819
diff changeset
   221
    try:
cbe400a8e217 doc: add generic frontend to rst2man and rst2html
Martin Geisler <mg@aragost.com>
parents: 9819
diff changeset
   222
        from docutils.core import publish_cmdline
22198
77142de48ae4 cleanup: make sure we always access members of imported modules
Mads Kiilerich <madski@unity3d.com>
parents: 22093
diff changeset
   223
        publish_cmdline # silence unused import
10971
cbe400a8e217 doc: add generic frontend to rst2man and rst2html
Martin Geisler <mg@aragost.com>
parents: 9819
diff changeset
   224
        return True
cbe400a8e217 doc: add generic frontend to rst2man and rst2html
Martin Geisler <mg@aragost.com>
parents: 9819
diff changeset
   225
    except ImportError:
cbe400a8e217 doc: add generic frontend to rst2man and rst2html
Martin Geisler <mg@aragost.com>
parents: 9819
diff changeset
   226
        return False
9446
57d682d7d2da test-gendoc: test documentation generation
Martin Geisler <mg@lazybytes.net>
parents: 9395
diff changeset
   227
14050
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 13543
diff changeset
   228
def getsvnversion():
17707
35674bd95200 subrepo, hghave: use "svn --version --quiet" to determine version number
Thomas Arendsen Hein <thomas@intevation.de>
parents: 17467
diff changeset
   229
    m = matchoutput('svn --version --quiet 2>&1', r'^(\d+)\.(\d+)')
14050
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 13543
diff changeset
   230
    if not m:
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 13543
diff changeset
   231
        return (0, 0)
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 13543
diff changeset
   232
    return (int(m.group(1)), int(m.group(2)))
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 13543
diff changeset
   233
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   234
@check("svn15", "subversion client and admin tools >= 1.5")
14050
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 13543
diff changeset
   235
def has_svn15():
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 13543
diff changeset
   236
    return getsvnversion() >= (1, 5)
9e8a9d45945c subrepo: handle svn tracked/unknown directory collisions
Patrick Mezard <pmezard@gmail.com>
parents: 13543
diff changeset
   237
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   238
@check("svn13", "subversion client and admin tools >= 1.3")
15346
53f37b24f26a tests: check for svn >= 1.3 and >= 1.5 in tests that require those versions
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14927
diff changeset
   239
def has_svn13():
53f37b24f26a tests: check for svn >= 1.3 and >= 1.5 in tests that require those versions
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14927
diff changeset
   240
    return getsvnversion() >= (1, 3)
53f37b24f26a tests: check for svn >= 1.3 and >= 1.5 in tests that require those versions
Thomas Arendsen Hein <thomas@intevation.de>
parents: 14927
diff changeset
   241
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   242
@check("svn", "subversion client and admin tools")
5253
d82ebcdf20e1 hghave: detect subversion client and admin tools availability
Patrick Mezard <pmezard@gmail.com>
parents: 5252
diff changeset
   243
def has_svn():
9819
dec177286deb convert: reenable SVN support after license issue solved
Patrick Mezard <pmezard@gmail.com>
parents: 9817
diff changeset
   244
    return matchoutput('svn --version 2>&1', r'^svn, version') and \
dec177286deb convert: reenable SVN support after license issue solved
Patrick Mezard <pmezard@gmail.com>
parents: 9817
diff changeset
   245
        matchoutput('svnadmin --version 2>&1', r'^svnadmin, version')
5253
d82ebcdf20e1 hghave: detect subversion client and admin tools availability
Patrick Mezard <pmezard@gmail.com>
parents: 5252
diff changeset
   246
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   247
@check("svn-bindings", "subversion python bindings")
5254
d61e98a82cee hghave: detect subversion bindings availability
Patrick Mezard <pmezard@gmail.com>
parents: 5253
diff changeset
   248
def has_svn_bindings():
d61e98a82cee hghave: detect subversion bindings availability
Patrick Mezard <pmezard@gmail.com>
parents: 5253
diff changeset
   249
    try:
d61e98a82cee hghave: detect subversion bindings availability
Patrick Mezard <pmezard@gmail.com>
parents: 5253
diff changeset
   250
        import svn.core
7315
408cf9eb9e5d tests: run svn tests only with svn bindings >1.3
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7061
diff changeset
   251
        version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
408cf9eb9e5d tests: run svn tests only with svn bindings >1.3
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7061
diff changeset
   252
        if version < (1, 4):
408cf9eb9e5d tests: run svn tests only with svn bindings >1.3
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7061
diff changeset
   253
            return False
5254
d61e98a82cee hghave: detect subversion bindings availability
Patrick Mezard <pmezard@gmail.com>
parents: 5253
diff changeset
   254
        return True
d61e98a82cee hghave: detect subversion bindings availability
Patrick Mezard <pmezard@gmail.com>
parents: 5253
diff changeset
   255
    except ImportError:
d61e98a82cee hghave: detect subversion bindings availability
Patrick Mezard <pmezard@gmail.com>
parents: 5253
diff changeset
   256
        return False
d61e98a82cee hghave: detect subversion bindings availability
Patrick Mezard <pmezard@gmail.com>
parents: 5253
diff changeset
   257
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   258
@check("p4", "Perforce server and client")
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 7773
diff changeset
   259
def has_p4():
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16369
diff changeset
   260
    return (matchoutput('p4 -V', r'Rev\. P4/') and
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16369
diff changeset
   261
            matchoutput('p4d -V', r'Rev\. P4D/'))
7823
11efa41037e2 convert: Perforce source for conversion to Mercurial
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents: 7773
diff changeset
   262
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   263
@check("symlink", "symbolic links")
5409
190c234c8fa0 hghave: reorder check functions and entries
Patrick Mezard <pmezard@gmail.com>
parents: 5308
diff changeset
   264
def has_symlink():
16685
43d55088415a cleanup: replace hasattr() usage with getattr() in hghave
Brodie Rao <brodie@sf.io>
parents: 16684
diff changeset
   265
    if getattr(os, "symlink", None) is None:
16319
ac0da5caebec tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 15568
diff changeset
   266
        return False
16968
456f457e376d tests/hghave: consistently use dir='.', prefix=tempprefix for tempfiles
Mads Kiilerich <mads@kiilerich.com>
parents: 16966
diff changeset
   267
    name = tempfile.mktemp(dir='.', prefix=tempprefix)
16319
ac0da5caebec tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 15568
diff changeset
   268
    try:
ac0da5caebec tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 15568
diff changeset
   269
        os.symlink(".", name)
ac0da5caebec tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 15568
diff changeset
   270
        os.unlink(name)
ac0da5caebec tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 15568
diff changeset
   271
        return True
ac0da5caebec tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 15568
diff changeset
   272
    except (OSError, AttributeError):
ac0da5caebec tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 15568
diff changeset
   273
        return False
5409
190c234c8fa0 hghave: reorder check functions and entries
Patrick Mezard <pmezard@gmail.com>
parents: 5308
diff changeset
   274
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   275
@check("hardlink", "hardlinks")
16971
8aeb2f1ae94c tests: introduce hghave hardlinks
Mads Kiilerich <mads@kiilerich.com>
parents: 16970
diff changeset
   276
def has_hardlink():
8aeb2f1ae94c tests: introduce hghave hardlinks
Mads Kiilerich <mads@kiilerich.com>
parents: 16970
diff changeset
   277
    from mercurial import util
8aeb2f1ae94c tests: introduce hghave hardlinks
Mads Kiilerich <mads@kiilerich.com>
parents: 16970
diff changeset
   278
    fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
8aeb2f1ae94c tests: introduce hghave hardlinks
Mads Kiilerich <mads@kiilerich.com>
parents: 16970
diff changeset
   279
    os.close(fh)
8aeb2f1ae94c tests: introduce hghave hardlinks
Mads Kiilerich <mads@kiilerich.com>
parents: 16970
diff changeset
   280
    name = tempfile.mktemp(dir='.', prefix=tempprefix)
8aeb2f1ae94c tests: introduce hghave hardlinks
Mads Kiilerich <mads@kiilerich.com>
parents: 16970
diff changeset
   281
    try:
25090
252412e24551 hghave: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24290
diff changeset
   282
        util.oslink(fn, name)
252412e24551 hghave: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24290
diff changeset
   283
        os.unlink(name)
252412e24551 hghave: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24290
diff changeset
   284
        return True
252412e24551 hghave: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24290
diff changeset
   285
    except OSError:
252412e24551 hghave: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24290
diff changeset
   286
        return False
16971
8aeb2f1ae94c tests: introduce hghave hardlinks
Mads Kiilerich <mads@kiilerich.com>
parents: 16970
diff changeset
   287
    finally:
8aeb2f1ae94c tests: introduce hghave hardlinks
Mads Kiilerich <mads@kiilerich.com>
parents: 16970
diff changeset
   288
        os.unlink(fn)
8aeb2f1ae94c tests: introduce hghave hardlinks
Mads Kiilerich <mads@kiilerich.com>
parents: 16970
diff changeset
   289
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   290
@check("tla", "GNU Arch tla client")
6079
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   291
def has_tla():
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   292
    return matchoutput('tla --version 2>&1', r'The GNU Arch Revision')
ea34059b89de convert: added GNU Arch (tla) tests and related fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents: 6078
diff changeset
   293
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   294
@check("gpg", "gpg client")
8809
6fce36336e42 gpg: add test
Brendan Cully <brendan@kublai.com>
parents: 8213
diff changeset
   295
def has_gpg():
6fce36336e42 gpg: add test
Brendan Cully <brendan@kublai.com>
parents: 8213
diff changeset
   296
    return matchoutput('gpg --version 2>&1', r'GnuPG')
6fce36336e42 gpg: add test
Brendan Cully <brendan@kublai.com>
parents: 8213
diff changeset
   297
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   298
@check("unix-permissions", "unix-style permissions")
6063
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   299
def has_unix_permissions():
16968
456f457e376d tests/hghave: consistently use dir='.', prefix=tempprefix for tempfiles
Mads Kiilerich <mads@kiilerich.com>
parents: 16966
diff changeset
   300
    d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
6063
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   301
    try:
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   302
        fname = os.path.join(d, 'foo')
25658
e93036747902 global: mass rewrite to use modern octal syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25413
diff changeset
   303
        for umask in (0o77, 0o07, 0o22):
6063
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   304
            os.umask(umask)
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   305
            f = open(fname, 'w')
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   306
            f.close()
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   307
            mode = os.stat(fname).st_mode
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   308
            os.unlink(fname)
25658
e93036747902 global: mass rewrite to use modern octal syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25413
diff changeset
   309
            if mode & 0o777 != ~umask & 0o666:
6063
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   310
                return False
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   311
        return True
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   312
    finally:
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   313
        os.rmdir(d)
b74a0c4bfb30 hghave: detect unix-style permissions
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5685
diff changeset
   314
22994
840be5ca03e1 cmdserver: add service that listens on unix domain socket and forks process
Yuya Nishihara <yuya@tcha.org>
parents: 22579
diff changeset
   315
@check("unix-socket", "AF_UNIX socket family")
840be5ca03e1 cmdserver: add service that listens on unix domain socket and forks process
Yuya Nishihara <yuya@tcha.org>
parents: 22579
diff changeset
   316
def has_unix_socket():
840be5ca03e1 cmdserver: add service that listens on unix domain socket and forks process
Yuya Nishihara <yuya@tcha.org>
parents: 22579
diff changeset
   317
    return getattr(socket, 'AF_UNIX', None) is not None
840be5ca03e1 cmdserver: add service that listens on unix domain socket and forks process
Yuya Nishihara <yuya@tcha.org>
parents: 22579
diff changeset
   318
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   319
@check("root", "root permissions")
20008
e54a078153f7 tests: skip tests that require not having root (issue4089)
Matt Mackall <mpm@selenic.com>
parents: 19931
diff changeset
   320
def has_root():
20114
390aff33c2f9 tests: fix `hghave root` on windows
Simon Heimberg <simohe@besonet.ch>
parents: 20008
diff changeset
   321
    return getattr(os, 'geteuid', None) and os.geteuid() == 0
20008
e54a078153f7 tests: skip tests that require not having root (issue4089)
Matt Mackall <mpm@selenic.com>
parents: 19931
diff changeset
   322
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   323
@check("pyflakes", "Pyflakes python linter")
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents: 14050
diff changeset
   324
def has_pyflakes():
16872
40d930848fd0 hghave: wrap command in 'sh -c "..."' for has_pyflakes()
Adrian Buehlmann <adrian@cadifra.com>
parents: 16688
diff changeset
   325
    return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"",
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents: 14050
diff changeset
   326
                       r"<stdin>:1: 're' imported but unused",
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents: 14050
diff changeset
   327
                       True)
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents: 14050
diff changeset
   328
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   329
@check("pygments", "Pygments source highlighting library")
6355
3b841c189ab7 tests: add highlight extension tests
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6079
diff changeset
   330
def has_pygments():
3b841c189ab7 tests: add highlight extension tests
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6079
diff changeset
   331
    try:
3b841c189ab7 tests: add highlight extension tests
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6079
diff changeset
   332
        import pygments
22198
77142de48ae4 cleanup: make sure we always access members of imported modules
Mads Kiilerich <madski@unity3d.com>
parents: 22093
diff changeset
   333
        pygments.highlight # silence unused import warning
6355
3b841c189ab7 tests: add highlight extension tests
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6079
diff changeset
   334
        return True
3b841c189ab7 tests: add highlight extension tests
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6079
diff changeset
   335
    except ImportError:
3b841c189ab7 tests: add highlight extension tests
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6079
diff changeset
   336
        return False
3b841c189ab7 tests: add highlight extension tests
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6079
diff changeset
   337
22579
36a940d82f88 test: protect the run-tests.py --json test behind an hghave rule
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22575
diff changeset
   338
@check("json", "some json module available")
36a940d82f88 test: protect the run-tests.py --json test behind an hghave rule
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22575
diff changeset
   339
def has_json():
36a940d82f88 test: protect the run-tests.py --json test behind an hghave rule
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22575
diff changeset
   340
    try:
23262
86a8658c77ff hghave: use a less brittle have-json check
Augie Fackler <raf@durin42.com>
parents: 22994
diff changeset
   341
        import json
22579
36a940d82f88 test: protect the run-tests.py --json test behind an hghave rule
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22575
diff changeset
   342
        json.dumps
36a940d82f88 test: protect the run-tests.py --json test behind an hghave rule
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22575
diff changeset
   343
        return True
36a940d82f88 test: protect the run-tests.py --json test behind an hghave rule
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22575
diff changeset
   344
    except ImportError:
23262
86a8658c77ff hghave: use a less brittle have-json check
Augie Fackler <raf@durin42.com>
parents: 22994
diff changeset
   345
        try:
86a8658c77ff hghave: use a less brittle have-json check
Augie Fackler <raf@durin42.com>
parents: 22994
diff changeset
   346
            import simplejson as json
86a8658c77ff hghave: use a less brittle have-json check
Augie Fackler <raf@durin42.com>
parents: 22994
diff changeset
   347
            json.dumps
86a8658c77ff hghave: use a less brittle have-json check
Augie Fackler <raf@durin42.com>
parents: 22994
diff changeset
   348
            return True
86a8658c77ff hghave: use a less brittle have-json check
Augie Fackler <raf@durin42.com>
parents: 22994
diff changeset
   349
        except ImportError:
86a8658c77ff hghave: use a less brittle have-json check
Augie Fackler <raf@durin42.com>
parents: 22994
diff changeset
   350
            pass
86a8658c77ff hghave: use a less brittle have-json check
Augie Fackler <raf@durin42.com>
parents: 22994
diff changeset
   351
    return False
22579
36a940d82f88 test: protect the run-tests.py --json test behind an hghave rule
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22575
diff changeset
   352
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   353
@check("outer-repo", "outer repo")
7429
dbc40381620e tests: Skip tests if they will fail because of outer repo
Mads Kiilerich <mads@kiilerich.com>
parents: 7315
diff changeset
   354
def has_outer_repo():
17016
468a950aebc3 tests: hghave outer-repo should be true even if a bad repo is found
Mads Kiilerich <mads@kiilerich.com>
parents: 16971
diff changeset
   355
    # failing for other reasons than 'no repo' imply that there is a repo
468a950aebc3 tests: hghave outer-repo should be true even if a bad repo is found
Mads Kiilerich <mads@kiilerich.com>
parents: 16971
diff changeset
   356
    return not matchoutput('hg root 2>&1',
468a950aebc3 tests: hghave outer-repo should be true even if a bad repo is found
Mads Kiilerich <mads@kiilerich.com>
parents: 16971
diff changeset
   357
                           r'abort: no repository found', True)
7429
dbc40381620e tests: Skip tests if they will fail because of outer repo
Mads Kiilerich <mads@kiilerich.com>
parents: 7315
diff changeset
   358
23825
b2358bc1407c hghave: we now support Python 2.7.9's ssl for https
Augie Fackler <augie@google.com>
parents: 23262
diff changeset
   359
@check("ssl", ("(python >= 2.6 ssl module and python OpenSSL) "
b2358bc1407c hghave: we now support Python 2.7.9's ssl for https
Augie Fackler <augie@google.com>
parents: 23262
diff changeset
   360
               "OR python >= 2.7.9 ssl"))
12740
b86c6954ec4c serve: fix https mode and add test
Mads Kiilerich <mads@kiilerich.com>
parents: 10971
diff changeset
   361
def has_ssl():
b86c6954ec4c serve: fix https mode and add test
Mads Kiilerich <mads@kiilerich.com>
parents: 10971
diff changeset
   362
    try:
b86c6954ec4c serve: fix https mode and add test
Mads Kiilerich <mads@kiilerich.com>
parents: 10971
diff changeset
   363
        import ssl
23825
b2358bc1407c hghave: we now support Python 2.7.9's ssl for https
Augie Fackler <augie@google.com>
parents: 23262
diff changeset
   364
        if getattr(ssl, 'create_default_context', False):
b2358bc1407c hghave: we now support Python 2.7.9's ssl for https
Augie Fackler <augie@google.com>
parents: 23262
diff changeset
   365
            return True
13418
28555e294104 tests: update ssl requirement for test-https.t
Mads Kiilerich <mads@kiilerich.com>
parents: 13289
diff changeset
   366
        import OpenSSL
28555e294104 tests: update ssl requirement for test-https.t
Mads Kiilerich <mads@kiilerich.com>
parents: 13289
diff changeset
   367
        OpenSSL.SSL.Context
12740
b86c6954ec4c serve: fix https mode and add test
Mads Kiilerich <mads@kiilerich.com>
parents: 10971
diff changeset
   368
        return True
b86c6954ec4c serve: fix https mode and add test
Mads Kiilerich <mads@kiilerich.com>
parents: 10971
diff changeset
   369
    except ImportError:
b86c6954ec4c serve: fix https mode and add test
Mads Kiilerich <mads@kiilerich.com>
parents: 10971
diff changeset
   370
        return False
b86c6954ec4c serve: fix https mode and add test
Mads Kiilerich <mads@kiilerich.com>
parents: 10971
diff changeset
   371
25413
4d705f6a3c35 test-https: test basic functions of client certificate authentication
Yuya Nishihara <yuya@tcha.org>
parents: 25106
diff changeset
   372
@check("sslcontext", "python >= 2.7.9 ssl")
4d705f6a3c35 test-https: test basic functions of client certificate authentication
Yuya Nishihara <yuya@tcha.org>
parents: 25106
diff changeset
   373
def has_sslcontext():
4d705f6a3c35 test-https: test basic functions of client certificate authentication
Yuya Nishihara <yuya@tcha.org>
parents: 25106
diff changeset
   374
    try:
4d705f6a3c35 test-https: test basic functions of client certificate authentication
Yuya Nishihara <yuya@tcha.org>
parents: 25106
diff changeset
   375
        import ssl
4d705f6a3c35 test-https: test basic functions of client certificate authentication
Yuya Nishihara <yuya@tcha.org>
parents: 25106
diff changeset
   376
        ssl.SSLContext
4d705f6a3c35 test-https: test basic functions of client certificate authentication
Yuya Nishihara <yuya@tcha.org>
parents: 25106
diff changeset
   377
        return True
4d705f6a3c35 test-https: test basic functions of client certificate authentication
Yuya Nishihara <yuya@tcha.org>
parents: 25106
diff changeset
   378
    except (ImportError, AttributeError):
4d705f6a3c35 test-https: test basic functions of client certificate authentication
Yuya Nishihara <yuya@tcha.org>
parents: 25106
diff changeset
   379
        return False
4d705f6a3c35 test-https: test basic functions of client certificate authentication
Yuya Nishihara <yuya@tcha.org>
parents: 25106
diff changeset
   380
24289
07fafcd4bc74 test-https: enable dummycert test only if Apple python is used (issue4500)
Yuya Nishihara <yuya@tcha.org>
parents: 23825
diff changeset
   381
@check("defaultcacerts", "can verify SSL certs by system's CA certs store")
07fafcd4bc74 test-https: enable dummycert test only if Apple python is used (issue4500)
Yuya Nishihara <yuya@tcha.org>
parents: 23825
diff changeset
   382
def has_defaultcacerts():
07fafcd4bc74 test-https: enable dummycert test only if Apple python is used (issue4500)
Yuya Nishihara <yuya@tcha.org>
parents: 23825
diff changeset
   383
    from mercurial import sslutil
24290
b76d8c641746 ssl: set explicit symbol "!" to web.cacerts to disable SSL verification (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 24289
diff changeset
   384
    return sslutil._defaultcacerts() != '!'
24289
07fafcd4bc74 test-https: enable dummycert test only if Apple python is used (issue4500)
Yuya Nishihara <yuya@tcha.org>
parents: 23825
diff changeset
   385
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   386
@check("windows", "Windows")
15444
e1f05d7a8c7b tests: use 'hghave no-windows' to avoid testing reserved file names on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 15441
diff changeset
   387
def has_windows():
e1f05d7a8c7b tests: use 'hghave no-windows' to avoid testing reserved file names on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 15441
diff changeset
   388
    return os.name == 'nt'
e1f05d7a8c7b tests: use 'hghave no-windows' to avoid testing reserved file names on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 15441
diff changeset
   389
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   390
@check("system-sh", "system() uses sh")
15445
7cbb81c47025 tests: use 'hghave system-sh' to guard tests that requires sh in system()
Mads Kiilerich <mads@kiilerich.com>
parents: 15444
diff changeset
   391
def has_system_sh():
7cbb81c47025 tests: use 'hghave system-sh' to guard tests that requires sh in system()
Mads Kiilerich <mads@kiilerich.com>
parents: 15444
diff changeset
   392
    return os.name != 'nt'
7cbb81c47025 tests: use 'hghave system-sh' to guard tests that requires sh in system()
Mads Kiilerich <mads@kiilerich.com>
parents: 15444
diff changeset
   393
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   394
@check("serve", "platform and python can manage 'hg serve -d'")
15446
c5c9ca3719f9 tests: use 'hghave serve' to guard tests that requires serve daemon management
Mads Kiilerich <mads@kiilerich.com>
parents: 15445
diff changeset
   395
def has_serve():
c5c9ca3719f9 tests: use 'hghave serve' to guard tests that requires serve daemon management
Mads Kiilerich <mads@kiilerich.com>
parents: 15445
diff changeset
   396
    return os.name != 'nt' # gross approximation
c5c9ca3719f9 tests: use 'hghave serve' to guard tests that requires serve daemon management
Mads Kiilerich <mads@kiilerich.com>
parents: 15445
diff changeset
   397
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   398
@check("test-repo", "running tests from repository")
21208
0e1cbd3d52f7 tests: add repository check for pyflakes test
Matt Mackall <mpm@selenic.com>
parents: 20644
diff changeset
   399
def has_test_repo():
0e1cbd3d52f7 tests: add repository check for pyflakes test
Matt Mackall <mpm@selenic.com>
parents: 20644
diff changeset
   400
    t = os.environ["TESTDIR"]
0e1cbd3d52f7 tests: add repository check for pyflakes test
Matt Mackall <mpm@selenic.com>
parents: 20644
diff changeset
   401
    return os.path.isdir(os.path.join(t, "..", ".hg"))
0e1cbd3d52f7 tests: add repository check for pyflakes test
Matt Mackall <mpm@selenic.com>
parents: 20644
diff changeset
   402
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   403
@check("tic", "terminfo compiler and curses module")
15539
d09ea5bbc9a4 tests: skip color test on platforms without tic
Mads Kiilerich <mads@kiilerich.com>
parents: 15446
diff changeset
   404
def has_tic():
20304
e457321a5687 tests: 'hghave tic' also requires curses support in Python
Mads Kiilerich <madski@unity3d.com>
parents: 20114
diff changeset
   405
    try:
e457321a5687 tests: 'hghave tic' also requires curses support in Python
Mads Kiilerich <madski@unity3d.com>
parents: 20114
diff changeset
   406
        import curses
e457321a5687 tests: 'hghave tic' also requires curses support in Python
Mads Kiilerich <madski@unity3d.com>
parents: 20114
diff changeset
   407
        curses.COLOR_BLUE
e457321a5687 tests: 'hghave tic' also requires curses support in Python
Mads Kiilerich <madski@unity3d.com>
parents: 20114
diff changeset
   408
        return matchoutput('test -x "`which tic`"', '')
e457321a5687 tests: 'hghave tic' also requires curses support in Python
Mads Kiilerich <madski@unity3d.com>
parents: 20114
diff changeset
   409
    except ImportError:
e457321a5687 tests: 'hghave tic' also requires curses support in Python
Mads Kiilerich <madski@unity3d.com>
parents: 20114
diff changeset
   410
        return False
15539
d09ea5bbc9a4 tests: skip color test on platforms without tic
Mads Kiilerich <mads@kiilerich.com>
parents: 15446
diff changeset
   411
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   412
@check("msys", "Windows with MSYS")
15567
8b84d040d9f9 tests: introduce 'hghave msys' to skip tests that would fail because of msys
Mads Kiilerich <mads@kiilerich.com>
parents: 15539
diff changeset
   413
def has_msys():
8b84d040d9f9 tests: introduce 'hghave msys' to skip tests that would fail because of msys
Mads Kiilerich <mads@kiilerich.com>
parents: 15539
diff changeset
   414
    return os.getenv('MSYSTEM')
8b84d040d9f9 tests: introduce 'hghave msys' to skip tests that would fail because of msys
Mads Kiilerich <mads@kiilerich.com>
parents: 15539
diff changeset
   415
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   416
@check("aix", "AIX")
19092
8c560ad1cdc4 tests: AIX can't handle negative date in test-dirstate.t
Jim Hague <jim.hague@acm.org>
parents: 18285
diff changeset
   417
def has_aix():
8c560ad1cdc4 tests: AIX can't handle negative date in test-dirstate.t
Jim Hague <jim.hague@acm.org>
parents: 18285
diff changeset
   418
    return sys.platform.startswith("aix")
8c560ad1cdc4 tests: AIX can't handle negative date in test-dirstate.t
Jim Hague <jim.hague@acm.org>
parents: 18285
diff changeset
   419
22575
d7f7f1860f00 ssl: on OS X, use a dummy cert to trick Python/OpenSSL to use system CA certs
Mads Kiilerich <madski@unity3d.com>
parents: 22198
diff changeset
   420
@check("osx", "OS X")
d7f7f1860f00 ssl: on OS X, use a dummy cert to trick Python/OpenSSL to use system CA certs
Mads Kiilerich <madski@unity3d.com>
parents: 22198
diff changeset
   421
def has_osx():
d7f7f1860f00 ssl: on OS X, use a dummy cert to trick Python/OpenSSL to use system CA certs
Mads Kiilerich <madski@unity3d.com>
parents: 22198
diff changeset
   422
    return sys.platform == 'darwin'
d7f7f1860f00 ssl: on OS X, use a dummy cert to trick Python/OpenSSL to use system CA certs
Mads Kiilerich <madski@unity3d.com>
parents: 22198
diff changeset
   423
26111
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   424
@check("docker", "docker support")
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   425
def has_docker():
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   426
    pat = r'A self-sufficient runtime for linux containers\.'
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   427
    if matchoutput('docker --help', pat):
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   428
        if 'linux' not in sys.platform:
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   429
            # TODO: in theory we should be able to test docker-based
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   430
            # package creation on non-linux using boot2docker, but in
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   431
            # practice that requires extra coordination to make sure
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   432
            # $TESTTEMP is going to be visible at the same path to the
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   433
            # boot2docker VM. If we figure out how to verify that, we
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   434
            # can use the following instead of just saying False:
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   435
            # return 'DOCKER_HOST' in os.environ
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   436
            return False
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   437
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   438
        return True
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   439
    return False
dcc12365fa38 hghave: add a check for docker support
Augie Fackler <augie@google.com>
parents: 26110
diff changeset
   440
26110
2dcfb98c5314 hghave: add a check for debian packaging tools
Augie Fackler <augie@google.com>
parents: 26109
diff changeset
   441
@check("debhelper", "debian packaging tools")
2dcfb98c5314 hghave: add a check for debian packaging tools
Augie Fackler <augie@google.com>
parents: 26109
diff changeset
   442
def has_debhelper():
2dcfb98c5314 hghave: add a check for debian packaging tools
Augie Fackler <augie@google.com>
parents: 26109
diff changeset
   443
    dpkg = matchoutput('dpkg --version',
2dcfb98c5314 hghave: add a check for debian packaging tools
Augie Fackler <augie@google.com>
parents: 26109
diff changeset
   444
                       "Debian `dpkg' package management program")
2dcfb98c5314 hghave: add a check for debian packaging tools
Augie Fackler <augie@google.com>
parents: 26109
diff changeset
   445
    dh = matchoutput('dh --help',
26145
ca9bb66c80e9 hghave: correct test for debhelper
Augie Fackler <augie@google.com>
parents: 26137
diff changeset
   446
                     'dh is a part of debhelper.', ignorestatus=True)
26110
2dcfb98c5314 hghave: add a check for debian packaging tools
Augie Fackler <augie@google.com>
parents: 26109
diff changeset
   447
    dh_py2 = matchoutput('dh_python2 --help',
2dcfb98c5314 hghave: add a check for debian packaging tools
Augie Fackler <augie@google.com>
parents: 26109
diff changeset
   448
                         'other supported Python versions')
2dcfb98c5314 hghave: add a check for debian packaging tools
Augie Fackler <augie@google.com>
parents: 26109
diff changeset
   449
    return dpkg and dh and dh_py2
2dcfb98c5314 hghave: add a check for debian packaging tools
Augie Fackler <augie@google.com>
parents: 26109
diff changeset
   450
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   451
@check("absimport", "absolute_import in __future__")
19930
b8316878a685 hghave: add "absimport" feature to check "absolute_import" in __future__
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19378
diff changeset
   452
def has_absimport():
b8316878a685 hghave: add "absimport" feature to check "absolute_import" in __future__
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19378
diff changeset
   453
    import __future__
b8316878a685 hghave: add "absimport" feature to check "absolute_import" in __future__
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19378
diff changeset
   454
    from mercurial import util
b8316878a685 hghave: add "absimport" feature to check "absolute_import" in __future__
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19378
diff changeset
   455
    return util.safehasattr(__future__, "absolute_import")
b8316878a685 hghave: add "absimport" feature to check "absolute_import" in __future__
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19378
diff changeset
   456
22093
45611a306f77 tests: use a decorator for hghave checks
Matt Mackall <mpm@selenic.com>
parents: 21208
diff changeset
   457
@check("py3k", "running with Python 3.x")
19931
8bbe208c1812 hghave: add "py3k" feature to check whether test runs with Python 3.x
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19930
diff changeset
   458
def has_py3k():
8bbe208c1812 hghave: add "py3k" feature to check whether test runs with Python 3.x
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19930
diff changeset
   459
    return 3 == sys.version_info[0]
25859
1619563959b3 tests: disable test of buffer overflow in parsers.c if --pure
Yuya Nishihara <yuya@tcha.org>
parents: 25658
diff changeset
   460
1619563959b3 tests: disable test of buffer overflow in parsers.c if --pure
Yuya Nishihara <yuya@tcha.org>
parents: 25658
diff changeset
   461
@check("pure", "running with pure Python code")
1619563959b3 tests: disable test of buffer overflow in parsers.c if --pure
Yuya Nishihara <yuya@tcha.org>
parents: 25658
diff changeset
   462
def has_pure():
1619563959b3 tests: disable test of buffer overflow in parsers.c if --pure
Yuya Nishihara <yuya@tcha.org>
parents: 25658
diff changeset
   463
    return os.environ.get("HGTEST_RUN_TESTS_PURE") == "--pure"
26109
bad09bd22b6a run-tests: add support for marking tests as very slow
Augie Fackler <augie@google.com>
parents: 26068
diff changeset
   464
bad09bd22b6a run-tests: add support for marking tests as very slow
Augie Fackler <augie@google.com>
parents: 26068
diff changeset
   465
@check("slow", "allow slow tests")
bad09bd22b6a run-tests: add support for marking tests as very slow
Augie Fackler <augie@google.com>
parents: 26068
diff changeset
   466
def has_slow():
bad09bd22b6a run-tests: add support for marking tests as very slow
Augie Fackler <augie@google.com>
parents: 26068
diff changeset
   467
    return os.environ.get('HGTEST_SLOW') == 'slow'
26842
0f76c64f5cc3 testing: add hypothesis fuzz testing
David R. MacIver <david@drmaciver.com>
parents: 26145
diff changeset
   468
0f76c64f5cc3 testing: add hypothesis fuzz testing
David R. MacIver <david@drmaciver.com>
parents: 26145
diff changeset
   469
@check("hypothesis", "is Hypothesis installed")
0f76c64f5cc3 testing: add hypothesis fuzz testing
David R. MacIver <david@drmaciver.com>
parents: 26145
diff changeset
   470
def has_hypothesis():
0f76c64f5cc3 testing: add hypothesis fuzz testing
David R. MacIver <david@drmaciver.com>
parents: 26145
diff changeset
   471
    try:
0f76c64f5cc3 testing: add hypothesis fuzz testing
David R. MacIver <david@drmaciver.com>
parents: 26145
diff changeset
   472
        import hypothesis
0f76c64f5cc3 testing: add hypothesis fuzz testing
David R. MacIver <david@drmaciver.com>
parents: 26145
diff changeset
   473
        hypothesis.given
0f76c64f5cc3 testing: add hypothesis fuzz testing
David R. MacIver <david@drmaciver.com>
parents: 26145
diff changeset
   474
        return True
0f76c64f5cc3 testing: add hypothesis fuzz testing
David R. MacIver <david@drmaciver.com>
parents: 26145
diff changeset
   475
    except ImportError:
0f76c64f5cc3 testing: add hypothesis fuzz testing
David R. MacIver <david@drmaciver.com>
parents: 26145
diff changeset
   476
        return False