opencover icon indicating copy to clipboard operation
opencover copied to clipboard

Add support for lcov output

Open chintans opened this issue 9 years ago • 6 comments

Please provide the following information when submitting an issue, where appropriate replace the [ ] with a [X]

My Framework

  • [ ] .NET 2
  • [ ] .NET 3.5
  • [ ] .NET 4
  • [ ] .NET 4.5
  • [ ] .NET 4.6
  • [ ] .NET 4.6.1
  • [ ] .NET 4.6.2
  • [ ] .NET Core 1.0.0
  • [X] Something else

My Environment

  • [ ] Windows 7 or below (not truly supported due to EOL)
  • [ ] Windows 8
  • [ ] Windows 8.1
  • [ ] Windows 10
  • [ ] Windows 10 IoT Core
  • [ ] Windows Server 2012
  • [ ] Windows Server 2012 R2
  • [ ] Windows Server 2016

I have already...

  • [ ] repeated the problem using the latest stable release of OpenCover.
  • [X] reviewed the usage guide and usage document.
  • [ ] have looked at the opencover output XML file in an attempt to resolve the issue.
  • [X] reviewed the current issues to check that the issue isn't already known.

My issue is related to (check only those which apply):

  • [ ] no coverage being recorded
  • [ ] 32 or 64 bit support
  • [X] feature request

Expected Behavior

Many of the modern projects have a lot of the logic written on front-end in a javascript framework. Most of the javascript testing framework and coverage frameworks generate lcov file for coverage. When, we use code coverage reporter service like coveralls. They take a single file as input. It can either be OpenCover.xml or coverage.lcov. If we want to combine both files, we wither have to do XML to lcov or lcov to XML conversion and merge both files and submit it to the service. It becomes hectic for each project. It would be a nice feature we could specify lcov format of output in opencover. Then we are left with the task of merging the files only.

Just to summarise, I am looking for support of lcov output format.

Actual Behavior

Fill me in...

Steps to reproduce the problem:

Fill me in...

chintans avatar Nov 22 '16 06:11 chintans

do you have the XML to LCOV converter - perhaps we can just chain that in.

sawilde avatar Nov 22 '16 22:11 sawilde

I tried searching for it but couldn't find anything useful.

chintans avatar Nov 23 '16 11:11 chintans

If we want to combine both files, we wither have to do XML to lcov or lcov to XML conversion and merge both files and submit it to the service

I assumed from this statement it was something you were doing already - no worries.

sawilde avatar Nov 23 '16 20:11 sawilde

The LCOV format is really as simple as documented here -- a whole lot of sections, starting with a TN: (which can be empty) and an SF: for the file which this block is concerned with, then all the other records, and ending with end_of_record.

SteveGilham avatar Sep 03 '17 12:09 SteveGilham

Here's a quick and dirty powershell script that should do OpenCover to lcov format; the main thing that might need tweaking is the branch block-number, which I've used the offset value for. If this has to be unique across more than a single method, then it would want to be something like (offset + 1000 * line number) to make unique per file

param ([string]$OpenCoverPath)

$x = [xml](Get-Content $OpenCoverPath)
$x.CoverageSession.Modules.Module.Files.File | % {
  Write-Output "TN:"
  Write-Output "SF:$($_.fullPath)"
  $uid = $_.uid
  $p = $_.ParentNode.ParentNode
  $methods = $p.Classes.Class.Methods.Method | ? { $_.FileRef.uid -eq $uid } 
  $methods | % {
    $s = $_.SequencePoints.SequencePoint
    if ($s) {
        $l = $s[0].sl
        if($l) {
            Write-Output "FN:$l,$($_.Name)"
        }
    }
  }

  $methods | % {
      $s = $_.SequencePoints.SequencePoint
      if ($s) {
        $l = $s[0].sl
        if($l) {
            Write-Output "FNDA:$($_.MethodPoint.vc),$($_.Name)"
        }
      }
  }

  Write-Output "FNF:$($Methods.Length)"
  $hit = $methods | ? { $_.visited -eq "true" }
  Write-Output "FNH:$($hit.Length)"

  $brf = 0
  $brh = 0
  $methods | % {
      $_.Branchpoints.BranchPoint | % {
         if ($_.sl) {
            $brf += 1
            if ([int]($_.vc)) { $brh += 1 }
            Write-Output "BRDA:$($_.sl),$($_.offset),$($_.path),$($_.vc)"
        }
      }
  }
  Write-Output "BRF:$brf"
  Write-Output "BRH:$brh"

  $lf = 0
  $lh = 0
  $methods | % {
      $_.SequencePoints.SequencePoint | % {
         if ($_.sl) {
            $lf += 1
            if ([int]($_.vc)) { $lh += 1 }
            Write-Output "DA:$($_.sl),$($_.vc)"
        }
      }
  }
  Write-Output "LF:$lf"
  Write-Output "LH:$lh"

  Write-Output "end_of_record"
}

SteveGilham avatar Sep 03 '17 13:09 SteveGilham

It will be great, because on vscode there is only Coverage plugins that use lcov format and no one other support xml report from Open Coverage.

equiman avatar Jan 23 '18 13:01 equiman