Skip to content

Output gets butchered if Invoke-Pester is called with 6>&1 #1384

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

Closed
abbbi opened this issue Oct 15, 2019 · 6 comments
Closed

Output gets butchered if Invoke-Pester is called with 6>&1 #1384

abbbi opened this issue Oct 15, 2019 · 6 comments

Comments

@abbbi
Copy link

abbbi commented Oct 15, 2019

If stream 6 is redirected via 6>&1 the output includes additional newlines and looks like:

       [?] test1
     , is inconclusive, because Skip test on linux
     11ms
     Describing testcaess
      [+] test2
      73ms
       [+] test3
     351ms
@fflaten
Copy link
Collaborator

fflaten commented May 18, 2021

Still reproduceable in Pester v5, but not sure how to address this issue.

Pester currently relies heavily on Write-Host to show progress without filling the output stream with noise. As of Powershell 5.0, Write-Host is just a wrapper around Write-Information which uses stream 6. When you redirect the stream, it loses the formatting when captured (redirected) and you get every message provided to Write-Host on it's own line, something that will happen often since we use multiple calls per line to modify colors.

Demo:

& { Write-Host "Demo" -NoNewline; Write-Host "Time" -NoNewline }
DemoTime

& { Write-Host "Demo" -NoNewline; Write-Host "Time" -NoNewline } 6>&1
Demo
Time

The only solutions I can think of is:

  • Use ANSI escaped sequences to output colors/style so we could use a single call to Write-Host per line. Then you'd only lose the formatting on stream-redirect while keeping the original lines/structure. However, ANSI-support is lacking pre-Win10. Would require us to check on $host.UI.SupportsVirtualTerminal -eq $true and provide two output-plugins. I know ANSI has been mentioned in RFC: Better API for Invoke-Pester #1265 too.
  • Replace Write-Host with [Console]::WriteLine/Write. Would be faster, but you'd lose the ability to redirect the output inside of powershell (would have to call invoke-pester in a sub-process).

@nohwnd
Copy link
Member

nohwnd commented May 19, 2021

@abbbi Why do you need that redirect? Maybe you can work around that in a different way.

@fflaten Both your suggestions are valid, but as you pointed out are also not without their downsides. Unless there is a really good reason for that redirect I'd say we should close this as won't fix.

@fflaten
Copy link
Collaborator

fflaten commented May 19, 2021

Correction about my ANSI-suggestion. Even redirected, you'd keep the formatting. I'd suggest implementing it at some point to support colors in CI/CD logs too as mentioned in the related issue.

We could then keep this issue in mind to use one call to write-host per line in that.

@nohwnd
Copy link
Member

nohwnd commented May 19, 2021

Moved that comment to #1953

@abbbi
Copy link
Author

abbbi commented May 19, 2021

@abbbi Why do you need that redirect? Maybe you can work around that in a different way.

its not a requirement. I was executing pester via vagrant provisioning scripts, and noticed that the output format is quite broken then.

@nohwnd
Copy link
Member

nohwnd commented May 19, 2021

In that case we won't fix that because it would just replace this issue with another. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants