@@ -16,7 +16,7 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
1616 # Add sample text to the file
1717 $content = " This is sample text!"
1818 $content | Out-File - FilePath $outputFilePath
19- Test-Path $outputFilePath | Should be $true
19+ Test-Path $outputFilePath | Should - BeTrue
2020 }
2121
2222 try {
@@ -27,16 +27,16 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
2727
2828 if ($expectedError ) {
2929 $ps.hadErrors | Should - BeTrue
30- $ps.Streams.Error.FullyQualifiedErrorId | Should be $expectedError
30+ $ps.Streams.Error.FullyQualifiedErrorId | Should - Be $expectedError
3131 } else {
3232 $ps.addscript (" Get-Date" ).Invoke()
3333 $ps.commands.clear ()
3434 $ps.addscript (" Stop-Transcript" ).Invoke()
3535
3636 Test-Path $outputFilePath | Should - BeTrue
37- $outputFilePath | should FileContentMatch " Get-Date"
37+ $outputFilePath | Should - FileContentMatch " Get-Date"
3838 if ($append ) {
39- $outputFilePath | Should FileContentMatch $content
39+ $outputFilePath | Should - FileContentMatch $content
4040 }
4141 }
4242 } finally {
@@ -53,6 +53,7 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
5353
5454 AfterEach {
5555 Remove-Item $transcriptFilePath - ErrorAction SilentlyContinue
56+ [System.Management.Automation.Internal.InternalTestHooks ]::SetTestHook(' ForcePromptForChoiceDefaultOption' , $False )
5657 }
5758
5859 It " Should create Transcript file at default path" {
@@ -122,29 +123,153 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
122123 }
123124 }
124125
125- Test-Path $transcriptFilePath | Should be $true
126- $transcriptFilePath | Should FileContentMatch " After Dispose"
126+ $transcriptFilePath | Should - Exist
127+ $transcriptFilePath | Should - FileContentMatch " After Dispose"
127128 }
128129
129130 It " Transcription should be closed if the only runspace gets closed" {
130131 $powerShellPath = [System.Diagnostics.Process ]::GetCurrentProcess().Path
131132 $powerShellCommand = $powerShellPath + ' -c "start-transcript $transcriptFilePath; Write-Host '' Before Dispose'' ;"'
132133 Invoke-Expression $powerShellCommand
133134
134- Test-Path $transcriptFilePath | Should - BeTrue
135- $transcriptFilePath | Should FileContentMatch " Before Dispose"
136- $transcriptFilePath | Should FileContentMatch " PowerShell transcript end"
135+ $transcriptFilePath | Should - Exist
136+ $transcriptFilePath | Should - FileContentMatch " Before Dispose"
137+ $transcriptFilePath | Should - FileContentMatch " PowerShell transcript end"
137138 }
138139
139140 It " Transcription should record native command output" {
140141 $script = {
141142 Start-Transcript - Path $transcriptFilePath
142143 hostname
143- Stop-Transcript }
144+ Stop-Transcript
145+ }
146+
144147 & $script
145- Test-Path $transcriptFilePath | Should - BeTrue
146148
149+ $transcriptFilePath | Should - Exist
147150 $machineName = [System.Environment ]::MachineName
148- $transcriptFilePath | Should FileContentMatch $machineName
151+ $transcriptFilePath | Should - FileContentMatch $machineName
152+ }
153+
154+ It " Transcription should record Write-Information output when InformationAction is set to Continue" {
155+ [String ]$message = New-Guid
156+ $script = {
157+ Start-Transcript - Path $transcriptFilePath
158+ Write-Information - Message $message - InformationAction Continue
159+ Stop-Transcript
160+ }
161+
162+ & $script
163+
164+ $transcriptFilePath | Should - Exist
165+ $transcriptFilePath | Should -Not - FileContentMatch " INFO: "
166+ $transcriptFilePath | Should - FileContentMatch $message
167+ }
168+
169+ It " Transcription should not record Write-Information output when InformationAction is set to SilentlyContinue" {
170+ [String ]$message = New-Guid
171+ $script = {
172+ Start-Transcript - Path $transcriptFilePath
173+ Write-Information - Message $message - InformationAction SilentlyContinue
174+ Stop-Transcript
175+ }
176+
177+ & $script
178+
179+ $transcriptFilePath | Should - Exist
180+ $transcriptFilePath | Should -Not - FileContentMatch " INFO: "
181+ $transcriptFilePath | Should -Not - FileContentMatch $message
182+ }
183+
184+ It " Transcription should not record Write-Information output when InformationAction is set to Ignore" {
185+ [String ]$message = New-Guid
186+ $script = {
187+ Start-Transcript - Path $transcriptFilePath
188+ Write-Information - Message $message - InformationAction Ignore
189+ Stop-Transcript
190+ }
191+
192+ & $script
193+
194+ $transcriptFilePath | Should - Exist
195+ $transcriptFilePath | Should -Not - FileContentMatch " INFO: "
196+ $transcriptFilePath | Should -Not - FileContentMatch $message
197+ }
198+
199+ It " Transcription should record Write-Information output in correct order when InformationAction is set to Inquire" {
200+ [String ]$message = New-Guid
201+ $newLine = [System.Environment ]::NewLine
202+ $expectedContent = " $message $ ( $newLine ) Confirm$ ( $newLine ) Continue with this operation?"
203+ $script = {
204+ [System.Management.Automation.Internal.InternalTestHooks ]::SetTestHook(' ForcePromptForChoiceDefaultOption' , $True )
205+ Start-Transcript - Path $transcriptFilePath
206+ Write-Information - Message $message - InformationAction Inquire
207+ Stop-Transcript
208+ }
209+
210+ & $script
211+
212+ $transcriptFilePath | Should - Exist
213+ $transcriptFilePath | Should -Not - FileContentMatch " INFO: "
214+ $transcriptFilePath | Should - FileContentMatchMultiline $expectedContent
215+ }
216+
217+ It " Transcription should record Write-Host output when InformationAction is set to Continue" {
218+ [String ]$message = New-Guid
219+ $script = {
220+ Start-Transcript - Path $transcriptFilePath
221+ Write-Host - Message $message - InformationAction Continue
222+ Stop-Transcript
223+ }
224+
225+ & $script
226+
227+ $transcriptFilePath | Should - Exist
228+ $transcriptFilePath | Should - FileContentMatch $message
229+ }
230+
231+ It " Transcription should record Write-Host output when InformationAction is set to SilentlyContinue" {
232+ [String ]$message = New-Guid
233+ $script = {
234+ Start-Transcript - Path $transcriptFilePath
235+ Write-Host - Message $message - InformationAction SilentlyContinue
236+ Stop-Transcript
237+ }
238+
239+ & $script
240+
241+ $transcriptFilePath | Should - Exist
242+ $transcriptFilePath | Should - FileContentMatch $message
243+ }
244+
245+ It " Transcription should not record Write-Host output when InformationAction is set to Ignore" {
246+ [String ]$message = New-Guid
247+ $script = {
248+ Start-Transcript - Path $transcriptFilePath
249+ Write-Host - Message $message - InformationAction Ignore
250+ Stop-Transcript
251+ }
252+
253+ & $script
254+
255+ $transcriptFilePath | Should - Exist
256+ $transcriptFilePath | Should -Not - FileContentMatch $message
257+ }
258+
259+ It " Transcription should record Write-Host output in correct order when InformationAction is set to Inquire" {
260+ [String ]$message = New-Guid
261+ $newLine = [System.Environment ]::NewLine
262+ $expectedContent = " $message $ ( $newLine ) Confirm$ ( $newLine ) Continue with this operation?"
263+ $script = {
264+ [System.Management.Automation.Internal.InternalTestHooks ]::SetTestHook(' ForcePromptForChoiceDefaultOption' , $True )
265+ Start-Transcript - Path $transcriptFilePath
266+ Write-Host - Message $message - InformationAction Inquire
267+ Stop-Transcript
268+ }
269+
270+ & $script
271+
272+ $transcriptFilePath | Should - Exist
273+ $transcriptFilePath | Should - FileContentMatchMultiline $expectedContent
149274 }
150275}
0 commit comments