mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Clean up workflow logic in the module loading component (#6523)
Clean up workflow logic in the module loading component. Workflow module is not supported in PSCore. Currently, Import-Module throws a terminating error when seeing .xaml modules. After the change, Import-Module throws a non-terminating error when seeing .xaml modules.
This commit is contained in:
committed by
Travis Plunk
parent
610ae1a63f
commit
d1cf82ec20
@@ -146,7 +146,7 @@ namespace ModuleCmdlets
|
||||
|
||||
$psdFile = Join-Path $TESTDRIVE test.psd1
|
||||
$nestedModule = Join-Path NOExistedPath Microsoft.PowerShell.Commands.Utility.dll
|
||||
New-ModuleManifest -Path $psdFile -NestedModules $nestedModule
|
||||
New-ModuleManifest -Path $psdFile -NestedModules $nestedModule
|
||||
try
|
||||
{
|
||||
$module = Import-Module $psdFile -PassThru
|
||||
@@ -158,7 +158,7 @@ namespace ModuleCmdlets
|
||||
{
|
||||
Remove-Module $module -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,3 +200,34 @@ Describe "Import-Module should be case insensitive" -Tags 'CI' {
|
||||
Get-Module tESTmODULE | Should -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Workflow .Xaml module is not supported in PSCore" -tags "Feature" {
|
||||
BeforeAll {
|
||||
$xamlFile = Join-Path $TestDrive "XamlTest.xaml"
|
||||
New-Item -Path $xamlFile -ItemType File -Force
|
||||
|
||||
$xamlRootModule = Join-Path $TestDrive "XamlRootModule"
|
||||
New-Item -Path $xamlRootModule -ItemType Directory -Force
|
||||
Copy-Item $xamlFile $xamlRootModule
|
||||
$xamlRootModuleManifest = Join-Path $xamlRootModule "XamlRootModule.psd1"
|
||||
New-ModuleManifest -Path $xamlRootModuleManifest -RootModule "XamlTest.xaml"
|
||||
|
||||
$xamlNestedModule = Join-Path $TestDrive "XamlNestedModule"
|
||||
New-Item -Path $xamlNestedModule -ItemType Directory -Force
|
||||
Copy-Item $xamlFile $xamlNestedModule
|
||||
$xamlNestedModuleManifest = Join-Path $xamlNestedModule "XamlNestedModule.psd1"
|
||||
New-ModuleManifest -Path $xamlNestedModuleManifest -NestedModules "XamlTest.xaml"
|
||||
}
|
||||
|
||||
It "Import a XAML file directly should raise a 'NotSupported' error" {
|
||||
{ Import-Module $xamlFile -ErrorAction Stop } | Should -Throw -ErrorId "Modules_WorkflowModuleNotSupported,Microsoft.PowerShell.Commands.ImportModuleCommand"
|
||||
}
|
||||
|
||||
It "Import a module with XAML root module should raise a 'NotSupportd' error" {
|
||||
{ Import-Module $xamlRootModule -ErrorAction Stop } | Should -Throw -ErrorId "Modules_WorkflowModuleNotSupported,Microsoft.PowerShell.Commands.ImportModuleCommand"
|
||||
}
|
||||
|
||||
It "Import a module with XAML nested module should raise a 'NotSupported' error" {
|
||||
{ Import-Module $xamlNestedModule -ErrorAction Stop } | Should -Throw -ErrorId "Modules_WorkflowModuleNotSupported,Microsoft.PowerShell.Commands.ImportModuleCommand"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ Describe "Test-ModuleManifest tests" -tags "CI" {
|
||||
|
||||
It "module manifest containing valid processed empty rootmodule file type fails: <rootModuleValue>" -TestCases (
|
||||
@{rootModuleValue = "foo.cdxml"; error = "System.Xml.XmlException"}, # fails when cmdlet tries to read it as XML
|
||||
@{rootModuleValue = "foo.xaml"; error = "NotSupported"} # not supported on PowerShell Core
|
||||
@{rootModuleValue = "foo.xaml"; error = "Modules_WorkflowModuleNotSupported"} # not supported on PowerShell Core
|
||||
) {
|
||||
|
||||
param($rootModuleValue, $error)
|
||||
@@ -231,7 +231,7 @@ Describe "Test-ModuleManifest Performance bug followup" -tags "CI" {
|
||||
It "Test-ModuleManifest should not load unnessary modules" {
|
||||
|
||||
$job = start-job -name "job1" -ScriptBlock {test-modulemanifest "$using:UserModulesPath\ModuleWithDependencies2\2.0\ModuleWithDependencies2.psd1" -verbose} | Wait-Job
|
||||
|
||||
|
||||
$verbose = $job.ChildJobs[0].Verbose.ReadAll()
|
||||
# Before the fix, all modules under $pshome will be imported and will be far more than 15 verbose messages. However, we cannot fix the number in case verbose message may vary.
|
||||
$verbose.Count | Should -BeLessThan 15
|
||||
|
||||
Reference in New Issue
Block a user