Browse Source

ILSpy.Tests.Windows (net10.0-windows TFM for OS-gated tests)

Splits Windows-only tests out of the cross-platform ILSpy.Avalonia.Tests
project so the Pdb2Xml / OpenFromGac code paths (which compile only on
Windows) can be exercised without conditional `#if WINDOWS` blocks inside
the main test suite.

Assisted-by: Claude:claude-opus-4-7:Claude Code
pull/3755/head
Siegfried Pammer 2 months ago
parent
commit
6496a7262a
  1. 69
      ILSpy.Tests.Windows/ILSpy.Tests.Windows.csproj
  2. 50
      ILSpy.Tests.Windows/OpenFromGacDialogTests.cs
  3. 14
      ILSpy.sln

69
ILSpy.Tests.Windows/ILSpy.Tests.Windows.csproj

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Windows-targeted TFM unlocks Microsoft.DiaSymReader (native COM) + System.Windows
registry APIs without conditional package gates. EnableWindowsTargeting lets the
build satisfy the -windows reference assemblies on non-Windows OSes via the
cross-targeting pack, so `dotnet build ILSpy.sln` succeeds on Linux/macOS; the
tests still only execute on Windows because the binaries P/Invoke into Win32. -->
<TargetFramework>net11.0-windows</TargetFramework>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<RootNamespace>ICSharpCode.ILSpy.Tests.Windows</RootNamespace>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<!-- Avalonia tests don't need WPF / WinForms reference assemblies even on the
-windows TFM. Suppress so the project doesn't pull in unused frameworks. -->
<UseWPF>false</UseWPF>
<UseWindowsForms>false</UseWindowsForms>
<!-- Strong-named with the shared snk so ICSharpCode.ILSpyX can grant
InternalsVisibleTo for the analyzer-library tests, mirroring the main
test project. -->
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.snk</AssemblyOriginatorKeyFile>
<!-- Microsoft.DiaSymReader.Converter.Xml/.Native transitively pull System.Net.Http
4.3.0 and System.Text.RegularExpressions 4.3.0 which carry known vulnerabilities
(NU1903). These transitive references are outside our control and not exploitable
in the test process. Audit only direct deps. -->
<NuGetAuditMode>direct</NuGetAuditMode>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" />
<PackageReference Include="Avalonia.Headless.NUnit" />
<PackageReference Include="Avalonia.Themes.Simple" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.MTP" />
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" />
<PackageReference Include="Microsoft.Testing.Extensions.VSTestBridge" />
<PackageReference Include="AwesomeAssertions" />
<PackageReference Include="NSubstitute" />
<!-- Windows-only native packages that the matching ILSpy commands gate
behind `Debug + IsOSPlatform(Windows)`. Available unconditionally here because
the project itself only builds on Windows. -->
<PackageReference Include="Microsoft.DiaSymReader.Converter.Xml" />
<PackageReference Include="Microsoft.DiaSymReader" />
<PackageReference Include="Microsoft.DiaSymReader.Native" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ILSpy\ILSpy.csproj" />
</ItemGroup>
<!-- Share TestApp + TestAppBuilder with the cross-platform test project. Linked
rather than duplicated so changes in the main project (data templates, theme
stack, settings sandbox) automatically apply here. -->
<ItemGroup>
<Compile Include="..\ILSpy.Tests\TestApp.axaml.cs" Link="TestApp.axaml.cs" />
<Compile Include="..\ILSpy.Tests\TestAppBuilder.cs" Link="TestAppBuilder.cs" />
<Compile Include="..\ILSpy.Tests\ResetAppStateAttribute.cs" Link="ResetAppStateAttribute.cs" />
<AvaloniaResource Include="..\ILSpy.Tests\TestApp.axaml" Link="TestApp.axaml" />
</ItemGroup>
</Project>

50
ILSpy.Tests.Windows/OpenFromGacDialogTests.cs

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System.Linq;
using AwesomeAssertions;
using ICSharpCode.Decompiler.Metadata;
using NUnit.Framework;
namespace ICSharpCode.ILSpy.Tests.Windows;
/// <summary>
/// Smoke test for the Windows-conditional GAC enumeration path used by
/// <c>ILSpy.Views.OpenFromGacDialog</c>. The shared
/// <see cref="UniversalAssemblyResolver.EnumerateGac"/> only returns entries when run
/// on Windows with a populated GAC; this test validates the project plumbing more than
/// the GAC contents — i.e. the call returns without throwing and the project compiles
/// against Windows-only BCL APIs.
/// </summary>
[TestFixture]
public class OpenFromGacDialogTests
{
[Test]
public void EnumerateGac_Returns_Without_Throwing_On_Windows()
{
// On a developer machine with .NET 4.x installed, this should also return a non-empty
// result. On a stripped CI runner the result may be empty; the test only asserts that
// the enumeration completes — that's enough to catch a regression where the call
// throws (e.g. registry permission change, native-method signature drift).
var result = UniversalAssemblyResolver.EnumerateGac().ToList();
result.Should().NotBeNull();
}
}

14
ILSpy.sln

@ -36,6 +36,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy", "ILSpy\ILSpy.csproj @@ -36,6 +36,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy", "ILSpy\ILSpy.csproj
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.Tests", "ILSpy.Tests\ILSpy.Tests.csproj", "{818CA2D4-175F-4DC1-9C83-189D2CA74ABA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.Tests.Windows", "ILSpy.Tests.Windows\ILSpy.Tests.Windows.csproj", "{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -154,6 +156,18 @@ Global @@ -154,6 +156,18 @@ Global
{818CA2D4-175F-4DC1-9C83-189D2CA74ABA}.Release|x64.Build.0 = Release|Any CPU
{818CA2D4-175F-4DC1-9C83-189D2CA74ABA}.Release|x86.ActiveCfg = Release|Any CPU
{818CA2D4-175F-4DC1-9C83-189D2CA74ABA}.Release|x86.Build.0 = Release|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Debug|x64.ActiveCfg = Debug|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Debug|x64.Build.0 = Debug|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Debug|x86.ActiveCfg = Debug|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Debug|x86.Build.0 = Debug|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Release|Any CPU.Build.0 = Release|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Release|x64.ActiveCfg = Release|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Release|x64.Build.0 = Release|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Release|x86.ActiveCfg = Release|Any CPU
{20AF56FB-DC0F-4048-B75D-83FEE0D669B2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save