From d250235a38d515c49d2866aa4d02bb90b2bfc286 Mon Sep 17 00:00:00 2001 From: Bruce Payette Date: Fri, 28 Sep 2018 14:42:13 -0700 Subject: [PATCH] Update manifest for RC; added ShouldProcess to Add-WindowsPSModulePath; fixed the test for that cmdlet; fixed tests for dir mirroring - they shouldnt be case sensative --- Tests/CompatibilitySession.Tests.ps1 | 8 ++++---- Tests/PSModulePath.Tests.ps1 | 19 ++++++++++++++++--- .../WindowsCompatibility.psd1 | 5 +++-- .../WindowsCompatibility.psm1 | 19 ++++++++++++++++++- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Tests/CompatibilitySession.Tests.ps1 b/Tests/CompatibilitySession.Tests.ps1 index 9f19b3b..75f63be 100644 --- a/Tests/CompatibilitySession.Tests.ps1 +++ b/Tests/CompatibilitySession.Tests.ps1 @@ -194,14 +194,14 @@ Describe "Test the Windows PowerShell Compatibility Session functions" { } } - It "Should mirror directory changes in the compatibility session" { + It 'Should mirror directory changes in the compatibility session' { # Verify that the initial directories are sync'ed - Invoke-WinCommand { $pwd.Path } | Should -BeExactly $pwd.Path + Invoke-WinCommand { $pwd.Path } | Should -Be $pwd.Path # Change location and verify that the compat session directory also changed Push-Location .. - Invoke-WinCommand { $pwd.Path } | Should -BeExactly $pwd.Path + Invoke-WinCommand { $pwd.Path } | Should -Be $pwd.Path # Change back and verify again Pop-Location - Invoke-WinCommand { $pwd.Path } | Should -BeExactly $pwd.Path + Invoke-WinCommand { $pwd.Path } | Should -Be $pwd.Path } } diff --git a/Tests/PSModulePath.Tests.ps1 b/Tests/PSModulePath.Tests.ps1 index 6fb8046..ba5f756 100644 --- a/Tests/PSModulePath.Tests.ps1 +++ b/Tests/PSModulePath.Tests.ps1 @@ -14,10 +14,23 @@ Describe "Test Add-WindowsPSModulePath cmdlet" { $env:PSModulePath = $originalPsModulePath } - It "Validate Windows PSModulePath is added on Core" { - $env:PSModulePath | Should -Not -BeLike "*\WindowsPowerShell\*" + It 'Validate that the system environment variable PSModulePath components are added to the $ENV:PSModulePath' { Add-WindowsPSModulePath | Should -BeNullOrEmpty + # a table of the current PSModulePath components + [hashtable] $currentPathTable = @{} + $env:PSModulePath.split(';').foreach{$currentPathTable[$_] = $true} $WindowsPSModulePath = [System.Environment]::GetEnvironmentVariable("psmodulepath", [System.EnvironmentVariableTarget]::Machine) - $env:PSModulePath | Should -BeLike "*$WindowsPSModulePath*" + $allComponentsInPath = $true + # Verify that all of the path components in the machine-scoped PSModulePath are + # also in the session module path. + foreach ($pc in $WindowsPSModulePath.Split(';')) + { + if ( -not $currentPathTable.ContainsKey($pc) ) + { + $allComponents = $false + } + } + $allComponents | Should -Be $true:w + } } diff --git a/WindowsCompatibility/WindowsCompatibility.psd1 b/WindowsCompatibility/WindowsCompatibility.psd1 index fb40fb4..31d231a 100644 --- a/WindowsCompatibility/WindowsCompatibility.psd1 +++ b/WindowsCompatibility/WindowsCompatibility.psd1 @@ -33,11 +33,12 @@ FunctionsToExport = @( AliasesToExport = @('Add-WinPSModulePath') PrivateData = @{ PSData = @{ - Tags = @('Compatibility', 'Core') + Tags = @('Windows PowerShell', 'Compatibility', 'Core') + Prerelease = 'RC' LicenseUri = 'https://opensource.org/licenses/MIT' ProjectUri = 'https://github.com/PowerShell/WindowsCompatibility' ReleaseNotes = @' -This is the first release of this module with the basic commands: +This is the first release candidate (RC) of this module with the following commands: Initialize-WinSession Add-WinFunction Invoke-WinCommand diff --git a/WindowsCompatibility/WindowsCompatibility.psm1 b/WindowsCompatibility/WindowsCompatibility.psm1 index e0379bf..2bf1d17 100644 --- a/WindowsCompatibility/WindowsCompatibility.psm1 +++ b/WindowsCompatibility/WindowsCompatibility.psm1 @@ -733,6 +733,10 @@ function Copy-WinModule function Add-WindowsPSModulePath { + [CmdletBinding(SupportsShouldProcess)] + [OutputType([void])] + param () + if ($PSVersionTable.PSEdition -eq 'Core' -and -not $IsWindows) { throw "This cmdlet is only supported on Windows" @@ -743,6 +747,8 @@ function Add-WindowsPSModulePath return } + [bool] $verboseFlag = $PSBoundParameters['Verbose'] + $paths = @( $Env:PSModulePath -split [System.IO.Path]::PathSeparator "${Env:UserProfile}\Documents\WindowsPowerShell\Modules" @@ -753,14 +759,25 @@ function Add-WindowsPSModulePath ) $pathTable = [ordered] @{} + $doUpdate = $false foreach ($path in $paths) { if ($pathTable[$path]) { continue } + + if ($PSCmdlet.ShouldProcess($path, "Add to PSModulePath")) + { + Write-Verbose -Verbose:$verboseFlag "Adding '$path' to the PSModulePath." + $doUpdate = $true + } + $pathTable[$path] = $true } - $Env:PSModulePath = $pathTable.Keys -join [System.IO.Path]::PathSeparator + if ($doUpdate) + { + $Env:PSModulePath = $pathTable.Keys -join [System.IO.Path]::PathSeparator + } }