tests/hghave
author David Soria Parra <dsp@experimentalworks.net>
Thu, 29 Aug 2013 09:22:13 -0700
branchstable
changeset 1295 8e66ac9c0f0e
parent 1182 e553e222bd7e
permissions -rwxr-xr-x
shelve: add a shelve extension to save/restore working changes This extension saves shelved changes using a temporary draft commit, and bundles the temporary commit and its draft ancestors, then strips them. This strategy makes it possible to use Mercurial's bundle and merge machinery to resolve conflicts if necessary when unshelving, even when the destination commit or its ancestors have been amended, squashed, or evolved. (Once a change has been unshelved, its associated unbundled commits are either rolled back or stripped.) Storing the shelved change as a bundle also avoids the difficulty that hidden commits would cause, of making it impossible to amend the parent if it is a draft commits (a common scenario). Although this extension shares its name and some functionality with the third party hgshelve extension, it has little else in common. Notably, the hgshelve extension shelves changes as unified diffs, which makes conflict resolution a matter of finding .rej files and conflict markers, and cleaning up the mess by hand. We do not yet allow hunk-level choosing of changes to record. Compared to the hgshelve extension, this is a small regression in usability, but we hope to integrate that at a later point, once the record machinery becomes more reusable and robust. [ 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
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     7
import sys
1098
72f57519a427 tests/hghave: extract hghave.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 1091
diff changeset
     8
import hghave
1007
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     9
1098
72f57519a427 tests/hghave: extract hghave.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 1091
diff changeset
    10
checks = hghave.checks
1007
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
def list_features():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    13
    for name, feature in checks.iteritems():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    14
        desc = feature[1]
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    15
        print name + ':', desc
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    16
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    17
def test_features():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    18
    failed = 0
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    19
    for name, feature in checks.iteritems():
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    20
        check, _ = feature
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
            check()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    23
        except Exception, e:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    24
            print "feature %s failed:  %s" % (name, e)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    25
            failed += 1
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    26
    return failed
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
parser = optparse.OptionParser("%prog [options] [features]")
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    29
parser.add_option("--test-features", action="store_true",
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    30
                  help="test available features")
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    31
parser.add_option("--list-features", action="store_true",
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    32
                  help="list available features")
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    33
parser.add_option("-q", "--quiet", action="store_true",
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    34
                  help="check features silently")
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    35
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    36
if __name__ == '__main__':
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    37
    options, args = parser.parse_args()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    38
    if options.list_features:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    39
        list_features()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    40
        sys.exit(0)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    41
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    42
    if options.test_features:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    43
        sys.exit(test_features())
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    44
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    45
    quiet = options.quiet
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    46
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    47
    failures = 0
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    48
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    49
    def error(msg):
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    50
        global failures
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    51
        if not quiet:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    52
            sys.stderr.write(msg + '\n')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    53
        failures += 1
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    54
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    55
    for feature in args:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    56
        negate = feature.startswith('no-')
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    57
        if negate:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    58
            feature = feature[3:]
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    59
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    60
        if feature not in checks:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    61
            error('skipped: unknown feature: ' + feature)
1182
e553e222bd7e tests: make hghave and run-tests exit on unknown feature requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 1098
diff changeset
    62
            sys.exit(2)
1007
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    63
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    64
        check, desc = checks[feature]
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    65
        try:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    66
            available = check()
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    67
        except Exception, e:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    68
            error('hghave check failed: ' + feature)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    69
            continue
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    70
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    71
        if not negate and not available:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    72
            error('skipped: missing feature: ' + desc)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    73
        elif negate and available:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    74
            error('skipped: system supports %s' % desc)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    75
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    76
    if failures != 0:
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    77
        sys.exit(1)