diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs index b0091c49c..0bfb719e7 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -617,7 +617,7 @@ namespace Microsoft.PowerShell break; } } -#if !CORECLR // windowstyle parameter not supported on NanoServer because ProcessWindowStyle does Not exist on CoreCLR +#if !UNIX else if (MatchSwitch(switchKey, "windowstyle", "w")) { ++i; diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs index 2513fe9e9..0f0c7f5cc 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs @@ -445,8 +445,7 @@ namespace Microsoft.PowerShell internal const int SW_FORCEMINIMIZE = 11; internal const int SW_MAX = 11; - -#if !CORECLR // ProcessWindowStyle does Not exist on CoreCLR +#if !UNIX /// /// Code to control the display properties of the a window... /// diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index 63b081b5f..16c803238 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -493,6 +493,95 @@ foo powershell -v | Should Match $psversiontable.GitCommitId } } + + Context "Ambiguous arguments" { + It "Ambiguous argument '' should return possible matches" -TestCases @( + @{testArg="-no";expectedMatches=@("-nologo","-noexit","-noprofile","-noninteractive")}, + @{testArg="-format";expectedMatches=@("-inputformat","-outputformat")} + ) { + param($testArg, $expectedMatches) + $output = & $powershell $testArg -File foo 2>&1 + $LASTEXITCODE | Should Be $ExitCodeBadCommandLineParameter + $outString = [String]::Join(",", $output) + foreach ($expectedMatch in $expectedMatches) + { + $outString | Should Match $expectedMatch + } + } + } +} + +Describe "WindowStyle argument" -Tag Feature { + BeforeAll { + $defaultParamValues = $PSDefaultParameterValues.Clone() + $PSDefaultParameterValues["it:skip"] = !$IsWindows + + if ($IsWindows) + { + $ExitCodeBadCommandLineParameter = 64 + Add-Type -Name User32 -Namespace Test -MemberDefinition @" +public static WINDOWPLACEMENT GetPlacement(IntPtr hwnd) +{ + WINDOWPLACEMENT placement = new WINDOWPLACEMENT(); + placement.length = Marshal.SizeOf(placement); + GetWindowPlacement(hwnd, ref placement); + return placement; +} + +[DllImport("user32.dll", SetLastError = true)] +[return: MarshalAs(UnmanagedType.Bool)] +public static extern bool GetWindowPlacement( + IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl); + +[Serializable] +[StructLayout(LayoutKind.Sequential)] +public struct WINDOWPLACEMENT +{ + public int length; + public int flags; + public ShowWindowCommands showCmd; + public System.Drawing.Point ptMinPosition; + public System.Drawing.Point ptMaxPosition; + public System.Drawing.Rectangle rcNormalPosition; +} + +public enum ShowWindowCommands : int +{ + Hidden = 0, + Normal = 1, + Minimized = 2, + Maximized = 3, +} +"@ + } + } + + AfterAll { + $global:PSDefaultParameterValues = $defaultParamValues + } + + It "-WindowStyle should work on Windows" -TestCases @( + @{WindowStyle="Normal"}, + @{WindowStyle="Minimized"}, + @{WindowStyle="Maximized"} # hidden doesn't work in CI/Server Core + ) { + param ($WindowStyle) + $ps = Start-Process powershell -ArgumentList "-WindowStyle $WindowStyle -noexit -interactive" -PassThru + $startTime = Get-Date + $showCmd = "Unknown" + while (((Get-Date) - $startTime).TotalSeconds -lt 10 -and $showCmd -ne $WindowStyle) + { + Start-Sleep -Milliseconds 100 + $showCmd = ([Test.User32]::GetPlacement($ps.MainWindowHandle)).showCmd + } + $showCmd | Should BeExactly $WindowStyle + $ps | Stop-Process -Force + } + + It "Invalid -WindowStyle returns error" { + powershell -WindowStyle invalid + $LASTEXITCODE | Should Be $ExitCodeBadCommandLineParameter + } } Describe "Console host api tests" -Tag CI {