Skip to content
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

AboutRedirection misses some spaces in output? #458

Open
DEberhardt opened this issue Sep 12, 2021 · 0 comments
Open

AboutRedirection misses some spaces in output? #458

DEberhardt opened this issue Sep 12, 2021 · 0 comments
Labels
Category-Koans Invoking the Great Doubt Issue-Discussion Let's talk about it!

Comments

@DEberhardt
Copy link
Contributor

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()
@DEberhardt DEberhardt added Category-Koans Invoking the Great Doubt Issue-Discussion Let's talk about it! labels Sep 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category-Koans Invoking the Great Doubt Issue-Discussion Let's talk about it!
Projects
None yet
Development

No branches or pull requests

1 participant