mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Added logic in AssemblyLoadContext to load assembly from GAC. (#3981)
This commit is contained in:
committed by
Dongbo Wang
parent
440590ef8a
commit
26a44abcec
@@ -30,9 +30,9 @@ Describe "Import-Module with ScriptsToProcess" -Tags "CI" {
|
||||
New-Item $moduleRootPath -ItemType Directory -Force | Out-Null
|
||||
Push-Location $moduleRootPath
|
||||
|
||||
"1 | Out-File out.txt -Append -NoNewline" | Out-File script1.ps1
|
||||
"2 | Out-File out.txt -Append -NoNewline" | Out-File script2.ps1
|
||||
New-ModuleManifest module1.psd1 -ScriptsToProcess script1.ps1
|
||||
"1 | Out-File out.txt -Append -NoNewline" | Out-File script1.ps1
|
||||
"2 | Out-File out.txt -Append -NoNewline" | Out-File script2.ps1
|
||||
New-ModuleManifest module1.psd1 -ScriptsToProcess script1.ps1
|
||||
New-ModuleManifest module2.psd1 -ScriptsToProcess script2.ps1 -NestedModules module1.psd1
|
||||
}
|
||||
|
||||
@@ -50,11 +50,11 @@ Describe "Import-Module with ScriptsToProcess" -Tags "CI" {
|
||||
Remove-Item out.txt -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$testCases = @(
|
||||
@{ TestNameSuffix = 'for top-level module'; ipmoParms = @{'Name'='.\module1.psd1'}; Expected = '1' }
|
||||
@{ TestNameSuffix = 'for top-level and nested module'; ipmoParms = @{'Name'='.\module2.psd1'}; Expected = '21' }
|
||||
@{ TestNameSuffix = 'for top-level module when -Version is specified'; ipmoParms = @{'Name'='.\module1.psd1'; 'Version'='1.0'}; Expected = '1' }
|
||||
@{ TestNameSuffix = 'for top-level and nested module when -Version is specified'; ipmoParms = @{'Name'='.\module2.psd1'; 'Version'='1.0'}; Expected = '21' }
|
||||
$testCases = @(
|
||||
@{ TestNameSuffix = 'for top-level module'; ipmoParms = @{'Name'='.\module1.psd1'}; Expected = '1' }
|
||||
@{ TestNameSuffix = 'for top-level and nested module'; ipmoParms = @{'Name'='.\module2.psd1'}; Expected = '21' }
|
||||
@{ TestNameSuffix = 'for top-level module when -Version is specified'; ipmoParms = @{'Name'='.\module1.psd1'; 'Version'='1.0'}; Expected = '1' }
|
||||
@{ TestNameSuffix = 'for top-level and nested module when -Version is specified'; ipmoParms = @{'Name'='.\module2.psd1'; 'Version'='1.0'}; Expected = '21' }
|
||||
)
|
||||
|
||||
It "Verify ScriptsToProcess are executed <TestNameSuffix>" -TestCases $testCases {
|
||||
@@ -63,3 +63,28 @@ Describe "Import-Module with ScriptsToProcess" -Tags "CI" {
|
||||
Get-Content out.txt | Should Be $Expected
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Import-Module for Binary Modules in GAC" -Tags 'CI' {
|
||||
Context "Modules are not loaded from GAC" {
|
||||
BeforeAll {
|
||||
[System.Management.Automation.PowerShellAssemblyLoadContextTestHooks]::SetTestHook('AllowGACLoading', $false)
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
[System.Management.Automation.PowerShellAssemblyLoadContextTestHooks]::SetTestHook('AllowGACLoading', $true)
|
||||
}
|
||||
|
||||
It "Load PSScheduledJob from Windows Powershell Modules folder should fail" -Skip:(-not $IsWindows) {
|
||||
$modulePath = Join-Path $env:windir "System32/WindowsPowershell/v1.0/Modules/PSScheduledJob"
|
||||
{ Import-Module $modulePath -ErrorAction SilentlyContinue } | ShouldBeErrorId 'FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Modules are loaded from GAC" {
|
||||
It "Load PSScheduledJob from Windows Powershell Modules folder" -Skip:(-not $IsWindows) {
|
||||
$modulePath = Join-Path $env:windir "System32/WindowsPowershell/v1.0/Modules/PSScheduledJob"
|
||||
Import-Module $modulePath
|
||||
(Get-Command New-JobTrigger).Name | Should Be 'New-JobTrigger'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user