microsoft/codecoverage

CoverageFileUtility.ConvertCoverageFile is culture depended

martin-strecker-sonarsource opened this issue · 6 comments

Version used

Microsoft.CodeCoverage.IO 17.7.0 https://www.nuget.org/packages/Microsoft.CodeCoverage.IO/17.7.0

Steps to reproduce

  1. Take a binary coverage file like this one: Sample.coverage
  2. Convert on a machine with a culture that has a decimal separator different from . like "de-DE".
using Microsoft.CodeCoverage.IO;
using System.Globalization;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var culture = CultureInfo.CreateSpecificCulture("de-DE"); // change this to "en-US" to get the expected outcome
            CultureInfo.DefaultThreadCurrentCulture = culture;
            CultureInfo.DefaultThreadCurrentUICulture = culture;
            new CoverageFileUtility().ConvertCoverageFile(
                path: "Sample.coverage",
                outputPath: "Sample.xmlcoverage",
                includeSkippedFunctions: false,
                includeSkippedModules: false);
        }
    }
}

Expected output

The Sample.xmlcoverage is serialized in a culture-neutral manner, e.g. block_coverage="33.33":

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<results>
  <modules>
    <module block_coverage="33.33" line_coverage="25.00" blocks_covered="1" blocks_not_covered="2" lines_covered="1" lines_partially_covered="0" lines_not_covered="3" name="consoleapp2.dll" path="consoleapp2.dll" 

Actual output

The Sample.xmlcoverage contains , as decimal separator block_coverage="33,33":

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<results>
  <modules>
    <module block_coverage="33,33" line_coverage="25,00" blocks_covered="1" blocks_not_covered="2" lines_covered="1" lines_partially_covered="0" lines_not_covered="3" name="consoleapp2.dll" path="consoleapp2.dll" 

This bug has been fixed, it will be available in the upcoming release.

Hi @mariam-abdulla, do you have an ETA for the next release?

Hi @costin-zaharia-sonarsource,
Visual Studio 17.9 has already been released on 13th February.

Hi @mariam-abdulla, We are using https://www.nuget.org/packages/Microsoft.CodeCoverage.IO, which includes CoverageFileUtility.ConvertCoverageFile, and we're interested in its release date.

@costin-zaharia-sonarsource @martin-strecker-sonarsource generally we recommend using dotnet-coverage merge to convert 1 report to another. You can find example here: https://learn.microsoft.com/en-us/dotnet/core/additional-tools/dotnet-coverage#merge-code-coverage-reports

Microsoft.CodeCoverage.IO is deprecated.

If you want to continue using direct approach you can try to use: CoverageFileUtilityV2 in https://dev.azure.com/dnceng/public/_artifacts/feed/test-tools/NuGet/Microsoft.CodeCoverage.Core/overview/17.10.3
Keep in mind that package is internal and you are using it on your own risk. We can easily break contract in upcoming releases.

Hi @jakubch1, thanks for the links. We will probably go with the internal package.