Mercurial > public > mercurial-scm > hg
comparison tests/run-tests.py @ 8095:f5428d4ffd97
run-tests: reduce global variables set by parse_args().
author | Greg Ward <greg-hg@gerg.ca> |
---|---|
date | Mon, 20 Apr 2009 21:50:11 -0400 |
parents | 60a9e3cf0cf4 |
children | a110d7a20f3f |
comparison
equal
deleted
inserted
replaced
8094:60a9e3cf0cf4 | 8095:f5428d4ffd97 |
---|---|
44 'jobs': ('HGTEST_JOBS', 1), | 44 'jobs': ('HGTEST_JOBS', 1), |
45 'timeout': ('HGTEST_TIMEOUT', 180), | 45 'timeout': ('HGTEST_TIMEOUT', 180), |
46 'port': ('HGTEST_PORT', 20059), | 46 'port': ('HGTEST_PORT', 20059), |
47 } | 47 } |
48 | 48 |
49 # globals set by parse_args() (ugh) | 49 python = sys.executable |
50 verbose = False | |
51 nodiff = False | |
52 coverage = False | |
53 python = None | |
54 | 50 |
55 def parse_args(): | 51 def parse_args(): |
56 parser = optparse.OptionParser("%prog [options] [tests]") | 52 parser = optparse.OptionParser("%prog [options] [tests]") |
57 parser.add_option("-C", "--annotate", action="store_true", | 53 parser.add_option("-C", "--annotate", action="store_true", |
58 help="output files annotated with coverage") | 54 help="output files annotated with coverage") |
96 for option, default in defaults.items(): | 92 for option, default in defaults.items(): |
97 defaults[option] = int(os.environ.get(*default)) | 93 defaults[option] = int(os.environ.get(*default)) |
98 parser.set_defaults(**defaults) | 94 parser.set_defaults(**defaults) |
99 (options, args) = parser.parse_args() | 95 (options, args) = parser.parse_args() |
100 | 96 |
101 global verbose, nodiff, coverage, python | 97 global vlog |
102 verbose = options.verbose | 98 options.anycoverage = (options.cover or |
103 nodiff = options.nodiff | 99 options.cover_stdlib or |
104 coverage = options.cover or options.cover_stdlib or options.annotate | 100 options.annotate) |
105 python = sys.executable | 101 |
102 if options.verbose: | |
103 def vlog(*msg): | |
104 for m in msg: | |
105 print m, | |
106 print | |
107 else: | |
108 vlog = lambda *msg: None | |
106 | 109 |
107 if options.jobs < 1: | 110 if options.jobs < 1: |
108 print >> sys.stderr, 'ERROR: -j/--jobs must be positive' | 111 print >> sys.stderr, 'ERROR: -j/--jobs must be positive' |
109 sys.exit(1) | 112 sys.exit(1) |
110 if options.interactive and options.jobs > 1: | 113 if options.interactive and options.jobs > 1: |
117 """Like os.rename(), trade atomicity and opened files friendliness | 120 """Like os.rename(), trade atomicity and opened files friendliness |
118 for existing destination support. | 121 for existing destination support. |
119 """ | 122 """ |
120 shutil.copy(src, dst) | 123 shutil.copy(src, dst) |
121 os.remove(src) | 124 os.remove(src) |
122 | |
123 def vlog(*msg): | |
124 if verbose: | |
125 for m in msg: | |
126 print m, | |
127 print | |
128 | 125 |
129 def splitnewlines(text): | 126 def splitnewlines(text): |
130 '''like str.splitlines, but only split on newlines. | 127 '''like str.splitlines, but only split on newlines. |
131 keep line endings.''' | 128 keep line endings.''' |
132 i = 0 | 129 i = 0 |
183 else: | 180 else: |
184 print "WARNING: Did not find prerequisite tool: "+p | 181 print "WARNING: Did not find prerequisite tool: "+p |
185 | 182 |
186 def cleanup_exit(options): | 183 def cleanup_exit(options): |
187 if not options.keep_tmpdir: | 184 if not options.keep_tmpdir: |
188 if verbose: | 185 if options.verbose: |
189 print "# Cleaning up HGTMP", HGTMP | 186 print "# Cleaning up HGTMP", HGTMP |
190 shutil.rmtree(HGTMP, True) | 187 shutil.rmtree(HGTMP, True) |
191 | 188 |
192 def use_correct_python(): | 189 def use_correct_python(): |
193 # some tests run python interpreter. they must use same | 190 # some tests run python interpreter. they must use same |
218 ' install --force --prefix="%s" --install-lib="%s"' | 215 ' install --force --prefix="%s" --install-lib="%s"' |
219 ' --install-scripts="%s" >%s 2>&1' | 216 ' --install-scripts="%s" >%s 2>&1' |
220 % (sys.executable, pure, INST, PYTHONDIR, BINDIR, installerrs)) | 217 % (sys.executable, pure, INST, PYTHONDIR, BINDIR, installerrs)) |
221 vlog("# Running", cmd) | 218 vlog("# Running", cmd) |
222 if os.system(cmd) == 0: | 219 if os.system(cmd) == 0: |
223 if not verbose: | 220 if not options.verbose: |
224 os.remove(installerrs) | 221 os.remove(installerrs) |
225 else: | 222 else: |
226 f = open(installerrs) | 223 f = open(installerrs) |
227 for line in f: | 224 for line in f: |
228 print line, | 225 print line, |
254 ' files += 1\n' | 251 ' files += 1\n' |
255 'sys.stdout.write("files patched: %d\\n" % files)\n') | 252 'sys.stdout.write("files patched: %d\\n" % files)\n') |
256 f.close() | 253 f.close() |
257 os.chmod(os.path.join(BINDIR, 'diffstat'), 0700) | 254 os.chmod(os.path.join(BINDIR, 'diffstat'), 0700) |
258 | 255 |
259 if coverage: | 256 if options.anycoverage: |
260 vlog("# Installing coverage wrapper") | 257 vlog("# Installing coverage wrapper") |
261 os.environ['COVERAGE_FILE'] = COVERAGE_FILE | 258 os.environ['COVERAGE_FILE'] = COVERAGE_FILE |
262 if os.path.exists(COVERAGE_FILE): | 259 if os.path.exists(COVERAGE_FILE): |
263 os.unlink(COVERAGE_FILE) | 260 os.unlink(COVERAGE_FILE) |
264 # Create a wrapper script to invoke hg via coverage.py | 261 # Create a wrapper script to invoke hg via coverage.py |
344 None -> skipped | 341 None -> skipped |
345 True -> passed | 342 True -> passed |
346 False -> failed''' | 343 False -> failed''' |
347 | 344 |
348 def skip(msg): | 345 def skip(msg): |
349 if not verbose: | 346 if not options.verbose: |
350 skips.append((test, msg)) | 347 skips.append((test, msg)) |
351 else: | 348 else: |
352 print "\nSkipping %s: %s" % (test, msg) | 349 print "\nSkipping %s: %s" % (test, msg) |
353 return None | 350 return None |
354 | 351 |
355 def fail(msg): | 352 def fail(msg): |
356 fails.append((test, msg)) | 353 fails.append((test, msg)) |
357 if not nodiff: | 354 if not options.nodiff: |
358 print "\nERROR: %s %s" % (test, msg) | 355 print "\nERROR: %s %s" % (test, msg) |
359 return None | 356 return None |
360 | 357 |
361 vlog("# Test", test) | 358 vlog("# Test", test) |
362 | 359 |
445 mark = '!' | 442 mark = '!' |
446 if ret: | 443 if ret: |
447 fail("output changed and returned error code %d" % ret) | 444 fail("output changed and returned error code %d" % ret) |
448 else: | 445 else: |
449 fail("output changed") | 446 fail("output changed") |
450 if not nodiff: | 447 if not options.nodiff: |
451 show_diff(ref_out, out) | 448 show_diff(ref_out, out) |
452 ret = 1 | 449 ret = 1 |
453 elif ret: | 450 elif ret: |
454 mark = '!' | 451 mark = '!' |
455 fail("returned error code %d" % ret) | 452 fail("returned error code %d" % ret) |
456 | 453 |
457 if not verbose: | 454 if not options.verbose: |
458 sys.stdout.write(mark) | 455 sys.stdout.write(mark) |
459 sys.stdout.flush() | 456 sys.stdout.flush() |
460 | 457 |
461 if ret != 0 and not skipped: | 458 if ret != 0 and not skipped: |
462 # Save errors to a file for diagnosis | 459 # Save errors to a file for diagnosis |
636 if hgpkg != expecthg: | 633 if hgpkg != expecthg: |
637 print '# Tested unexpected mercurial: %s' % hgpkg | 634 print '# Tested unexpected mercurial: %s' % hgpkg |
638 print "# Ran %d tests, %d skipped, %d failed." % ( | 635 print "# Ran %d tests, %d skipped, %d failed." % ( |
639 tested, skipped, failed) | 636 tested, skipped, failed) |
640 | 637 |
641 if coverage: | 638 if options.anycoverage: |
642 output_coverage(options) | 639 output_coverage(options) |
643 except KeyboardInterrupt: | 640 except KeyboardInterrupt: |
644 failed = True | 641 failed = True |
645 print "\ninterrupted!" | 642 print "\ninterrupted!" |
646 | 643 |