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

Cannot exclude auto-generated code from code coverage with .runsettings file #123

Open
cliffAtOsaic opened this issue May 30, 2024 · 3 comments
Assignees

Comments

@cliffAtOsaic
Copy link

cliffAtOsaic commented May 30, 2024

Description

Cannot exclude auto-generated code from code coverage with .runsettings file.

We are importing ElasticSearch which generates code under the path "/_/src/Elastic.Clients.Elasticsearch/_Generated" which is then deleted after the build is complete. (I cannot find this code when I search; we have no src and no _Generated directories.)

In our .runsettings file, I have tried multiple ways to exclude the ElasticSearch DLLs and the ElasticSearch generated code with negative results.

<ModulePaths>
    <Include>
      <!-- Include all loaded .dll assemblies (but not .exe assemblies): -->
      <ModulePath>.*\.dll$</ModulePath>
    </Include>
    <Exclude>
      <!-- But exclude some assemblies: -->
      <ModulePath>.*\Elastic.Clients.Elasticsearch.dll$</ModulePath>
      <ModulePath>.*\Elastic.Transport.dll$</ModulePath>
      <!-- Exclude all file paths that contain "Temp": -->
      <ModulePath>.*Temp.*</ModulePath>
      <ModulePath>.*src.*</ModulePath>
      <ModulePath>.*_Generated.*</ModulePath>
    </Exclude>
  </ModulePaths>

  <Functions>
    <Exclude>
      <Function>^Elastic.Clients.Elasticsearch.*</Function>
    </Exclude>
  </Functions>

  <Sources>
    <Exclude>
      <Source>.*src.*</Source>
      <Source>.*_Generated.*</Source>
    </Exclude>
  </Sources>

Steps to reproduce

What steps can reproduce the defect?

  1. Import ElasticSearch
  2. Create a .runsettings file with the code snippit above.
  3. Run the following command:
    dotnet-coverage collect -f cobertura,coverage "dotnet test --logger trx" -s .\.runsettings

Expected behavior

Auto-generated source code under the "src" and/or "_Generated" directories are excluded from code coverage.

Actual behavior

All auto-generated source code under the "src" and/or "_Generated" directories is included with code covaerage.

Diagnostic logs

log.txt

Environment

Windows 11 Version 23H2 (OS Build 22631.3447)
dotnet --version = 8.0.204

@nohwnd
Copy link
Member

nohwnd commented May 31, 2024

@fhnaseer plese help here if you can :)

@fhnaseer fhnaseer transferred this issue from microsoft/vstest Jun 3, 2024
@fhnaseer fhnaseer self-assigned this Jun 3, 2024
@fhnaseer
Copy link
Member

fhnaseer commented Jun 3, 2024

@cliffAtOsaic <Include>/<Exclude> are regex patterns. Can you please check if your source path/module path match patterns provided in runsettings?
If it still persists, then can you please provide a small repro solution?

@cliffAtOsaic
Copy link
Author

@cliffAtOsaic <Include>/<Exclude> are regex patterns. Can you please check if your source path/module path match patterns provided in runsettings? If it still persists, then can you please provide a small repro solution?

Just seeing this; not sure why I didn't get an email. I'll take a look at this tomorrow and post what I learn. Thanks!

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

No branches or pull requests

3 participants