Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -3229,6 +3229,7 @@ internal static void SetSessionStateDrive(ExecutionContext context, bool setLoca

try
{
providerContext.SuppressWildcardExpansion = true;
Copy link

Choose a reason for hiding this comment

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

(style) Maybe it's just my OCD, by why configuring providerContext inside try block rather than right after initialization?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wanted the two operations to be visually close, putting the assignment in the block did that for me

context.EngineSessionState.SetLocation(Directory.GetCurrentDirectory(), providerContext);
}
catch (ItemNotFoundException)
Expand Down
24 changes: 24 additions & 0 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -683,3 +683,27 @@ Describe "Pwsh exe resources tests" -Tag CI {
$psversiontable.os | Should -MatchExactly "$($osversion.Major).$($osversion.Minor)"
}
}

Describe 'Pwsh startup in directories that contain wild cards' -Tag CI {
BeforeAll {
$powershell = Join-Path -Path $PsHome -ChildPath "pwsh"
$dirnames = "[T]est","[Test","T][est","Test"
$testcases = @()
foreach ( $d in $dirnames ) {
$null = New-Item -type Directory -path "${TESTDRIVE}/$d"
$testcases += @{ Dirname = $d }
}
}

It "pwsh can startup in a directory named <dirname>" -testcases $testcases {
param ( $dirname )
try {
Push-Location -LiteralPath "${TESTDRIVE}/${dirname}"
$result = & $powershell -c '(Get-Item .).Name'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we use cmdlet? Maybe better .Net method to get current directory or -LiteralPath?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it really doesn't matter, does it?

Copy link
Member

Choose a reason for hiding this comment

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

I agree, maybe use

$result = & $powershell -c '([Environment]::CurrentDirectory)'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

also, I want to check only the name, ason some systems, Environment.CurrentDirectory will include a symlink which is a problem because PS does not, I'm I need to call split-path, I can use this form just as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we are testing PowerShell, it would makes sense to use PowerShell i.e. the way Jim has written it rather then calling .NET. Why do you think it should be a .NET call? Is there some reason not to use native PowerShell capabilities?

Copy link
Collaborator

Choose a reason for hiding this comment

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

My misunderstanding is that we use Directory.GetCurrentDirectory() in the code and Set-Location and Get-Item in the test - do we work with different current directories (first in .Net, second in FileSystem provider)?

$result | Should -BeExactly $dirname
}
finally {
Pop-Location
}
}
}