From a31b1c911e96dd8351419269fddf11a9e922b886 Mon Sep 17 00:00:00 2001 From: Andrew Menagarishvili Date: Fri, 26 Jan 2018 15:55:51 -0800 Subject: [PATCH 01/11] Added Skipping if MicrosoftPowerShellCorePathIsReadOnly --- .../engine/Help/HelpSystem.Tests.ps1 | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index a48268f8622..81d34da2102 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -29,7 +29,7 @@ function RunTestCase $moduleName = "Microsoft.PowerShell.Core" - UpdateHelpFromLocalContentPath $moduleName $tag + UpdateHelpFromLocalContentPath $moduleName $tag # this runs Update-Help and fails if $PSHOME is Not writable $cmdlets = get-command -module $moduleName @@ -64,6 +64,27 @@ function RunTestCase } } +function PathIsReadOnly +{ + param ([string]$Path) + # attempt to write to location and catch + $readonly = $false + try + { + $filepath = Join-Path $Path "testfile-deleteme.txt" + "test" | Out-File $filepath + } + catch + { + $readonly = $_.Exception.GetType().Name -eq 'UnauthorizedAccessException' + } + Remove-Item -Path $filepath -ErrorAction SilentlyContinue + + $readonly +} + +$MicrosoftPowerShellCorePathIsReadOnly = PathIsReadOnly $PSHOME + Describe "Validate that //default.help.txt is present" -Tags @('CI') { It "Get-Help returns information about the help system." { @@ -75,7 +96,7 @@ Describe "Validate that //default.help.txt is present" -Tags @( } } -Describe "Validate that get-help works" -Tags @('CI', 'RequireAdminOnWindows') { +Describe "Validate that get-help works" -Tags @('CI', 'RequireAdminOnWindows') -Skip:$MicrosoftPowerShellCorePathIsReadOnly { BeforeAll { $SavedProgressPreference = $ProgressPreference $ProgressPreference = "SilentlyContinue" @@ -86,7 +107,7 @@ Describe "Validate that get-help works" -Tags @('CI', 'RequireAdmin RunTestCase -tag "CI" } -Describe "Validate Get-Help for all cmdlets in 'Microsoft.PowerShell.Core'" -Tags @('Feature', 'RequireAdminOnWindows') { +Describe "Validate Get-Help for all cmdlets in 'Microsoft.PowerShell.Core'" -Tags @('Feature', 'RequireAdminOnWindows') -Skip:$MicrosoftPowerShellCorePathIsReadOnly { BeforeAll { $SavedProgressPreference = $ProgressPreference $ProgressPreference = "SilentlyContinue" From 979af9ee071dfa448f8623a58068304e11a1ebf9 Mon Sep 17 00:00:00 2001 From: Andrew Menagarishvili Date: Fri, 26 Jan 2018 16:12:14 -0800 Subject: [PATCH 02/11] Moved Skipping to It block --- test/powershell/engine/Help/HelpSystem.Tests.ps1 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 81d34da2102..491ded38d3e 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -29,7 +29,10 @@ function RunTestCase $moduleName = "Microsoft.PowerShell.Core" - UpdateHelpFromLocalContentPath $moduleName $tag # this runs Update-Help and fails if $PSHOME is Not writable + if (-not $MicrosoftPowerShellCorePathIsReadOnly) + { + UpdateHelpFromLocalContentPath $moduleName $tag # this runs Update-Help and fails if $PSHOME is Not writable + } $cmdlets = get-command -module $moduleName @@ -47,7 +50,7 @@ function RunTestCase { if ($cmdletsToSkip -notcontains $cmdletName) { - It "Validate -Description and -Examples sections in help content. Run 'Get-help -name $cmdletName'" { + It "Validate -Description and -Examples sections in help content. Run 'Get-help -name $cmdletName'" -Skip:$MicrosoftPowerShellCorePathIsReadOnly { $help = get-help -name $cmdletName $help.Description | Out-String | Should Match $cmdletName @@ -96,7 +99,7 @@ Describe "Validate that //default.help.txt is present" -Tags @( } } -Describe "Validate that get-help works" -Tags @('CI', 'RequireAdminOnWindows') -Skip:$MicrosoftPowerShellCorePathIsReadOnly { +Describe "Validate that get-help works" -Tags @('CI', 'RequireAdminOnWindows') { BeforeAll { $SavedProgressPreference = $ProgressPreference $ProgressPreference = "SilentlyContinue" @@ -107,7 +110,7 @@ Describe "Validate that get-help works" -Tags @('CI', 'RequireAdmin RunTestCase -tag "CI" } -Describe "Validate Get-Help for all cmdlets in 'Microsoft.PowerShell.Core'" -Tags @('Feature', 'RequireAdminOnWindows') -Skip:$MicrosoftPowerShellCorePathIsReadOnly { +Describe "Validate Get-Help for all cmdlets in 'Microsoft.PowerShell.Core'" -Tags @('Feature', 'RequireAdminOnWindows') { BeforeAll { $SavedProgressPreference = $ProgressPreference $ProgressPreference = "SilentlyContinue" From bef2ee4784d168e5fdce6c5817816ee1b3df6368 Mon Sep 17 00:00:00 2001 From: Andrew Menagarishvili Date: Fri, 2 Feb 2018 13:32:02 -0800 Subject: [PATCH 03/11] Updated function UpdateHelpFromLocalContentPath --- .../powershell/engine/Help/HelpSystem.Tests.ps1 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 491ded38d3e..db4719d2a02 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -5,6 +5,18 @@ function UpdateHelpFromLocalContentPath { param ([string]$ModuleName, [string]$Tag = 'CI') + # Update-Help fails if module path is Not writable, so skip tests in this situation + if ($moduleName -eq "Microsoft.PowerShell.Core") + { + if ($MicrosoftPowerShellCorePathIsReadOnly) return + } + else + { + $modulePath = (Get-Module -Name $ModuleName -ListAvailable).ModuleBase + $modulePathIsReadOnly = PathIsReadOnly $modulePath + if ($modulePathIsReadOnly) return + } + if ($Tag -eq 'CI') { $helpContentPath = Join-Path $PSScriptRoot "assets" @@ -29,10 +41,7 @@ function RunTestCase $moduleName = "Microsoft.PowerShell.Core" - if (-not $MicrosoftPowerShellCorePathIsReadOnly) - { - UpdateHelpFromLocalContentPath $moduleName $tag # this runs Update-Help and fails if $PSHOME is Not writable - } + UpdateHelpFromLocalContentPath $moduleName $tag $cmdlets = get-command -module $moduleName From 28cb469eb4e6ce8a85cc3e4f95a24899ceb43c64 Mon Sep 17 00:00:00 2001 From: Andrew Menagarishvili Date: Fri, 2 Feb 2018 13:43:49 -0800 Subject: [PATCH 04/11] replaced tabs with spaces --- .../engine/Help/HelpSystem.Tests.ps1 | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index db4719d2a02..3e38782f091 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -5,17 +5,17 @@ function UpdateHelpFromLocalContentPath { param ([string]$ModuleName, [string]$Tag = 'CI') - # Update-Help fails if module path is Not writable, so skip tests in this situation - if ($moduleName -eq "Microsoft.PowerShell.Core") - { - if ($MicrosoftPowerShellCorePathIsReadOnly) return - } - else - { - $modulePath = (Get-Module -Name $ModuleName -ListAvailable).ModuleBase - $modulePathIsReadOnly = PathIsReadOnly $modulePath - if ($modulePathIsReadOnly) return - } + # Update-Help fails if module path is Not writable, so skip tests in this situation + if ($moduleName -eq "Microsoft.PowerShell.Core") + { + if ($MicrosoftPowerShellCorePathIsReadOnly) { return } + } + else + { + $modulePath = (Get-Module -Name $ModuleName -ListAvailable).ModuleBase + $modulePathIsReadOnly = PathIsReadOnly $modulePath + if ($modulePathIsReadOnly) { return } + } if ($Tag -eq 'CI') { From e51a32a13f419abc797d80d7375c7e6299060a29 Mon Sep 17 00:00:00 2001 From: Andrew Menagarishvili Date: Fri, 2 Feb 2018 13:59:21 -0800 Subject: [PATCH 05/11] Fixed about_help.txt tests --- .../engine/Help/HelpSystem.Tests.ps1 | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 3e38782f091..13e339b349c 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -217,9 +217,21 @@ Describe "Validate that Get-Help returns provider-specific help" -Tags @('CI', ' } Describe "Validate about_help.txt under culture specific folder works" -Tags @('CI', 'RequireAdminOnWindows') { + + $skip = $false + BeforeAll { $modulePath = "$pshome\Modules\Test" - $null = New-Item -Path $modulePath\en-US -ItemType Directory -Force + try + { + $null = New-Item -Path $modulePath\en-US -ItemType Directory -Force + } + catch + { + # $pshome is readonly-path for non-sudo on Linux, skip tests in this case + $skip = $_.Exception.GetType().Name -eq 'CreateDirectoryUnauthorizedAccessError' + if ($skip) {return} + } New-ModuleManifest -Path $modulePath\test.psd1 -RootModule test.psm1 Set-Content -Path $modulePath\test.psm1 -Value "function foo{}" Set-Content -Path $modulePath\en-US\about_testhelp.help.txt -Value "Hello" -NoNewline @@ -234,19 +246,19 @@ Describe "Validate about_help.txt under culture specific folder works" -Tags @(' } AfterAll { - Remove-Item $modulePath -Recurse -Force + Remove-Item $modulePath -Recurse -Force -ErrorAction SilentlyContinue # Remove all the help content. Get-ChildItem -Path $PSHOME -Include @('about_*.txt', "*help.xml") -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue } - It "Get-Help should return help text and not multiple HelpInfo objects when help is under `$pshome path" { + It "Get-Help should return help text and not multiple HelpInfo objects when help is under `$pshome path" -Skip:$skip { $help = Get-Help about_testhelp $help.count | Should Be 1 $help | Should BeExactly "Hello" } - It "Get-Help for about_Variable should return only one help object" { + It "Get-Help for about_Variable should return only one help object" -Skip:$skip { $help = Get-Help about_Variables $help.count | Should Be 1 } From bc3238ed968503d4ea12eb7568be8f307c18d123 Mon Sep 17 00:00:00 2001 From: Andrew Menagarishvili Date: Fri, 2 Feb 2018 14:05:31 -0800 Subject: [PATCH 06/11] Fixed typo in condition --- test/powershell/engine/Help/HelpSystem.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 13e339b349c..52162dd6359 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -229,7 +229,7 @@ Describe "Validate about_help.txt under culture specific folder works" -Tags @(' catch { # $pshome is readonly-path for non-sudo on Linux, skip tests in this case - $skip = $_.Exception.GetType().Name -eq 'CreateDirectoryUnauthorizedAccessError' + $skip = $_.Exception.GetType().Name -eq 'UnauthorizedAccessException' if ($skip) {return} } New-ModuleManifest -Path $modulePath\test.psd1 -RootModule test.psm1 From 6c10641aaf91987935043773cb28e5f2b63bd2af Mon Sep 17 00:00:00 2001 From: Andrew Menagarishvili Date: Fri, 2 Feb 2018 14:10:47 -0800 Subject: [PATCH 07/11] make error terminating --- test/powershell/engine/Help/HelpSystem.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 52162dd6359..51147a33a19 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -224,7 +224,7 @@ Describe "Validate about_help.txt under culture specific folder works" -Tags @(' $modulePath = "$pshome\Modules\Test" try { - $null = New-Item -Path $modulePath\en-US -ItemType Directory -Force + $null = New-Item -Path $modulePath\en-US -ItemType Directory -Force -ErrorAction Stop } catch { From 5cd8bfd16411cf757e982e2a76492e2a6aeb6651 Mon Sep 17 00:00:00 2001 From: Andrew Menagarishvili Date: Fri, 2 Feb 2018 14:22:01 -0800 Subject: [PATCH 08/11] Fixed skip not triggering --- test/powershell/engine/Help/HelpSystem.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 51147a33a19..9ad506eae7b 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -218,8 +218,6 @@ Describe "Validate that Get-Help returns provider-specific help" -Tags @('CI', ' Describe "Validate about_help.txt under culture specific folder works" -Tags @('CI', 'RequireAdminOnWindows') { - $skip = $false - BeforeAll { $modulePath = "$pshome\Modules\Test" try From 75826f80960da659015f9a1eaa959d5f728213ba Mon Sep 17 00:00:00 2001 From: Andrew Menagarishvili Date: Fri, 2 Feb 2018 14:48:11 -0800 Subject: [PATCH 09/11] Fixed more tests --- .../engine/Help/HelpSystem.Tests.ps1 | 5 +-- .../engine/Help/UpdatableHelpSystem.Tests.ps1 | 32 ++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 9ad506eae7b..477af4e51f4 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -95,7 +95,8 @@ function PathIsReadOnly $readonly } -$MicrosoftPowerShellCorePathIsReadOnly = PathIsReadOnly $PSHOME +$PsHomePathIsReadOnly = PathIsReadOnly $PSHOME +$MicrosoftPowerShellCorePathIsReadOnly = $PsHomePathIsReadOnly Describe "Validate that //default.help.txt is present" -Tags @('CI') { @@ -263,7 +264,7 @@ Describe "Validate about_help.txt under culture specific folder works" -Tags @(' } Describe "Get-Help should find help info within help files" -Tags @('CI', 'RequireAdminOnWindows') { - It "Get-Help should find help files under pshome" { + It "Get-Help should find help files under pshome" -Skip:$PsHomePathIsReadOnly { $helpFile = "about_testCase.help.txt" $culture = (Get-Culture).Name $helpFolderPath = Join-Path $PSHOME $culture diff --git a/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 b/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 index 0f38be9a5e6..935554c99ac 100644 --- a/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 @@ -133,6 +133,27 @@ $testCases = @{ $modulesInBox = @("Microsoft.PowerShell.Core" Get-Module -ListAvailable | ForEach-Object{$_.Name} ) +function PathIsReadOnly +{ + param ([string]$Path) + # attempt to write to location and catch + $readonly = $false + try + { + $filepath = Join-Path $Path "testfile-deleteme.txt" + "test" | Out-File $filepath + } + catch + { + $readonly = $_.Exception.GetType().Name -eq 'UnauthorizedAccessException' + } + Remove-Item -Path $filepath -ErrorAction SilentlyContinue + + $readonly +} + +$PsHomePathIsReadOnly = PathIsReadOnly $PSHOME +$MicrosoftPowerShellCorePathIsReadOnly = $PsHomePathIsReadOnly function GetFiles { @@ -174,8 +195,17 @@ function RunUpdateHelpTests { if ($powershellCoreModules -contains $moduleName) { + if ($moduleName -eq "Microsoft.PowerShell.Core") + { + $modulePathIsReadOnly = $MicrosoftPowerShellCorePathIsReadOnly + } + else + { + $modulePath = (Get-Module -Name $moduleName -ListAvailable).ModuleBase + $modulePathIsReadOnly = PathIsReadOnly $modulePath + } - It "Validate Update-Help for module '$moduleName'" -Pending:$Pending { + It "Validate Update-Help for module '$moduleName'" -Pending:$Pending -Skip:$modulePathIsReadOnly { # If the help file is already installed, delete it. Get-ChildItem $testCases[$moduleName].HelpInstallationPath -Include @("*help.xml") -Recurse -ea SilentlyContinue | From 417310c6630d87a5a1d14d3e463ddf585958669f Mon Sep 17 00:00:00 2001 From: Andrew Menagarishvili Date: Fri, 2 Feb 2018 14:55:37 -0800 Subject: [PATCH 10/11] Fixed RunUpdateHelpTests --- test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 b/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 index 935554c99ac..44c82a54a37 100644 --- a/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 @@ -205,7 +205,10 @@ function RunUpdateHelpTests $modulePathIsReadOnly = PathIsReadOnly $modulePath } - It "Validate Update-Help for module '$moduleName'" -Pending:$Pending -Skip:$modulePathIsReadOnly { + # -Skip and -$Pending are mutually exclusive on It block, so skip Pending tests + If ($Pending) {$modulePathIsReadOnly = $true} + + It "Validate Update-Help for module '$moduleName'" -Skip:$modulePathIsReadOnly { # If the help file is already installed, delete it. Get-ChildItem $testCases[$moduleName].HelpInstallationPath -Include @("*help.xml") -Recurse -ea SilentlyContinue | From 82e35f822c8a321066972a5242ee64eb04d3f5a7 Mon Sep 17 00:00:00 2001 From: Andrew Menagarishvili Date: Fri, 2 Feb 2018 15:02:57 -0800 Subject: [PATCH 11/11] Fixed RunUpdateHelpTests --- test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 b/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 index 44c82a54a37..33865c01e55 100644 --- a/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 @@ -197,18 +197,18 @@ function RunUpdateHelpTests { if ($moduleName -eq "Microsoft.PowerShell.Core") { - $modulePathIsReadOnly = $MicrosoftPowerShellCorePathIsReadOnly + $skip = $MicrosoftPowerShellCorePathIsReadOnly } else { $modulePath = (Get-Module -Name $moduleName -ListAvailable).ModuleBase - $modulePathIsReadOnly = PathIsReadOnly $modulePath + $skip = PathIsReadOnly $modulePath } # -Skip and -$Pending are mutually exclusive on It block, so skip Pending tests - If ($Pending) {$modulePathIsReadOnly = $true} + If ($Pending) {$skip = $true} - It "Validate Update-Help for module '$moduleName'" -Skip:$modulePathIsReadOnly { + It "Validate Update-Help for module '$moduleName'" -Skip:$skip { # If the help file is already installed, delete it. Get-ChildItem $testCases[$moduleName].HelpInstallationPath -Include @("*help.xml") -Recurse -ea SilentlyContinue |