Show More
@@ -1,98 +1,106 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 os |
|
7 | import os | |
8 | import sys |
|
8 | import sys | |
9 | import tempfile |
|
9 | import tempfile | |
10 |
|
10 | |||
11 | tempprefix = 'hg-hghave-' |
|
11 | tempprefix = 'hg-hghave-' | |
12 |
|
12 | |||
13 | def has_symlink(): |
|
13 | def has_symlink(): | |
14 | return hasattr(os, "symlink") |
|
14 | return hasattr(os, "symlink") | |
15 |
|
15 | |||
16 | def has_fifo(): |
|
16 | def has_fifo(): | |
17 | return hasattr(os, "mkfifo") |
|
17 | return hasattr(os, "mkfifo") | |
18 |
|
18 | |||
19 | def has_executablebit(): |
|
19 | def has_executablebit(): | |
20 | fd, path = tempfile.mkstemp(prefix=tempprefix) |
|
20 | fd, path = tempfile.mkstemp(prefix=tempprefix) | |
21 | os.close(fd) |
|
21 | os.close(fd) | |
22 | try: |
|
22 | try: | |
23 | s = os.lstat(path).st_mode |
|
23 | s = os.lstat(path).st_mode | |
24 | os.chmod(path, s | 0100) |
|
24 | os.chmod(path, s | 0100) | |
25 | return (os.lstat(path).st_mode & 0100 != 0) |
|
25 | return (os.lstat(path).st_mode & 0100 != 0) | |
26 | finally: |
|
26 | finally: | |
27 | os.remove(path) |
|
27 | os.remove(path) | |
28 |
|
28 | |||
29 | def has_eol_in_paths(): |
|
29 | def has_eol_in_paths(): | |
30 | try: |
|
30 | try: | |
31 | fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') |
|
31 | fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') | |
32 | os.close(fd) |
|
32 | os.close(fd) | |
33 | os.remove(path) |
|
33 | os.remove(path) | |
34 | return True |
|
34 | return True | |
35 | except: |
|
35 | except: | |
36 | return False |
|
36 | return False | |
37 |
|
37 | |||
|
38 | def has_hotshot(): | |||
|
39 | try: | |||
|
40 | import hotshot | |||
|
41 | return True | |||
|
42 | except ImportError: | |||
|
43 | return False | |||
|
44 | ||||
38 | def has_lsprof(): |
|
45 | def has_lsprof(): | |
39 | try: |
|
46 | try: | |
40 | import _lsprof |
|
47 | import _lsprof | |
41 | return True |
|
48 | return True | |
42 | except ImportError: |
|
49 | except ImportError: | |
43 | return False |
|
50 | return False | |
44 |
|
51 | |||
45 | checks = { |
|
52 | checks = { | |
46 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), |
|
53 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), | |
47 | "execbit": (has_executablebit, "executable bit"), |
|
54 | "execbit": (has_executablebit, "executable bit"), | |
48 | "fifo": (has_fifo, "named pipes"), |
|
55 | "fifo": (has_fifo, "named pipes"), | |
|
56 | "hotshot": (has_hotshot, "python hotshot module"), | |||
49 | "lsprof": (has_lsprof, "python lsprof module"), |
|
57 | "lsprof": (has_lsprof, "python lsprof module"), | |
50 | "symlink": (has_symlink, "symbolic links"), |
|
58 | "symlink": (has_symlink, "symbolic links"), | |
51 | } |
|
59 | } | |
52 |
|
60 | |||
53 | def list_features(): |
|
61 | def list_features(): | |
54 | for name, feature in checks.iteritems(): |
|
62 | for name, feature in checks.iteritems(): | |
55 | desc = feature[1] |
|
63 | desc = feature[1] | |
56 | print name + ':', desc |
|
64 | print name + ':', desc | |
57 |
|
65 | |||
58 | parser = optparse.OptionParser("%prog [options] [features]") |
|
66 | parser = optparse.OptionParser("%prog [options] [features]") | |
59 | parser.add_option("--list-features", action="store_true", |
|
67 | parser.add_option("--list-features", action="store_true", | |
60 | help="list available features") |
|
68 | help="list available features") | |
61 | parser.add_option("-q", "--quiet", action="store_true", |
|
69 | parser.add_option("-q", "--quiet", action="store_true", | |
62 | help="check features silently") |
|
70 | help="check features silently") | |
63 |
|
71 | |||
64 | if __name__ == '__main__': |
|
72 | if __name__ == '__main__': | |
65 | options, args = parser.parse_args() |
|
73 | options, args = parser.parse_args() | |
66 | if options.list_features: |
|
74 | if options.list_features: | |
67 | list_features() |
|
75 | list_features() | |
68 | sys.exit(0) |
|
76 | sys.exit(0) | |
69 |
|
77 | |||
70 | quiet = options.quiet |
|
78 | quiet = options.quiet | |
71 |
|
79 | |||
72 | failures = 0 |
|
80 | failures = 0 | |
73 |
|
81 | |||
74 | def error(msg): |
|
82 | def error(msg): | |
75 | global failures |
|
83 | global failures | |
76 | if not quiet: |
|
84 | if not quiet: | |
77 | sys.stderr.write(msg + '\n') |
|
85 | sys.stderr.write(msg + '\n') | |
78 | failures += 1 |
|
86 | failures += 1 | |
79 |
|
87 | |||
80 | for feature in args: |
|
88 | for feature in args: | |
81 | negate = feature.startswith('no-') |
|
89 | negate = feature.startswith('no-') | |
82 | if negate: |
|
90 | if negate: | |
83 | feature = feature[3:] |
|
91 | feature = feature[3:] | |
84 |
|
92 | |||
85 | if feature not in checks: |
|
93 | if feature not in checks: | |
86 | error('hghave: unknown feature: ' + feature) |
|
94 | error('hghave: unknown feature: ' + feature) | |
87 | continue |
|
95 | continue | |
88 |
|
96 | |||
89 | check, desc = checks[feature] |
|
97 | check, desc = checks[feature] | |
90 | if not negate and not check(): |
|
98 | if not negate and not check(): | |
91 | error('hghave: missing feature: ' + desc) |
|
99 | error('hghave: missing feature: ' + desc) | |
92 | elif negate and check(): |
|
100 | elif negate and check(): | |
93 | error('hghave: system supports %s' % desc) |
|
101 | error('hghave: system supports %s' % desc) | |
94 |
|
102 | |||
95 | if failures != 0: |
|
103 | if failures != 0: | |
96 | sys.exit(1) |
|
104 | sys.exit(1) | |
97 |
|
105 | |||
98 |
|
106 |
@@ -1,12 +1,15 b'' | |||||
1 | #!/bin/sh |
|
1 | #!/bin/sh | |
2 |
|
2 | |||
3 | echo % test --time |
|
3 | echo % test --time | |
4 |
hg --time help 2>&1 | grep |
|
4 | hg --time help -q help 2>&1 | grep Time > /dev/null || echo --time failed | |
5 |
|
5 | |||
6 | echo % test --profile |
|
6 | echo % test --profile | |
7 | hg --profile help 2>&1 | grep -q ncalls || echo --profile failed |
|
7 | if "$TESTDIR/hghave" -q hotshot; then | |
|
8 | # hotshot might be missing for licensing issues | |||
|
9 | hg --profile help -q help 2>&1 | grep ncalls > /dev/null || echo --profile failed | |||
|
10 | fi | |||
8 |
|
11 | |||
9 | echo % test --lsprof |
|
12 | echo % test --lsprof | |
10 | if "$TESTDIR/hghave" -q lsprof; then |
|
13 | if "$TESTDIR/hghave" -q lsprof; then | |
11 |
hg --lsprof help 2>&1 | grep |
|
14 | hg --lsprof help -q help 2>&1 | grep CallCount > /dev/null || echo --lsprof failed | |
12 | fi No newline at end of file |
|
15 | fi |
General Comments 0
You need to be logged in to leave comments.
Login now