Mercurial > hg
annotate tests/hghave @ 5099:105d4cf7ec24
Test --time, --profile and --lsprof
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Tue, 14 Aug 2007 16:27:35 +0200 |
parents | 6e040f6c2c9c |
children | 9b0efeb725f4 |
rev | line source |
---|---|
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
2 """Test the running system for features availability. Exit with zero |
5084
80309fa23cdb
hghave: feature absence can be checked by prefixing with 'no-'
Patrick Mezard <pmezard@gmail.com>
parents:
5081
diff
changeset
|
3 if all features are there, non-zero otherwise. If a feature name is |
80309fa23cdb
hghave: feature absence can be checked by prefixing with 'no-'
Patrick Mezard <pmezard@gmail.com>
parents:
5081
diff
changeset
|
4 prefixed with "no-", the absence of feature is tested. |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
5 """ |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
6 import optparse |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
7 import os |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
8 import sys |
5072
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
9 import tempfile |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
10 |
5090
bf60e4bd6672
hghave: prefix temporary files with "hg-hghave-"
Patrick Mezard <pmezard@gmail.com>
parents:
5084
diff
changeset
|
11 tempprefix = 'hg-hghave-' |
bf60e4bd6672
hghave: prefix temporary files with "hg-hghave-"
Patrick Mezard <pmezard@gmail.com>
parents:
5084
diff
changeset
|
12 |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
13 def has_symlink(): |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
14 return hasattr(os, "symlink") |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
15 |
5070
4cf6f8dbd1b4
hghave: detect FIFO availability
Patrick Mezard <pmezard@gmail.com>
parents:
4881
diff
changeset
|
16 def has_fifo(): |
4cf6f8dbd1b4
hghave: detect FIFO availability
Patrick Mezard <pmezard@gmail.com>
parents:
4881
diff
changeset
|
17 return hasattr(os, "mkfifo") |
4cf6f8dbd1b4
hghave: detect FIFO availability
Patrick Mezard <pmezard@gmail.com>
parents:
4881
diff
changeset
|
18 |
5072
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
19 def has_executablebit(): |
5090
bf60e4bd6672
hghave: prefix temporary files with "hg-hghave-"
Patrick Mezard <pmezard@gmail.com>
parents:
5084
diff
changeset
|
20 fd, path = tempfile.mkstemp(prefix=tempprefix) |
5072
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
21 os.close(fd) |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
22 try: |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
23 s = os.lstat(path).st_mode |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
24 os.chmod(path, s | 0100) |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
25 return (os.lstat(path).st_mode & 0100 != 0) |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
26 finally: |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
27 os.remove(path) |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
28 |
5074
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
29 def has_eol_in_paths(): |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
30 try: |
5090
bf60e4bd6672
hghave: prefix temporary files with "hg-hghave-"
Patrick Mezard <pmezard@gmail.com>
parents:
5084
diff
changeset
|
31 fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') |
5074
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
32 os.close(fd) |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
33 os.remove(path) |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
34 return True |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
35 except: |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
36 return False |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
37 |
5099
105d4cf7ec24
Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents:
5092
diff
changeset
|
38 def has_lsprof(): |
105d4cf7ec24
Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents:
5092
diff
changeset
|
39 try: |
105d4cf7ec24
Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents:
5092
diff
changeset
|
40 import _lsprof |
105d4cf7ec24
Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents:
5092
diff
changeset
|
41 return True |
105d4cf7ec24
Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents:
5092
diff
changeset
|
42 except ImportError: |
105d4cf7ec24
Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents:
5092
diff
changeset
|
43 return False |
105d4cf7ec24
Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents:
5092
diff
changeset
|
44 |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
45 checks = { |
5099
105d4cf7ec24
Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents:
5092
diff
changeset
|
46 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), |
105d4cf7ec24
Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents:
5092
diff
changeset
|
47 "execbit": (has_executablebit, "executable bit"), |
5070
4cf6f8dbd1b4
hghave: detect FIFO availability
Patrick Mezard <pmezard@gmail.com>
parents:
4881
diff
changeset
|
48 "fifo": (has_fifo, "named pipes"), |
5099
105d4cf7ec24
Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents:
5092
diff
changeset
|
49 "lsprof": (has_lsprof, "python lsprof module"), |
105d4cf7ec24
Test --time, --profile and --lsprof
Patrick Mezard <pmezard@gmail.com>
parents:
5092
diff
changeset
|
50 "symlink": (has_symlink, "symbolic links"), |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
51 } |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
52 |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
53 def list_features(): |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
54 for name, feature in checks.iteritems(): |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
55 desc = feature[1] |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
56 print name + ':', desc |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
57 |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
58 parser = optparse.OptionParser("%prog [options] [features]") |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
59 parser.add_option("--list-features", action="store_true", |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
60 help="list available features") |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
61 parser.add_option("-q", "--quiet", action="store_true", |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
62 help="check features silently") |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
63 |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
64 if __name__ == '__main__': |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
65 options, args = parser.parse_args() |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
66 if options.list_features: |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
67 list_features() |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
68 sys.exit(0) |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5074
diff
changeset
|
69 |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
70 quiet = options.quiet |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
71 |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
72 failures = 0 |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
73 |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
74 def error(msg): |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
75 global failures |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
76 if not quiet: |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
77 sys.stderr.write(msg + '\n') |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
78 failures += 1 |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5074
diff
changeset
|
79 |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
80 for feature in args: |
5084
80309fa23cdb
hghave: feature absence can be checked by prefixing with 'no-'
Patrick Mezard <pmezard@gmail.com>
parents:
5081
diff
changeset
|
81 negate = feature.startswith('no-') |
80309fa23cdb
hghave: feature absence can be checked by prefixing with 'no-'
Patrick Mezard <pmezard@gmail.com>
parents:
5081
diff
changeset
|
82 if negate: |
80309fa23cdb
hghave: feature absence can be checked by prefixing with 'no-'
Patrick Mezard <pmezard@gmail.com>
parents:
5081
diff
changeset
|
83 feature = feature[3:] |
5091
fc6106267198
Hide absolute path from test-no-symlinks output.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5090
diff
changeset
|
84 |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
85 if feature not in checks: |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
86 error('hghave: unknown feature: ' + feature) |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
87 continue |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5074
diff
changeset
|
88 |
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5074
diff
changeset
|
89 check, desc = checks[feature] |
5084
80309fa23cdb
hghave: feature absence can be checked by prefixing with 'no-'
Patrick Mezard <pmezard@gmail.com>
parents:
5081
diff
changeset
|
90 if not negate and not check(): |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
91 error('hghave: missing feature: ' + desc) |
5084
80309fa23cdb
hghave: feature absence can be checked by prefixing with 'no-'
Patrick Mezard <pmezard@gmail.com>
parents:
5081
diff
changeset
|
92 elif negate and check(): |
5092
6e040f6c2c9c
Print less scary message if the system supports symlinks:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5091
diff
changeset
|
93 error('hghave: system supports %s' % desc) |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
94 |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
95 if failures != 0: |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
96 sys.exit(1) |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
97 |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5074
diff
changeset
|
98 |