##// END OF EJS Templates
hghave: allow adding customized features at runtime...
FUJIWARA Katsunori -
r25732:b94df10c default
parent child Browse files
Show More
@@ -1,77 +1,99 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 """Test the running system for features availability. Exit with zero
2 """Test the running system for features availability. Exit with zero
3 if all features are there, non-zero otherwise. If a feature name is
3 if all features are there, non-zero otherwise. If a feature name is
4 prefixed with "no-", the absence of feature is tested.
4 prefixed with "no-", the absence of feature is tested.
5 """
5 """
6 import optparse
6 import optparse
7 import sys
7 import os, sys
8 import hghave
8 import hghave
9
9
10 checks = hghave.checks
10 checks = hghave.checks
11
11
12 def list_features():
12 def list_features():
13 for name, feature in sorted(checks.iteritems()):
13 for name, feature in sorted(checks.iteritems()):
14 desc = feature[1]
14 desc = feature[1]
15 print name + ':', desc
15 print name + ':', desc
16
16
17 def test_features():
17 def test_features():
18 failed = 0
18 failed = 0
19 for name, feature in checks.iteritems():
19 for name, feature in checks.iteritems():
20 check, _ = feature
20 check, _ = feature
21 try:
21 try:
22 check()
22 check()
23 except Exception, e:
23 except Exception, e:
24 print "feature %s failed: %s" % (name, e)
24 print "feature %s failed: %s" % (name, e)
25 failed += 1
25 failed += 1
26 return failed
26 return failed
27
27
28 parser = optparse.OptionParser("%prog [options] [features]")
28 parser = optparse.OptionParser("%prog [options] [features]")
29 parser.add_option("--test-features", action="store_true",
29 parser.add_option("--test-features", action="store_true",
30 help="test available features")
30 help="test available features")
31 parser.add_option("--list-features", action="store_true",
31 parser.add_option("--list-features", action="store_true",
32 help="list available features")
32 help="list available features")
33 parser.add_option("-q", "--quiet", action="store_true",
33 parser.add_option("-q", "--quiet", action="store_true",
34 help="check features silently")
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 if __name__ == '__main__':
57 if __name__ == '__main__':
37 options, args = parser.parse_args()
58 options, args = parser.parse_args()
59 _loadaddon(options.quiet)
38 if options.list_features:
60 if options.list_features:
39 list_features()
61 list_features()
40 sys.exit(0)
62 sys.exit(0)
41
63
42 if options.test_features:
64 if options.test_features:
43 sys.exit(test_features())
65 sys.exit(test_features())
44
66
45 quiet = options.quiet
67 quiet = options.quiet
46
68
47 failures = 0
69 failures = 0
48
70
49 def error(msg):
71 def error(msg):
50 global failures
72 global failures
51 if not quiet:
73 if not quiet:
52 sys.stderr.write(msg + '\n')
74 sys.stderr.write(msg + '\n')
53 failures += 1
75 failures += 1
54
76
55 for feature in args:
77 for feature in args:
56 negate = feature.startswith('no-')
78 negate = feature.startswith('no-')
57 if negate:
79 if negate:
58 feature = feature[3:]
80 feature = feature[3:]
59
81
60 if feature not in checks:
82 if feature not in checks:
61 error('skipped: unknown feature: ' + feature)
83 error('skipped: unknown feature: ' + feature)
62 sys.exit(2)
84 sys.exit(2)
63
85
64 check, desc = checks[feature]
86 check, desc = checks[feature]
65 try:
87 try:
66 available = check()
88 available = check()
67 except Exception, e:
89 except Exception, e:
68 error('hghave check failed: ' + feature)
90 error('hghave check failed: ' + feature)
69 continue
91 continue
70
92
71 if not negate and not available:
93 if not negate and not available:
72 error('skipped: missing feature: ' + desc)
94 error('skipped: missing feature: ' + desc)
73 elif negate and available:
95 elif negate and available:
74 error('skipped: system supports %s' % desc)
96 error('skipped: system supports %s' % desc)
75
97
76 if failures != 0:
98 if failures != 0:
77 sys.exit(1)
99 sys.exit(1)
@@ -1,3 +1,39 b''
1 Testing that hghave does not crash when checking features
1 Testing that hghave does not crash when checking features
2
2
3 $ hghave --test-features 2>/dev/null
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