microsoft / codecoverage

MIT License
84 stars 11 forks source link

dotnet-coverage 17.8.4 doesn't report module info in XML output when .runsettings file specified #45

Closed pdxcodemonkey closed 1 year ago

pdxcodemonkey commented 1 year ago

We use the following .runsettings file for our coverage runs:

<?xml version="1.0" encoding="utf-8"?>
<Configuration>
  <CodeCoverage>
    <ModulePaths>
      <Include>
        <ModulePath>name.of.our.dll</ModulePath>
      </Include>
    </ModulePaths>
    <Functions>
      <Exclude>
        <Function>.*MoveNext.*</Function>
      </Exclude>
    </Functions>
  </CodeCoverage>
</Configuration>

Our command line is as follows:

dotnet-coverage collect dotnet test -f xml -l coverage.log -ll Verbose --settings CodeCoverage.runsettings

Our CI pipeline recently picked up v17.8.4 of dotnet-coverage, and when run as shown above the output.xml file contains no <modules> node, only <skipped_modules>. This has worked perfectly up to and including v17.8.3.

jakubch1 commented 1 year ago

Could you please include all logs and result coverage report?

jakubch1 commented 1 year ago

As workaround you can specify in pipeline version 17.8.3 when installing dotnet-coverage

jakubch1 commented 1 year ago

@pdxcodemonkey I will still investigate why we got this change but correct configuration should be:

<?xml version="1.0" encoding="utf-8"?>
<Configuration>
  <CodeCoverage>
    <ModulePaths>
      <Include>
        <ModulePath>.*name.of.our.dll$</ModulePath>
      </Include>
    </ModulePaths>
    <Functions>
      <Exclude>
        <Function>.*MoveNext.*</Function>
      </Exclude>
    </Functions>
  </CodeCoverage>
</Configuration>

You need to add .* to module path as it is regex checked against full path of the file.

pdxcodemonkey commented 1 year ago

coverage.log output.xml.txt

Thanks for the prompt replies! We have already pinned the version back to 17.8.3 in our CI pipeline, as you suggested. As above, I've replaced the real library name(s) with "name.of.my," e.g. "name.of.my.dll", "name.of.my.test.unit.dll", etc. And I do see the following in coverage.log:

2023-08-22 13:40:54.483 -07:00 [VRB] ProcessFactory: Starting process: fileName: dotnet, arguments: "test" "name.of.my.test.unit"
2023-08-22 13:41:01.102 -07:00 [INF] LoggerBase.CreateStream[52776]: k:StreamKey { Id = 4e9ed5f1-a601-4958-ba57-e40c4101296c, Prefix = entrypoint:\ } type:b157a3a4-9542-4546-859b-abd1367a08ed path:c:\Users\bblake\src\dot-net-client\name.of.my.test.unit\bin\Debug\net6.0\testhost.exe
2023-08-22 13:41:24.189 -07:00 [VRB] CoverageMessagesReader.ReadSkippedModules: path: name.of.my.test.unit.dll, skipReason: path_is_excluded.
2023-08-22 13:41:24.189 -07:00 [VRB] CoverageMessagesReader.ReadSkippedModules: path: name.of.my.dll, skipReason: path_is_excluded.
2023-08-22 13:41:24.190 -07:00 [VRB] CoverageMessagesReader.ReadSkippedModules: path: name.of.my.test.framework.dll, skipReason: path_is_excluded.

Which makes sense, given what you say about using regexes. I will tweak the format of our .runsettings file and verify that it works with 17.8.4.

One other thing I should mention, that seemed strange - this appears to be specific to Windows (?). We run coverage for RHEL-9 and Ubuntu-22 as well, and the Linux platforms haven't had any problems.

pdxcodemonkey commented 1 year ago

Confirmed, the change to my .runsettings works with 17.8.4, and also FYI with 17.8.3. Thanks again for the help!