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

Commit5d8a7d1

Browse files
committed
Add test for -Verbose:$false and fix VerbosePreference state management
- Add test case for -Verbose:$false taking precedence over $VerbosePreference- Save and restore $VerbosePreference in all test cases using try-finally blocks- Clean up whitespace
1 parent6898479 commit5d8a7d1

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

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

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the MIT License.
33

44
Describe"ShouldProcess respects VerbosePreference"-Tags"CI","Feature" {
5-
5+
66
BeforeAll {
77
functionTest-ShouldProcess {
88
[CmdletBinding(SupportsShouldProcess)]
@@ -13,34 +13,60 @@ Describe "ShouldProcess respects VerbosePreference" -Tags "CI","Feature" {
1313

1414
Context"VerbosePreference variable" {
1515
It"Emits verbose output when VerbosePreference is Continue" {
16-
$VerbosePreference='Continue'
17-
$output=Test-ShouldProcess4>&1
18-
$VerbosePreference='SilentlyContinue'
19-
20-
$output|Where-Object {$_-eq"OK" }| Should-Not-BeNullOrEmpty
21-
$verboseOutput=$output|Where-Object {$_-is [System.Management.Automation.VerboseRecord] }
22-
$verboseOutput| Should-Not-BeNullOrEmpty
23-
$verboseOutput.Message| Should-Match"TestAction.*TestTarget"
16+
$originalVerbosePreference=$VerbosePreference
17+
try {
18+
$VerbosePreference='Continue'
19+
$output=Test-ShouldProcess4>&1
20+
21+
$output|Where-Object {$_-eq"OK" }| Should-Not-BeNullOrEmpty
22+
$verboseOutput=$output|Where-Object {$_-is [System.Management.Automation.VerboseRecord] }
23+
$verboseOutput| Should-Not-BeNullOrEmpty
24+
$verboseOutput.Message| Should-Match"TestAction.*TestTarget"
25+
}
26+
finally {
27+
$VerbosePreference=$originalVerbosePreference
28+
}
2429
}
2530

2631
It"Does not emit verbose output when VerbosePreference is SilentlyContinue" {
27-
$VerbosePreference='SilentlyContinue'
28-
$output=Test-ShouldProcess4>&1
29-
30-
$output|Where-Object {$_-eq"OK" }| Should-Not-BeNullOrEmpty
31-
$verboseOutput=$output|Where-Object {$_-is [System.Management.Automation.VerboseRecord] }
32-
$verboseOutput| Should-BeNullOrEmpty
32+
$originalVerbosePreference=$VerbosePreference
33+
try {
34+
$VerbosePreference='SilentlyContinue'
35+
$output=Test-ShouldProcess4>&1
36+
37+
$output|Where-Object {$_-eq"OK" }| Should-Not-BeNullOrEmpty
38+
$verboseOutput=$output|Where-Object {$_-is [System.Management.Automation.VerboseRecord] }
39+
$verboseOutput| Should-BeNullOrEmpty
40+
}
41+
finally {
42+
$VerbosePreference=$originalVerbosePreference
43+
}
3344
}
3445
}
3546

3647
Context"Verbose parameter" {
3748
It"Emits verbose output when -Verbose is specified" {
3849
$output=Test-ShouldProcess-Verbose4>&1
39-
50+
4051
$output|Where-Object {$_-eq"OK" }| Should-Not-BeNullOrEmpty
4152
$verboseOutput=$output|Where-Object {$_-is [System.Management.Automation.VerboseRecord] }
4253
$verboseOutput| Should-Not-BeNullOrEmpty
4354
$verboseOutput.Message| Should-Match"TestAction.*TestTarget"
4455
}
56+
57+
It"Does not emit verbose output when -Verbose:`$false is specified even if VerbosePreference is Continue" {
58+
$originalVerbosePreference=$VerbosePreference
59+
try {
60+
$VerbosePreference='Continue'
61+
$output=Test-ShouldProcess-Verbose:$false4>&1
62+
63+
$output|Where-Object {$_-eq"OK" }| Should-Not-BeNullOrEmpty
64+
$verboseOutput=$output|Where-Object {$_-is [System.Management.Automation.VerboseRecord] }
65+
$verboseOutput| Should-BeNullOrEmpty
66+
}
67+
finally {
68+
$VerbosePreference=$originalVerbosePreference
69+
}
70+
}
4571
}
4672
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp