Skip to content
This repository was archived by the owner on Jun 16, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Tests/CompatibilitySession.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
19 changes: 16 additions & 3 deletions Tests/PSModulePath.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
}
5 changes: 3 additions & 2 deletions WindowsCompatibility/WindowsCompatibility.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion WindowsCompatibility/WindowsCompatibility.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
}
}