Show More
@@ -0,0 +1,6 b'' | |||
|
1 | try: | |
|
2 | import coverage | |
|
3 | if hasattr(coverage, 'process_startup'): | |
|
4 | coverage.process_startup() | |
|
5 | except ImportError: | |
|
6 | pass |
@@ -41,6 +41,7 b'' | |||
|
41 | 41 | # completes fairly quickly, includes both shell and Python scripts, and |
|
42 | 42 | # includes some scripts that run daemon processes.) |
|
43 | 43 | |
|
44 | from distutils import version | |
|
44 | 45 | import difflib |
|
45 | 46 | import errno |
|
46 | 47 | import optparse |
@@ -110,8 +111,6 b' def parseargs():' | |||
|
110 | 111 | " (default: $%s or %d)" % defaults['port']) |
|
111 | 112 | parser.add_option("-r", "--retest", action="store_true", |
|
112 | 113 | help="retest failed tests") |
|
113 | parser.add_option("-s", "--cover_stdlib", action="store_true", | |
|
114 | help="print a test coverage report inc. standard libraries") | |
|
115 | 114 | parser.add_option("-S", "--noskips", action="store_true", |
|
116 | 115 | help="don't report skip tests verbosely") |
|
117 | 116 | parser.add_option("-t", "--timeout", type="int", |
@@ -155,16 +154,20 b' def parseargs():' | |||
|
155 | 154 | % hgbin) |
|
156 | 155 | options.with_hg = hgbin |
|
157 | 156 | |
|
158 |
options.anycoverage = |
|
|
159 | options.cover_stdlib or | |
|
160 | options.annotate) | |
|
157 | options.anycoverage = options.cover or options.annotate | |
|
158 | if options.anycoverage: | |
|
159 | try: | |
|
160 | import coverage | |
|
161 | covver = version.StrictVersion(coverage.__version__).version | |
|
162 | if covver < (3, 3): | |
|
163 | parser.error('coverage options require coverage 3.3 or later') | |
|
164 | except ImportError: | |
|
165 | parser.error('coverage options now require the coverage package') | |
|
161 | 166 | |
|
162 |
if options.anycoverage and options. |
|
|
163 | # I'm not sure if this is a fundamental limitation or just a | |
|
164 | # bug. But I don't want to waste people's time and energy doing | |
|
165 | # test runs that don't give the results they want. | |
|
166 | parser.error("sorry, coverage options do not work when --with-hg " | |
|
167 | "or --local specified") | |
|
167 | if options.anycoverage and options.local: | |
|
168 | # this needs some path mangling somewhere, I guess | |
|
169 | parser.error("sorry, coverage options do not work when --local " | |
|
170 | "is specified") | |
|
168 | 171 | |
|
169 | 172 | global vlog |
|
170 | 173 | if options.verbose: |
@@ -390,20 +393,15 b' def installhg(options):' | |||
|
390 | 393 | f.close() |
|
391 | 394 | |
|
392 | 395 | if options.anycoverage: |
|
393 | vlog("# Installing coverage wrapper") | |
|
394 | os.environ['COVERAGE_FILE'] = COVERAGE_FILE | |
|
395 | if os.path.exists(COVERAGE_FILE): | |
|
396 | os.unlink(COVERAGE_FILE) | |
|
397 | # Create a wrapper script to invoke hg via coverage.py | |
|
398 | os.rename(os.path.join(BINDIR, "hg"), os.path.join(BINDIR, "_hg.py")) | |
|
399 | f = open(os.path.join(BINDIR, 'hg'), 'w') | |
|
400 | f.write('#!' + sys.executable + '\n') | |
|
401 | f.write('import sys, os; os.execv(sys.executable, [sys.executable, ' | |
|
402 | '"%s", "-x", "-p", "%s"] + sys.argv[1:])\n' % | |
|
403 | (os.path.join(TESTDIR, 'coverage.py'), | |
|
404 | os.path.join(BINDIR, '_hg.py'))) | |
|
405 | f.close() | |
|
406 | os.chmod(os.path.join(BINDIR, 'hg'), 0700) | |
|
396 | custom = os.path.join(TESTDIR, 'sitecustomize.py') | |
|
397 | target = os.path.join(PYTHONDIR, 'sitecustomize.py') | |
|
398 | vlog('# Installing coverage trigger to %s' % target) | |
|
399 | shutil.copyfile(custom, target) | |
|
400 | rc = os.path.join(TESTDIR, '.coveragerc') | |
|
401 | vlog('# Installing coverage rc to %s' % rc) | |
|
402 | os.environ['COVERAGE_PROCESS_START'] = rc | |
|
403 | fn = os.path.join(INST, '..', '.coverage') | |
|
404 | os.environ['COVERAGE_FILE'] = fn | |
|
407 | 405 | |
|
408 | 406 | def outputcoverage(options): |
|
409 | 407 | |
@@ -411,22 +409,15 b' def outputcoverage(options):' | |||
|
411 | 409 | os.chdir(PYTHONDIR) |
|
412 | 410 | |
|
413 | 411 | def covrun(*args): |
|
414 | start = sys.executable, os.path.join(TESTDIR, 'coverage.py') | |
|
415 | cmd = '"%s" "%s" %s' % (start[0], start[1], ' '.join(args)) | |
|
412 | cmd = 'coverage %s' % ' '.join(args) | |
|
416 | 413 | vlog('# Running: %s' % cmd) |
|
417 | 414 | os.system(cmd) |
|
418 | 415 | |
|
419 | omit = [BINDIR, TESTDIR, PYTHONDIR] | |
|
420 | if not options.cover_stdlib: | |
|
421 | # Exclude as system paths (ignoring empty strings seen on win) | |
|
422 | omit += [x for x in sys.path if x != ''] | |
|
423 | omit = ','.join(omit) | |
|
416 | if options.child: | |
|
417 | return | |
|
424 | 418 | |
|
425 | covrun('-c') # combine from parallel processes | |
|
426 | for fn in os.listdir(TESTDIR): | |
|
427 | if fn.startswith('.coverage.'): | |
|
428 | os.unlink(os.path.join(TESTDIR, fn)) | |
|
429 | ||
|
419 | covrun('-c') | |
|
420 | omit = ','.join([BINDIR, TESTDIR]) | |
|
430 | 421 | covrun('-i', '-r', '"--omit=%s"' % omit) # report |
|
431 | 422 | if options.annotate: |
|
432 | 423 | adir = os.path.join(TESTDIR, 'annotated') |
@@ -668,6 +659,8 b' def runchildren(options, tests):' | |||
|
668 | 659 | optcopy['jobs'] = 1 |
|
669 | 660 | if optcopy['with_hg'] is None: |
|
670 | 661 | optcopy['with_hg'] = os.path.join(BINDIR, "hg") |
|
662 | optcopy.pop('anycoverage', None) | |
|
663 | ||
|
671 | 664 | opts = [] |
|
672 | 665 | for opt, value in optcopy.iteritems(): |
|
673 | 666 | name = '--' + opt.replace('_', '-') |
@@ -729,6 +722,9 b' def runchildren(options, tests):' | |||
|
729 | 722 | _checkhglib("Tested") |
|
730 | 723 | print "# Ran %d tests, %d skipped, %d failed." % ( |
|
731 | 724 | tested, skipped, failed) |
|
725 | ||
|
726 | if options.anycoverage: | |
|
727 | outputcoverage(options) | |
|
732 | 728 | sys.exit(failures != 0) |
|
733 | 729 | |
|
734 | 730 | def runtests(options, tests): |
General Comments 0
You need to be logged in to leave comments.
Login now