Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into refactor_orchestration
Browse files Browse the repository at this point in the history
  • Loading branch information
dupdob committed Mar 1, 2024
2 parents fe5ea05 + a14b64b commit e93bbb6
Show file tree
Hide file tree
Showing 22 changed files with 463 additions and 213 deletions.
3 changes: 2 additions & 1 deletion src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ _____ _ _ _ _ ______ _______  
[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Bug", "S3168:\"async\" methods should not return \"void\"", Justification = "This method is fire and forget. Task.Run also doesn't work in unit tests")]
private async void PrintStrykerVersionInformationAsync()
{
var logger = ApplicationLogging.LoggerFactory.CreateLogger<StrykerCli>();
var assembly = Assembly.GetExecutingAssembly();
var version = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;

if (!SemanticVersion.TryParse(version, out var currentVersion))
{
var logger = ApplicationLogging.LoggerFactory.CreateLogger<StrykerCli>();
if (string.IsNullOrEmpty(version))
{
logger.LogWarning("{Attribute} is missing in {Assembly} at {AssemblyLocation}", nameof(AssemblyInformationalVersionAttribute), assembly, assembly.Location);
Expand All @@ -166,6 +166,7 @@ private async void PrintStrykerVersionInformationAsync()
}

_console.MarkupLine($"Version: [Green]{currentVersion}[/]");
logger.LogDebug("Stryker starting, version: {Version}", currentVersion);
_console.WriteLine();

var latestVersion = await _nugetClient.GetLatestVersionAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void InitialBuildProcess_WithPathAsBuildCommand_TriesWithMsBuildIfDotnetF
@"C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe" + "\" \"" + _cProjectsExampleCsproj + "\"\"");

processMock.Verify(x =>x.Start(It.IsAny<string>(), It.Is<string>(app => app.Contains("dotnet")), It.IsAny<string>(), It.IsAny<IEnumerable<KeyValuePair<string, string>>>(), 0), Times.Once());
processMock.Verify(x =>x.Start(It.IsAny<string>(), It.Is<string>(app => app.Contains("MSBuild.exe")), It.IsAny<string>(), It.IsAny<IEnumerable<KeyValuePair<string, string>>>(), 0), Times.Once());
processMock.Verify(x =>x.Start(It.IsAny<string>(), It.Is<string>(app => app.Contains("MSBuild.exe")), It.IsAny<string>(), It.IsAny<IEnumerable<KeyValuePair<string, string>>>(), 0), Times.Exactly(3));
}

[Fact]
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void ShouldInitializeEachProjectInSolution()
public void ShouldPassWhenProjectNameIsGiven()
{
// arrange
// when a solutionPath is given and it's inside the current directory (basePath)
// when a solutionPath is given, and it's inside the current directory (basePath)
var csprojPathName = _fileSystem.Path.Combine(_projectPath, "sourceproject.csproj");
var testCsprojPathName = _fileSystem.Path.Combine(_projectPath, "test", "testproject.csproj");
var options = new StrykerOptions
Expand All @@ -90,6 +90,31 @@ public void ShouldPassWhenProjectNameIsGiven()
result.ShouldHaveSingleItem();
}

[Fact]
public void ShouldRestoreWhenAnalysisFails()
{
// arrange
// when a solutionPath is given, and it's inside the current directory (basePath)
var csprojPathName = _fileSystem.Path.Combine(_projectPath, "sourceproject.csproj");
var testCsprojPathName = _fileSystem.Path.Combine(_projectPath, "test", "testproject.csproj");
var options = new StrykerOptions
{
ProjectPath = _fileSystem.Path.GetFullPath(testCsprojPathName),
SourceProjectName = csprojPathName,
SolutionPath = _fileSystem.Path.Combine(_projectPath, "MySolution.sln")
};

var csPathName = _fileSystem.Path.Combine(_projectPath, "someFile.cs");
var target = BuildProjectOrchestratorForSimpleProject(SourceProjectAnalyzerMock(csprojPathName, new[] { csPathName }).Object,
TestProjectAnalyzerMock(testCsprojPathName, csprojPathName, "net4.5", false).Object, out var mockRunner);

// act
var result = target.MutateProjects(options, _reporterMock.Object, mockRunner.Object).ToList();

// assert
result.ShouldHaveSingleItem();
}

[Fact]
public void ShouldFailIfNoProjectFound()
{
Expand Down Expand Up @@ -330,7 +355,7 @@ private ProjectOrchestrator BuildProjectOrchestrator(Dictionary<string, IProject

var target = new ProjectOrchestrator(_projectMutatorMock.Object,
initialBuildProcessMock.Object,
new InputFileResolver(_fileSystem, new ProjectFileReader(null, _buildalyzerProviderMock.Object)));
new InputFileResolver(_fileSystem, new ProjectFileReader(new Mock<INugetRestoreProcess>().Object, _buildalyzerProviderMock.Object)));

var buildalyzerAnalyzerManagerMock = new Mock<IAnalyzerManager>(MockBehavior.Strict);
buildalyzerAnalyzerManagerMock.Setup(x => x.Projects)
Expand Down Expand Up @@ -361,7 +386,7 @@ private ProjectOrchestrator BuildProjectOrchestrator(Dictionary<string, IProject
/// </summary>
/// <param name="csprojPathName">project pathname</param>
/// <param name="sourceFiles">project source files</param>
/// <param name="projectReferences">project cross references</param>
/// <param name="projectReferences">project references</param>
private Mock<IProjectAnalyzer> SourceProjectAnalyzerMock(string csprojPathName, string[] sourceFiles, IEnumerable<string> projectReferences = null)
{
var properties = new Dictionary<string, string>
Expand All @@ -376,13 +401,15 @@ private Mock<IProjectAnalyzer> SourceProjectAnalyzerMock(string csprojPathName,
/// </summary>
/// <param name="testCsprojPathName">test project pathname</param>
/// <param name="csprojPathName">production code project pathname</param>
/// <param name="framework"></param>
/// <param name="success"></param>
/// <returns>a mock project analyzer</returns>
/// <remarks>the test project references the production code project and contains no source file</remarks>
private Mock<IProjectAnalyzer> TestProjectAnalyzerMock(string testCsprojPathName, string csprojPathName)
private Mock<IProjectAnalyzer> TestProjectAnalyzerMock(string testCsprojPathName, string csprojPathName, string framework = "net6.0", bool success = true)
{
var properties = new Dictionary<string, string>{ { "IsTestProject", "True" }, { "Language", "C#" } };

return BuildProjectAnalyzerMock(testCsprojPathName, Array.Empty<string>(), properties, new List<string> { csprojPathName });
return BuildProjectAnalyzerMock(testCsprojPathName, Array.Empty<string>(), properties, new List<string> { csprojPathName }, framework, success);
}

/// <summary>
Expand All @@ -391,13 +418,17 @@ private Mock<IProjectAnalyzer> TestProjectAnalyzerMock(string testCsprojPathName
/// <param name="csprojPathName">project file name</param>
/// <param name="sourceFiles">source files to return</param>
/// <param name="properties">project properties</param>
/// <param name="projectReferences">project cross references</param>
/// <param name="projectReferences">project references</param>
/// <param name="success">analysis success</param>
/// <returns>a mock project analyzer</returns>
/// <remarks>
/// 1. project and source files will be created (empty) in the file system
/// 2. the project analyzer mock returns a single project result</remarks>

private Mock<IProjectAnalyzer> BuildProjectAnalyzerMock(string csprojPathName, string[] sourceFiles, Dictionary<string, string> properties, IEnumerable<string> projectReferences)
private Mock<IProjectAnalyzer> BuildProjectAnalyzerMock(string csprojPathName,
string[] sourceFiles, Dictionary<string, string> properties,
IEnumerable<string> projectReferences,
string framework = "net6.0",
bool success = true)
{
var sourceProjectAnalyzerMock = new Mock<IProjectAnalyzer>(MockBehavior.Strict);
var sourceProjectAnalyzerResultsMock = new Mock<IAnalyzerResults>(MockBehavior.Strict);
Expand Down Expand Up @@ -428,8 +459,8 @@ private Mock<IProjectAnalyzer> BuildProjectAnalyzerMock(string csprojPathName, s

sourceProjectAnalyzerResultMock.Setup(x => x.Properties).Returns(properties);
sourceProjectAnalyzerResultMock.Setup(x => x.ProjectFilePath).Returns(csprojPathName);
sourceProjectAnalyzerResultMock.Setup(x => x.TargetFramework).Returns("net6.0");
sourceProjectAnalyzerResultMock.Setup(x => x.Succeeded).Returns(true);
sourceProjectAnalyzerResultMock.Setup(x => x.TargetFramework).Returns(framework);
sourceProjectAnalyzerResultMock.Setup(x => x.Succeeded).Returns(success);

IEnumerable<IAnalyzerResult> analyzerResults = new[] { sourceProjectAnalyzerResultMock.Object };
sourceProjectAnalyzerResultsMock.Setup(x => x.Results).Returns(analyzerResults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public void SelectMutantEarlyIfSingle()
var collector = new CoverageCollector();

var testCase = new TestCase("theTest", new Uri("xunit://"), "source.cs");
var nonCoveringTestCase = new TestCase("theOtherTest", new Uri("xunit://"), "source.cs");
var mutantMap = new List<(int, IEnumerable<Guid>)> {(5, new List<Guid>{testCase.Id})};

var start = new TestSessionStartArgs
Expand Down
Loading

0 comments on commit e93bbb6

Please sign in to comment.