Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb502098

Browse files
cmkb3daxian-dbw
andauthored
Fix the common parameter-ProgressAction for advanced functions (#24591)
Co-authored-by: Dongbo Wang <dongbow@microsoft.com>
1 parent4e03546 commitb502098

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

‎docs/community/working-group-definitions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The PowerShell developer experience includes the **development of modules** (in
3030
as well as the experience of**hosting PowerShell and its APIs** in other applications and language runtimes.
3131
Special 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 forVS Code).
33+
(e.g. .NET CLI or the PowerShell extension forVisual Studio Code).
3434

3535
###Members
3636

‎src/System.Management.Automation/engine/SpecialVariables.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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
internalstaticreadonlyType[]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

‎src/System.Management.Automation/engine/parser/Compiler.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,14 @@ internal class Compiler : ICustomAstVisitor2
833833

834834
staticCompiler()
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

‎test/powershell/Language/Scripting/CommonParameters.Tests.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff 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-Be0
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-Be0
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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp