Show More
@@ -1,77 +1,99 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | """Test the running system for features availability. Exit with zero |
|
3 | 3 | if all features are there, non-zero otherwise. If a feature name is |
|
4 | 4 | prefixed with "no-", the absence of feature is tested. |
|
5 | 5 | """ |
|
6 | 6 | import optparse |
|
7 | import sys | |
|
7 | import os, sys | |
|
8 | 8 | import hghave |
|
9 | 9 | |
|
10 | 10 | checks = hghave.checks |
|
11 | 11 | |
|
12 | 12 | def list_features(): |
|
13 | 13 | for name, feature in sorted(checks.iteritems()): |
|
14 | 14 | desc = feature[1] |
|
15 | 15 | print name + ':', desc |
|
16 | 16 | |
|
17 | 17 | def test_features(): |
|
18 | 18 | failed = 0 |
|
19 | 19 | for name, feature in checks.iteritems(): |
|
20 | 20 | check, _ = feature |
|
21 | 21 | try: |
|
22 | 22 | check() |
|
23 | 23 | except Exception, e: |
|
24 | 24 | print "feature %s failed: %s" % (name, e) |
|
25 | 25 | failed += 1 |
|
26 | 26 | return failed |
|
27 | 27 | |
|
28 | 28 | parser = optparse.OptionParser("%prog [options] [features]") |
|
29 | 29 | parser.add_option("--test-features", action="store_true", |
|
30 | 30 | help="test available features") |
|
31 | 31 | parser.add_option("--list-features", action="store_true", |
|
32 | 32 | help="list available features") |
|
33 | 33 | parser.add_option("-q", "--quiet", action="store_true", |
|
34 | 34 | help="check features silently") |
|
35 | 35 | |
|
36 | def _loadaddon(quiet): | |
|
37 | if 'TESTDIR' in os.environ: | |
|
38 | # loading from '.' isn't needed, because `hghave` should be | |
|
39 | # running at TESTTMP in this case | |
|
40 | path = os.environ['TESTDIR'] | |
|
41 | else: | |
|
42 | path = '.' | |
|
43 | ||
|
44 | if not os.path.exists(os.path.join(path, 'hghaveaddon.py')): | |
|
45 | return | |
|
46 | ||
|
47 | sys.path.insert(0, path) | |
|
48 | try: | |
|
49 | import hghaveaddon | |
|
50 | except BaseException, inst: | |
|
51 | if not quiet: | |
|
52 | sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n' | |
|
53 | % (path, inst)) | |
|
54 | sys.exit(2) | |
|
55 | sys.path.pop(0) | |
|
56 | ||
|
36 | 57 | if __name__ == '__main__': |
|
37 | 58 | options, args = parser.parse_args() |
|
59 | _loadaddon(options.quiet) | |
|
38 | 60 | if options.list_features: |
|
39 | 61 | list_features() |
|
40 | 62 | sys.exit(0) |
|
41 | 63 | |
|
42 | 64 | if options.test_features: |
|
43 | 65 | sys.exit(test_features()) |
|
44 | 66 | |
|
45 | 67 | quiet = options.quiet |
|
46 | 68 | |
|
47 | 69 | failures = 0 |
|
48 | 70 | |
|
49 | 71 | def error(msg): |
|
50 | 72 | global failures |
|
51 | 73 | if not quiet: |
|
52 | 74 | sys.stderr.write(msg + '\n') |
|
53 | 75 | failures += 1 |
|
54 | 76 | |
|
55 | 77 | for feature in args: |
|
56 | 78 | negate = feature.startswith('no-') |
|
57 | 79 | if negate: |
|
58 | 80 | feature = feature[3:] |
|
59 | 81 | |
|
60 | 82 | if feature not in checks: |
|
61 | 83 | error('skipped: unknown feature: ' + feature) |
|
62 | 84 | sys.exit(2) |
|
63 | 85 | |
|
64 | 86 | check, desc = checks[feature] |
|
65 | 87 | try: |
|
66 | 88 | available = check() |
|
67 | 89 | except Exception, e: |
|
68 | 90 | error('hghave check failed: ' + feature) |
|
69 | 91 | continue |
|
70 | 92 | |
|
71 | 93 | if not negate and not available: |
|
72 | 94 | error('skipped: missing feature: ' + desc) |
|
73 | 95 | elif negate and available: |
|
74 | 96 | error('skipped: system supports %s' % desc) |
|
75 | 97 | |
|
76 | 98 | if failures != 0: |
|
77 | 99 | sys.exit(1) |
@@ -1,3 +1,39 b'' | |||
|
1 | 1 | Testing that hghave does not crash when checking features |
|
2 | 2 | |
|
3 | 3 | $ hghave --test-features 2>/dev/null |
|
4 | ||
|
5 | Testing hghave extensibility for third party tools | |
|
6 | ||
|
7 | $ cat > hghaveaddon.py <<EOF | |
|
8 | > import hghave | |
|
9 | > @hghave.check("custom", "custom hghave feature") | |
|
10 | > def has_custom(): | |
|
11 | > return True | |
|
12 | > EOF | |
|
13 | ||
|
14 | (invocation via run-tests.py) | |
|
15 | ||
|
16 | $ cat > test-hghaveaddon.t <<EOF | |
|
17 | > #require custom | |
|
18 | > $ echo foo | |
|
19 | > foo | |
|
20 | > EOF | |
|
21 | $ run-tests.py test-hghaveaddon.t | |
|
22 | . | |
|
23 | # Ran 1 tests, 0 skipped, 0 warned, 0 failed. | |
|
24 | ||
|
25 | (invocation via command line) | |
|
26 | ||
|
27 | $ unset TESTDIR | |
|
28 | $ hghave custom | |
|
29 | ||
|
30 | (terminate with exit code 2 at failure of importing hghaveaddon.py) | |
|
31 | ||
|
32 | $ rm hghaveaddon.* | |
|
33 | $ cat > hghaveaddon.py <<EOF | |
|
34 | > importing this file should cause syntax error | |
|
35 | > EOF | |
|
36 | ||
|
37 | $ hghave custom | |
|
38 | failed to import hghaveaddon.py from '.': invalid syntax (hghaveaddon.py, line 1) | |
|
39 | [2] |
General Comments 0
You need to be logged in to leave comments.
Login now