tests/hghave
author Siddharth Agarwal <sid0@fb.com>
Sat, 10 Nov 2012 11:37:41 -0800
branchstable
changeset 1160 5a89f5217625
parent 1098 72f57519a427
child 1182 e553e222bd7e
permissions -rwxr-xr-x
run-tests: open child-parent pipes in binary mode Python's pickle is a binary format. [ 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)
4fad25af75dd Add hghave test as of 5635a4017061
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    62
            continue
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)