~allanlesage/+junk/gcovr-packaging

« back to all changes in this revision

Viewing changes to scripts/gcovr

  • Committer: wehart
  • Date: 2010-11-26 21:54:29 UTC
  • Revision ID: svn-v4:c9093e8b-e624-0410-814a-e3c5b6d4c2ac:gcovr/trunk:2517
Adding error checking when no coverage results are found.  The line and
branch counts can be zero...

Adding logic to process the -o/--output option.  (Resolves #3870)

Show diffs side-by-side

added added

removed removed

Lines of Context:
382
382
    def _alpha(key):
383
383
        return key
384
384
 
 
385
    if options.output:
 
386
        OUTPUT = open(options.output,'w')
 
387
    else:
 
388
        OUTPUT = sys.stdout
385
389
    total_lines=0
386
390
    total_covered=0
387
391
    # Header
388
 
    print "-"*78
 
392
    print >>OUTPUT, "-"*78
389
393
    a = options.show_branch and "Branch" or "Lines"
390
394
    b = options.show_branch and "Taken" or "Exec"
391
 
    print "File".ljust(40) + a.rjust(8) + b.rjust(8)+ "  Cover   Missing"
392
 
    print "-"*78
 
395
    print >>OUTPUT, "File".ljust(40) + a.rjust(8) + b.rjust(8)+ "  Cover   Missing"
 
396
    print >>OUTPUT, "-"*78
393
397
 
394
398
    # Data
395
399
    keys = covdata.keys()
399
403
        (t, n, txt) = covdata[key].summary(options.root)
400
404
        total_lines += t
401
405
        total_covered += n
402
 
        print txt
 
406
        print >>OUTPUT, txt
403
407
 
404
408
    # Footer & summary
405
 
    print "-"*78
 
409
    print >>OUTPUT, "-"*78
406
410
    percent = total_lines and str(int(100.0*total_covered/total_lines)) or "--"
407
 
    print "TOTAL".ljust(40) + str(total_lines).rjust(8) + \
 
411
    print >>OUTPUT, "TOTAL".ljust(40) + str(total_lines).rjust(8) + \
408
412
          str(total_covered).rjust(8) + str(percent).rjust(6)+"%"
409
 
    print "-"*78
 
413
    print >>OUTPUT, "-"*78
 
414
 
 
415
    # Close logfile
 
416
    if options.output:
 
417
        OUTPUT.close()
410
418
 
411
419
#
412
420
# Produce an XML report in the Cobertura format
437
445
        "http://cobertura.sourceforge.net/xml/coverage-03.dtd" )
438
446
    doc = impl.createDocument(None, "coverage", docType)
439
447
    root = doc.documentElement
440
 
    root.setAttribute("line-rate", str(lineCovered * 1.0 / lineTotal))
441
 
    root.setAttribute("branch-rate", str(branchCovered * 1.0 / branchTotal))
 
448
    if lineTotal == 0:
 
449
        root.setAttribute("line-rate", '0.0')
 
450
    else:
 
451
        root.setAttribute("line-rate", str(lineCovered * 1.0 / lineTotal))
 
452
    if branchTotal == 0:
 
453
        root.setAttribute("branch-rate", '0.0')
 
454
    else:
 
455
        root.setAttribute("branch-rate", str(branchCovered * 1.0 / branchTotal))
442
456
        
443
457
    if options.root is not None:
444
458
        source = doc.createElement("source")
532
546
 
533
547
 
534
548
    xmlString = doc.toprettyxml()
535
 
    print xmlString
536
549
    #xml.dom.ext.PrettyPrint(doc)
 
550
    if options.output is None:
 
551
        print xmlString
 
552
    else:
 
553
        OUTPUT = open(options.output, 'w')
 
554
        print >>OUTPUT, xmlString
 
555
        OUTPUT.close()
537
556
 
538
557
 
539
558
##