From d7a8b1cd6efa7a3d204ec99fd5726c24cd98708f Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Tue, 27 Feb 2018 16:17:20 -0800 Subject: [PATCH 1/8] Tests for Get-Process cmdlet. --- .../Get-Process.Tests.ps1 | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 index afd99b6f00e..4fa5e4d3fc5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 @@ -10,6 +10,7 @@ Describe "Get-Process" -Tags "CI" { # These tests are no good, please replace! BeforeAll { $ps = Get-Process + $idleProcessPid = 0 } It "Should return a type of Object[] for Get-Process cmdlet" -Pending:$IsMacOS { ,$ps | Should BeOfType "System.Object[]" @@ -18,6 +19,31 @@ Describe "Get-Process" -Tags "CI" { It "Should have not empty Name flags set for Get-Process object" -Pending:$IsMacOS { $ps | foreach-object { $_.Name | Should Not BeNullOrEmpty } } + + It "Should throw an error for non existing process id." { + $randomId = 123456789 + { Get-Process -Id $randomId -ErrorAction Stop } | ShouldBeErrorId "NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand" + } + + It "Should throw an exception when process id is null." { + { Get-Process -id $null } | Should -Throw + } + + It "Should throw an exception when -InputObject parameter is null." { + { Get-Process -InputObject $null } | Should -Throw + } + + It "Returns empty string when process name is unavailable." { + (Get-Process -Id $idleProcessPid).Name | Should -BeNullOrEmpty + } + + It "Test for process property = Name" { + (Get-Process -Id $pid).Name | Should -BeExactly "pwsh" + } + + It "Test for process property = Id" { + (Get-Process -Id $pid).Id | Should -BeExactly $pid + } } Describe "Get-Process Formatting" -Tags "Feature" { From 7e71abe4ca90dea7f41f0d09a88d4514f8f3c97f Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Wed, 28 Feb 2018 10:39:40 -0800 Subject: [PATCH 2/8] Tests for Get-Process run ad admin. --- .../Get-Process.Tests.ps1 | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 index 4fa5e4d3fc5..91fbbd768d4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 @@ -4,6 +4,19 @@ Describe "Get-Process for admin" -Tags @('CI', 'RequireAdminOnWindows') { It "Should support -IncludeUserName" { (Get-Process -Id $pid -IncludeUserName).UserName | Should Match $env:USERNAME } + + It "Should support -Module" { + $modules = Get-Process -Id $pid -Module + $modules.GetType() | Should -BeExactly "System.Object[]" + foreach ($module in $modules) { + $module.GetType() | Should -BeExactly "System.Diagnostics.ProcessModule" + } + } + + It "Should support -FileVersionInfo" { + $pwshVersion = Get-Process -Id $pid -FileVersionInfo + $pwshVersion.FileVersion | Should -BeExactly $PSVersionTable.PSVersion + } } Describe "Get-Process" -Tags "CI" { @@ -33,8 +46,8 @@ Describe "Get-Process" -Tags "CI" { { Get-Process -InputObject $null } | Should -Throw } - It "Returns empty string when process name is unavailable." { - (Get-Process -Id $idleProcessPid).Name | Should -BeNullOrEmpty + It "Should not fail to get process name even if it is unavailable." { + { (Get-Process -Id $idleProcessPid).Name } | Should -Not -Throw } It "Test for process property = Name" { @@ -44,6 +57,18 @@ Describe "Get-Process" -Tags "CI" { It "Test for process property = Id" { (Get-Process -Id $pid).Id | Should -BeExactly $pid } + + It "Should fail to run Get-Process with -IncludeUserName without admin" { + { Get-Process -IncludeUserName } | Should -Throw + } + + It "Should fail to run Get-Process with -Module without admin" { + { Get-Process -Module -ErrorAction Stop } | ShouldBeErrorId "CouldNotEnumerateModules,Microsoft.PowerShell.Commands.GetProcessCommand" + } + + It "Should fail to run Get-Process with -FileVersionInfo without admin" { + { Get-Process -FileVersionInfo -ErrorAction Stop } | Should -Throw + } } Describe "Get-Process Formatting" -Tags "Feature" { From 8922a69e0b44e3a6eedd5397e296cd0840b494c3 Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Wed, 28 Feb 2018 11:30:26 -0800 Subject: [PATCH 3/8] Skipping some Get-Process tests on Linux --- .../Microsoft.PowerShell.Management/Get-Process.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 index 91fbbd768d4..dc2bba977b1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 @@ -13,7 +13,7 @@ Describe "Get-Process for admin" -Tags @('CI', 'RequireAdminOnWindows') { } } - It "Should support -FileVersionInfo" { + It "Should support -FileVersionInfo" -Skip:(!$IsWindows) { $pwshVersion = Get-Process -Id $pid -FileVersionInfo $pwshVersion.FileVersion | Should -BeExactly $PSVersionTable.PSVersion } @@ -58,15 +58,15 @@ Describe "Get-Process" -Tags "CI" { (Get-Process -Id $pid).Id | Should -BeExactly $pid } - It "Should fail to run Get-Process with -IncludeUserName without admin" { + It "Should fail to run Get-Process with -IncludeUserName without admin" -Skip:(!$IsWindows) { { Get-Process -IncludeUserName } | Should -Throw } - It "Should fail to run Get-Process with -Module without admin" { + It "Should fail to run Get-Process with -Module without admin" -Skip:(!$IsWindows) { { Get-Process -Module -ErrorAction Stop } | ShouldBeErrorId "CouldNotEnumerateModules,Microsoft.PowerShell.Commands.GetProcessCommand" } - It "Should fail to run Get-Process with -FileVersionInfo without admin" { + It "Should fail to run Get-Process with -FileVersionInfo without admin" -Skip:(!$IsWindows) { { Get-Process -FileVersionInfo -ErrorAction Stop } | Should -Throw } } From 2a892a6452c6b5454dcac0584e6c23f1ed0bbe7c Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Wed, 28 Feb 2018 16:50:28 -0800 Subject: [PATCH 4/8] Skip test for -FileVersionInfo parameter for Linux because of the bug that cause the command to hang. --- .../Microsoft.PowerShell.Management/Get-Process.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 index dc2bba977b1..3cb1313687b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Get-Process for admin" -Tags @('CI', 'RequireAdminOnWindows') { It "Should support -FileVersionInfo" -Skip:(!$IsWindows) { $pwshVersion = Get-Process -Id $pid -FileVersionInfo - $pwshVersion.FileVersion | Should -BeExactly $PSVersionTable.PSVersion + $pwshVersion.FileVersion | Should -Match $PSVersionTable.PSVersion } } From 6dea7ea01731ce773eb20f7c450c7e061003689c Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Wed, 28 Feb 2018 17:19:01 -0800 Subject: [PATCH 5/8] test correction --- .../Microsoft.PowerShell.Management/Get-Process.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 index 3cb1313687b..2ad91d3dc5b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 @@ -15,7 +15,7 @@ Describe "Get-Process for admin" -Tags @('CI', 'RequireAdminOnWindows') { It "Should support -FileVersionInfo" -Skip:(!$IsWindows) { $pwshVersion = Get-Process -Id $pid -FileVersionInfo - $pwshVersion.FileVersion | Should -Match $PSVersionTable.PSVersion + $PSVersionTable.PSVersion | Should -Match $pwshVersion.FileVersion } } From 346969ed55295b62295f1d51dd7bf82a2bc62081 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 28 Feb 2018 21:08:17 -0800 Subject: [PATCH 6/8] FixBuild: Revert the changes to get Pester from NuGet cache (#6282) Attempt to fix the macOS build. In #6263, I tried flushing the cache and it worked in the PR. However, after merging the PR, it turns out the master CI build failed again with the same Pester package restore error. So I'm reverting the change that got Pester from NuGet cache. --- build.psm1 | 32 +++-------------------------- src/Modules/PSGalleryModules.csproj | 1 - 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/build.psm1 b/build.psm1 index 80424229aec..f690b9ca15d 100644 --- a/build.psm1 +++ b/build.psm1 @@ -671,7 +671,7 @@ function Restore-PSPester [ValidateNotNullOrEmpty()] [string] $Destination = ([IO.Path]::Combine((Split-Path (Get-PSOptions -DefaultToNew).Output), "Modules")) ) - Copy-PSGalleryModules -Destination $Destination -ModuleNames Pester + Save-Module -Name Pester -Path $Destination -Repository PSGallery } function Compress-TestContent { @@ -2303,15 +2303,9 @@ function Copy-PSGalleryModules [CmdletBinding()] param( [Parameter(Mandatory=$true)] - [string]$Destination, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [string[]]$ModuleNames + [string]$Destination ) - $ModulesOnlyForCI = @("Pester") - if (!$Destination.EndsWith("Modules")) { throw "Installing to an unexpected location" } @@ -2329,15 +2323,6 @@ function Copy-PSGalleryModules foreach ($m in $psGalleryProj.Project.ItemGroup.PackageReference) { $name = $m.Include $version = $m.Version - - if ($null -ne $ModuleNames) { - # When '-ModuleNames' is specified, then we only copy those specified modules - if ($name -notin $ModuleNames) { continue } - } else { - # When '-ModuleNames' is NOT specified, copy all modules except the CI-only ones - if ($name -in $ModulesOnlyForCI) { continue } - } - log "Name='$Name', Version='$version', Destination='$Destination'" # Remove the build revision from the src (nuget drops it). @@ -2361,18 +2346,7 @@ function Copy-PSGalleryModules Remove-Item -Force -ErrorAction Ignore -Recurse "$Destination/$name" New-Item -Path $dest -ItemType Directory -Force -ErrorAction Stop > $null $dontCopy = '*.nupkg', '*.nupkg.sha512', '*.nuspec', 'System.Runtime.InteropServices.RuntimeInformation.dll' - - switch ($name) - { - "Pester" { - $toolsDir = Join-Path -Path $src -ChildPath "tools" - Copy-Item -Path $toolsDir/* -Destination $dest -Recurse -Force - } - - default { - Copy-Item -Exclude $dontCopy -Recurse $src/* $dest - } - } + Copy-Item -Exclude $dontCopy -Recurse $src/* $dest } } diff --git a/src/Modules/PSGalleryModules.csproj b/src/Modules/PSGalleryModules.csproj index 47046317808..6d0ed858cb8 100644 --- a/src/Modules/PSGalleryModules.csproj +++ b/src/Modules/PSGalleryModules.csproj @@ -6,7 +6,6 @@ - From fb5cbb8ee08e5b0bac9c25d4037f798a35fa64ea Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Thu, 1 Mar 2018 14:01:51 -0800 Subject: [PATCH 7/8] Add checks for ErrorId in Get-Process tests --- .../Get-Process.Tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 index 2ad91d3dc5b..382cbd795ce 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 @@ -35,15 +35,15 @@ Describe "Get-Process" -Tags "CI" { It "Should throw an error for non existing process id." { $randomId = 123456789 - { Get-Process -Id $randomId -ErrorAction Stop } | ShouldBeErrorId "NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand" + { Get-Process -Id $randomId -ErrorAction Stop } | Should -Throw -ErrorId "NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand" } It "Should throw an exception when process id is null." { - { Get-Process -id $null } | Should -Throw + { Get-Process -id $null } | Should -Throw -ErrorId "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetProcessCommand" } It "Should throw an exception when -InputObject parameter is null." { - { Get-Process -InputObject $null } | Should -Throw + { Get-Process -InputObject $null } | Should -Throw -ErrorId "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetProcessCommand" } It "Should not fail to get process name even if it is unavailable." { @@ -59,15 +59,15 @@ Describe "Get-Process" -Tags "CI" { } It "Should fail to run Get-Process with -IncludeUserName without admin" -Skip:(!$IsWindows) { - { Get-Process -IncludeUserName } | Should -Throw + { Get-Process -IncludeUserName } | Should -Throw -ErrorId "IncludeUserNameRequiresElevation,Microsoft.PowerShell.Commands.GetProcessCommand" } It "Should fail to run Get-Process with -Module without admin" -Skip:(!$IsWindows) { - { Get-Process -Module -ErrorAction Stop } | ShouldBeErrorId "CouldNotEnumerateModules,Microsoft.PowerShell.Commands.GetProcessCommand" + { Get-Process -Module -ErrorAction Stop } | Should -Throw -ErrorId "CouldNotEnumerateModules,Microsoft.PowerShell.Commands.GetProcessCommand" } It "Should fail to run Get-Process with -FileVersionInfo without admin" -Skip:(!$IsWindows) { - { Get-Process -FileVersionInfo -ErrorAction Stop } | Should -Throw + { Get-Process -FileVersionInfo -ErrorAction Stop } | Should -Throw -ErrorId "CouldNotEnumerateFileVer,Microsoft.PowerShell.Commands.GetProcessCommand" } } From 1b39f45b2386639d5c75e1637fcf1987ff8fbb4f Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Thu, 1 Mar 2018 17:18:51 -0800 Subject: [PATCH 8/8] Change one Get-Process test status to pending for MacOs --- .../Microsoft.PowerShell.Management/Get-Process.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 index 382cbd795ce..b6328317875 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 @@ -5,7 +5,7 @@ Describe "Get-Process for admin" -Tags @('CI', 'RequireAdminOnWindows') { (Get-Process -Id $pid -IncludeUserName).UserName | Should Match $env:USERNAME } - It "Should support -Module" { + It "Should support -Module" -Pending:$IsMacOS { $modules = Get-Process -Id $pid -Module $modules.GetType() | Should -BeExactly "System.Object[]" foreach ($module in $modules) {