tests/hghave
author A. S. Budden <abudden@gmail.com>
Fri, 30 Mar 2012 22:08:46 +0100
branchstable
changeset 1057 66d2754c6f30
parent 1056 0e6cee08a2f8
child 1063 0e3b1a8a243c
permissions -rwxr-xr-x
record: allow splitting of hunks by manually editing patches It is possible that unrelated changes in a file are on sequential lines. The current record extension does not allow these to be committed independently. An example use case for this is in software development for deeply embedded real-time systems. In these environments, it is not always possible to use a debugger (due to time-constraints) and hence inline UART-based printing is often used. When fixing a bug in a module, it is often convenient to add a large number of 'printf's (linked to the UART via a custom fputc) to the module in order to work out what is going wrong. printf is a very slow function (and also variadic so somewhat frowned upon by the MISRA standard) and hence it is highly undesirable to commit these lines to the repository. If only a partial fix is implemented, however, it is desirable to commit the fix without deleting all of the printf lines. This is also simplifies removal of the printf lines as once the final fix is committed, 'hg revert' does the rest. It is likely that the printf lines will be very near the actual fix, so being able to split the hunk is very useful in this case. There were two alternatives I considered for the user interface. One was to manually edit the patch, the other to allow a hunk to be split into individual lines for consideration. The latter option would require a significant refactor of the record module and is less flexible. While the former is potentially more complicated to use, this is a feature that is likely to only be used in certain exceptional cases (such as the use case proposed above) and hence I felt that the complexity would not be a considerable issue. I've also written a follow-up patch that refactors the 'prompt' code to base everything on the choices variable. This tidies up and clarifies the code a bit (removes constructs like 'if ret == 7' and removes the 'e' option from the file scope options as it's not relevant there. It's not really a necessity, so I've excluded it from this submission for now, but I can send it separately if there's a desire and it's on bitbucket (see below) in the meantime. Possible future improvements include: * Tidying up the 'prompt' code to base everything on the choices variable. This would allow entries to be removed from the prompt as currently 'e' is offered even for entire file patches, which is currently unsupported. * Allowing the entire file (or even multi-file) patch to be edited manually: this would require quite a large refactor without much benefit, so I decided to exclude it from the initial submission. * Allow the option to retry if a patch fails to apply (this is what Git does). This would require quite a bit of refactoring given the current 'hg record' implementation, so it's debatable whether it's worth it. Output is similar to existing record user interface except that an additional option ('e') exists to allow manual editing of the patch. This opens the user's configured editor with the patch. A comment is added to the bottom of the patch explaining what to do (based on Git's one). A large proportion of the changeset is test-case changes to update the options reported by record (Ynesfdaq? instead of Ynsfdaq?). Functional changes are in record.py and there are some new test cases in test-record.t. [ original upstream message ]
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1007
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     1
#!/usr/bin/env python
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     2
"""Test the running system for features availability. Exit with zero
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     3
if all features are there, non-zero otherwise. If a feature name is
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     4
prefixed with "no-", the absence of feature is tested.
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     5
"""
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     6
import optparse
1056
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
     7
import os, stat
1007
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     8
import re
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     9
import sys
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    10
import tempfile
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    11
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    12
tempprefix = 'hg-hghave-'
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    13
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    14
def matchoutput(cmd, regexp, ignorestatus=False):
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    15
    """Return True if cmd executes successfully and its output
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    16
    is matched by the supplied regular expression.
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    17
    """
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    18
    r = re.compile(regexp)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    19
    fh = os.popen(cmd)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    20
    s = fh.read()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    21
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    22
        ret = fh.close()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    23
    except IOError:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    24
        # Happen in Windows test environment
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    25
        ret = 1
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    26
    return (ignorestatus or ret is None) and r.search(s)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    27
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    28
def has_baz():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    29
    return matchoutput('baz --version 2>&1', r'baz Bazaar version')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    30
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    31
def has_bzr():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    32
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    33
        import bzrlib
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    34
        return bzrlib.__doc__ != None
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    35
    except ImportError:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    36
        return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    37
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    38
def has_bzr114():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    39
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    40
        import bzrlib
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    41
        return (bzrlib.__doc__ != None
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    42
                and bzrlib.version_info[:2] >= (1, 14))
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    43
    except ImportError:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    44
        return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    45
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    46
def has_cvs():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    47
    re = r'Concurrent Versions System.*?server'
1032
5923d03569b3 tests: skip cvs tests with msys on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 1031
diff changeset
    48
    return matchoutput('cvs --version 2>&1', re) and not has_msys()
1007
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    49
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    50
def has_darcs():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    51
    return matchoutput('darcs --version', r'2\.[2-9]', True)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    52
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    53
def has_mtn():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    54
    return matchoutput('mtn --version', r'monotone', True) and not matchoutput(
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    55
        'mtn --version', r'monotone 0\.', True)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    56
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    57
def has_eol_in_paths():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    58
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    59
        fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    60
        os.close(fd)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    61
        os.remove(path)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    62
        return True
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    63
    except:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    64
        return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    65
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    66
def has_executablebit():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    67
    try:
1056
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    68
        EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    69
        fh, fn = tempfile.mkstemp(dir=".", prefix='hg-checkexec-')
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    70
        try:
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    71
            os.close(fh)
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    72
            m = os.stat(fn).st_mode & 0777
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    73
            new_file_has_exec = m & EXECFLAGS
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    74
            os.chmod(fn, m ^ EXECFLAGS)
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    75
            exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m)
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    76
        finally:
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    77
            os.unlink(fn)
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    78
    except (IOError, OSError):
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    79
        # we don't care, the user probably won't be able to commit anyway
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    80
        return False
0e6cee08a2f8 tests: make hghave handle exec bit on Linux with vfat
Matt Mackall <mpm@selenic.com>
parents: 1055
diff changeset
    81
    return not (new_file_has_exec or exec_flags_cannot_flip)
1007
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    82
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    83
def has_icasefs():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    84
    # Stolen from mercurial.util
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    85
    fd, path = tempfile.mkstemp(prefix=tempprefix, dir='.')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    86
    os.close(fd)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    87
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    88
        s1 = os.stat(path)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    89
        d, b = os.path.split(path)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    90
        p2 = os.path.join(d, b.upper())
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    91
        if path == p2:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    92
            p2 = os.path.join(d, b.lower())
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    93
        try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    94
            s2 = os.stat(p2)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    95
            return s2 == s1
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    96
        except:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    97
            return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    98
    finally:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    99
        os.remove(path)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   100
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   101
def has_inotify():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   102
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   103
        import hgext.inotify.linux.watcher
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   104
        return True
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   105
    except ImportError:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   106
        return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   107
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   108
def has_fifo():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   109
    return hasattr(os, "mkfifo")
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   110
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   111
def has_cacheable_fs():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   112
    from mercurial import util
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   113
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   114
    fd, path = tempfile.mkstemp(prefix=tempprefix)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   115
    os.close(fd)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   116
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   117
        return util.cachestat(path).cacheable()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   118
    finally:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   119
        os.remove(path)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   120
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   121
def has_lsprof():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   122
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   123
        import _lsprof
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   124
        return True
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   125
    except ImportError:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   126
        return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   127
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   128
def has_gettext():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   129
    return matchoutput('msgfmt --version', 'GNU gettext-tools')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   130
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   131
def has_git():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   132
    return matchoutput('git --version 2>&1', r'^git version')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   133
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   134
def has_docutils():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   135
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   136
        from docutils.core import publish_cmdline
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   137
        return True
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   138
    except ImportError:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   139
        return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   140
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   141
def getsvnversion():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   142
    m = matchoutput('svn --version 2>&1', r'^svn,\s+version\s+(\d+)\.(\d+)')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   143
    if not m:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   144
        return (0, 0)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   145
    return (int(m.group(1)), int(m.group(2)))
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   146
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   147
def has_svn15():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   148
    return getsvnversion() >= (1, 5)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   149
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   150
def has_svn13():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   151
    return getsvnversion() >= (1, 3)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   152
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   153
def has_svn():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   154
    return matchoutput('svn --version 2>&1', r'^svn, version') and \
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   155
        matchoutput('svnadmin --version 2>&1', r'^svnadmin, version')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   156
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   157
def has_svn_bindings():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   158
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   159
        import svn.core
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   160
        version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   161
        if version < (1, 4):
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   162
            return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   163
        return True
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   164
    except ImportError:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   165
        return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   166
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   167
def has_p4():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   168
    return matchoutput('p4 -V', r'Rev\. P4/') and matchoutput('p4d -V', r'Rev\. P4D/')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   169
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   170
def has_symlink():
1055
dabed2cabd5e tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 1032
diff changeset
   171
    if not hasattr(os, "symlink"):
dabed2cabd5e tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 1032
diff changeset
   172
        return False
dabed2cabd5e tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 1032
diff changeset
   173
    name = tempfile.mktemp(dir=".", prefix='hg-checklink-')
dabed2cabd5e tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 1032
diff changeset
   174
    try:
dabed2cabd5e tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 1032
diff changeset
   175
        os.symlink(".", name)
dabed2cabd5e tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 1032
diff changeset
   176
        os.unlink(name)
dabed2cabd5e tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 1032
diff changeset
   177
        return True
dabed2cabd5e tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 1032
diff changeset
   178
    except (OSError, AttributeError):
dabed2cabd5e tests: teach hghave to actually test for symlink support
Matt Mackall <mpm@selenic.com>
parents: 1032
diff changeset
   179
        return False
1010
13862cca5537 tests: use 'hghave symlink' for tests using symlinks
Mads Kiilerich <mads@kiilerich.com>
parents: 1007
diff changeset
   180
    return hasattr(os, "symlink") # FIXME: should also check file system and os
1007
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   181
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   182
def has_tla():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   183
    return matchoutput('tla --version 2>&1', r'The GNU Arch Revision')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   184
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   185
def has_gpg():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   186
    return matchoutput('gpg --version 2>&1', r'GnuPG')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   187
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   188
def has_unix_permissions():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   189
    d = tempfile.mkdtemp(prefix=tempprefix, dir=".")
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   190
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   191
        fname = os.path.join(d, 'foo')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   192
        for umask in (077, 007, 022):
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   193
            os.umask(umask)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   194
            f = open(fname, 'w')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   195
            f.close()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   196
            mode = os.stat(fname).st_mode
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   197
            os.unlink(fname)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   198
            if mode & 0777 != ~umask & 0666:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   199
                return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   200
        return True
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   201
    finally:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   202
        os.rmdir(d)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   203
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   204
def has_pyflakes():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   205
    return matchoutput('echo "import re" 2>&1 | pyflakes',
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   206
                       r"<stdin>:1: 're' imported but unused",
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   207
                       True)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   208
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   209
def has_pygments():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   210
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   211
        import pygments
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   212
        return True
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   213
    except ImportError:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   214
        return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   215
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   216
def has_outer_repo():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   217
    return matchoutput('hg root 2>&1', r'')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   218
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   219
def has_ssl():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   220
    try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   221
        import ssl
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   222
        import OpenSSL
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   223
        OpenSSL.SSL.Context
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   224
        return True
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   225
    except ImportError:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   226
        return False
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   227
1012
018ef69bbe2f tests: use 'hghave no-windows' to avoid testing reserved file names on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 1010
diff changeset
   228
def has_windows():
018ef69bbe2f tests: use 'hghave no-windows' to avoid testing reserved file names on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 1010
diff changeset
   229
    return os.name == 'nt'
018ef69bbe2f tests: use 'hghave no-windows' to avoid testing reserved file names on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 1010
diff changeset
   230
1013
e00f51032041 tests: use 'hghave system-sh' to guard tests that requires sh in system()
Mads Kiilerich <mads@kiilerich.com>
parents: 1012
diff changeset
   231
def has_system_sh():
e00f51032041 tests: use 'hghave system-sh' to guard tests that requires sh in system()
Mads Kiilerich <mads@kiilerich.com>
parents: 1012
diff changeset
   232
    return os.name != 'nt'
e00f51032041 tests: use 'hghave system-sh' to guard tests that requires sh in system()
Mads Kiilerich <mads@kiilerich.com>
parents: 1012
diff changeset
   233
1014
58b7f58ae08c tests: use 'hghave serve' to guard tests that requires serve daemon management
Mads Kiilerich <mads@kiilerich.com>
parents: 1013
diff changeset
   234
def has_serve():
58b7f58ae08c tests: use 'hghave serve' to guard tests that requires serve daemon management
Mads Kiilerich <mads@kiilerich.com>
parents: 1013
diff changeset
   235
    return os.name != 'nt' # gross approximation
58b7f58ae08c tests: use 'hghave serve' to guard tests that requires serve daemon management
Mads Kiilerich <mads@kiilerich.com>
parents: 1013
diff changeset
   236
1027
f8c2547c8f16 tests: skip color test on platforms without tic
Mads Kiilerich <mads@kiilerich.com>
parents: 1014
diff changeset
   237
def has_tic():
f8c2547c8f16 tests: skip color test on platforms without tic
Mads Kiilerich <mads@kiilerich.com>
parents: 1014
diff changeset
   238
    return matchoutput('test -x "`which tic`"', '')
f8c2547c8f16 tests: skip color test on platforms without tic
Mads Kiilerich <mads@kiilerich.com>
parents: 1014
diff changeset
   239
1031
b914fc162545 tests: introduce 'hghave msys' to skip tests that would fail because of msys
Mads Kiilerich <mads@kiilerich.com>
parents: 1027
diff changeset
   240
def has_msys():
b914fc162545 tests: introduce 'hghave msys' to skip tests that would fail because of msys
Mads Kiilerich <mads@kiilerich.com>
parents: 1027
diff changeset
   241
    return os.getenv('MSYSTEM')
b914fc162545 tests: introduce 'hghave msys' to skip tests that would fail because of msys
Mads Kiilerich <mads@kiilerich.com>
parents: 1027
diff changeset
   242
1007
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   243
checks = {
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   244
    "baz": (has_baz, "GNU Arch baz client"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   245
    "bzr": (has_bzr, "Canonical's Bazaar client"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   246
    "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   247
    "cacheable": (has_cacheable_fs, "cacheable filesystem"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   248
    "cvs": (has_cvs, "cvs client/server"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   249
    "darcs": (has_darcs, "darcs client"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   250
    "docutils": (has_docutils, "Docutils text processing library"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   251
    "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   252
    "execbit": (has_executablebit, "executable bit"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   253
    "fifo": (has_fifo, "named pipes"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   254
    "gettext": (has_gettext, "GNU Gettext (msgfmt)"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   255
    "git": (has_git, "git command line client"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   256
    "gpg": (has_gpg, "gpg client"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   257
    "icasefs": (has_icasefs, "case insensitive file system"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   258
    "inotify": (has_inotify, "inotify extension support"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   259
    "lsprof": (has_lsprof, "python lsprof module"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   260
    "mtn": (has_mtn, "monotone client (>= 1.0)"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   261
    "outer-repo": (has_outer_repo, "outer repo"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   262
    "p4": (has_p4, "Perforce server and client"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   263
    "pyflakes": (has_pyflakes, "Pyflakes python linter"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   264
    "pygments": (has_pygments, "Pygments source highlighting library"),
1014
58b7f58ae08c tests: use 'hghave serve' to guard tests that requires serve daemon management
Mads Kiilerich <mads@kiilerich.com>
parents: 1013
diff changeset
   265
    "serve": (has_serve, "platform and python can manage 'hg serve -d'"),
1007
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   266
    "ssl": (has_ssl, "python >= 2.6 ssl module and python OpenSSL"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   267
    "svn": (has_svn, "subversion client and admin tools"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   268
    "svn13": (has_svn13, "subversion client and admin tools >= 1.3"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   269
    "svn15": (has_svn15, "subversion client and admin tools >= 1.5"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   270
    "svn-bindings": (has_svn_bindings, "subversion python bindings"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   271
    "symlink": (has_symlink, "symbolic links"),
1013
e00f51032041 tests: use 'hghave system-sh' to guard tests that requires sh in system()
Mads Kiilerich <mads@kiilerich.com>
parents: 1012
diff changeset
   272
    "system-sh": (has_system_sh, "system() uses sh"),
1027
f8c2547c8f16 tests: skip color test on platforms without tic
Mads Kiilerich <mads@kiilerich.com>
parents: 1014
diff changeset
   273
    "tic": (has_tic, "terminfo compiler"),
1007
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   274
    "tla": (has_tla, "GNU Arch tla client"),
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   275
    "unix-permissions": (has_unix_permissions, "unix-style permissions"),
1012
018ef69bbe2f tests: use 'hghave no-windows' to avoid testing reserved file names on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 1010
diff changeset
   276
    "windows": (has_windows, "Windows"),
1031
b914fc162545 tests: introduce 'hghave msys' to skip tests that would fail because of msys
Mads Kiilerich <mads@kiilerich.com>
parents: 1027
diff changeset
   277
    "msys": (has_msys, "Windows with MSYS"),
1007
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   278
}
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   279
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   280
def list_features():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   281
    for name, feature in checks.iteritems():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   282
        desc = feature[1]
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   283
        print name + ':', desc
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   284
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   285
def test_features():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   286
    failed = 0
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   287
    for name, feature in checks.iteritems():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   288
        check, _ = feature
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   289
        try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   290
            check()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   291
        except Exception, e:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   292
            print "feature %s failed:  %s" % (name, e)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   293
            failed += 1
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   294
    return failed
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   295
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   296
parser = optparse.OptionParser("%prog [options] [features]")
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   297
parser.add_option("--test-features", action="store_true",
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   298
                  help="test available features")
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   299
parser.add_option("--list-features", action="store_true",
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   300
                  help="list available features")
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   301
parser.add_option("-q", "--quiet", action="store_true",
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   302
                  help="check features silently")
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   303
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   304
if __name__ == '__main__':
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   305
    options, args = parser.parse_args()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   306
    if options.list_features:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   307
        list_features()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   308
        sys.exit(0)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   309
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   310
    if options.test_features:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   311
        sys.exit(test_features())
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   312
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   313
    quiet = options.quiet
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   314
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   315
    failures = 0
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   316
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   317
    def error(msg):
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   318
        global failures
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   319
        if not quiet:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   320
            sys.stderr.write(msg + '\n')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   321
        failures += 1
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   322
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   323
    for feature in args:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   324
        negate = feature.startswith('no-')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   325
        if negate:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   326
            feature = feature[3:]
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   327
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   328
        if feature not in checks:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   329
            error('skipped: unknown feature: ' + feature)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   330
            continue
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   331
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   332
        check, desc = checks[feature]
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   333
        try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   334
            available = check()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   335
        except Exception, e:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   336
            error('hghave check failed: ' + feature)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   337
            continue
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   338
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   339
        if not negate and not available:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   340
            error('skipped: missing feature: ' + desc)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   341
        elif negate and available:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   342
            error('skipped: system supports %s' % desc)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   343
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   344
    if failures != 0:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   345
        sys.exit(1)