Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage: use nuget package #1737

Conversation

martin-strecker-sonarsource
Copy link
Contributor

@martin-strecker-sonarsource martin-strecker-sonarsource commented Oct 31, 2023

Based on #1736
To Dos

  • Remove ICoverageReportConverter.Initialize() (follow-up PR)
  • Remove (whole or in parts) of IVisualStudioSetupConfigurationFactory (follow-up PR)
  • Check the usage of the resx resources 54f16bc
  • Look for alternatives to the "change the global culture and reset" approach. Open a ticket in the MSTest repo if needed. CoverageFileUtility.ConvertCoverageFile is culture depended microsoft/codecoverage#63
  • Add a test that runs util.ConvertCoverageFile in a problematic culture like "de-DE" (1.123d is serialized as 1,123) 1d63afd
  • Add tests for ApplicationCultureInfo 2ad12e3
  • Remove CodeCoverageExeTestMethodAttribute 4b89eed

Fixes #1652

@martin-strecker-sonarsource martin-strecker-sonarsource changed the title Martin/code voerage use nuget package Cde coverage: use nuget package Oct 31, 2023
@costin-zaharia-sonarsource costin-zaharia-sonarsource deleted the branch feature/BreakingChanges October 31, 2023 14:23
@costin-zaharia-sonarsource costin-zaharia-sonarsource changed the title Cde coverage: use nuget package Code coverage: use nuget package Oct 31, 2023
@martin-strecker-sonarsource
Copy link
Contributor Author

martin-strecker-sonarsource commented Oct 31, 2023

The XML Serializer does not set any culture. This results in "," vs "." problems in the conversion (see e.g. block_coverage). There seems to be no way to set the Microsoft.CodeCoverage.Core.IO.XmlObjectSerializer.XmlWriterSettings for a specific culture. It seems we have to resort to setting the default culture of the appdomain and resetting it afterward.

Before:

<?xml version="1.0" encoding="UTF-8" ?>
<results>
  <modules>
    <module name="consoleapp2.dll" path="consoleapp2.dll" id="24DC3BD206049A4BBC0F96655A7CC2A601000000" 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">

After:

<?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" id="24DC3BD206049A4BBC0F96655A7CC2A601000000">

@martin-strecker-sonarsource
Copy link
Contributor Author

                util.ConvertCoverageFile(
                    path: inputBinaryFilePath,
                    outputPath: outputXmlFilePath,
                    includeSkippedFunctions: true,
                    includeSkippedModules: true);

includeSkippedFunctions and includeSkippedModules add <skipped_functions> and <skipped_module> entries:

    <module block_coverage="100,00" line_coverage="100,00" blocks_covered="3" blocks_not_covered="0" lines_covered="4" lines_partially_covered="0" lines_not_covered="0" name="testproject1.dll" path="testproject1.dll" id="9FEC91B69E3A6F429ABE0FF734AB036A01000000">
      <functions>
        <function block_coverage="100,00" line_coverage="100,00" blocks_covered="3" blocks_not_covered="0" lines_covered="4" lines_partially_covered="0" lines_not_covered="0" id="8284" token="0x6000003" name="TestMethod1()" namespace="TestProject1" type_name="UnitTest1">
          <ranges>
            <range source_id="0" covered="yes" start_line="9" start_column="9" end_line="9" end_column="10" />
            <range source_id="0" covered="yes" start_line="10" start_column="13" end_line="10" end_column="43" />
            <range source_id="0" covered="yes" start_line="11" start_column="13" end_line="11" end_column="35" />
            <range source_id="0" covered="yes" start_line="12" start_column="9" end_line="12" end_column="10" />
          </ranges>
        </function>
      </functions>
      <skipped_functions>
        <skipped_function id="8272" original_id="8272" token="0x6000001" name="Main(string[])" type_name="AutoGeneratedProgram" reason="attribute_excluded" />
      </skipped_functions>
      <source_files>
        <source_file id="0" path="E:\ConsoleApp2\TestProject1\UnitTest1.cs" checksum_type="SHA256" checksum="1E5F51A4FC20C14E35B72D29D21E6372AA9BA14E42E52F33FB7ABC8AA21C1C96" />
      </source_files>
    </module>
  </modules>
  <skipped_modules>
    <skipped_module name="clrjit.dll" path="clrjit.dll" reason="path_is_excluded" />
    <skipped_module name="icu.dll" path="icu.dll" reason="no_symbols" />

We probably want this to be turned off.

@martin-strecker-sonarsource
Copy link
Contributor Author

The current generated file looks a bit different than the expected file, but the content is the same:

https://www.diffchecker.com/5GRnrmvr/

Base automatically changed from Martin/UpgradeProjects to feature/BreakingChanges November 3, 2023 10:06
Copy link

sonarcloud bot commented Nov 3, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@costin-zaharia-sonarsource costin-zaharia-sonarsource marked this pull request as ready for review November 6, 2023 09:34
@andrei-epure-sonarsource andrei-epure-sonarsource merged commit 567335b into feature/BreakingChanges Nov 6, 2023
23 of 24 checks passed
@andrei-epure-sonarsource andrei-epure-sonarsource deleted the Martin/CodeVoerage_UseNugetPackage branch November 6, 2023 09:46
costin-zaharia-sonarsource added a commit that referenced this pull request Nov 20, 2023
costin-zaharia-sonarsource added a commit that referenced this pull request Nov 20, 2023
@antonioaversa antonioaversa added this to the 6.0.0 milestone Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants