##// END OF EJS Templates
run-tests: reduce global variables set by parse_args().
Greg Ward -
r8095:f5428d4f default
parent child Browse files
Show More
@@ -46,11 +46,7 b' defaults = {'
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]")
@@ -98,11 +94,18 b' def parse_args():'
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'
@@ -120,12 +123,6 b' def rename(src, dst):'
120 shutil.copy(src, dst)
123 shutil.copy(src, dst)
121 os.remove(src)
124 os.remove(src)
122
125
123 def vlog(*msg):
124 if verbose:
125 for m in msg:
126 print m,
127 print
128
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.'''
@@ -185,7 +182,7 b' def check_required_tools():'
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
@@ -220,7 +217,7 b' def install_hg(options):'
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)
@@ -256,7 +253,7 b' def install_hg(options):'
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):
@@ -346,7 +343,7 b' def run_one(options, test, skips, fails)'
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)
@@ -354,7 +351,7 b' def run_one(options, test, skips, fails)'
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
@@ -447,14 +444,14 b' def run_one(options, test, skips, fails)'
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
@@ -638,7 +635,7 b' def run_tests(options, expecthg, tests):'
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
General Comments 0
You need to be logged in to leave comments. Login now