danielpalme/ReportGenerator

Strange source file references in a HTML report from dotnet-coverage on Linux

Closed this issue · 1 comments

Describe the bug
In a Linux docker setup, dotnet-coverage is used to collect coverage data and save into an XML file.

The target application is NopCommerce (https://github.com/nopSolutions/nopCommerce) that is

  • debug compiled
  • debug published
  • run with 'dotnet-coverage collect'
    The attached Dockerfile.txt shows how the NopCommerce web image is created
    The attached entrypoint.sh.txt shows how the NopCommerce web is run with dotnet-coverage in the Docker container.

The report generator is used to create the HTML output based on the XML file.
The generated source file references, in the HTML report, are not correct and not useful.

To Reproduce
The following input helps to reproduce your issue:

  1. Clone NopCommerce repo. Build NopCommerce web Docker image using the attached Dockerfile. The following docs describe the setup procedures: https://docs.nopcommerce.com/en/developer/tutorials/docker.html)
  2. Run NopCommerce in the Docker setup and perform some manual or automated test.
  3. Extract the generated dotnet-coverage XML as 'test_1.xml'
  4. Use the report generator: reportgenerator -reports:test_1.xml -targetdir:./test_1. This command can be tried both in the Linux Docker container or on the host.

Some examples how source file references are stored in the XML:

 <source_files>
        <source_file id="0" path="/src/Libraries/Nop.Core/obj/Debug/net8.0/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs" checksum_type="SHA1" checksum="5A3634E095356C1C744D983F21D854FAC5DA65C8" />
        <source_file id="1" path="/src/Libraries/Nop.Core/BaseEntity.cs" checksum_type="SHA256" checksum="E61E59CC5CE760C9C2FB3E763A1296B616B73B7525F20ED708BDA22557ACFBFD" />

Example how the HTML output presents a file reference: attached

Small files can be send as an attachment. Large files should can be shared via Dropbox, Google Drive, Onedrive.
Shared files are treated confidentially and will be deleted after the issue is resolved.
Dockerfile.txt
entrypoint.sh.txt
Coverage

The paths starting with /src/ are only valid within the running container.

If you generate the coverage report inside the container, the file(s) can be found and are listed in the report.
Example /src/Libraries/Nop.Core/Domain/Messages/EmailAccount.cs:

image

If you want to generate the coverage report outside your container, you have to adjust the paths, so that they match your local path.
You can do this with a powershell script:

(gc "test_1.xml") | % { $_ -replace "/src/", "/real/path/" } | Out-File "test_1.xml" -Encoding UTF8