File tree Expand file tree Collapse file tree 4 files changed +49
-1
lines changed
src/System.Management.Automation/engine
test/powershell/Language/Scripting Expand file tree Collapse file tree 4 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ The PowerShell developer experience includes the **development of modules** (in
3030as well as the experience of ** hosting PowerShell and its APIs** in other applications and language runtimes.
3131Special consideration should be given to topics like ** backwards compatibility** with Windows PowerShell
3232(e.g. with ** PowerShell Standard** ) and ** integration with related developer tools**
33- (e.g. .NET CLI or the PowerShell extension for VS Code).
33+ (e.g. .NET CLI or the PowerShell extension for Visual Studio Code).
3434
3535### Members
3636
Original file line number Diff line number Diff line change @@ -341,6 +341,7 @@ internal static class SpecialVariables
341341 SpecialVariables . WarningPreference ,
342342 SpecialVariables . InformationPreference ,
343343 SpecialVariables . ConfirmPreference ,
344+ SpecialVariables . ProgressPreference ,
344345 } ;
345346
346347 internal static readonly Type [ ] PreferenceVariableTypes =
@@ -352,6 +353,7 @@ internal static class SpecialVariables
352353 /* WarningPreference */ typeof ( ActionPreference ) ,
353354 /* InformationPreference */ typeof ( ActionPreference ) ,
354355 /* ConfirmPreference */ typeof ( ConfirmImpact ) ,
356+ /* ProgressPreference */ typeof ( ActionPreference ) ,
355357 } ;
356358
357359 // The following variables are created in every session w/ AllScope. We avoid creating local slots when we
Original file line number Diff line number Diff line change @@ -833,6 +833,14 @@ internal class Compiler : ICustomAstVisitor2
833833
834834 static Compiler ( )
835835 {
836+ Diagnostics . Assert ( SpecialVariables . AutomaticVariables . Length == ( int ) AutomaticVariable . NumberOfAutomaticVariables
837+ && SpecialVariables . AutomaticVariableTypes . Length == ( int ) AutomaticVariable . NumberOfAutomaticVariables ,
838+ "The 'AutomaticVariable' enum length does not match both 'AutomaticVariables' and 'AutomaticVariableTypes' length." ) ;
839+
840+ Diagnostics . Assert ( Enum . GetNames ( typeof ( PreferenceVariable ) ) . Length == SpecialVariables . PreferenceVariables . Length
841+ && Enum . GetNames ( typeof ( PreferenceVariable ) ) . Length == SpecialVariables . PreferenceVariableTypes . Length ,
842+ "The 'PreferenceVariable' enum length does not match both 'PreferenceVariables' and 'PreferenceVariableTypes' length." ) ;
843+
836844 s_functionContext = Expression . Parameter ( typeof ( FunctionContext ) , "funcContext" ) ;
837845 s_executionContextParameter = Expression . Variable ( typeof ( ExecutionContext ) , "context" ) ;
838846
Original file line number Diff line number Diff line change @@ -147,6 +147,44 @@ Describe "Common parameters support for script cmdlets" -Tags "CI" {
147147 }
148148 }
149149
150+ Context " ProgressAction" {
151+ It " Ignores progress actions on advanced script function with no variables" {
152+ $ps.AddScript (
153+ @'
154+ function test-function {
155+ [CmdletBinding()]param()
156+
157+ Write-Progress "progress foo"
158+ }
159+ test-function -ProgressAction Ignore
160+ '@ ).Invoke()
161+
162+ $ps.Streams.Progress.Count | Should - Be 0
163+ $ps.Streams.Error | ForEach-Object {
164+ Write-Error - ErrorRecord $_ - ErrorAction Stop
165+ }
166+ }
167+
168+ It " Ignores progress actions on advanced script function with variables" {
169+ $ps.AddScript (
170+ @'
171+ function test-function {
172+ [CmdletBinding()]param([string]$path)
173+
174+ switch($false) { default { "echo $path" } }
175+
176+ Write-Progress "progress foo"
177+ }
178+ test-function -ProgressAction Ignore
179+ '@ ).Invoke()
180+
181+ $ps.Streams.Progress.Count | Should - Be 0
182+ $ps.Streams.Error | ForEach-Object {
183+ Write-Error - ErrorRecord $_ - ErrorAction Stop
184+ }
185+ }
186+ }
187+
150188 Context " SupportShouldprocess" {
151189 $script = '
152190 function get-foo
You can’t perform that action at this time.
0 commit comments