-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix conditions for transcription of Write-Information command. #6917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
56386b1
7536e3f
2fe68a6
6f5b4a1
16d7181
d9e8f24
056446d
2c6d024
b2d9103
bae894d
d00d946
c67c20c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" { | |
| #Add sample text to the file | ||
| $content = "This is sample text!" | ||
| $content | Out-File -FilePath $outputFilePath | ||
| Test-Path $outputFilePath | Should be $true | ||
| Test-Path $outputFilePath | Should -BeTrue | ||
| } | ||
|
|
||
| try { | ||
|
|
@@ -27,16 +27,16 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" { | |
|
|
||
| if($expectedError) { | ||
| $ps.hadErrors | Should -BeTrue | ||
| $ps.Streams.Error.FullyQualifiedErrorId | Should be $expectedError | ||
| $ps.Streams.Error.FullyQualifiedErrorId | Should -Be $expectedError | ||
| } else { | ||
| $ps.addscript("Get-Date").Invoke() | ||
| $ps.commands.clear() | ||
| $ps.addscript("Stop-Transcript").Invoke() | ||
|
|
||
| Test-Path $outputFilePath | Should -BeTrue | ||
| $outputFilePath | should FileContentMatch "Get-Date" | ||
| $outputFilePath | Should -FileContentMatch "Get-Date" | ||
| if($append) { | ||
| $outputFilePath | Should FileContentMatch $content | ||
| $outputFilePath | Should -FileContentMatch $content | ||
| } | ||
| } | ||
| } finally { | ||
|
|
@@ -53,6 +53,7 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" { | |
|
|
||
| AfterEach { | ||
| Remove-Item $transcriptFilePath -ErrorAction SilentlyContinue | ||
| [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('ForcePromptForChoiceDefaultOption', $False) | ||
| } | ||
|
|
||
| It "Should create Transcript file at default path" { | ||
|
|
@@ -122,29 +123,153 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" { | |
| } | ||
| } | ||
|
|
||
| Test-Path $transcriptFilePath | Should be $true | ||
| $transcriptFilePath | Should FileContentMatch "After Dispose" | ||
| $transcriptFilePath | Should -Exist | ||
| $transcriptFilePath | Should -FileContentMatch "After Dispose" | ||
| } | ||
|
|
||
| It "Transcription should be closed if the only runspace gets closed" { | ||
| $powerShellPath = [System.Diagnostics.Process]::GetCurrentProcess().Path | ||
| $powerShellCommand = $powerShellPath + ' -c "start-transcript $transcriptFilePath; Write-Host ''Before Dispose'';"' | ||
| Invoke-Expression $powerShellCommand | ||
|
|
||
| Test-Path $transcriptFilePath | Should -BeTrue | ||
| $transcriptFilePath | Should FileContentMatch "Before Dispose" | ||
| $transcriptFilePath | Should FileContentMatch "PowerShell transcript end" | ||
| $transcriptFilePath | Should -Exist | ||
| $transcriptFilePath | Should -FileContentMatch "Before Dispose" | ||
| $transcriptFilePath | Should -FileContentMatch "PowerShell transcript end" | ||
| } | ||
|
|
||
| It "Transcription should record native command output" { | ||
| $script = { | ||
| Start-Transcript -Path $transcriptFilePath | ||
| hostname | ||
| Stop-Transcript } | ||
| Stop-Transcript | ||
| } | ||
|
|
||
| & $script | ||
| Test-Path $transcriptFilePath | Should -BeTrue | ||
|
|
||
| $transcriptFilePath | Should -Exist | ||
| $machineName = [System.Environment]::MachineName | ||
| $transcriptFilePath | Should FileContentMatch $machineName | ||
| $transcriptFilePath | Should -FileContentMatch $machineName | ||
| } | ||
|
|
||
| It "Transcription should record Write-Information output when InformationAction is set to Continue" { | ||
| [String]$message = New-Guid | ||
| $script = { | ||
| Start-Transcript -Path $transcriptFilePath | ||
| Write-Information -Message $message -InformationAction Continue | ||
| Stop-Transcript | ||
| } | ||
|
|
||
| & $script | ||
|
|
||
| $transcriptFilePath | Should -Exist | ||
| $transcriptFilePath | Should -Not -FileContentMatch "INFO: " | ||
| $transcriptFilePath | Should -FileContentMatch $message | ||
| } | ||
|
|
||
| It "Transcription should not record Write-Information output when InformationAction is set to SilentlyContinue" { | ||
| [String]$message = New-Guid | ||
| $script = { | ||
| Start-Transcript -Path $transcriptFilePath | ||
| Write-Information -Message $message -InformationAction SilentlyContinue | ||
| Stop-Transcript | ||
| } | ||
|
|
||
| & $script | ||
|
|
||
| $transcriptFilePath | Should -Exist | ||
| $transcriptFilePath | Should -Not -FileContentMatch "INFO: " | ||
| $transcriptFilePath | Should -Not -FileContentMatch $message | ||
| } | ||
|
|
||
| It "Transcription should not record Write-Information output when InformationAction is set to Ignore" { | ||
| [String]$message = New-Guid | ||
| $script = { | ||
| Start-Transcript -Path $transcriptFilePath | ||
| Write-Information -Message $message -InformationAction Ignore | ||
| Stop-Transcript | ||
| } | ||
|
|
||
| & $script | ||
|
|
||
| $transcriptFilePath | Should -Exist | ||
| $transcriptFilePath | Should -Not -FileContentMatch "INFO: " | ||
| $transcriptFilePath | Should -Not -FileContentMatch $message | ||
| } | ||
|
|
||
| It "Transcription should record Write-Information output in correct order when InformationAction is set to Inquire" { | ||
| [String]$message = New-Guid | ||
| $newLine = [System.Environment]::NewLine | ||
| $expectedContent = "$message$($newLine)Confirm$($newLine)Continue with this operation?" | ||
| $script = { | ||
| [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('ForcePromptForChoiceDefaultOption', $True) | ||
|
||
| Start-Transcript -Path $transcriptFilePath | ||
| Write-Information -Message $message -InformationAction Inquire | ||
| Stop-Transcript | ||
| } | ||
|
|
||
| & $script | ||
|
|
||
| $transcriptFilePath | Should -Exist | ||
| $transcriptFilePath | Should -Not -FileContentMatch "INFO: " | ||
| $transcriptFilePath | Should -FileContentMatchMultiline $expectedContent | ||
| } | ||
|
|
||
| It "Transcription should record Write-Host output when InformationAction is set to Continue" { | ||
| [String]$message = New-Guid | ||
| $script = { | ||
| Start-Transcript -Path $transcriptFilePath | ||
| Write-Host -Message $message -InformationAction Continue | ||
| Stop-Transcript | ||
| } | ||
|
|
||
| & $script | ||
|
|
||
| $transcriptFilePath | Should -Exist | ||
| $transcriptFilePath | Should -FileContentMatch $message | ||
| } | ||
|
|
||
| It "Transcription should record Write-Host output when InformationAction is set to SilentlyContinue" { | ||
| [String]$message = New-Guid | ||
| $script = { | ||
| Start-Transcript -Path $transcriptFilePath | ||
| Write-Host -Message $message -InformationAction SilentlyContinue | ||
|
||
| Stop-Transcript | ||
| } | ||
|
|
||
| & $script | ||
|
|
||
| $transcriptFilePath | Should -Exist | ||
| $transcriptFilePath | Should -FileContentMatch $message | ||
| } | ||
|
|
||
| It "Transcription should not record Write-Host output when InformationAction is set to Ignore" { | ||
| [String]$message = New-Guid | ||
| $script = { | ||
| Start-Transcript -Path $transcriptFilePath | ||
| Write-Host -Message $message -InformationAction Ignore | ||
| Stop-Transcript | ||
| } | ||
|
|
||
| & $script | ||
|
|
||
| $transcriptFilePath | Should -Exist | ||
| $transcriptFilePath | Should -Not -FileContentMatch $message | ||
| } | ||
|
|
||
| It "Transcription should record Write-Host output in correct order when InformationAction is set to Inquire" { | ||
| [String]$message = New-Guid | ||
| $newLine = [System.Environment]::NewLine | ||
| $expectedContent = "$message$($newLine)Confirm$($newLine)Continue with this operation?" | ||
| $script = { | ||
| [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('ForcePromptForChoiceDefaultOption', $True) | ||
| Start-Transcript -Path $transcriptFilePath | ||
| Write-Host -Message $message -InformationAction Inquire | ||
| Stop-Transcript | ||
| } | ||
|
|
||
| & $script | ||
|
|
||
| $transcriptFilePath | Should -Exist | ||
| $transcriptFilePath | Should -FileContentMatchMultiline $expectedContent | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already created three test for transcription of Write-Host command (Continue, SilentlyContinue, Ignore).
I have no idea how costly would it be to create a test for Inquire action as it makes the test interactive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we should mosk but I don't know how.
@adityapatwardhan Can we ignore the lack of this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to add a test hook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not clear where the hook should be to emulate the user interaction. Maybe in PromptForChoice method in ConsoleHostUserInterfacePromptForChoice.cs file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hubuk You can add hook here
PowerShell/src/System.Management.Automation/engine/Utils.cs
Line 1492 in c1c5344
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests added.