Skip to content

Fix RuntimeConfigurationReader to support SelfContained builds #1705

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

Merged
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
7 changes: 7 additions & 0 deletions coverlet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "coverlet.tests.projectsampl
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.tests.utils", "test\coverlet.tests.utils\coverlet.tests.utils.csproj", "{0B109210-03CB-413F-888C-3023994AA384}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.tests.projectsample.wpf8.selfcontained", "test\coverlet.tests.projectsample.wpf8.selfcontained\coverlet.tests.projectsample.wpf8.selfcontained.csproj", "{71004336-9896-4AE5-8367-B29BB1680542}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -190,6 +192,10 @@ Global
{0B109210-03CB-413F-888C-3023994AA384}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B109210-03CB-413F-888C-3023994AA384}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B109210-03CB-413F-888C-3023994AA384}.Release|Any CPU.Build.0 = Release|Any CPU
{71004336-9896-4AE5-8367-B29BB1680542}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71004336-9896-4AE5-8367-B29BB1680542}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71004336-9896-4AE5-8367-B29BB1680542}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71004336-9896-4AE5-8367-B29BB1680542}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -220,6 +226,7 @@ Global
{351A034E-E642-4DB9-A21D-F71C8151C243} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
{03400776-1F9A-4326-B927-1CA9B64B42A1} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
{0B109210-03CB-413F-888C-3023994AA384} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
{71004336-9896-4AE5-8367-B29BB1680542} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9CA57C02-97B0-4C38-A027-EA61E8741F10}
Expand Down
5 changes: 5 additions & 0 deletions src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ public RuntimeConfigurationReader(string runtimeConfigFile)
return runtimeOptionsElement["frameworks"].Select(x => (x["name"]?.Value<string>(), x["version"]?.Value<string>())).ToList();
}

if (runtimeOptionsElement?["includedFrameworks"] != null)
{
return runtimeOptionsElement["includedFrameworks"].Select(x => (x["name"]?.Value<string>(), x["version"]?.Value<string>())).ToList();
}

throw new InvalidOperationException($"Unable to read runtime configuration from {_runtimeConfigFile}.");
}
}
Expand Down
28 changes: 28 additions & 0 deletions test/coverlet.integration.tests/WpfResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,33 @@ public void TestInstrument_NetCoreSharedFrameworkResolver()
"sample assembly shall be resolved");
Assert.NotEmpty(assemblies);
}

[ConditionalFact]
[SkipOnOS(OS.Linux, "WPF only runs on Windows")]
[SkipOnOS(OS.MacOS, "WPF only runs on Windows")]
public void TestInstrument_NetCoreSharedFrameworkResolver_SelfContained()
{
string buildConfiguration = TestUtils.GetAssemblyBuildConfiguration().ToString().ToLowerInvariant();
string wpfProjectPath = TestUtils.GetTestProjectPath("coverlet.tests.projectsample.wpf8.selfcontained");
string testBinaryPath = Path.Combine(TestUtils.GetTestBinaryPath("coverlet.tests.projectsample.wpf8.selfcontained"), $"{buildConfiguration}_win-x64");
Assert.True(DotnetCli($"build \"{wpfProjectPath}\"", out string output, out string error));
string assemblyLocation = Directory.GetFiles(testBinaryPath, "coverlet.tests.projectsample.wpf8.selfcontained.dll", SearchOption.AllDirectories).First();

var mockLogger = new Mock<ILogger>();
var resolver = new NetCoreSharedFrameworkResolver(assemblyLocation, mockLogger.Object);
var compilationLibrary = new CompilationLibrary(
"package",
"System.Drawing",
"0.0.0.0",
"sha512-not-relevant",
Enumerable.Empty<string>(),
Enumerable.Empty<Dependency>(),
true);

var assemblies = new List<string>();
Assert.True(resolver.TryResolveAssemblyPaths(compilationLibrary, assemblies),
"sample assembly shall be resolved");
Assert.NotEmpty(assemblies);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# top-most EditorConfig file
# We don't want to import other EditorConfig files and we want
# to ensure no rules are enabled for these asset source files.
root = true

[*.cs]
# Default severity for all analyzer diagnostics
dotnet_analyzer_diagnostic.severity = none
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Toni Solarin-Sodara
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace coverlet.tests.projectsample.wpf8.selfcontained;

public static class Program
{
public static void Main() { }
}
12 changes: 12 additions & 0 deletions test/coverlet.tests.projectsample.wpf8.selfcontained/TestClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Toni Solarin-Sodara
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Windows.Controls;

namespace coverlet.tests.projectsample.wpf8.selfcontained
{
public class TestClass
{
public UserControl? Control { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWpf>true</UseWpf>
<IsTestProject>false</IsTestProject>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<IsPackable>false</IsPackable>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion test/coverlet.tests.projectsample.wpf8/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Toni Solarin-Sodara
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace coverlet.tests.projectsample.wpf6;
namespace coverlet.tests.projectsample.wpf8;

public static class Program
{
Expand Down
2 changes: 1 addition & 1 deletion test/coverlet.tests.projectsample.wpf8/TestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Windows.Controls;

namespace coverlet.tests.projectsample.wpf6
namespace coverlet.tests.projectsample.wpf8
{
public class TestClass
{
Expand Down