From a21fd2475d09252a7f3b270cfe514abf0b14bbe7 Mon Sep 17 00:00:00 2001 From: pougetat Date: Tue, 2 Apr 2019 19:59:20 +0200 Subject: [PATCH 01/14] Adding tests for remove-module --- .../Remove-Module.Tests.ps1 | 194 ++++++++++++++++++ 1 file changed, 194 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index 70a5b544b57..6d6efb96ce2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -1,5 +1,199 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +Describe "Remove-Module -Name" -Tags "CI" { + BeforeAll { + + New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\" -Force > $null + New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null + New-Item -ItemType Directory -Path "$testdrive\Modules\Baz\" -Force > $null + + New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo.psd1" + New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" + New-ModuleManifest -Path "$testdrive\Modules\Baz\Baz.psd1" + + New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Baz\Baz.psm1" > $null + + $removeModuleByNameTestCases = @( + # Simple patterns + @{ PatternsToRemove = "Foo"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"} + @{ PatternsToRemove = "Bar", "Foo"; ShouldBeRemoved = "Bar", "Foo"; ShouldBePresent = "Baz"} + @{ PatternsToRemove = "Bar", "Baz", "Foo"; ShouldBeRemoved = "Bar", "Baz", "Foo"; ShouldBePresent = ""} + @{ PatternsToRemove = "Foo", "Foo"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"} + @{ PatternsToRemove = "Foo", "Foo", "Bar"; ShouldBeRemoved = "Bar", "Foo"; ShouldBePresent = "Baz"} + @{ PatternsToRemove = "Fo", "Foo"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"} + + # Regex patterns + #@{ PatternsToRemove = "*"; ShouldBeRemoved = "Bar", "Baz", "Foo"; ShouldBePresent = ""} -> this breaks pester for some reason + @{ PatternsToRemove = "B*"; ShouldBeRemoved = "Bar", "Baz"; ShouldBePresent = "Foo"} + @{ PatternsToRemove = "F*"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"} + @{ PatternsToRemove = "Foo*"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"} + @{ PatternsToRemove = "F*", "Bar"; ShouldBeRemoved = "Foo", "Bar"; ShouldBePresent = "Baz"} + @{ PatternsToRemove = "F*", "F*"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"} + @{ PatternsToRemove = "FF*"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo"} + ) + + $removeModuleByNameErrorTestCases = @( + # Invalid patterns + @{ PatternsToRemove = "Fo"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo"} + @{ PatternsToRemove = "Fo", "Ba"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo"} + ) + } + + AfterAll { + Remove-Module -Name "Foo", "Bar", "Baz" + } + + BeforeEach { + Import-Module -Name "$testdrive\Modules\Foo\Foo.psd1" -Force + Import-Module -Name "$testdrive\Modules\Bar\Bar.psd1" -Force + Import-Module -Name "$testdrive\Modules\Baz\Baz.psd1" -Force + + (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo" + } + + It "Remove-Module -Name " -TestCases $removeModuleByNameTestCases { + param([string[]]$PatternsToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + + { Remove-Module -Name $PatternsToRemove} | Should -Not -Throw + + if ($ShouldBeRemoved) { + (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty + } + + if ($ShouldBePresent) { + (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent + } + } + + It "Remove-Module -Name (Error cases)" -TestCases $removeModuleByNameErrorTestCases { + param([string[]]$PatternsToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + + { Remove-Module -Name $PatternsToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_NoModulesRemoved,Microsoft.PowerShell.Commands.RemoveModuleCommand" + + if ($ShouldBeRemoved) { + (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty + } + + if ($ShouldBePresent) { + (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent + } + } +} + +Describe "Remove-Module -FullyQualifiedName" -Tags "CI" { + BeforeAll { + + New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\1.0\" -Force > $null + New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\2.0\" -Force > $null + New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null + New-Item -ItemType Directory -Path "$testdrive\Modules\Baz\" -Force > $null + + New-ModuleManifest -Path "$testdrive\Modules\Foo\1.0\Foo.psd1" -ModuleVersion 1.0 + New-ModuleManifest -Path "$testdrive\Modules\Foo\2.0\Foo.psd1" -ModuleVersion 2.0 + New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" -ModuleVersion 1.0 + New-ModuleManifest -Path "$testdrive\Modules\Baz\Baz.psd1" -ModuleVersion 1.0 + + New-Item -ItemType File -Path "$testdrive\Modules\Foo\1.0\Foo.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Foo\2.0\Foo.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar.psm1" > $null + + $removeModuleByFQNTestCases = @( + @{ + FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "1.0"}; + ShouldBeRemoved = "Foo"; + ShouldBePresent = "Bar", "Baz"; + } + @{ + FqnToRemove = @{ModuleName = "Foo"; RequiredVersion = "1.0"}; + ShouldBeRemoved = ""; + ShouldBePresent = "Bar", "Baz", "Foo"; + } + @{ + FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "2.0"}; + ShouldBeRemoved = ""; + ShouldBePresent = "Bar", "Baz", "Foo"; + } + @{ + FqnToRemove = @{ModuleName = "Foo"; RequiredVersion = "2.0"}; + ShouldBeRemoved = ""; + ShouldBePresent = "Bar", "Baz", "Foo"; + } + @{ + FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "1.0"}; + ShouldBeRemoved = "Foo"; + ShouldBePresent = "Bar", "Baz"; + } + @{ + FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "1.0"}, @{ModuleName = "Bar"; ModuleVersion = "1.0"}; + ShouldBeRemoved = "Foo", "Bar"; + ShouldBePresent = "Baz"; + } + @{ + FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "3.0"}, @{ModuleName = "Bar"; ModuleVersion = "1.0"}; + ShouldBeRemoved = "Bar"; + ShouldBePresent = "Baz", "Foo", "Foo"; + } + ) + + $removeModuleByFQNErrorTestCases = @( + @{ + FqnToRemove = @{ModuleName = "Fo"; ModuleVersion = "1.0"}; + ShouldBeRemoved = ""; + ShouldBePresent = "Bar", "Baz", "Foo", "Foo"; + } + @{ + FqnToRemove = @{ModuleName = "Foo"; ModuleVersion = "3.0"}; + ShouldBeRemoved = ""; + ShouldBePresent = "Bar", "Baz", "Foo", "Foo"; + } + @{ + FqnToRemove = @{ModuleName = "Baz"; RequiredVersion = "3.0"}; + ShouldBeRemoved = ""; + ShouldBePresent = "Bar", "Baz", "Foo", "Foo"; + } + ) + } + + BeforeEach { + Import-Module -Name "$testdrive\Modules\Foo\1.0\Foo.psd1" -Force + Import-Module -Name "$testdrive\Modules\Foo\2.0\Foo.psd1" -Force + Import-Module -Name "$testdrive\Modules\Bar\Bar.psd1" -Force + Import-Module -Name "$testdrive\Modules\Baz\Baz.psd1" -Force + + (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo" + } + + It "Remove-Module -FullyQualifiedName " -TestCases $removeModuleByFQNTestCases { + param([Microsoft.PowerShell.Commands.ModuleSpecification[]]$FqnToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + + { Remove-Module -FullyQualifiedName $FqnToRemove } | Should -Not -Throw + + if ($ShouldBeRemoved) { + (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty + } + + if ($ShouldBePresent) { + (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent + } + } + + It "Remove-Module -FullyQualifiedName (Error cases)" -TestCases $removeModuleByFQNErrorTestCases { + param([Microsoft.PowerShell.Commands.ModuleSpecification[]]$FqnToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + + { Remove-Module -FullyQualifiedName $FqnToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_NoModulesRemoved,Microsoft.PowerShell.Commands.RemoveModuleCommand" + + if ($ShouldBeRemoved) { + (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty + } + + if ($ShouldBePresent) { + (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent + } + } +} + Describe "Remove-Module core module on module path by name" -Tags "CI" { $moduleName = "Microsoft.PowerShell.Security" From a55695800d9f01472bd7db6c9cd1db8014fef61d Mon Sep 17 00:00:00 2001 From: thomas Date: Wed, 3 Apr 2019 01:36:52 +0200 Subject: [PATCH 02/14] Attempting to fix CI tests --- .../Remove-Module.Tests.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index 6d6efb96ce2..d5cfffa7188 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -2,6 +2,7 @@ # Licensed under the MIT License. Describe "Remove-Module -Name" -Tags "CI" { BeforeAll { + Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\" -Force > $null New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null @@ -41,10 +42,6 @@ Describe "Remove-Module -Name" -Tags "CI" { ) } - AfterAll { - Remove-Module -Name "Foo", "Bar", "Baz" - } - BeforeEach { Import-Module -Name "$testdrive\Modules\Foo\Foo.psd1" -Force Import-Module -Name "$testdrive\Modules\Bar\Bar.psd1" -Force @@ -53,6 +50,10 @@ Describe "Remove-Module -Name" -Tags "CI" { (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo" } + AfterAll { + Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue + } + It "Remove-Module -Name " -TestCases $removeModuleByNameTestCases { param([string[]]$PatternsToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) @@ -84,6 +85,7 @@ Describe "Remove-Module -Name" -Tags "CI" { Describe "Remove-Module -FullyQualifiedName" -Tags "CI" { BeforeAll { + Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\1.0\" -Force > $null New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\2.0\" -Force > $null @@ -165,6 +167,10 @@ Describe "Remove-Module -FullyQualifiedName" -Tags "CI" { (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo" } + AfterAll { + Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue + } + It "Remove-Module -FullyQualifiedName " -TestCases $removeModuleByFQNTestCases { param([Microsoft.PowerShell.Commands.ModuleSpecification[]]$FqnToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) From 4ecb512e0581560d285008b2d6b2c81b8786b425 Mon Sep 17 00:00:00 2001 From: pougetat Date: Wed, 3 Apr 2019 11:46:22 +0200 Subject: [PATCH 03/14] Adding tests for Remove-Module -ModuleInfo --- .../Remove-Module.Tests.ps1 | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index d5cfffa7188..3a94ca82024 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -83,7 +83,7 @@ Describe "Remove-Module -Name" -Tags "CI" { } } -Describe "Remove-Module -FullyQualifiedName" -Tags "CI" { +Describe "Remove-Module -FullyQualifiedName | -ModuleInfo" -Tags "CI" { BeforeAll { Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue @@ -198,6 +198,30 @@ Describe "Remove-Module -FullyQualifiedName" -Tags "CI" { (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent } } + + It "Remove-Module -ModuleInfo " -TestCases $removeModuleByFQNTestCases { + param([Microsoft.PowerShell.Commands.ModuleSpecification[]]$FqnToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + + $modInfo = Get-Module -FullyQualifiedName $FqnToRemove + + { Remove-Module -ModuleInfo $modInfo } | Should -Not -Throw + + if ($ShouldBeRemoved) { + (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty + } + + if ($ShouldBePresent) { + (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent + } + } + + It "Remove-Module -ModuleInfo (removing twice works)" { + $modInfo = Get-Module -Name "Bar" + + # Contrary to -Name and -FullyQualifiedName removing a non imported module works using ModuleInfo + { Remove-Module -ModuleInfo $modInfo } | Should -Not -Throw + { Remove-Module -ModuleInfo $modInfo } | Should -Not -Throw + } } Describe "Remove-Module core module on module path by name" -Tags "CI" { From 4561f238e117bee2624028fdfa10647b2a29a6cf Mon Sep 17 00:00:00 2001 From: pougetat Date: Wed, 3 Apr 2019 12:28:35 +0200 Subject: [PATCH 04/14] Rearranging tests --- .../Remove-Module.Tests.ps1 | 113 +++++++----------- 1 file changed, 42 insertions(+), 71 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index 3a94ca82024..7f95693f472 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -1,23 +1,26 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -Describe "Remove-Module -Name" -Tags "CI" { +Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { BeforeAll { Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue - New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\" -Force > $null + New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\1.0\" -Force > $null + New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\2.0\" -Force > $null New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null New-Item -ItemType Directory -Path "$testdrive\Modules\Baz\" -Force > $null - New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo.psd1" - New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" - New-ModuleManifest -Path "$testdrive\Modules\Baz\Baz.psd1" + New-ModuleManifest -Path "$testdrive\Modules\Foo\1.0\Foo.psd1" -ModuleVersion 1.0 + New-ModuleManifest -Path "$testdrive\Modules\Foo\2.0\Foo.psd1" -ModuleVersion 2.0 + New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" -ModuleVersion 1.0 + New-ModuleManifest -Path "$testdrive\Modules\Baz\Baz.psd1" -ModuleVersion 1.0 - New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Foo\1.0\Foo.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Foo\2.0\Foo.psm1" > $null New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar.psm1" > $null - New-Item -ItemType File -Path "$testdrive\Modules\Baz\Baz.psm1" > $null $removeModuleByNameTestCases = @( # Simple patterns + @{ PatternsToRemove = "Bar"; ShouldBeRemoved = "Bar"; ShouldBePresent = "Baz", "Foo", "Foo"} @{ PatternsToRemove = "Foo"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"} @{ PatternsToRemove = "Bar", "Foo"; ShouldBeRemoved = "Bar", "Foo"; ShouldBePresent = "Baz"} @{ PatternsToRemove = "Bar", "Baz", "Foo"; ShouldBeRemoved = "Bar", "Baz", "Foo"; ShouldBePresent = ""} @@ -27,79 +30,19 @@ Describe "Remove-Module -Name" -Tags "CI" { # Regex patterns #@{ PatternsToRemove = "*"; ShouldBeRemoved = "Bar", "Baz", "Foo"; ShouldBePresent = ""} -> this breaks pester for some reason - @{ PatternsToRemove = "B*"; ShouldBeRemoved = "Bar", "Baz"; ShouldBePresent = "Foo"} + @{ PatternsToRemove = "B*"; ShouldBeRemoved = "Bar", "Baz"; ShouldBePresent = "Foo", "Foo"} @{ PatternsToRemove = "F*"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"} @{ PatternsToRemove = "Foo*"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"} @{ PatternsToRemove = "F*", "Bar"; ShouldBeRemoved = "Foo", "Bar"; ShouldBePresent = "Baz"} @{ PatternsToRemove = "F*", "F*"; ShouldBeRemoved = "Foo"; ShouldBePresent = "Bar", "Baz"} - @{ PatternsToRemove = "FF*"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo"} + @{ PatternsToRemove = "FF*"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo", "Foo"} ) $removeModuleByNameErrorTestCases = @( # Invalid patterns - @{ PatternsToRemove = "Fo"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo"} - @{ PatternsToRemove = "Fo", "Ba"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo"} + @{ PatternsToRemove = "Fo"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo", "Foo"} + @{ PatternsToRemove = "Fo", "Ba"; ShouldBeRemoved = ""; ShouldBePresent = "Bar", "Baz", "Foo", "Foo"} ) - } - - BeforeEach { - Import-Module -Name "$testdrive\Modules\Foo\Foo.psd1" -Force - Import-Module -Name "$testdrive\Modules\Bar\Bar.psd1" -Force - Import-Module -Name "$testdrive\Modules\Baz\Baz.psd1" -Force - - (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo" - } - - AfterAll { - Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue - } - - It "Remove-Module -Name " -TestCases $removeModuleByNameTestCases { - param([string[]]$PatternsToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) - - { Remove-Module -Name $PatternsToRemove} | Should -Not -Throw - - if ($ShouldBeRemoved) { - (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty - } - - if ($ShouldBePresent) { - (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent - } - } - - It "Remove-Module -Name (Error cases)" -TestCases $removeModuleByNameErrorTestCases { - param([string[]]$PatternsToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) - - { Remove-Module -Name $PatternsToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_NoModulesRemoved,Microsoft.PowerShell.Commands.RemoveModuleCommand" - - if ($ShouldBeRemoved) { - (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty - } - - if ($ShouldBePresent) { - (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent - } - } -} - -Describe "Remove-Module -FullyQualifiedName | -ModuleInfo" -Tags "CI" { - BeforeAll { - Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue - - New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\1.0\" -Force > $null - New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\2.0\" -Force > $null - New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null - New-Item -ItemType Directory -Path "$testdrive\Modules\Baz\" -Force > $null - - New-ModuleManifest -Path "$testdrive\Modules\Foo\1.0\Foo.psd1" -ModuleVersion 1.0 - New-ModuleManifest -Path "$testdrive\Modules\Foo\2.0\Foo.psd1" -ModuleVersion 2.0 - New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" -ModuleVersion 1.0 - New-ModuleManifest -Path "$testdrive\Modules\Baz\Baz.psd1" -ModuleVersion 1.0 - - New-Item -ItemType File -Path "$testdrive\Modules\Foo\1.0\Foo.psm1" > $null - New-Item -ItemType File -Path "$testdrive\Modules\Foo\2.0\Foo.psm1" > $null - New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar.psm1" > $null $removeModuleByFQNTestCases = @( @{ @@ -171,6 +114,34 @@ Describe "Remove-Module -FullyQualifiedName | -ModuleInfo" -Tags "CI" { Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue } + It "Remove-Module -Name " -TestCases $removeModuleByNameTestCases { + param([string[]]$PatternsToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + + { Remove-Module -Name $PatternsToRemove} | Should -Not -Throw + + if ($ShouldBeRemoved) { + (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty + } + + if ($ShouldBePresent) { + (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent + } + } + + It "Remove-Module -Name (Error cases)" -TestCases $removeModuleByNameErrorTestCases { + param([string[]]$PatternsToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + + { Remove-Module -Name $PatternsToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_NoModulesRemoved,Microsoft.PowerShell.Commands.RemoveModuleCommand" + + if ($ShouldBeRemoved) { + (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty + } + + if ($ShouldBePresent) { + (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent + } + } + It "Remove-Module -FullyQualifiedName " -TestCases $removeModuleByFQNTestCases { param([Microsoft.PowerShell.Commands.ModuleSpecification[]]$FqnToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) From b0e42cf69ca496ed4a624fe2f9fb5328ed5e6d92 Mon Sep 17 00:00:00 2001 From: pougetat Date: Thu, 4 Apr 2019 09:23:58 +0200 Subject: [PATCH 05/14] Adding remove-module readonly modules tests --- .../Remove-Module.Tests.ps1 | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index 7f95693f472..2d2bcb485e8 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -195,6 +195,117 @@ Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { } } +Describe "Remove-Module : module is readOnly" -Tags "CI" { + + BeforeAll { + Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue + + New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\" -Force > $null + New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null + New-Item -ItemType Directory -Path "$testdrive\Modules\Baz\" -Force > $null + + New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo_ro.psd1" + New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo_rw.psd1" + New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar_rw.psd1" + New-ModuleManifest -Path "$testdrive\Modules\Baz\Baz_ro.psd1" + + New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo_ro.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo_rw.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar_rw.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Baz\Baz_ro.psm1" > $null + + $removeReadOnlyModulesStopOnErrorTestCases = @( + # Simple patterns + @{ NamesToRemove = "Foo_ro"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} + @{ NamesToRemove = "Foo_ro", "Foo_rw"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} + @{ NamesToRemove = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} + + # Regex patterns + @{ NamesToRemove = "Foo_*"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} + @{ NamesToRemove = "Foo_*", "Ba*"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} + ) + + $removeReadOnlyModulesContinueOnErrorTestCases = @( + # Simple patterns + @{ NamesToRemove = "Foo_ro"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} + @{ NamesToRemove = "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro"} + @{ NamesToRemove = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Bar_rw", "Foo_rw"; ShouldBePresent = "Baz_ro", "Foo_ro"} + + # Regex patterns + @{ NamesToRemove = "Foo_*"; ShouldBeRemoved = "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro"} + @{ NamesToRemove = "Foo_*", "Ba*"; ShouldBeRemoved = "Bar_rw", "Foo_rw"; ShouldBePresent = "Baz_ro", "Foo_ro"} + ) + + $removeForceReadOnlyModules = @( + # Simple patterns + @{ NamesToRemove = "Foo_ro"; ShouldBeRemoved = "Foo_ro"; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_rw"} + @{ NamesToRemove = "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Foo_ro", "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_ro"} + @{ NamesToRemove = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"; ShouldBePresent = ""} + + # Regex patterns + @{ NamesToRemove = "Foo_*"; ShouldBeRemoved = "Foo_ro", "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_ro"} + @{ NamesToRemove = "Foo_*", "Ba*"; ShouldBeRemoved = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"; ShouldBePresent = ""} + ) + } + + AfterAll { + Remove-Module -Force -Name "Foo_*", "Ba*" -ErrorAction SilentlyContinue + } + + BeforeEach { + Import-Module -Name "$testdrive\Modules\Foo\Foo_ro.psd1" -Force + (Get-Module -Name "Foo_ro").AccessMode = "readOnly" + Import-Module -Name "$testdrive\Modules\Foo\Foo_rw.psd1" -Force + Import-Module -Name "$testdrive\Modules\Bar\Bar_rw.psd1" -Force + Import-Module -Name "$testdrive\Modules\Baz\Baz_ro.psd1" -Force + (Get-Module -Name "Baz_ro").AccessMode = "readOnly" + + (Get-Module -Name "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw" + } + + It "Remove-Module -ErrorAction Stop (ReadOnly modules): " -TestCases $removeReadOnlyModulesStopOnErrorTestCases{ + param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + + { Remove-Module -Name $NamesToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_ModuleIsReadOnly,Microsoft.PowerShell.Commands.RemoveModuleCommand" + + if ($ShouldBeRemoved) { + (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty + } + + if ($ShouldBePresent) { + (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent + } + } + + It "Remove-Module -ErrorAction SilentlyContinue (ReadOnly modules): " -TestCases $removeReadOnlyModulesContinueOnErrorTestCases{ + param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + + { Remove-Module -Name $NamesToRemove -ErrorAction SilentlyContinue } | Should -Not -Throw + + if ($ShouldBeRemoved) { + (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty + } + + if ($ShouldBePresent) { + (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent + } + } + + It "Remove-Module -Force (ReadOnly modules): " -TestCases $removeForceReadOnlyModules{ + param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + + { Remove-Module -Force -Name $NamesToRemove -ErrorAction Stop } | Should -Not -Throw + + if ($ShouldBeRemoved) { + (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty + } + + if ($ShouldBePresent) { + (Get-Module -Name $ShouldBePresent).Name | Should -BeExactly $ShouldBePresent + } + } +} + Describe "Remove-Module core module on module path by name" -Tags "CI" { $moduleName = "Microsoft.PowerShell.Security" From b4c99c2cd50643f3b98fb9ba51a956a60b5e9537 Mon Sep 17 00:00:00 2001 From: pougetat Date: Thu, 4 Apr 2019 13:01:16 +0200 Subject: [PATCH 06/14] Addressing PR comment --- .../Remove-Module.Tests.ps1 | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index 2d2bcb485e8..f069e06fb2c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -106,8 +106,6 @@ Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { Import-Module -Name "$testdrive\Modules\Foo\2.0\Foo.psd1" -Force Import-Module -Name "$testdrive\Modules\Bar\Bar.psd1" -Force Import-Module -Name "$testdrive\Modules\Baz\Baz.psd1" -Force - - (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo" } AfterAll { @@ -117,6 +115,8 @@ Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { It "Remove-Module -Name " -TestCases $removeModuleByNameTestCases { param([string[]]$PatternsToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo" + { Remove-Module -Name $PatternsToRemove} | Should -Not -Throw if ($ShouldBeRemoved) { @@ -131,6 +131,8 @@ Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { It "Remove-Module -Name (Error cases)" -TestCases $removeModuleByNameErrorTestCases { param([string[]]$PatternsToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo" + { Remove-Module -Name $PatternsToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_NoModulesRemoved,Microsoft.PowerShell.Commands.RemoveModuleCommand" if ($ShouldBeRemoved) { @@ -145,6 +147,8 @@ Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { It "Remove-Module -FullyQualifiedName " -TestCases $removeModuleByFQNTestCases { param([Microsoft.PowerShell.Commands.ModuleSpecification[]]$FqnToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo" + { Remove-Module -FullyQualifiedName $FqnToRemove } | Should -Not -Throw if ($ShouldBeRemoved) { @@ -159,6 +163,8 @@ Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { It "Remove-Module -FullyQualifiedName (Error cases)" -TestCases $removeModuleByFQNErrorTestCases { param([Microsoft.PowerShell.Commands.ModuleSpecification[]]$FqnToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo" + { Remove-Module -FullyQualifiedName $FqnToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_NoModulesRemoved,Microsoft.PowerShell.Commands.RemoveModuleCommand" if ($ShouldBeRemoved) { @@ -173,8 +179,9 @@ Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { It "Remove-Module -ModuleInfo " -TestCases $removeModuleByFQNTestCases { param([Microsoft.PowerShell.Commands.ModuleSpecification[]]$FqnToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) - $modInfo = Get-Module -FullyQualifiedName $FqnToRemove + (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo" + $modInfo = Get-Module -FullyQualifiedName $FqnToRemove { Remove-Module -ModuleInfo $modInfo } | Should -Not -Throw if ($ShouldBeRemoved) { @@ -187,8 +194,9 @@ Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { } It "Remove-Module -ModuleInfo (removing twice works)" { - $modInfo = Get-Module -Name "Bar" + (Get-Module -Name "Bar", "Baz", "Foo").Name | Should -BeExactly "Bar", "Baz", "Foo", "Foo" + $modInfo = Get-Module -Name "Bar" # Contrary to -Name and -FullyQualifiedName removing a non imported module works using ModuleInfo { Remove-Module -ModuleInfo $modInfo } | Should -Not -Throw { Remove-Module -ModuleInfo $modInfo } | Should -Not -Throw @@ -259,13 +267,13 @@ Describe "Remove-Module : module is readOnly" -Tags "CI" { Import-Module -Name "$testdrive\Modules\Bar\Bar_rw.psd1" -Force Import-Module -Name "$testdrive\Modules\Baz\Baz_ro.psd1" -Force (Get-Module -Name "Baz_ro").AccessMode = "readOnly" - - (Get-Module -Name "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw" } It "Remove-Module -ErrorAction Stop (ReadOnly modules): " -TestCases $removeReadOnlyModulesStopOnErrorTestCases{ param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + (Get-Module -Name "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw" + { Remove-Module -Name $NamesToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_ModuleIsReadOnly,Microsoft.PowerShell.Commands.RemoveModuleCommand" if ($ShouldBeRemoved) { @@ -280,6 +288,8 @@ Describe "Remove-Module : module is readOnly" -Tags "CI" { It "Remove-Module -ErrorAction SilentlyContinue (ReadOnly modules): " -TestCases $removeReadOnlyModulesContinueOnErrorTestCases{ param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + (Get-Module -Name "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw" + { Remove-Module -Name $NamesToRemove -ErrorAction SilentlyContinue } | Should -Not -Throw if ($ShouldBeRemoved) { @@ -294,6 +304,8 @@ Describe "Remove-Module : module is readOnly" -Tags "CI" { It "Remove-Module -Force (ReadOnly modules): " -TestCases $removeForceReadOnlyModules{ param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) + (Get-Module -Name "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw" + { Remove-Module -Force -Name $NamesToRemove -ErrorAction Stop } | Should -Not -Throw if ($ShouldBeRemoved) { @@ -311,15 +323,18 @@ Describe "Remove-Module core module on module path by name" -Tags "CI" { BeforeEach { Import-Module -Name $moduleName -Force - (Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName } It "should be able to remove a module with using Name switch" { + (Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName + { Remove-Module -Name $moduleName } | Should -Not -Throw (Get-Module -Name $moduleName).Name | Should -BeNullOrEmpty } It "should be able to remove a module with using ModuleInfo switch" { + (Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName + $a = Get-Module -Name $moduleName { Remove-Module -ModuleInfo $a } | Should -Not -Throw (Get-Module -Name $moduleName).Name | Should -BeNullOrEmpty @@ -350,13 +365,11 @@ Describe "Remove-Module custom module with FullyQualifiedName" -Tags "Feature" { @{ ModPath = "$TestDrive/Modules\$moduleName/$moduleName.psd1" } ) - BeforeEach { - Get-Module $moduleName | Remove-Module - } - It "Removes a module with fully qualified name with path " -TestCases $testCases -Pending { param([string]$ModPath) + Get-Module $moduleName | Remove-Module + $m = Import-Module $modulePath -PassThru $m.Name | Should -Be $moduleName From 5b3b0d414d41cfaa5d39420d488027a3a3458240 Mon Sep 17 00:00:00 2001 From: pougetat Date: Thu, 4 Apr 2019 13:42:00 +0200 Subject: [PATCH 07/14] Adding Const module removal tests + cleaning up other tests --- .../Remove-Module.Tests.ps1 | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index f069e06fb2c..b6cb687ec0f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -206,7 +206,7 @@ Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { Describe "Remove-Module : module is readOnly" -Tags "CI" { BeforeAll { - Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue + Remove-Module -Force -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\" -Force > $null New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null @@ -215,44 +215,42 @@ Describe "Remove-Module : module is readOnly" -Tags "CI" { New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo_ro.psd1" New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo_rw.psd1" New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar_rw.psd1" - New-ModuleManifest -Path "$testdrive\Modules\Baz\Baz_ro.psd1" + New-ModuleManifest -Path "$testdrive\Modules\Baz\Baz_const.psd1" New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo_ro.psm1" > $null New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo_rw.psm1" > $null New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar_rw.psm1" > $null - New-Item -ItemType File -Path "$testdrive\Modules\Baz\Baz_ro.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Baz\Baz_const.psm1" > $null - $removeReadOnlyModulesStopOnErrorTestCases = @( + $removeReadOnlyModulesTestCases = @( # Simple patterns - @{ NamesToRemove = "Foo_ro"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} - @{ NamesToRemove = "Foo_ro", "Foo_rw"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} - @{ NamesToRemove = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} + @{ NamesToRemove = "Foo_ro"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_const", "Foo_ro", "Foo_rw"} + @{ NamesToRemove = "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_const", "Foo_ro"} + @{ NamesToRemove = "Bar_rw", "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Bar_rw", "Foo_rw"; ShouldBePresent = "Baz_const", "Foo_ro"} # Regex patterns - @{ NamesToRemove = "Foo_*"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} - @{ NamesToRemove = "Foo_*", "Ba*"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} + @{ NamesToRemove = "Foo_*"; ShouldBeRemoved = "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_const", "Foo_ro"} + @{ NamesToRemove = "Foo_*", "Bar_*"; ShouldBeRemoved = "Bar_rw", "Foo_rw"; ShouldBePresent = "Baz_const", "Foo_ro"} ) - $removeReadOnlyModulesContinueOnErrorTestCases = @( + $removeForceReadOnlyModulesTestCases = @( # Simple patterns - @{ NamesToRemove = "Foo_ro"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"} - @{ NamesToRemove = "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro"} - @{ NamesToRemove = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Bar_rw", "Foo_rw"; ShouldBePresent = "Baz_ro", "Foo_ro"} + @{ NamesToRemove = "Foo_ro"; ShouldBeRemoved = "Foo_ro"; ShouldBePresent = "Bar_rw", "Baz_const", "Foo_rw"} + @{ NamesToRemove = "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Foo_ro", "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_const"} + @{ NamesToRemove = "Bar_rw", "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Bar_rw", "Foo_ro", "Foo_rw"; ShouldBePresent = "Baz_const"} # Regex patterns - @{ NamesToRemove = "Foo_*"; ShouldBeRemoved = "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_ro"} - @{ NamesToRemove = "Foo_*", "Ba*"; ShouldBeRemoved = "Bar_rw", "Foo_rw"; ShouldBePresent = "Baz_ro", "Foo_ro"} + @{ NamesToRemove = "Foo_*"; ShouldBeRemoved = "Foo_ro", "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_const"} + @{ NamesToRemove = "Foo_*", "Bar_*"; ShouldBeRemoved = "Bar_rw", "Foo_ro", "Foo_rw"; ShouldBePresent = "Baz_const"} ) - $removeForceReadOnlyModules = @( + $removeConstantModulesTestCases = @( # Simple patterns - @{ NamesToRemove = "Foo_ro"; ShouldBeRemoved = "Foo_ro"; ShouldBePresent = "Bar_rw", "Baz_ro", "Foo_rw"} - @{ NamesToRemove = "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Foo_ro", "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_ro"} - @{ NamesToRemove = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"; ShouldBePresent = ""} + @{ NamesToRemove = "Baz_const"; ShouldBeRemoved = ""; ShouldBePresent = "Bar_rw", "Baz_const", "Foo_ro", "Foo_rw"} + @{ NamesToRemove = "Baz_const", "Foo_ro", "Foo_rw"; ShouldBeRemoved = "Foo_ro", "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_const"} # Regex patterns - @{ NamesToRemove = "Foo_*"; ShouldBeRemoved = "Foo_ro", "Foo_rw"; ShouldBePresent = "Bar_rw", "Baz_ro"} - @{ NamesToRemove = "Foo_*", "Ba*"; ShouldBeRemoved = "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw"; ShouldBePresent = ""} + @{ NamesToRemove = "Foo_*", "Ba*"; ShouldBeRemoved = "Bar_rw", "Foo_ro", "Foo_rw"; ShouldBePresent = "Baz_const"} ) } @@ -265,16 +263,17 @@ Describe "Remove-Module : module is readOnly" -Tags "CI" { (Get-Module -Name "Foo_ro").AccessMode = "readOnly" Import-Module -Name "$testdrive\Modules\Foo\Foo_rw.psd1" -Force Import-Module -Name "$testdrive\Modules\Bar\Bar_rw.psd1" -Force - Import-Module -Name "$testdrive\Modules\Baz\Baz_ro.psd1" -Force - (Get-Module -Name "Baz_ro").AccessMode = "readOnly" + Import-Module -Name "$testdrive\Modules\Baz\Baz_const.psd1" -Force + (Get-Module -Name "Baz_const").AccessMode = "Constant" } - It "Remove-Module -ErrorAction Stop (ReadOnly modules): " -TestCases $removeReadOnlyModulesStopOnErrorTestCases{ + It "Remove-Module (ReadOnly modules): " -TestCases $removeReadOnlyModulesTestCases { param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) - (Get-Module -Name "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw" + (Get-Module -Name "Bar_rw", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Foo_ro", "Foo_rw" { Remove-Module -Name $NamesToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_ModuleIsReadOnly,Microsoft.PowerShell.Commands.RemoveModuleCommand" + { Remove-Module -Name $NamesToRemove -ErrorAction SilentlyContinue } | Should -Not -Throw if ($ShouldBeRemoved) { (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty @@ -285,12 +284,12 @@ Describe "Remove-Module : module is readOnly" -Tags "CI" { } } - It "Remove-Module -ErrorAction SilentlyContinue (ReadOnly modules): " -TestCases $removeReadOnlyModulesContinueOnErrorTestCases{ + It "Remove-Module -Force (ReadOnly modules): " -TestCases $removeForceReadOnlyModulesTestCases { param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) - (Get-Module -Name "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw" + (Get-Module -Name "Bar_rw", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Foo_ro", "Foo_rw" - { Remove-Module -Name $NamesToRemove -ErrorAction SilentlyContinue } | Should -Not -Throw + { Remove-Module -Force -Name $NamesToRemove -ErrorAction Stop } | Should -Not -Throw if ($ShouldBeRemoved) { (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty @@ -301,12 +300,13 @@ Describe "Remove-Module : module is readOnly" -Tags "CI" { } } - It "Remove-Module -Force (ReadOnly modules): " -TestCases $removeForceReadOnlyModules{ + It "Remove-Module -Force (Constant modules): " -TestCases $removeConstantModulesTestCases { param([string[]]$NamesToRemove, [string[]]$ShouldBeRemoved, [string[]]$ShouldBePresent) - (Get-Module -Name "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Baz_ro", "Foo_ro", "Foo_rw" + (Get-Module -Name "Bar_rw", "Baz_const", "Foo_ro", "Foo_rw").Name | Should -BeExactly "Bar_rw", "Baz_const", "Foo_ro", "Foo_rw" - { Remove-Module -Force -Name $NamesToRemove -ErrorAction Stop } | Should -Not -Throw + { Remove-Module -Force -Name $NamesToRemove -ErrorAction Stop } | Should -Throw -ErrorId "Modules_ModuleIsConstant,Microsoft.PowerShell.Commands.RemoveModuleCommand" + { Remove-Module -Force -Name $NamesToRemove -ErrorAction SilentlyContinue } | Should -Not -Throw if ($ShouldBeRemoved) { (Get-Module -Name $ShouldBeRemoved).Name | Should -BeNullOrEmpty From 8da1d44399963b46e79682a3b791d0052a2145b6 Mon Sep 17 00:00:00 2001 From: pougetat Date: Fri, 5 Apr 2019 15:50:50 +0200 Subject: [PATCH 08/14] Adding tests to remove-module : module provides PSDrive for current PS Session --- .../Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index b6cb687ec0f..928b9c31d57 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -318,6 +318,14 @@ Describe "Remove-Module : module is readOnly" -Tags "CI" { } } +Describe "Remove-Module : module provides the PSDrive for current PS Session" -Tags "CI" { + It "Remove-Module : module provides the PSDrive for current PS Session" { + + $module = Get-Module (Join-Path $PSHome "System.Management.Automation.dll") -ListAvailable + { Remove-Module $module -ErrorAction Stop } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.RemoveModuleCommand" + } +} + Describe "Remove-Module core module on module path by name" -Tags "CI" { $moduleName = "Microsoft.PowerShell.Security" From 516ec279fed2f62c5137b3c337cba5d17b39c340 Mon Sep 17 00:00:00 2001 From: pougetat Date: Fri, 5 Apr 2019 19:14:38 +0200 Subject: [PATCH 09/14] Adding remove-module test : module contains nested modules --- .../Remove-Module.Tests.ps1 | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index 928b9c31d57..dba51d088ff 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -203,7 +203,7 @@ Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { } } -Describe "Remove-Module : module is readOnly" -Tags "CI" { +Describe "Remove-Module : module is readOnly | Constant" -Tags "CI" { BeforeAll { Remove-Module -Force -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue @@ -326,6 +326,33 @@ Describe "Remove-Module : module provides the PSDrive for current PS Session" -T } } +Describe "Remove-Module : module contains nested modules" -Tags "CI" { + + BeforeAll { + Remove-Module -Force -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue + + New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\" -Force > $null + New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null + + New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo.psd1" -NestedModules "..\Bar\Bar.psd1" -FunctionsToExport "BarFunc" + New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" -RootModule "Bar.psm1" -FunctionsToExport "BarFunc" + + New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar.psm1" > $null + Set-Content -Path "$testdrive\Modules\Bar\Bar.psm1" -Value "function BarFunc {}" + } + + It "Remove-Module : module contains nested modules" { + Import-Module "$testdrive\Modules\Foo\Foo.psd1" -Force + (Get-Module -Name "Foo").Name | Should -BeExactly "Foo" + + { Get-Command BarFunc -ErrorAction Stop } | Should -Not -Throw + { Remove-Module -Name Foo -ErrorAction Stop } | Should -Not -Throw + { Get-Command BarFunc -ErrorAction Stop } | Should -Throw + (Get-Module -Name Foo).Name | Should -BeNullOrEmpty + } +} + Describe "Remove-Module core module on module path by name" -Tags "CI" { $moduleName = "Microsoft.PowerShell.Security" From 6b31ef2e37bd72e0abc0c0818d65c6a48d95bc01 Mon Sep 17 00:00:00 2001 From: pougetat Date: Fri, 5 Apr 2019 19:31:59 +0200 Subject: [PATCH 10/14] test currently failing --- .../Remove-Module.Tests.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index dba51d088ff..105a27fa5e5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -333,16 +333,24 @@ Describe "Remove-Module : module contains nested modules" -Tags "CI" { New-Item -ItemType Directory -Path "$testdrive\Modules\Foo\" -Force > $null New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null + New-Item -ItemType Directory -Path "$testdrive\Modules\Baz\" -Force > $null - New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo.psd1" -NestedModules "..\Bar\Bar.psd1" -FunctionsToExport "BarFunc" - New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" -RootModule "Bar.psm1" -FunctionsToExport "BarFunc" + New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo.psd1" + New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" + New-ModuleManifest -Path "$testdrive\Modules\Baz\Baz.psd1" New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo.psm1" > $null New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar.psm1" > $null + New-Item -ItemType File -Path "$testdrive\Modules\Baz\Baz.psm1" > $null + Set-Content -Path "$testdrive\Modules\Foo\Foo.psm1" -Value "function FooFunc {}" Set-Content -Path "$testdrive\Modules\Bar\Bar.psm1" -Value "function BarFunc {}" + Set-Content -Path "$testdrive\Modules\Baz\Baz.psm1" -Value "function BazFunc {}" } It "Remove-Module : module contains nested modules" { + Update-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" -RootModule "Bar.psm1" -FunctionsToExport "BarFunc" + Update-ModuleManifest -Path "$testdrive\Modules\Foo\Foo.psd1" -NestedModules "..\Bar\Bar.psd1" -FunctionsToExport "BarFunc" + Import-Module "$testdrive\Modules\Foo\Foo.psd1" -Force (Get-Module -Name "Foo").Name | Should -BeExactly "Foo" From ff3c386e570a703ef22ac4800c4b6abdeccb1cae Mon Sep 17 00:00:00 2001 From: pougetat Date: Fri, 5 Apr 2019 22:21:55 +0200 Subject: [PATCH 11/14] Fixing tests and adding remove-module circular dependencies test --- .../Remove-Module.Tests.ps1 | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index 105a27fa5e5..bdc901dcf7a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -335,21 +335,17 @@ Describe "Remove-Module : module contains nested modules" -Tags "CI" { New-Item -ItemType Directory -Path "$testdrive\Modules\Bar\" -Force > $null New-Item -ItemType Directory -Path "$testdrive\Modules\Baz\" -Force > $null - New-ModuleManifest -Path "$testdrive\Modules\Foo\Foo.psd1" - New-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" - New-ModuleManifest -Path "$testdrive\Modules\Baz\Baz.psd1" - New-Item -ItemType File -Path "$testdrive\Modules\Foo\Foo.psm1" > $null New-Item -ItemType File -Path "$testdrive\Modules\Bar\Bar.psm1" > $null New-Item -ItemType File -Path "$testdrive\Modules\Baz\Baz.psm1" > $null + Set-Content -Path "$testdrive\Modules\Foo\Foo.psm1" -Value "function FooFunc {}" Set-Content -Path "$testdrive\Modules\Bar\Bar.psm1" -Value "function BarFunc {}" - Set-Content -Path "$testdrive\Modules\Baz\Baz.psm1" -Value "function BazFunc {}" } It "Remove-Module : module contains nested modules" { - Update-ModuleManifest -Path "$testdrive\Modules\Bar\Bar.psd1" -RootModule "Bar.psm1" -FunctionsToExport "BarFunc" - Update-ModuleManifest -Path "$testdrive\Modules\Foo\Foo.psd1" -NestedModules "..\Bar\Bar.psd1" -FunctionsToExport "BarFunc" + New-ModuleManifest "$testdrive\Modules\Bar\Bar.psd1" -RootModule "./Bar.psm1" -FunctionsToExport "BarFunc" + New-ModuleManifest "$testdrive\Modules\Foo\Foo.psd1" -NestedModules "../Bar/Bar.psd1" -FunctionsToExport "BarFunc" Import-Module "$testdrive\Modules\Foo\Foo.psd1" -Force (Get-Module -Name "Foo").Name | Should -BeExactly "Foo" @@ -359,6 +355,18 @@ Describe "Remove-Module : module contains nested modules" -Tags "CI" { { Get-Command BarFunc -ErrorAction Stop } | Should -Throw (Get-Module -Name Foo).Name | Should -BeNullOrEmpty } + + It "Remove-Module : module contains nested modules with circular dependencies" { + New-ModuleManifest "$testdrive\Modules\Bar\Bar.psd1" -RootModule "Bar" -FunctionsToExport "BarFunc" -NestedModules "Bar" + + Import-Module "$testdrive\Modules\Bar\Bar.psd1" -Force + (Get-Module -Name "Bar").Name | Should -BeExactly "Bar" + + { Get-Command BarFunc -ErrorAction Stop } | Should -Not -Throw + { Remove-Module -Name "Bar" -ErrorAction Stop } | Should -Not -Throw + { Get-Command BarFunc -ErrorAction Stop } | Should -Throw + (Get-Module -Name "Bar").Name | Should -BeNullOrEmpty + } } Describe "Remove-Module core module on module path by name" -Tags "CI" { From eacde042bab0ba01de2ecfac3ef6e7c4235e0571 Mon Sep 17 00:00:00 2001 From: pougetat Date: Fri, 5 Apr 2019 23:10:36 +0200 Subject: [PATCH 12/14] Adding test for remove-module where modules are required by others --- .../Remove-Module.Tests.ps1 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index bdc901dcf7a..d156853749a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -351,9 +351,9 @@ Describe "Remove-Module : module contains nested modules" -Tags "CI" { (Get-Module -Name "Foo").Name | Should -BeExactly "Foo" { Get-Command BarFunc -ErrorAction Stop } | Should -Not -Throw - { Remove-Module -Name Foo -ErrorAction Stop } | Should -Not -Throw + { Remove-Module -Name "Foo" -ErrorAction Stop } | Should -Not -Throw { Get-Command BarFunc -ErrorAction Stop } | Should -Throw - (Get-Module -Name Foo).Name | Should -BeNullOrEmpty + (Get-Module -Name "Foo").Name | Should -BeNullOrEmpty } It "Remove-Module : module contains nested modules with circular dependencies" { @@ -367,6 +367,17 @@ Describe "Remove-Module : module contains nested modules" -Tags "CI" { { Get-Command BarFunc -ErrorAction Stop } | Should -Throw (Get-Module -Name "Bar").Name | Should -BeNullOrEmpty } + + It "Remove-Module : modules are required by other modules" { + New-ModuleManifest "$testdrive\Modules\Bar\Bar.psd1" + New-ModuleManifest "$testdrive\Modules\Foo\Foo.psd1" -RequiredModules "Bar" + + Import-Module "$testdrive\Modules\Bar\Bar.psd1" -Force + Import-Module "$testdrive\Modules\Foo\Foo.psd1" -Force + + (Get-Module -Name "Bar").Name | Should -BeExactly "Bar" + { Remove-Module "Bar" -ErrorAction Stop } | Should -Throw -ErrorId "Modules_ModuleIsRequired,Microsoft.PowerShell.Commands.RemoveModuleCommand" + } } Describe "Remove-Module core module on module path by name" -Tags "CI" { From adc0f24c72be1f0b83286a4d8ddb2cf5dcfa7339 Mon Sep 17 00:00:00 2001 From: pougetat Date: Fri, 5 Apr 2019 23:22:11 +0200 Subject: [PATCH 13/14] Adding remove-module module required by other modules test --- .../Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index d156853749a..cb35fe52f30 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -374,8 +374,12 @@ Describe "Remove-Module : module contains nested modules" -Tags "CI" { Import-Module "$testdrive\Modules\Bar\Bar.psd1" -Force Import-Module "$testdrive\Modules\Foo\Foo.psd1" -Force - (Get-Module -Name "Bar").Name | Should -BeExactly "Bar" + (Get-Module -Name "Foo").Name | Should -BeExactly "Foo" + + {Remove-Module "Foo" -ErrorAction Stop } | Should -Not -Throw + Import-Module "$testdrive\Modules\Foo\Foo.psd1" -Force + { Remove-Module "Bar" -ErrorAction Stop } | Should -Throw -ErrorId "Modules_ModuleIsRequired,Microsoft.PowerShell.Commands.RemoveModuleCommand" } } From 0f147ad4cc8e1a94cfe4d55cfb3d9a44a34fc3b9 Mon Sep 17 00:00:00 2001 From: thomas Date: Sat, 13 Apr 2019 07:53:18 +0200 Subject: [PATCH 14/14] Addressing PR comment --- .../Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 index cb35fe52f30..37739cdb7ad 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Remove-Module.Tests.ps1 @@ -1,5 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. + Describe "Remove-Module -Name | -FullyQualifiedName | -ModuleInfo" -Tags "CI" { BeforeAll { Remove-Module -Name "Foo", "Bar", "Baz" -ErrorAction SilentlyContinue