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

chore: Extract abstractions into separate project #3064

Merged
merged 17 commits into from
Oct 14, 2024
Merged
  •  
  •  
  •  
66 changes: 66 additions & 0 deletions integrationtest/TargetProjects/IntegrationTestApp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32421.90
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library", "Library\Library.csproj", "{506AB0A3-E830-4504-A1EE-0C9F531A9ACE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreTestProject.NUnit", "NetCoreTestProject.NUnit\NetCoreTestProject.NUnit.csproj", "{602929D8-22C6-47AD-BD1F-9DB81FB76231}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreTestProject.XUnit", "NetCoreTestProject.XUnit\NetCoreTestProject.XUnit.csproj", "{D2502C99-4676-4F4F-88F2-4F0384BF76EA}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SharedProject", "SharedProject\SharedProject.shproj", "{AE33CEEA-7EB1-438D-ABD4-3208D032C5D3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TargetProject", "TargetProject\TargetProject.csproj", "{FD5B399F-F31D-4E95-824D-EF3FDC2F610C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExtraProject", "ExtraProject\ExtraProject.csproj", "{70462F5F-6EC9-43F9-B360-3F61C9636804}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExtraProject.XUnit", "ExtraProject.XUnit\ExtraProject.XUnit.csproj", "{A862920A-7A81-4317-984E-2302A47B1792}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmptyTestProject", "EmptyTestProject\EmptyTestProject.csproj", "{4EF7D9F7-8BEC-48B7-A336-0CD89EEBF627}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{506AB0A3-E830-4504-A1EE-0C9F531A9ACE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{506AB0A3-E830-4504-A1EE-0C9F531A9ACE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{506AB0A3-E830-4504-A1EE-0C9F531A9ACE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{506AB0A3-E830-4504-A1EE-0C9F531A9ACE}.Release|Any CPU.Build.0 = Release|Any CPU
{602929D8-22C6-47AD-BD1F-9DB81FB76231}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{602929D8-22C6-47AD-BD1F-9DB81FB76231}.Debug|Any CPU.Build.0 = Debug|Any CPU
{602929D8-22C6-47AD-BD1F-9DB81FB76231}.Release|Any CPU.ActiveCfg = Release|Any CPU
{602929D8-22C6-47AD-BD1F-9DB81FB76231}.Release|Any CPU.Build.0 = Release|Any CPU
{D2502C99-4676-4F4F-88F2-4F0384BF76EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D2502C99-4676-4F4F-88F2-4F0384BF76EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D2502C99-4676-4F4F-88F2-4F0384BF76EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D2502C99-4676-4F4F-88F2-4F0384BF76EA}.Release|Any CPU.Build.0 = Release|Any CPU
{FD5B399F-F31D-4E95-824D-EF3FDC2F610C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD5B399F-F31D-4E95-824D-EF3FDC2F610C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD5B399F-F31D-4E95-824D-EF3FDC2F610C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD5B399F-F31D-4E95-824D-EF3FDC2F610C}.Release|Any CPU.Build.0 = Release|Any CPU
{70462F5F-6EC9-43F9-B360-3F61C9636804}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{70462F5F-6EC9-43F9-B360-3F61C9636804}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70462F5F-6EC9-43F9-B360-3F61C9636804}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70462F5F-6EC9-43F9-B360-3F61C9636804}.Release|Any CPU.Build.0 = Release|Any CPU
{A862920A-7A81-4317-984E-2302A47B1792}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A862920A-7A81-4317-984E-2302A47B1792}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A862920A-7A81-4317-984E-2302A47B1792}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A862920A-7A81-4317-984E-2302A47B1792}.Release|Any CPU.Build.0 = Release|Any CPU
{4EF7D9F7-8BEC-48B7-A336-0CD89EEBF627}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4EF7D9F7-8BEC-48B7-A336-0CD89EEBF627}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EF7D9F7-8BEC-48B7-A336-0CD89EEBF627}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EF7D9F7-8BEC-48B7-A336-0CD89EEBF627}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0C29E1AA-5805-4524-8160-B0C28E4050D8}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
SharedProject\SharedProject.projitems*{ae33ceea-7eb1-438d-abd4-3208d032c5d3}*SharedItemsImports = 13
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 1,
"dependencies": {
"net8.0": {}
"net7.0": {}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": 1,
"dependencies": {
"net8.0": {
"net7.0": {
"Microsoft.CodeAnalysis.Common": {
"type": "Direct",
"requested": "[4.11.0, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Text;
using Newtonsoft.Json;
using Shouldly;
using Stryker.Core.Mutants;
using Stryker.Abstractions.Mutants;
using Stryker.Abstractions.Reporting;
using Stryker.Core.Reporters.Json;
using Xunit;

Expand Down Expand Up @@ -48,7 +49,7 @@ public class ValidateStrykerResults

[Fact]
[Trait("Category", "SingleTestProject")]
public void CSharp_NetFramework_SingleTestProject()
public async Task CSharp_NetFramework_SingleTestProject()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand All @@ -59,36 +60,36 @@ public void CSharp_NetFramework_SingleTestProject()
.OrderByDescending(f => f.LastWriteTime)
.First();

var strykerRunOutput = File.ReadAllText(latestReport.FullName);
using var strykerRunOutput = File.OpenRead(latestReport.FullName);

var report = JsonConvert.DeserializeObject<JsonReport>(strykerRunOutput);
var report = await JsonReportSerialization.DeserializeJsonReportAsync(strykerRunOutput);

CheckReportMutants(report, total: 29, ignored: 7, survived: 3, killed: 7, timeout: 0, nocoverage: 11);
}
}

[Fact]
[Trait("Category", "SingleTestProject")]
public void CSharp_NetCore_SingleTestProject()
public async Task CSharp_NetCore_SingleTestProject()
{
var directory = new DirectoryInfo("../../../../../TargetProjects/NetCore/NetCoreTestProject.XUnit/StrykerOutput");
directory.GetFiles("*.json", SearchOption.AllDirectories).ShouldNotBeEmpty("No reports available to assert");

var latestReport = directory.GetFiles(MutationReportJson, SearchOption.AllDirectories)
.OrderByDescending(f => f.LastWriteTime)
.First();

var strykerRunOutput = File.ReadAllText(latestReport.FullName);

var report = JsonConvert.DeserializeObject<JsonReport>(strykerRunOutput);
using var strykerRunOutput = File.OpenRead(latestReport.FullName);

var report = await JsonReportSerialization.DeserializeJsonReportAsync(strykerRunOutput);

CheckReportMutants(report, total: 589, ignored: 246, survived: 4, killed: 9, timeout: 2, nocoverage: 297);
CheckReportTestCounts(report, total: 11);
}

[Fact]
[Trait("Category", "FSharp")]
public void FSharp_SingleTestProject()
public async Task FSharp_SingleTestProject()
{
var directory = new DirectoryInfo("../../../../../TargetProjects/NetCore/Library.FSharp.XUnit/StrykerOutput");
directory.GetFiles("*.json", SearchOption.AllDirectories).ShouldNotBeEmpty("No reports available to assert");
Expand All @@ -98,17 +99,17 @@ public void FSharp_SingleTestProject()
.OrderByDescending(f => f.LastWriteTime)
.First();

var strykerRunOutput = File.ReadAllText(latestReport.FullName);
using var strykerRunOutput = File.OpenRead(latestReport.FullName);

var report = JsonConvert.DeserializeObject<JsonReport>(strykerRunOutput);
var report = await JsonReportSerialization.DeserializeJsonReportAsync(strykerRunOutput);

CheckReportMutants(report, total: 0, ignored: 0, survived: 0, killed: 0, timeout: 0, nocoverage: 0);
CheckReportTestCounts(report, total: 0);
}

[Fact]
[Trait("Category", "MultipleTestProjects")]
public void CSharp_NetCore_WithTwoTestProjects()
public async Task CSharp_NetCore_WithTwoTestProjects()
{
var directory = new DirectoryInfo("../../../../../TargetProjects/NetCore/Targetproject/StrykerOutput");
directory.GetFiles("*.json", SearchOption.AllDirectories).ShouldNotBeEmpty("No reports available to assert");
Expand All @@ -117,17 +118,17 @@ public void CSharp_NetCore_WithTwoTestProjects()
.OrderByDescending(f => f.LastWriteTime)
.First();

var strykerRunOutput = File.ReadAllText(latestReport.FullName);
using var strykerRunOutput = File.OpenRead(latestReport.FullName);

var report = JsonConvert.DeserializeObject<JsonReport>(strykerRunOutput);
var report = await JsonReportSerialization.DeserializeJsonReportAsync(strykerRunOutput);

CheckReportMutants(report, total: 589, ignored: 105, survived: 5, killed: 11, timeout: 2, nocoverage: 435);
CheckReportTestCounts(report, total: 21);
}

[Fact]
[Trait("Category", "Solution")]
public void CSharp_NetCore_SolutionRun()
public async Task CSharp_NetCore_SolutionRun()
{
var directory = new DirectoryInfo("../../../../../TargetProjects/NetCore/StrykerOutput");
directory.GetFiles("*.json", SearchOption.AllDirectories).ShouldNotBeEmpty("No reports available to assert");
Expand All @@ -136,15 +137,15 @@ public void CSharp_NetCore_SolutionRun()
.OrderByDescending(f => f.LastWriteTime)
.First();

var strykerRunOutput = File.ReadAllText(latestReport.FullName);
using var strykerRunOutput = File.OpenRead(latestReport.FullName);

var report = JsonConvert.DeserializeObject<JsonReport>(strykerRunOutput);
var report = await JsonReportSerialization.DeserializeJsonReportAsync(strykerRunOutput);

CheckReportMutants(report, total: 589, ignored: 246, survived: 4, killed: 9, timeout: 2, nocoverage: 297);
CheckReportTestCounts(report, total: 23);
}

private void CheckMutationKindsValidity(JsonReport report)
private void CheckMutationKindsValidity(IJsonReport report)
{
foreach (var file in report.Files)
{
Expand All @@ -164,7 +165,7 @@ private void CheckMutationKindsValidity(JsonReport report)
}
}

private void CheckReportMutants(JsonReport report, int total, int ignored, int survived, int killed, int timeout, int nocoverage)
private void CheckReportMutants(IJsonReport report, int total, int ignored, int survived, int killed, int timeout, int nocoverage)
{
var actualTotal = report.Files.Select(f => f.Value.Mutants.Count()).Sum();
var actualIgnored = report.Files.Select(f => f.Value.Mutants.Count(m => m.Status == MutantStatus.Ignored.ToString())).Sum();
Expand All @@ -185,7 +186,7 @@ private void CheckReportMutants(JsonReport report, int total, int ignored, int s
CheckMutationKindsValidity(report);
}

private void CheckReportTestCounts(JsonReport report, int total)
private void CheckReportTestCounts(IJsonReport report, int total)
{
var actualTotal = report.TestFiles.Sum(tf => tf.Value.Tests.Count);

Expand Down
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
<ImplicitUsings>disable</ImplicitUsings>
<RestoreLockedMode Condition="'$(RestoreLockedMode)' == 'true'">true</RestoreLockedMode>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<PackageVersion Include="Microsoft.TestPlatform.TranslationLayer" Version="17.11.1" />
<PackageVersion Include="TestableIO.System.IO.Abstractions.Wrappers" Version="21.0.29" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Stryker.Core.Baseline.Providers
namespace Stryker.Abstractions.Baseline
{
public enum BaselineProvider
{
Expand Down
11 changes: 11 additions & 0 deletions src/Stryker.Abstractions/Baseline/IBaselineProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Threading.Tasks;
using Stryker.Abstractions.Reporting;

namespace Stryker.Abstractions.Baseline
{
public interface IBaselineProvider
{
Task<IJsonReport> Load(string version);
Task Save(IJsonReport report, string version);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Stryker.Core.Exceptions;
namespace Stryker.Abstractions.Exceptions;

/// <summary>
/// Represents errors which are related to roslyn compilation errors that we cannot fix,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Text;

namespace Stryker.Core.Exceptions
namespace Stryker.Abstractions.Exceptions
{
/// <summary>
/// Represents errors which are caused by known exceptions in Stryker.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Text;

namespace Stryker.Core.Exceptions;
namespace Stryker.Abstractions.Exceptions;

/// <summary>
/// Represents errors which are related to user input.
Expand All @@ -12,7 +12,7 @@
{
public string Details { get; }

public InputException(string message)

Check warning on line 15 in src/Stryker.Abstractions/Exceptions/InputException.cs

View workflow job for this annotation

GitHub Actions / integration-test

Non-nullable property 'Details' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
: base(message)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Stryker.Core.Exceptions;
namespace Stryker.Abstractions.Exceptions;

/// <summary>
/// Represents error when no test projects are found in the solution or configured for stryker.
Expand Down
22 changes: 22 additions & 0 deletions src/Stryker.Abstractions/IMutant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Stryker.Abstractions.TestRunners;
using Stryker.Abstractions;

namespace Stryker.Abstractions.Mutants;

public interface IMutant : IReadOnlyMutant
{
new int Id { get; set; }
new Mutation Mutation { get; set; }
new MutantStatus ResultStatus { get; set; }
new string ResultStatusReason { get; set; }
new ITestGuids CoveringTests { get; set; }
new ITestGuids KillingTests { get; set; }
new ITestGuids AssessingTests { get; set; }
new bool CountForStats { get; }
new bool IsStaticValue { get; set; }

string DisplayName { get; }
bool MustBeTestedInIsolation { get; set; }

void AnalyzeTestRun(ITestGuids failedTests, ITestGuids resultRanTests, ITestGuids timedOutTests, bool sessionTimedOut);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Microsoft.CodeAnalysis;
using Stryker.Core.Mutants;
using Stryker.Core.Options;
using Stryker.Abstractions.Options;
using Stryker.Abstractions.Mutants;
using System.Collections.Generic;

namespace Stryker.Core.Mutators;
namespace Stryker.Abstractions.Mutators;

public interface IMutator
{
IEnumerable<Mutation> Mutate(SyntaxNode node, SemanticModel semanticModel, StrykerOptions options);
IEnumerable<Mutation> Mutate(SyntaxNode node, SemanticModel semanticModel, IStrykerOptions options);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;
using Stryker.Core.ProjectComponents.TestProjects;
using Stryker.Abstractions.ProjectComponents;

namespace Stryker.Core.Initialisation;
namespace Stryker.Abstractions.Initialisation;

public interface IProjectAndTests
{
TestProjectsInfo TestProjectsInfo { get;}
ITestProjectsInfo TestProjectsInfo { get;}

string HelperNamespace { get; }

Expand Down
6 changes: 6 additions & 0 deletions src/Stryker.Abstractions/IProvideId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Stryker.Abstractions;

public interface IProvideId
{
int NextId();
}
20 changes: 20 additions & 0 deletions src/Stryker.Abstractions/IReadOnlyMutant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Stryker.Abstractions.TestRunners;
using Stryker.Abstractions.Mutants;

namespace Stryker.Abstractions;

/// <summary>
/// This interface should only contain readonly properties to ensure that others than the mutation test process cannot modify mutants.
/// </summary>
public interface IReadOnlyMutant
{
int Id { get; }
Mutation Mutation { get; }
MutantStatus ResultStatus { get; }
string ResultStatusReason { get; }
ITestGuids CoveringTests { get; }
ITestGuids KillingTests { get; }
ITestGuids AssessingTests { get; }
bool CountForStats { get; }
bool IsStaticValue { get; }
}
7 changes: 7 additions & 0 deletions src/Stryker.Abstractions/ITimeoutValueCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Stryker.Abstractions;

public interface ITimeoutValueCalculator
{
int CalculateTimeoutValue(int estimatedTime);
int DefaultTimeout { get; }
}
Loading
Loading