From 25670e7bf44385d2b38b46d9fa5108acaf6cc9e6 Mon Sep 17 00:00:00 2001 From: James Truher Date: Thu, 5 Jul 2018 23:18:03 -0700 Subject: [PATCH 1/4] Support pwsh starting in directories which may have wildcard characters in the name. There's really no reason why you should glob a path when you're attempting to go to Directory.GetCurrentDirectory() --- .../engine/InitialSessionState.cs | 1 + test/powershell/Host/ConsoleHost.Tests.ps1 | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 320961e1674..de5ad69f78e 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -3229,6 +3229,7 @@ internal static void SetSessionStateDrive(ExecutionContext context, bool setLoca try { + providerContext.SuppressWildcardExpansion = true; context.EngineSessionState.SetLocation(Directory.GetCurrentDirectory(), providerContext); } catch (ItemNotFoundException) diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index 91400a5b122..1364de3cf0b 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -683,3 +683,24 @@ 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","T*est","Test" + foreach ( $d in $dirnames ) { new-item -type Directory -path "${TESTDRIVE}/$d" } + $testcases = foreach ( $d in $dirnames ) { @{ Dirname = $d } } + } + + It "pwsh can startup in a directory named " -testcases $testcases { + param ( $dirname ) + try { + Push-Location -LiteralPath "${TESTDRIVE}/${dirname}" + $result = & $powershell -c '(Get-Item .).Name' + $result | Should -BeExactly $dirname + } + finally { + Pop-Location + } + } +} From 206ca71907fc1a8ea7f7e5832192e37a2230ac16 Mon Sep 17 00:00:00 2001 From: "James Truher [MSFT]" Date: Fri, 6 Jul 2018 09:53:36 -0700 Subject: [PATCH 2/4] Update ConsoleHost.Tests.ps1 --- test/powershell/Host/ConsoleHost.Tests.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index 1364de3cf0b..58be89b0a47 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -687,9 +687,12 @@ Describe "Pwsh exe resources tests" -Tag CI { 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","T*est","Test" - foreach ( $d in $dirnames ) { new-item -type Directory -path "${TESTDRIVE}/$d" } - $testcases = foreach ( $d in $dirnames ) { @{ Dirname = $d } } + $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 " -testcases $testcases { From aa76ace89d3d0adf5ebb142fa6ae5e872a5819ec Mon Sep 17 00:00:00 2001 From: James Truher Date: Mon, 9 Jul 2018 11:57:43 -0700 Subject: [PATCH 3/4] Address a timing issue in ThreadJobs tests. Sometimes the job object will return with state Running before it is actually running --- test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 b/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 index b9eceb17761..e54a3e89343 100644 --- a/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 +++ b/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 @@ -275,6 +275,7 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { $job2 = Start-ThreadJob -ScriptBlock { "Hello 2!" } $job3 = Start-ThreadJob -ScriptBlock { "Hello 3!" } $job4 = Start-ThreadJob -ScriptBlock { "Hello 4!" } + wait-forrunning $job4 $job1,$job2,$job3,$job4 | Wait-Job From 7b3e866bdf89d7a2984a365cffdcfc0e80e8687c Mon Sep 17 00:00:00 2001 From: James Truher Date: Wed, 11 Jul 2018 16:02:30 -0700 Subject: [PATCH 4/4] remove changes in threadjob tests --- test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 b/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 index e54a3e89343..b9eceb17761 100644 --- a/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 +++ b/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 @@ -275,7 +275,6 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { $job2 = Start-ThreadJob -ScriptBlock { "Hello 2!" } $job3 = Start-ThreadJob -ScriptBlock { "Hello 3!" } $job4 = Start-ThreadJob -ScriptBlock { "Hello 4!" } - wait-forrunning $job4 $job1,$job2,$job3,$job4 | Wait-Job