##// END OF EJS Templates
Add hghave utility and run-tests.py support....
Patrick Mezard -
r4881:c51c9bc4 default
parent child Browse files
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 import tempfile
19 import tempfile
20 import time
20 import time
21
21
22 # hghave reserved exit code to skip test
23 SKIPPED_STATUS = 80
24
22 required_tools = ["python", "diff", "grep", "unzip", "gunzip", "bunzip2", "sed"]
25 required_tools = ["python", "diff", "grep", "unzip", "gunzip", "bunzip2", "sed"]
23
26
24 parser = optparse.OptionParser("%prog [options] [tests]")
27 parser = optparse.OptionParser("%prog [options] [tests]")
@@ -68,6 +71,17 b' def splitnewlines(text):'
68 lines.append(text[i:n+1])
71 lines.append(text[i:n+1])
69 i = n + 1
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 def show_diff(expected, output):
85 def show_diff(expected, output):
72 for line in difflib.unified_diff(expected, output,
86 for line in difflib.unified_diff(expected, output,
73 "Expected output", "Test output"):
87 "Expected output", "Test output"):
@@ -283,6 +297,7 b' def run_one(test):'
283 if options.timeout > 0:
297 if options.timeout > 0:
284 signal.alarm(0)
298 signal.alarm(0)
285
299
300 skipped = (ret == SKIPPED_STATUS)
286 diffret = 0
301 diffret = 0
287 # If reference output file exists, check test output against it
302 # If reference output file exists, check test output against it
288 if os.path.exists(ref):
303 if os.path.exists(ref):
@@ -291,16 +306,22 b' def run_one(test):'
291 f.close()
306 f.close()
292 else:
307 else:
293 ref_out = []
308 ref_out = []
294 if out != ref_out:
309 if not skipped and out != ref_out:
295 diffret = 1
310 diffret = 1
296 print "\nERROR: %s output changed" % (test)
311 print "\nERROR: %s output changed" % (test)
297 show_diff(ref_out, out)
312 show_diff(ref_out, out)
298 if ret:
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 print "\nERROR: %s failed with error code %d" % (test, ret)
319 print "\nERROR: %s failed with error code %d" % (test, ret)
300 elif diffret:
320 elif diffret:
301 ret = diffret
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 f = open(err, "wb")
325 f = open(err, "wb")
305 for line in out:
326 for line in out:
306 f.write(line)
327 f.write(line)
@@ -332,6 +353,8 b' def run_one(test):'
332
353
333 os.chdir(TESTDIR)
354 os.chdir(TESTDIR)
334 shutil.rmtree(tmpd, True)
355 shutil.rmtree(tmpd, True)
356 if skipped:
357 return None
335 return ret == 0
358 return ret == 0
336
359
337
360
General Comments 0
You need to be logged in to leave comments. Login now