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

.NET coverage #20

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/net.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: .NET - coverlet test coverage

on:
workflow_dispatch:
pull_request:
push:
branches:
- main
- 'releases/*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0'

- name: Restore dependencies
working-directory: NET/coverlet
run: dotnet restore

- name: Build solution
working-directory: NET/coverlet
run: dotnet build --no-restore

- name: Change directory to test project
working-directory: NET/coverlet
run: |
dotnet add package coverlet.msbuild

- name: Run tests with code coverage
run: dotnet test /p:CollectCoverage=true /p:CoverletOutput=./.qodana/code-coverage /p:CoverletOutputFormat=lcov
working-directory: NET/coverlet

- name: Archive coverage data
uses: actions/upload-artifact@v2
with:
name: net-coverage-data
path: NET/coverlet/.qodana/code-coverage

- name: Qodana Scan
uses: JetBrains/qodana-action@main
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN_NET }}
with:
args: "-i,NET/coverlet,--linter,jetbrains/qodana-dotnet:latest"
pr-mode: false
44 changes: 44 additions & 0 deletions NET/coverlet/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace QodanaCoverageTest;

public class Class1 : Interface1
{
public Class1()
{
var y = 5;
}

public void UsedMethod()
{
LocalMethod();
void LocalMethod()
{
var x = 5;
}
void UnusedLocalMethod() { }
}

public void UsedMethodWithIf(int i)
{
if (i == 1)
{
Console.Write(i);
}
else
{
Console.Write(i);
Console.Write(i);
}
}

public int UsedLambdaMethod() => 4;

public int UnusedLambdaMethod() => 5;

private void UnusedMethod()
{
void UnusedLocalMethod()
{

}
}
}
28 changes: 28 additions & 0 deletions NET/coverlet/Class2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace QodanaCoverageTest;

public class Class2
{
public Class2()
{

}

public void UnusedMethod()
{

}

public int MyProperty => 42;

public int MyProperty1
{
get => MyProperty;
set => MyProperty = value;
}

public int MyProperty2
{
get;
set;
}
}
7 changes: 7 additions & 0 deletions NET/coverlet/Enum1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace QodanaCoverageTest;

public enum Enum1
{
VAL1,
VAL2,
}
14 changes: 14 additions & 0 deletions NET/coverlet/Interface1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace QodanaCoverageTest;

public interface Interface1
{
void Foo()
{

}

void Bar()
{

}
}
22 changes: 22 additions & 0 deletions NET/coverlet/NotInReportClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace QodanaCoverageTest;

public class NotInReportClass : Interface1
{
public Class1()
{
var y = 42;
}

public void UsedMethodWithIf(int i)
{
if (i == 1)
{
Console.Write(i);
}
else
{
Console.Write(i);
Console.Write(i);
}
}
}
21 changes: 21 additions & 0 deletions NET/coverlet/QodanaCoverageTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="UnitTestProject\**" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Remove="UnitTestProject\**" />
</ItemGroup>

<ItemGroup>
<None Remove="UnitTestProject\**" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions NET/coverlet/QodanaCoverageTest.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QodanaCoverageTest", "QodanaCoverageTest.csproj", "{2849E952-A756-4191-AC98-AF80D2848500}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestProject", "UnitTestProject\UnitTestProject.csproj", "{4ED497EE-E195-4408-B5B9-861FED661884}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2849E952-A756-4191-AC98-AF80D2848500}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2849E952-A756-4191-AC98-AF80D2848500}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2849E952-A756-4191-AC98-AF80D2848500}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2849E952-A756-4191-AC98-AF80D2848500}.Release|Any CPU.Build.0 = Release|Any CPU
{4ED497EE-E195-4408-B5B9-861FED661884}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4ED497EE-E195-4408-B5B9-861FED661884}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4ED497EE-E195-4408-B5B9-861FED661884}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4ED497EE-E195-4408-B5B9-861FED661884}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions NET/coverlet/UnitTestProject/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using QodanaCoverageTest;

namespace UnitTestProject;

public class Tests
{
[SetUp]
public void Setup()
{
}

[Test]
public void Test1()
{
var cls = new Class1();
cls.UsedMethod();
cls.UsedMethodWithIf(1);
cls.UsedLambdaMethod();
Assert.Pass();
}
}
22 changes: 22 additions & 0 deletions NET/coverlet/UnitTestProject/UnitTestProject.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2"/>
<PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0"/>
<PackageReference Include="NUnit.Analyzers" Version="3.5.0"/>
</ItemGroup>

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

</Project>
1 change: 1 addition & 0 deletions NET/coverlet/UnitTestProject/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using NUnit.Framework;
Loading