Skip to content
Merged
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
16 changes: 14 additions & 2 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1190,11 +1190,23 @@ Describe 'Pwsh startup and PATH' -Tag CI {
$version | Should -BeExactly "PowerShell $($PSVersionTable.GitCommitId)"
}

It 'pwsh starts even if PATH is not defined' {
It 'pwsh updates PATH correctly even if PATH is not defined' {
$pwsh = Join-Path -Path $PSHOME -ChildPath "pwsh"
Remove-Item Env:\PATH
$path = & $pwsh -noprofile -command '$env:PATH'
$path | Should -BeExactly ($PSHOME + [System.IO.Path]::PathSeparator)

$ExpectedPath = $PSHOME
if ($PSHOME.StartsWith("$env:ProgramFiles\WindowsApps\Microsoft.PowerShell")) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name is "pwsh starts even if PATH is not defined" - is this only we should test? If so, we can simply return and check any other value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what you meant. This test is to validate if PowerShell can add exe path to PATH when the PATH env var doesn't exist.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this test only says that pwsh is running successfully in the absence of a PATH. If you want to check exactly the PATH value that pwsh creates, then name the test accordingly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. I updated the test name.

# MSIX installed PowerShell uses the stable path instead of PSHOME.
$ExpectedPath = $PSHOME.Replace($env:ProgramFiles, "$env:LOCALAPPDATA\Microsoft")

# Remove the version-specific part from the expected path.
$version = $PSVersionTable.PSVersion
$verStrRegex = "$($version.Major)\.$($version.Minor)\.$($version.Build).+__"
$ExpectedPath = $ExpectedPath -replace $verStrRegex, ''
}

$path | Should -BeExactly ($ExpectedPath + [System.IO.Path]::PathSeparator)
}
}

Expand Down
Loading