comparison tests/hghave @ 4881:c51c9bc4579d

Add hghave utility and run-tests.py support. hghave detects system features like symlinks availability at run-time. Tests can be skipped by starting them with: "$TESTDIR/hghave" symlink || exit 80 The 80 exit status triggers hghave output handling by run-tests.py. Also, tests output can be locally patched on the fly to match reference output.
author Patrick Mezard <pmezard@gmail.com>
date Sat, 14 Jul 2007 18:34:06 +0200
parents
children 4cf6f8dbd1b4
comparison
equal deleted inserted replaced
4880:6403f948bd6b 4881:c51c9bc4579d
1 #!/usr/bin/env python
2 """Test the running system for features availability. Exit with zero
3 if all features are there, non-zero otherwise.
4 """
5 import optparse
6 import os
7 import sys
8
9 def has_symlink():
10 return hasattr(os, "symlink")
11
12 checks = {
13 "symlink": (has_symlink, "symbolic links"),
14 }
15
16 def list_features():
17 for name, feature in checks.iteritems():
18 desc = feature[1]
19 print name + ':', desc
20
21 parser = optparse.OptionParser("%prog [options] [features]")
22 parser.add_option("--list-features", action="store_true",
23 help="list available features")
24 parser.add_option("-q", "--quiet", action="store_true",
25 help="check features silently")
26
27 if __name__ == '__main__':
28 options, args = parser.parse_args()
29 if options.list_features:
30 list_features()
31 sys.exit(0)
32
33 quiet = options.quiet
34
35 failures = 0
36
37 def error(msg):
38 global failures
39 if not quiet:
40 sys.stderr.write(msg + '\n')
41 failures += 1
42
43 for feature in args:
44 if feature not in checks:
45 error('hghave: unknown feature: ' + feature)
46 continue
47
48 check, desc = checks[feature]
49 if not check():
50 error('hghave: missing feature: ' + desc)
51
52 if failures != 0:
53 sys.exit(1)
54
55