##// END OF EJS Templates
hghave: allow adding customized features at runtime...
FUJIWARA Katsunori -
r25732:b94df10c default
parent child Browse files
Show More
@@ -4,7 +4,7 b' if all features are there, non-zero othe'
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
@@ -33,8 +33,30 b' parser.add_option("--list-features", act'
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)
@@ -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