From 1f5f8f591e2e8252ee955be2b88e5de21930e2b1 Mon Sep 17 00:00:00 2001 From: Greg Zimmerman Date: Sun, 21 Jan 2018 19:45:49 -0500 Subject: [PATCH 1/5] Return better error for WindowStyle on unsupported platforms. --- .../host/msh/CommandLineParameterParser.cs | 11 +++++++---- .../resources/CommandLineParameterParserStrings.resx | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs index b297c248a1d..fec6c04e61b 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -182,9 +182,7 @@ internal class CommandLineParameterParser "noninteractive", "inputformat", "outputformat", -#if !UNIX "windowstyle", -#endif "encodedcommand", "configurationname", "file", @@ -588,9 +586,13 @@ private void ParseHelper(string[] args) break; } } -#if !UNIX else if (MatchSwitch(switchKey, "windowstyle", "w")) { +#if UNIX + WriteCommandLineError( + CommandLineParameterParserStrings.WindowStyleArgumentNotImplemented); + break; +#else ++i; if (i >= args.Length) { @@ -611,8 +613,9 @@ private void ParseHelper(string[] args) string.Format(CultureInfo.CurrentCulture, CommandLineParameterParserStrings.InvalidWindowStyleArgument, args[i], e.Message)); break; } - } #endif + + } else if (MatchSwitch(switchKey, "file", "f")) { if (!ParseFile(args, ref i, noexitSeen)) diff --git a/src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx b/src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx index 7ad30993383..0edbaf3af33 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx +++ b/src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx @@ -189,4 +189,7 @@ Invalid argument '{0}', did you mean: + + WindowStyle is not implemented on this platform. + From 090a61edb4975e4e06516fdc1c8b5f0ae119bed9 Mon Sep 17 00:00:00 2001 From: Greg Zimmerman Date: Mon, 22 Jan 2018 08:39:44 -0500 Subject: [PATCH 2/5] Reword message. --- .../resources/CommandLineParameterParserStrings.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx b/src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx index 0edbaf3af33..93b299bc817 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx +++ b/src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx @@ -190,6 +190,6 @@ Invalid argument '{0}', did you mean: - WindowStyle is not implemented on this platform. + Parameter -WindowStyle is not implemented on this platform. From 4ab2078caca22209321d21e8d458b75cb42a7387 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Mon, 22 Jan 2018 11:22:21 -0800 Subject: [PATCH 3/5] Remove an extra new line --- .../host/msh/CommandLineParameterParser.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs index fec6c04e61b..8321cb8b810 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -614,7 +614,6 @@ private void ParseHelper(string[] args) break; } #endif - } else if (MatchSwitch(switchKey, "file", "f")) { From c322fa76806870a042b78d1b1e2b58cbd098ba58 Mon Sep 17 00:00:00 2001 From: Greg Zimmerman Date: Mon, 22 Jan 2018 19:50:33 -0500 Subject: [PATCH 4/5] Add test for WindowStyle error on Linux and macOS. --- test/powershell/Host/ConsoleHost.Tests.ps1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index f6b08ca4dbc..56583505279 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -516,11 +516,10 @@ foo Describe "WindowStyle argument" -Tag Feature { BeforeAll { $defaultParamValues = $PSDefaultParameterValues.Clone() - $PSDefaultParameterValues["it:skip"] = !$IsWindows + $ExitCodeBadCommandLineParameter = 64 if ($IsWindows) { - $ExitCodeBadCommandLineParameter = 64 Add-Type -Name User32 -Namespace Test -MemberDefinition @" public static WINDOWPLACEMENT GetPlacement(IntPtr hwnd) { @@ -562,7 +561,7 @@ public enum ShowWindowCommands : int $global:PSDefaultParameterValues = $defaultParamValues } - It "-WindowStyle should work on Windows" -TestCases @( + It "-WindowStyle should work on Windows" -Skip:(!$IsWindows) -TestCases @( @{WindowStyle="Normal"}, @{WindowStyle="Minimized"}, @{WindowStyle="Maximized"} # hidden doesn't work in CI/Server Core @@ -580,10 +579,15 @@ public enum ShowWindowCommands : int $ps | Stop-Process -Force } - It "Invalid -WindowStyle returns error" { + It "Invalid -WindowStyle returns error on Windows" -Skip:(!$IsWindows) { pwsh -WindowStyle invalid $LASTEXITCODE | Should Be $ExitCodeBadCommandLineParameter } + + It "-WindowStyle returns error on Linux and macOS" -Skip:$IsWindows { + pwsh -WindowStyle + $LASTEXITCODE | Should Be $ExitCodeBadCommandLineParameter + } } Describe "Console host api tests" -Tag CI { From d021cf805b194c5529f87c06caf790f710c2288c Mon Sep 17 00:00:00 2001 From: Greg Zimmerman Date: Tue, 23 Jan 2018 19:11:34 -0500 Subject: [PATCH 5/5] Revert "Add test for WindowStyle error on Linux and macOS." This reverts commit c322fa76806870a042b78d1b1e2b58cbd098ba58. --- test/powershell/Host/ConsoleHost.Tests.ps1 | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index 56583505279..f6b08ca4dbc 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -516,10 +516,11 @@ foo Describe "WindowStyle argument" -Tag Feature { BeforeAll { $defaultParamValues = $PSDefaultParameterValues.Clone() - $ExitCodeBadCommandLineParameter = 64 + $PSDefaultParameterValues["it:skip"] = !$IsWindows if ($IsWindows) { + $ExitCodeBadCommandLineParameter = 64 Add-Type -Name User32 -Namespace Test -MemberDefinition @" public static WINDOWPLACEMENT GetPlacement(IntPtr hwnd) { @@ -561,7 +562,7 @@ public enum ShowWindowCommands : int $global:PSDefaultParameterValues = $defaultParamValues } - It "-WindowStyle should work on Windows" -Skip:(!$IsWindows) -TestCases @( + It "-WindowStyle should work on Windows" -TestCases @( @{WindowStyle="Normal"}, @{WindowStyle="Minimized"}, @{WindowStyle="Maximized"} # hidden doesn't work in CI/Server Core @@ -579,15 +580,10 @@ public enum ShowWindowCommands : int $ps | Stop-Process -Force } - It "Invalid -WindowStyle returns error on Windows" -Skip:(!$IsWindows) { + It "Invalid -WindowStyle returns error" { pwsh -WindowStyle invalid $LASTEXITCODE | Should Be $ExitCodeBadCommandLineParameter } - - It "-WindowStyle returns error on Linux and macOS" -Skip:$IsWindows { - pwsh -WindowStyle - $LASTEXITCODE | Should Be $ExitCodeBadCommandLineParameter - } } Describe "Console host api tests" -Tag CI {