mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Enable -WindowStyle to work
This commit is contained in:
1 parent
4c22b10a38
commit
26f7db720c
3 files changed
+91
-3
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// Code to control the display properties of the a window...
|
||||
/// </summary>
|
||||
|
||||
@@ -493,6 +493,95 @@ foo
|
||||
powershell -v | Should Match $psversiontable.GitCommitId
|
||||
}
|
||||
}
|
||||
|
||||
Context "Ambiguous arguments" {
|
||||
It "Ambiguous argument '<testArg>' 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 <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 {
|
||||
|
||||
Reference in new issue
Block a user