8000 Fix the isolated module test that was disabled previously (#25420) · PowerShell/PowerShell@f53865d · GitHub
[go: up one dir, main page]

Skip to content

Commit f53865d

Browse files
authored
Fix the isolated module test that was disabled previously (#25420)
1 parent 6120c2a commit f53865d

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

test/powershell/engine/Module/IsolatedModule.Tests.ps1

+14-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Describe "Isolated module scenario - load the whole module in custom ALC" -Tag 'CI' {
55
It "Loading 'IsolatedModule' should work as expected" {
66

7-
Set-ItResult -Pending -Because "The test is failing as we cannot depend on Newtonsoft.Json v10.0.0 as it has security vulnerabilities."
8-
97
## The 'IsolatedModule' module can be found at '<repo-root>\test\tools\Modules'.
108
## The module assemblies are created and deployed by '<repo-root>\test\tools\TestAlc'.
119
## The module defines its own custom ALC and has its module structure organized in a special way that allows the module to be loaded in that custom ALC.
@@ -14,9 +12,15 @@ Describe "Isolated module scenario - load the whole module in custom ALC" -Tag '
1412
## │ Test.Isolated.Init.dll (contains the custom ALC and code to setup 'Resolving' handler)
1513
## │
1614
## └───Dependencies
17-
## Newtonsoft.Json.dll (version 10.0.0.0 dependency)
15+
## System.CommandLine.dll (version 2.0.0.0 dependency)
1816
## Test.Isolated.Nested.dll (nested binary module)
1917
## Test.Isolated.Root.dll (root binary module)
18+
19+
## The assembly 'System.CommandLine.dll' should not be loaded in the PowerShell default ALC by default.
20+
[System.Runtime.Loader.AssemblyLoadContext]::Default.Assemblies |
21+
Where-Object FullName -Like 'System.CommandLine,*' |
22+
Should -Be $null
23+
2024
$module = Import-Module IsolatedModule -PassThru
2125
$nestedCmd = Get-Command Test-NestedCommand
2226
$rootCmd = Get-Command Test-RootCommand
@@ -30,10 +34,14 @@ Describe "Isolated module scenario - load the whole module in custom ALC" -Tag '
3034
$context1.Name | Should -BeExactly "MyCustomALC"
3135
$context1 | Should -Be $context2
3236

33-
## Test-NestedCommand depends on NewtonSoft.Json 10.0.0.0 while PowerShell depends on 13.0.0.0 or higher.
34-
## The exact version of NewtonSoft.Json should be loaded to the custom ALC.
37+
## Test-NestedCommand depends on 'System.CommandLine.dll' which is loaded in the module's ALC.
3538
$foo = [Test.Isolated.Nested.Foo]::new("Hello", "World")
36-
Test-NestedCommand -Param $foo | Should -BeExactly "Hello-World-Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"
39+
Test-NestedCommand -Param $foo | Should -BeExactly "Hello-World-System.CommandLine, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
40+
41+
## The assembly 'System.CommandLine.dll' should still not be loaded in the PowerShell default ALC.
42+
[System.Runtime.Loader.AssemblyLoadContext]::Default.Assemblies |
43+
Where-Object FullName -Like 'System.CommandLine,*' |
44+
Should -Be $null
3745

3846
## The type 'Test.Isolated.Root.Red' from the root module can be resolved and should be from the same load context.
3947
$context3 = [System.Runtime.Loader.AssemblyLoadContext]::GetLoadContext($rootCmd.ImplementingType.Assembly)

test/tools/TestAlc/nested/NestedCommand.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using System.CommandLine;
45
using System.Management.Automation;
5-
using Newtonsoft.Json;
66

77
namespace Test.Isolated.Nested
88
{
@@ -14,7 +14,7 @@ public class TestNestedCommand : PSCmdlet
1414

1515
protected override void ProcessRecord()
1616
{
17-
WriteObject($"{Param.Name}-{Param.Path}-{typeof(StringEscapeHandling).Assembly.FullName}");
17+
WriteObject($"{Param.Name}-{Param.Path}-{typeof(RootCommand).Assembly.FullName}");
1818
}
1919
}
2020

test/tools/TestAlc/nested/Test.Isolated.Nested.csproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
<Import Project="..\..\..\Test.Common.props" />
44

55
<PropertyGroup>
6+
<!-- Suppress language folders -->
7+
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
8+
69
<!-- Disable PDB generation -->
710
<DebugSymbols>false</DebugSymbols>
811
<DebugType>None</DebugType>
912

1013
<!-- Disable deps.json generation -->
1114
<GenerateDependencyFile>false</GenerateDependencyFile>
12-
<NoWarn>NU1901;NU1902;NU1903;NU1904</NoWarn>
1315

1416
<!-- Deploy the produced assembly -->
1517
<PublishDir>..\..\Modules\IsolatedModule\Dependencies</PublishDir>
1618
</PropertyGroup>
1719

1820
<ItemGroup>
1921
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" PrivateAssets="All" />
20-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
22+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
2123
</ItemGroup>
2224

2325
</Project>

0 commit comments

Comments
 (0)
0