8000 Fix typos and formatting in Clear-Content.Tests.ps1 (#6592) · PowerShell/PowerShell@3ec98bb · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ec98bb

Browse files
sethvsiSazonov
authored andcommitted
Fix typos and formatting in Clear-Content.Tests.ps1 (#6592)
* Fix typos and formatting. * Capitalize function parameters.
1 parent a3e8929 commit 3ec98bb

File tree

1 file changed

+47
-42
lines changed

1 file changed

+47
-42
lines changed

test/powershell/Modules/Microsoft.PowerShell.Management/Clear-Content.Tests.ps1

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,38 @@
44
# get a random string of characters a-z and A-Z
55
function Get-RandomString
66
{
7-
param ( [int]$length = 8 )
7+
param ( [int]$Length = 8 )
88
$chars = .{ ([int][char]'a')..([int][char]'z');([int][char]'A')..([int][char]'Z') }
9-
([char[]]($chars | get-random -count $length)) -join ""
9+
([char[]]($chars | Get-Random -Count $Length)) -join ""
1010
}
1111

1212
# get a random string which is not the name of an existing provider
1313
function Get-NonExistantProviderName
1414
{
15-
param ( [int]$length = 8 )
15+
param ( [int]$Length = 8 )
1616
do {
17-
$providerName = get-randomstring -length $length
18-
} until ( $null -eq (get-psprovider -PSProvider $providername -erroraction silentlycontinue) )
17+
$providerName = Get-RandomString -Length $Length
18+
} until ( $null -eq (Get-PSProvider -PSProvider $providername -ErrorAction SilentlyContinue) )
1919
$providerName
2020
}
2121

2222
# get a random string which is not the name of an existing drive
2323
function Get-NonExistantDriveName
2424
{
25-
param ( [int]$length = 8 )
25+
param ( [int]$Length = 8 )
2626
do {
27-
$driveName = Get-RandomString -length $length
28-
} until ( $null -eq (get-psdrive $driveName -erroraction silentlycontinue) )
27+
$driveName = Get-RandomString -Length $Length
28+
} until ( $null -eq (Get-PSDrive $driveName -ErrorAction SilentlyContinue) )
2929
$drivename
3030
}
3131

3232
# get a random string which is not the name of an existing function
3333
function Get-NonExistantFunctionName
3434
{
35-
param ( [int]$length = 8 )
35+
param ( [int]$Length = 8 )
3636
do {
37-
$functionName = Get-RandomString -length $length
38-
} until ( (test-path function:$functionName) -eq $false )
37+
$functionName = Get-RandomString -Length $Length
38+
} until ( (Test-Path -Path function:$functionName) -eq $false )
3939
$functionName
4040
}
4141

@@ -54,121 +54,126 @@ Describe "Clear-Content cmdlet tests" -Tags "CI" {
5454
}
5555

5656
Context "Clear-Content should actually clear content" {
57-
It "should clear-Content of testdrive:\$file1" {
58-
set-content -path testdrive:\$file1 -value "ExpectedContent" -passthru | Should -BeExactly "ExpectedContent"
59-
clear-content -Path testdrive:\$file1
57+
It "should clear-Content of TestDrive:\$file1" {
58+
Set-Content -Path TestDrive:\$file1 -Value "ExpectedContent" -PassThru | Should -BeExactly "ExpectedContent"
59+
Clear-Content -Path TestDrive:\$file1
6060
}
6161

62-
It "shouldn't get any content from testdrive:\$file1" {
63-
$result = get-content -path testdrive:\$file1
62+
It "shouldn't get any content from TestDrive:\$file1" {
63+
$result = Get-Content -Path TestDrive:\$file1
6464
$result | Should -BeNullOrEmpty
6565
}
6666

6767
# we could suppress the WhatIf output here if we use the testhost, but it's not necessary
6868
It "The filesystem provider supports should process" -skip:(!$IsWindows) {
69-
clear-content TESTDRIVE:\$file2 -WhatIf
70-
"TESTDRIVE:\$file2" | Should -FileContentMatch "This is content"
69+
Clear-Content -Path TestDrive:\$file2 -WhatIf
70+
"TestDrive:\$file2" | Should -FileContentMatch "This is content"
7171
}
7272

7373
It "The filesystem provider should support ShouldProcess (reference ProviderSupportsShouldProcess member)" {
74-
$cci = ((get-command clear-content).ImplementingType)::new()
74+
$cci = ((Get-Command -Name Clear-Content).ImplementingType)::new()
7575
$cci.SupportsShouldProcess | Should -BeTrue
7676
}
7777

7878
It "Alternate streams should be cleared with clear-content" -skip:(!$IsWindows) {
7979
# make sure that the content is correct
8080
# this is here rather than BeforeAll because only windows can write to an alternate stream
81-
set-content -path "TESTDRIVE:/$file3" -stream $streamName -value $streamContent
82-
get-content -path "TESTDRIVE:/$file3" | Should -BeExactly $content2
83-
get-content -Path "TESTDRIVE:/$file3" -stream $streamName | Should -BeExactly $streamContent
84-
clear-content -PATH "TESTDRIVE:/$file3" -stream $streamName
85-
get-content -Path "TESTDRIVE:/$file3" | Should -BeExactly $content2
86-
get-content -Path "TESTDRIVE:/$file3" -stream $streamName | Should -BeNullOrEmpty
81+
Set-Content -Path "TestDrive:/$file3" -Stream $streamName -Value $streamContent
82+
Get-Content -Path "TestDrive:/$file3" | Should -BeExactly $content2
83+
Get-Content -Path "TestDrive:/$file3" -Stream $streamName | Should -BeExactly $streamContent
84+
Clear-Content -Path "TestDrive:/$file3" -Stream $streamName
85+
Get-Content -Path "TestDrive:/$file3" | Should -BeExactly $content2
86+
Get-Content -Path "TestDrive:/$file3" -Stream $streamName | Should -BeNullOrEmpty
8787
}
8888

8989
It "the '-Stream' dynamic parameter is visible to get-command in the filesystem" -Skip:(!$IsWindows) {
9090
try {
91-
push-location TESTDRIVE:
92-
(get-command clear-content -stream foo).parameters.keys -eq "stream" | Should -Be "stream"
91+
Push-Location -Path TestDrive:
92+
(Get-Command Clear-Content -Stream foo).parameters.keys -eq "stream" | Should -Be "stream"
9393
}
9494
finally {
95-
pop-location
95+
Pop-Location
9696
}
9797
}
9898

99-
It "the '-stream' dynamic parameter should not be visible to get-command in the function provider" {
99+
It "the '-Stream' dynamic parameter should not be visible to get-command in the function provider" {
100100
try {
101-
push-location function:
102-
get-command clear-content -stream $streamName
101+
Push-Location -Path function:
102+
Get-Command Clear-Content -Stream $streamName
103103
throw "ExpectedExceptionNotDelivered"
104104
}
105105
catch {
106106
$_.FullyQualifiedErrorId | Should -Be "NamedParameterNotFound,Microsoft.PowerShell.Commands.GetCommandCommand"
107107
}
108108
finally {
109-
pop-location
109+
Pop-Location
110110
}
111111
}
112112
}
113113

114114
Context "Proper errors should be delivered when bad locations are specified" {
115115
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$null" {
116116
try {
117-
clear-content -path $null -ErrorAction Stop
117+
Clear-Content -Path $null -ErrorAction Stop
118118
throw "expected exception was not delivered"
119119
}
120120
catch {
121121
$_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand"
122122
}
123123
}
124+
124125
#[BugId(BugDatabase.WindowsOutOfBandReleases, 903880)]
125126
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$()" {
126127
try {
127-
clear-content -path $() -ErrorAction Stop
128+
Clear-Content -Path $() -ErrorAction Stop
128129
throw "expected exception was not delivered"
129130
}
130131
catch {
131132
$_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand"
132133
}
133134
}
135+
134136
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
135137
It "should throw 'PSNotSupportedException' when you clear-content to an unsupported provider" {
136138
$functionName = Get-NonExistantFunctionName
137-
$null = new-item function:$functionName -Value { 1 }
139+
$null = New-Item -Path function:$functionName -Value { 1 }
138140
try {
139-
clear-content -path function:$functionName -ErrorAction Stop
141+
Clear-Content -Path function:$functionName -ErrorAction Stop
140142
throw "Expected exception was not thrown"
141143
}
142144
catch {
143145
$_.FullyQualifiedErrorId | Should -Be "NotSupported,Microsoft.PowerShell.Commands.ClearContentCommand"
144146
}
145147
}
148+
146149
It "should throw FileNotFound error when referencing a non-existant file" {
147150
try {
148-
$badFile = "TESTDRIVE:/badfilename.txt"
149-
clear-content -path $badFile -ErrorAction Stop
151+
$badFile = "TestDrive:/badfilename.txt"
152+
Clear-Content -Path $badFile -ErrorAction Stop
150153
throw "ExpectedExceptionNotDelivered"
151154
}
152155
catch {
153156
$_.FullyQualifiedErrorId | Should -Be "PathNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"
154157
}
155158
}
159+
156160
It "should throw DriveNotFound error when referencing a non-existant drive" {
157161
try {
158162
$badDrive = "{0}:/file.txt" -f (Get-NonExistantDriveName)
159-
clear-content -path $badDrive -ErrorAction Stop
160-
thow "ExpectedExcep A1D1 tionNotDelivered"
163+
Clear-Content -Path $badDrive -ErrorAction Stop
164+
throw "ExpectedExceptionNotDelivered"
161165
}
162166
catch {
163167
$_.FullyQualifiedErrorId | Should -Be "DriveNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"
164168
}
165169
}
170+
166171
# we'll use a provider qualified path to produce this error
167172
It "should throw ProviderNotFound error when referencing a non-existant provider" {
168173
try {
169174
$badProviderPath = "{0}::C:/file.txt" -f (Get-NonExistantProviderName)
170-
clear-content -path $badProviderPath -ErrorAction Stop
171-
thow "ExpectedExceptionNotDelivered"
175+
Clear-Content -Path $badProviderPath -ErrorAction Stop
176+
throw "ExpectedExceptionNotDelivered"
172177
}
173178
catch {
174179
$_.FullyQualifiedErrorId | Should -Be "ProviderNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"

0 commit comments

Comments
 (0)
0