Show More
@@ -0,0 +1,55 b'' | |||
|
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 |
@@ -19,6 +19,9 b' import sys' | |||
|
19 | 19 | import tempfile |
|
20 | 20 | import time |
|
21 | 21 | |
|
22 | # hghave reserved exit code to skip test | |
|
23 | SKIPPED_STATUS = 80 | |
|
24 | ||
|
22 | 25 | required_tools = ["python", "diff", "grep", "unzip", "gunzip", "bunzip2", "sed"] |
|
23 | 26 | |
|
24 | 27 | parser = optparse.OptionParser("%prog [options] [tests]") |
@@ -68,6 +71,17 b' def splitnewlines(text):' | |||
|
68 | 71 | lines.append(text[i:n+1]) |
|
69 | 72 | i = n + 1 |
|
70 | 73 | |
|
74 | def extract_missing_features(lines): | |
|
75 | '''Extract missing/unknown features log lines as a list''' | |
|
76 | missing = [] | |
|
77 | for line in lines: | |
|
78 | if not line.startswith('hghave: '): | |
|
79 | continue | |
|
80 | line = line.splitlines()[0] | |
|
81 | missing.append(line[8:]) | |
|
82 | ||
|
83 | return missing | |
|
84 | ||
|
71 | 85 | def show_diff(expected, output): |
|
72 | 86 | for line in difflib.unified_diff(expected, output, |
|
73 | 87 | "Expected output", "Test output"): |
@@ -283,6 +297,7 b' def run_one(test):' | |||
|
283 | 297 | if options.timeout > 0: |
|
284 | 298 | signal.alarm(0) |
|
285 | 299 | |
|
300 | skipped = (ret == SKIPPED_STATUS) | |
|
286 | 301 | diffret = 0 |
|
287 | 302 | # If reference output file exists, check test output against it |
|
288 | 303 | if os.path.exists(ref): |
@@ -291,16 +306,22 b' def run_one(test):' | |||
|
291 | 306 | f.close() |
|
292 | 307 | else: |
|
293 | 308 | ref_out = [] |
|
294 | if out != ref_out: | |
|
309 | if not skipped and out != ref_out: | |
|
295 | 310 | diffret = 1 |
|
296 | 311 | print "\nERROR: %s output changed" % (test) |
|
297 | 312 | show_diff(ref_out, out) |
|
298 |
if |
|
|
313 | if skipped: | |
|
314 | missing = extract_missing_features(out) | |
|
315 | if not missing: | |
|
316 | missing = ['irrelevant'] | |
|
317 | print '\nSkipping %s: %s' % (test, missing[-1]) | |
|
318 | elif ret: | |
|
299 | 319 | print "\nERROR: %s failed with error code %d" % (test, ret) |
|
300 | 320 | elif diffret: |
|
301 | 321 | ret = diffret |
|
302 | 322 | |
|
303 | if ret != 0: # Save errors to a file for diagnosis | |
|
323 | if ret != 0 and not skipped: | |
|
324 | # Save errors to a file for diagnosis | |
|
304 | 325 | f = open(err, "wb") |
|
305 | 326 | for line in out: |
|
306 | 327 | f.write(line) |
@@ -332,6 +353,8 b' def run_one(test):' | |||
|
332 | 353 | |
|
333 | 354 | os.chdir(TESTDIR) |
|
334 | 355 | shutil.rmtree(tmpd, True) |
|
356 | if skipped: | |
|
357 | return None | |
|
335 | 358 | return ret == 0 |
|
336 | 359 | |
|
337 | 360 |
General Comments 0
You need to be logged in to leave comments.
Login now