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

Module ignored/skipped if EntityFramework enum with default value is used in method #469

Closed
harvzor opened this issue Jun 14, 2019 · 4 comments
Labels
as-designed Expected behaviour

Comments

@harvzor
Copy link

harvzor commented Jun 14, 2019

I made a repo showing the error: https://github.com/Harvzor/coverlet-enum-test

How to reproduce:

  1. clone https://github.com/Harvzor/coverlet-enum-test
  2. run dotnet build
  3. run coverlet ./Tests/bin/Debug/netcoreapp2.1/Tests.dll --target "dotnet" --targetargs "test ./Tests/Tests.csproj --no-build" --format opencover

Expected output:

+--------+--------+--------+--------+
| Module | Line   | Branch | Method |
+--------+--------+--------+--------+
| Source | 0%     | 100%   | 0%     |
+--------+--------+--------+--------+

+---------+--------+--------+--------+
|         | Line   | Branch | Method |
+---------+--------+--------+--------+
| Total   | 0%     | 100%   | 0%     |
+---------+--------+--------+--------+
| Average | 0%     | 100%   | 0%     |
+---------+--------+--------+--------+

Actual output:

+--------+--------+--------+--------+
| Module | Line   | Branch | Method |
+--------+--------+--------+--------+

+---------+--------+--------+--------+
|         | Line   | Branch | Method |
+---------+--------+--------+--------+
| Total   | 100%   | 100%   | 100%   |
+---------+--------+--------+--------+
| Average | ∞%     | ∞%     | ∞%     |
+---------+--------+--------+--------+

In the actual input, there's no module! No warnings are shown.

The issue appears because of this code:

public void SimpleMethod(EntityState entityState = EntityState.Added)
{

}

If the entityState var does not have a default value, then everything works as expected:

public void SimpleMethod(EntityState entityState)
{

}

Versions

coverlet: 1.4.1.0
dotnet: 2.1.505

@MarcoRossignoli
Copy link
Collaborator

Can you try with last version 1.5.2 https://www.nuget.org/packages/coverlet.console/?

@MarcoRossignoli MarcoRossignoli added the needs more info More details are needed label Jun 14, 2019
@harvzor
Copy link
Author

harvzor commented Jun 17, 2019

Updated my dotnet version to 2.2 and updated coverlet to 1.5.2, I'm getting a useful message from the report now:

λ coverlet ./Tests/bin/Debug/netcoreapp2.1/Tests.dll --target "dotnet" --targetargs "test ./Tests/Tests.csproj --no-build" --format opencover
Unable to instrument module: .\Tests\bin\Debug\netcoreapp2.1\Source.dll because : Failed to resolve assembly: 'Microsoft.EntityFrameworkCore, Version=2.1.11.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

Calculating coverage result...
  Generating report 'D:\Dev\Code\coverlet-enum-test\coverage.opencover.xml'
+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 100% | 100%   | 100%   |
+---------+------+--------+--------+
| Average | ∞%   | ∞%     | ∞%     |
+---------+------+--------+--------+

The issue looks related to #21.

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Jun 17, 2019

@harvzor I found the issue...at the moment Cecil resolver does not search on "nuget package" cache.
Update you test project with <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <IsPackable>false</IsPackable>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.11" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Source\Source.csproj" />
  </ItemGroup>

</Project>

So Microsoft.EntityFrameworkCore libs will be copied in output folder and correctly loaded by cecil(we add "test lib path" as probing path).
I advice to exclude also microsoft/xunit lib from instrumentation

C:\git\coverlet-enum-test (master -> origin)                                                                                                                                                                      
λ coverlet ./Tests/bin/Debug/netcoreapp2.1/Tests.dll --target "dotnet" --targetargs "test ./Tests/Tests.csproj --no-build" --format opencover  --verbosity detailed --exclude [Microsoft*]* --exclude [xunit*]*   
Excluded module filter '[Microsoft*]*'                                                                                                                                                                            
Excluded module filter '[xunit*]*'                                                                                                                                                                                
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.EntityFrameworkCore.Abstractions.dll'                                                                                                                 
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.EntityFrameworkCore.dll'                                                                                                                              
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.Extensions.Caching.Abstractions.dll'                                                                                                                  
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.Extensions.Caching.Memory.dll'                                                                                                                        
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.Extensions.Configuration.Abstractions.dll'                                                                                                            
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.Extensions.Configuration.Binder.dll'                                                                                                                  
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.Extensions.Configuration.dll'                                                                                                                         
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.Extensions.DependencyInjection.Abstractions.dll'                                                                                                      
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.Extensions.DependencyInjection.dll'                                                                                                                   
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.Extensions.Logging.Abstractions.dll'                                                                                                                  
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.Extensions.Logging.dll'                                                                                                                               
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.Extensions.Options.dll'                                                                                                                               
Excluded module: '.\Tests\bin\Debug\netcoreapp2.1\Microsoft.Extensions.Primitives.dll'                                                                                                                            
Instrumented module: '.\Tests\bin\Debug\netcoreapp2.1\Source.dll'                                                                                                                                                 
                                                                                                                                                                                                                  
Calculating coverage result...                                                                                                                                                                                    
Hits file:'C:\Users\Marco\AppData\Local\Temp\Source_9abb458b-019a-4a50-8399-14eab4bf251f' not found for module: 'Source'                                                                                          
  Generating report 'C:\git\coverlet-enum-test\coverage.opencover.xml'                                                                                                                                            
+--------+------+--------+--------+                                                                                                                                                                               
| Module | Line | Branch | Method |                                                                                                                                                                               
+--------+------+--------+--------+                                                                                                                                                                               
| Source | 0%   | 100%   | 0%     |                                                                                                                                                                               
+--------+------+--------+--------+                                                                                                                                                                               
                                                                                                                                                                                                                  
+---------+------+--------+--------+                                                                                                                                                                              
|         | Line | Branch | Method |                                                                                                                                                                              
+---------+------+--------+--------+                                                                                                                                                                              
| Total   | 0%   | 100%   | 0%     |                                                                                                                                                                              
+---------+------+--------+--------+                                                                                                                                                                              
| Average | 0%   | 100%   | 0%     |                                                                                                                                                                              
+---------+------+--------+--------+                                                                                                                                                                              
                                                                                                                                                                                                                  

No coverlet correctly tell you that coverage file for Source.dll lib isn't found because you don't have any test so no code has got covered, btw we cannot be more "precise" on the reason..because file could be missing for mainly 2 reason

https://github.com/tonerdo/coverlet/blob/5a139b200f7bf51c21660b93f41906f4571c971b/src/coverlet.core/Coverage.cs#L231

Let me know if we can close this.

@MarcoRossignoli MarcoRossignoli added as-designed Expected behaviour and removed needs more info More details are needed labels Jun 17, 2019
@harvzor
Copy link
Author

harvzor commented Jun 17, 2019

Thanks I can confirm that adding <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> worked:

harvzor/coverlet-enum-test@64e6d2b

Thanks for the extra advice too!

@harvzor harvzor closed this as completed Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as-designed Expected behaviour
Projects
None yet
Development

No branches or pull requests

2 participants