summaryrefslogtreecommitdiff
path: root/tests/hghave
blob: dad166770098b9cb8d6ee4c2beccef22b2f5bb1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
"""Test the running system for features availability. Exit with zero
if all features are there, non-zero otherwise. If a feature name is
prefixed with "no-", the absence of feature is tested.
"""
import optparse
import sys
import hghave

checks = hghave.checks

def list_features():
    for name, feature in checks.iteritems():
        desc = feature[1]
        print name + ':', desc

def test_features():
    failed = 0
    for name, feature in checks.iteritems():
        check, _ = feature
        try:
            check()
        except Exception, e:
            print "feature %s failed:  %s" % (name, e)
            failed += 1
    return failed

parser = optparse.OptionParser("%prog [options] [features]")
parser.add_option("--test-features", action="store_true",
                  help="test available features")
parser.add_option("--list-features", action="store_true",
                  help="list available features")
parser.add_option("-q", "--quiet", action="store_true",
                  help="check features silently")

if __name__ == '__main__':
    options, args = parser.parse_args()
    if options.list_features:
        list_features()
        sys.exit(0)

    if options.test_features:
        sys.exit(test_features())

    quiet = options.quiet

    failures = 0

    def error(msg):
        global failures
        if not quiet:
            sys.stderr.write(msg + '\n')
        failures += 1

    for feature in args:
        negate = feature.startswith('no-')
        if negate:
            feature = feature[3:]

        if feature not in checks:
            error('skipped: unknown feature: ' + feature)
            continue

        check, desc = checks[feature]
        try:
            available = check()
        except Exception, e:
            error('hghave check failed: ' + feature)
            continue

        if not negate and not available:
            error('skipped: missing feature: ' + desc)
        elif negate and available:
            error('skipped: system supports %s' % desc)

    if failures != 0:
        sys.exit(1)