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

fix: Simplify embedding the Microsoft.TestPlatform.Portable nupkg #3105

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
3 changes: 0 additions & 3 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ jobs:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: Restore vstest
run: dotnet restore --packages .vstest
working-directory: ${{ github.workspace }}/src/Stryker.Core/Stryker.Core/ToolHelpers/
- name: Pack integration test package
run: dotnet pack ${{ github.workspace }}/src/Stryker.CLI/Stryker.CLI/Stryker.CLI.csproj -p:PackageVersion=$VERSION --output ${{ github.workspace }}/publish
- name: Publish integration test package
Expand Down
14 changes: 0 additions & 14 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,6 @@ stages:
displayName: 'Use dotnet'
inputs:
version: 8.x
- task: DotNetCoreCLI@2
displayName: 'Restore vstest binaries'
inputs:
command: 'custom'
custom: 'restore'
arguments: '--packages ./.vstest/'
workingDirectory: 'src/Stryker.Core/Stryker.Core/ToolHelpers/'
- task: DotNetCoreCLI@2
displayName: 'Pack integrationtest packages'
inputs:
Expand Down Expand Up @@ -287,13 +280,6 @@ stages:
displayName: 'Use dotnet'
inputs:
version: 8.x
- task: DotNetCoreCLI@2
displayName: 'Restore vstest binaries'
inputs:
command: 'custom'
custom: 'restore'
arguments: '--packages ./.vstest/'
workingDirectory: 'src/Stryker.Core/Stryker.Core/ToolHelpers/'
- task: DotNetCoreCLI@2
displayName: 'Pack Stryker.CLI'
inputs:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
using Stryker.Core.Helpers;

namespace Stryker.Core.UnitTest.Helpers;

[TestClass]
public class VsTestHelperTests : TestBase
{
[TestMethod]
public void DeployEmbeddedVsTestBinaries()
{
var deployPath = new VsTestHelper().DeployEmbeddedVsTestBinaries();

var vsTestFiles = Directory.EnumerateFiles(deployPath, "*", SearchOption.AllDirectories).Select(Path.GetFileName).ToList();

try
{
vsTestFiles.ShouldContain("vstest.console.dll");
vsTestFiles.ShouldContain("vstest.console.exe");
}
finally
{
Directory.Delete(deployPath, recursive: true);
}
}
}
26 changes: 17 additions & 9 deletions src/Stryker.Core/Stryker.Core/Helpers/VsTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,27 @@ static bool TryGetNonEmptyEnvironmentVariable(string variable, out string value)
}
}

private string DeployEmbeddedVsTestBinaries()
internal string DeployEmbeddedVsTestBinaries()
{
var vsTestZip = typeof(VsTestHelper).Assembly
.GetManifestResourceNames()
.Single(r =>
r.Contains("Microsoft.TestPlatform.Portable", StringComparison.InvariantCultureIgnoreCase));
var assembly = typeof(VsTestHelper).Assembly;
var vsTestZips = assembly.GetManifestResourceNames().Where(r => r == "Microsoft.TestPlatform.Portable.nupkg").ToList();

var tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName(), ".vstest");
var vsTestZip = vsTestZips.Count switch
{
0 => throw new InvalidOperationException($"The Microsoft.TestPlatform.Portable.nupkg embedded resource was not found in {assembly.GetName().Name}. " +
"Please report this issue at https://github.com/stryker-mutator/stryker-net/issues"),
1 => vsTestZips[0],
_ => throw new InvalidOperationException($"Multiple Microsoft.TestPlatform.Portable.nupkg embedded resources were found in {assembly.GetName().Name}. " +
"Please report this issue at https://github.com/stryker-mutator/stryker-net/issues"),
};

using var stream = typeof(VsTestHelper).Assembly
.GetManifestResourceStream(vsTestZip);
using var stream = assembly.GetManifestResourceStream(vsTestZip)
?? throw new InvalidOperationException($"Failed to get the resource stream of {vsTestZip} in {assembly.GetName().Name}. " +
"Please report this issue at https://github.com/stryker-mutator/stryker-net/issues");

var tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName(), ".vstest");
var zipPath = Path.Combine(tempDir, "vstest.zip");
_fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(zipPath));
_fileSystem.Directory.CreateDirectory(tempDir);

using (var file = _fileSystem.FileStream.New(zipPath, FileMode.Create))
{
Expand Down
3 changes: 2 additions & 1 deletion src/Stryker.Core/Stryker.Core/Stryker.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<EmbeddedResource Include="InjectedHelpers\Coverage\MutantContext.cs" />
<EmbeddedResource Include="Reporters\Html\Files\dist\mutation-test-elements.js" />
<EmbeddedResource Include="Reporters\Html\Files\mutation-report.html" />
<EmbeddedResource Include="$(PkgMicrosoft_TestPlatform_Portable)\*.nupkg" LogicalName="Microsoft.TestPlatform.Portable.nupkg" Visible="false" />
</ItemGroup>

<ItemGroup>
Expand All @@ -46,7 +47,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.TestPlatform" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" />
<PackageReference Include="Microsoft.TestPlatform.Portable" />
<PackageReference Include="Microsoft.TestPlatform.Portable" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.TestPlatform.TranslationLayer" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" />
<PackageReference Include="Mono.Cecil" />
Expand Down
19 changes: 0 additions & 19 deletions src/Stryker.Core/Stryker.Core/ToolHelpers/packages.lock.json

This file was deleted.

This file was deleted.

Loading