-
-
Notifications
You must be signed in to change notification settings - Fork 179
Open
Labels
Category-KoansInvoking the Great DoubtInvoking the Great DoubtIssue-DiscussionLet's talk about it!Let's talk about it!
Description
Describe "Koan Bug, Issue, or Help Request"
You have not yet reached enlightenment.
The answers you seek...
Expected strings to be the same, but they were different.
Expected length: 82
Actual length: 78
Strings differ at index 0.
Expected: ' + Cate...'
But was: '+ Category...'
Context "The Problematic Assertions"
It 'can use the error stream (number 2)' {
# Redirecting errors can generally only be done from any scope above where the error is generated.
& { Write-Error 'The gasoline is in the water.' } 2> $FilePath
$FileContent = Get-Content -Path $FilePath
' Write-Error ''The gasoline is in the water.'' : The gasoline is in the water.' | Should -Be $FileContent[0]
"+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException" |
Should -Be $FileContent[4]
"+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException" |
Should -Be $FileContent[5]
}Context "Your Attempts"
The last two lines were pre-filled, so I didn't even touch them.
Testing the redirect output to file myself, I get the following output:
❯ Get-Content -Path C:\Temp\test.txt
Write-Error 'The gasoline is in the water.' : The gasoline is in the water.
At line:1 char:1
+ & { Write-Error 'The gasoline is in the water.' } 2> C:\Temp\Test.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
the following works:
It 'can use the error stream (number 2)' {
# Redirecting errors can generally only be done from any scope above where the error is generated.
& { Write-Error 'The gasoline is in the water.' } 2> $FilePath
$FileContent = Get-Content -Path $FilePath
' Write-Error ''The gasoline is in the water.'' : The gasoline is in the water.' | Should -Be $FileContent[0]
' + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException' |
Should -Be $FileContent[4]
' + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException' |
Should -Be $FileContent[5]
}Context "Additional Information"
I think it would be better/more consistent to do something like:
'+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException' |
Should -Be $FileContent[4].TrimStart()
'+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException' |
Should -Be $FileContent[5].TrimStart()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Category-KoansInvoking the Great DoubtInvoking the Great DoubtIssue-DiscussionLet's talk about it!Let's talk about it!