From 91757993984326d413768bddfbea4e682dc6427b Mon Sep 17 00:00:00 2001
From: hybloid <48032702+hybloid@users.noreply.github.com>
Date: Wed, 28 Aug 2024 10:47:24 +0200
Subject: [PATCH] .NET coverage (#20)
* Provide example for .NET coverage
* Remove coverlet from refs
---
.github/workflows/net.yml | 51 +++++++++++++++++++
NET/coverlet/Class1.cs | 44 ++++++++++++++++
NET/coverlet/Class2.cs | 28 ++++++++++
NET/coverlet/Enum1.cs | 7 +++
NET/coverlet/Interface1.cs | 14 +++++
NET/coverlet/NotInReportClass.cs | 22 ++++++++
NET/coverlet/QodanaCoverageTest.csproj | 21 ++++++++
NET/coverlet/QodanaCoverageTest.sln | 22 ++++++++
NET/coverlet/UnitTestProject/UnitTest1.cs | 21 ++++++++
.../UnitTestProject/UnitTestProject.csproj | 22 ++++++++
NET/coverlet/UnitTestProject/Usings.cs | 1 +
NET/coverlet/qodana.yaml | 2 +
12 files changed, 255 insertions(+)
create mode 100644 .github/workflows/net.yml
create mode 100644 NET/coverlet/Class1.cs
create mode 100644 NET/coverlet/Class2.cs
create mode 100644 NET/coverlet/Enum1.cs
create mode 100644 NET/coverlet/Interface1.cs
create mode 100644 NET/coverlet/NotInReportClass.cs
create mode 100644 NET/coverlet/QodanaCoverageTest.csproj
create mode 100644 NET/coverlet/QodanaCoverageTest.sln
create mode 100644 NET/coverlet/UnitTestProject/UnitTest1.cs
create mode 100644 NET/coverlet/UnitTestProject/UnitTestProject.csproj
create mode 100644 NET/coverlet/UnitTestProject/Usings.cs
create mode 100644 NET/coverlet/qodana.yaml
diff --git a/.github/workflows/net.yml b/.github/workflows/net.yml
new file mode 100644
index 0000000..3f2f43a
--- /dev/null
+++ b/.github/workflows/net.yml
@@ -0,0 +1,51 @@
+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: Add coverlet dependencies
+ working-directory: NET/coverlet/UnitTestProject
+ run: |
+ dotnet add package coverlet.msbuild; dotnet add package coverlet.collector
+
+ - name: Build solution
+ working-directory: NET/coverlet
+ run: dotnet build
+
+ - 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
diff --git a/NET/coverlet/Class1.cs b/NET/coverlet/Class1.cs
new file mode 100644
index 0000000..65f6640
--- /dev/null
+++ b/NET/coverlet/Class1.cs
@@ -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()
+ {
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/NET/coverlet/Class2.cs b/NET/coverlet/Class2.cs
new file mode 100644
index 0000000..ef5fd32
--- /dev/null
+++ b/NET/coverlet/Class2.cs
@@ -0,0 +1,28 @@
+namespace QodanaCoverageTest;
+
+public class Class2
+{
+ public Class2()
+ {
+
+ }
+
+ public void UnusedMethod()
+ {
+
+ }
+
+ public int MyProperty => 42;
+
+ public int MyProperty1
+ {
+ get => MyProperty;
+ set => MyProperty2 = value;
+ }
+
+ public int MyProperty2
+ {
+ get;
+ set;
+ }
+}
\ No newline at end of file
diff --git a/NET/coverlet/Enum1.cs b/NET/coverlet/Enum1.cs
new file mode 100644
index 0000000..645756f
--- /dev/null
+++ b/NET/coverlet/Enum1.cs
@@ -0,0 +1,7 @@
+namespace QodanaCoverageTest;
+
+public enum Enum1
+{
+ VAL1,
+ VAL2,
+}
\ No newline at end of file
diff --git a/NET/coverlet/Interface1.cs b/NET/coverlet/Interface1.cs
new file mode 100644
index 0000000..49fe44b
--- /dev/null
+++ b/NET/coverlet/Interface1.cs
@@ -0,0 +1,14 @@
+namespace QodanaCoverageTest;
+
+public interface Interface1
+{
+ void Foo()
+ {
+
+ }
+
+ void Bar()
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/NET/coverlet/NotInReportClass.cs b/NET/coverlet/NotInReportClass.cs
new file mode 100644
index 0000000..e455d18
--- /dev/null
+++ b/NET/coverlet/NotInReportClass.cs
@@ -0,0 +1,22 @@
+namespace QodanaCoverageTest;
+
+public class NotInReportClass : Interface1
+{
+ public NotInReportClass()
+ {
+ var y = 42;
+ }
+
+ public void UsedMethodWithIf(int i)
+ {
+ if (i == 1)
+ {
+ Console.Write(i);
+ }
+ else
+ {
+ Console.Write(i);
+ Console.Write(i);
+ }
+ }
+}
\ No newline at end of file
diff --git a/NET/coverlet/QodanaCoverageTest.csproj b/NET/coverlet/QodanaCoverageTest.csproj
new file mode 100644
index 0000000..a29f1f3
--- /dev/null
+++ b/NET/coverlet/QodanaCoverageTest.csproj
@@ -0,0 +1,21 @@
+
+
+
+ net7.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/NET/coverlet/QodanaCoverageTest.sln b/NET/coverlet/QodanaCoverageTest.sln
new file mode 100644
index 0000000..d3501e2
--- /dev/null
+++ b/NET/coverlet/QodanaCoverageTest.sln
@@ -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
diff --git a/NET/coverlet/UnitTestProject/UnitTest1.cs b/NET/coverlet/UnitTestProject/UnitTest1.cs
new file mode 100644
index 0000000..172fa70
--- /dev/null
+++ b/NET/coverlet/UnitTestProject/UnitTest1.cs
@@ -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();
+ }
+}
\ No newline at end of file
diff --git a/NET/coverlet/UnitTestProject/UnitTestProject.csproj b/NET/coverlet/UnitTestProject/UnitTestProject.csproj
new file mode 100644
index 0000000..1b915f4
--- /dev/null
+++ b/NET/coverlet/UnitTestProject/UnitTestProject.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net7.0
+ enable
+ enable
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/NET/coverlet/UnitTestProject/Usings.cs b/NET/coverlet/UnitTestProject/Usings.cs
new file mode 100644
index 0000000..cefced4
--- /dev/null
+++ b/NET/coverlet/UnitTestProject/Usings.cs
@@ -0,0 +1 @@
+global using NUnit.Framework;
\ No newline at end of file
diff --git a/NET/coverlet/qodana.yaml b/NET/coverlet/qodana.yaml
new file mode 100644
index 0000000..29ec9c6
--- /dev/null
+++ b/NET/coverlet/qodana.yaml
@@ -0,0 +1,2 @@
+profile:
+ name: qodana.single:NetCoverageInspection
\ No newline at end of file