4
4
# get a random string of characters a-z and A-Z
5
5
function Get-RandomString
6
6
{
7
- param ( [int ]$length = 8 )
7
+ param ( [int ]$Length = 8 )
8
8
$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 " "
10
10
}
11
11
12
12
# get a random string which is not the name of an existing provider
13
13
function Get-NonExistantProviderName
14
14
{
15
- param ( [int ]$length = 8 )
15
+ param ( [int ]$Length = 8 )
16
16
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 ) )
19
19
$providerName
20
20
}
21
21
22
22
# get a random string which is not the name of an existing drive
23
23
function Get-NonExistantDriveName
24
24
{
25
- param ( [int ]$length = 8 )
25
+ param ( [int ]$Length = 8 )
26
26
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 ) )
29
29
$drivename
30
30
}
31
31
32
32
# get a random string which is not the name of an existing function
33
33
function Get-NonExistantFunctionName
34
34
{
35
- param ( [int ]$length = 8 )
35
+ param ( [int ]$Length = 8 )
36
36
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 )
39
39
$functionName
40
40
}
41
41
@@ -54,121 +54,126 @@ Describe "Clear-Content cmdlet tests" -Tags "CI" {
54
54
}
55
55
56
56
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
60
60
}
61
61
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
64
64
$result | Should - BeNullOrEmpty
65
65
}
66
66
67
67
# we could suppress the WhatIf output here if we use the testhost, but it's not necessary
68
68
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"
71
71
}
72
72
73
73
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()
75
75
$cci.SupportsShouldProcess | Should - BeTrue
76
76
}
77
77
78
78
It " Alternate streams should be cleared with clear-content" - skip:(! $IsWindows ) {
79
79
# make sure that the content is correct
80
80
# 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
87
87
}
88
88
89
89
It " the '-Stream' dynamic parameter is visible to get-command in the filesystem" - Skip:(! $IsWindows ) {
90
90
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"
93
93
}
94
94
finally {
95
- pop-location
95
+ Pop-Location
96
96
}
97
97
}
98
98
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" {
100
100
try {
101
- push-location function:
102
- get-command clear-content - stream $streamName
101
+ Push-Location - Path function:
102
+ Get-Command Clear-Content - Stream $streamName
103
103
throw " ExpectedExceptionNotDelivered"
104
104
}
105
105
catch {
106
106
$_.FullyQualifiedErrorId | Should - Be " NamedParameterNotFound,Microsoft.PowerShell.Commands.GetCommandCommand"
107
107
}
108
108
finally {
109
- pop-location
109
+ Pop-Location
110
110
}
111
111
}
112
112
}
113
113
114
114
Context " Proper errors should be delivered when bad locations are specified" {
115
115
It " should throw `" Cannot bind argument to parameter 'Path'`" when -Path is `$ null" {
116
116
try {
117
- clear-content - path $null - ErrorAction Stop
117
+ Clear-Content - Path $null - ErrorAction Stop
118
118
throw " expected exception was not delivered"
119
119
}
120
120
catch {
121
121
$_.FullyQualifiedErrorId | Should - Be " ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand"
122
122
}
123
123
}
124
+
124
125
# [BugId(BugDatabase.WindowsOutOfBandReleases, 903880)]
125
126
It " should throw `" Cannot bind argument to parameter 'Path'`" when -Path is `$ ()" {
126
127
try {
127
- clear-content - path $ () - ErrorAction Stop
128
+ Clear-Content - Path $ () - ErrorAction Stop
128
129
throw " expected exception was not delivered"
129
130
}
130
131
catch {
131
132
$_.FullyQualifiedErrorId | Should - Be " ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand"
132
133
}
133
134
}
135
+
134
136
# [DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
135
137
It " should throw 'PSNotSupportedException' when you clear-content to an unsupported provider" {
136
138
$functionName = Get-NonExistantFunctionName
137
- $null = new-item function:$functionName - Value { 1 }
139
+ $null = New-Item - Path function:$functionName - Value { 1 }
138
140
try {
139
- clear-content - path function:$functionName - ErrorAction Stop
141
+ Clear-Content - Path function:$functionName - ErrorAction Stop
140
142
throw " Expected exception was not thrown"
141
143
}
142
144
catch {
143
145
$_.FullyQualifiedErrorId | Should - Be " NotSupported,Microsoft.PowerShell.Commands.ClearContentCommand"
144
146
}
145
147
}
148
+
146
149
It " should throw FileNotFound error when referencing a non-existant file" {
147
150
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
150
153
throw " ExpectedExceptionNotDelivered"
151
154
}
152
155
catch {
153
156
$_.FullyQualifiedErrorId | Should - Be " PathNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"
154
157
}
155
158
}
159
+
156
160
It " should throw DriveNotFound error when referencing a non-existant drive" {
157
161
try {
158
162
$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"
161
165
}
162
166
catch {
163
167
$_.FullyQualifiedErrorId | Should - Be " DriveNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"
164
168
}
165
169
}
170
+
166
171
# we'll use a provider qualified path to produce this error
167
172
It " should throw ProviderNotFound error when referencing a non-existant provider" {
168
173
try {
169
174
$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"
172
177
}
173
178
catch {
174
179
$_.FullyQualifiedErrorId | Should - Be " ProviderNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"
0 commit comments