-
Notifications
You must be signed in to change notification settings - Fork 8.1k
don't insert linebreaks to output (except for tables) #5193
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
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| Describe "Write-Debug tests" -Tags "CI" { | ||
| It "Should not have added line breaks" { | ||
| $text = "0123456789" | ||
| while ($text.Length -lt [Console]::WindowWidth) { | ||
| $text += $text | ||
| } | ||
| $origDebugPref = $DebugPreference | ||
| $DebugPreference = "Continue" | ||
| try { | ||
| $out = Write-Debug $text 5>&1 | ||
| $out | Should BeExactly $text | ||
| } | ||
| finally { | ||
| $DebugPreference = $origDebugPref | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| Describe "Write-Error DRT Unit Tests" -Tags "CI" { | ||
| Describe "Write-Error Tests" -Tags "CI" { | ||
| It "Should be works with command: write-error myerrortext" { | ||
| $e = Write-Error myerrortext 2>&1 | ||
| $e | Should BeOfType 'System.Management.Automation.ErrorRecord' | ||
|
|
@@ -74,40 +74,49 @@ Describe "Write-Error DRT Unit Tests" -Tags "CI" { | |
| $e.CategoryInfo.TargetType | Should Be 'fooTargetType' | ||
| $e.CategoryInfo.GetMessage() | Should Be 'NotSpecified: (fooTargetName:fooTargetType) [fooAct], fooReason' | ||
| } | ||
| } | ||
|
|
||
| Describe "Write-Error" -Tags "CI" { | ||
| It "Should be able to throw" { | ||
| Write-Error "test throw" -ErrorAction SilentlyContinue | Should Throw | ||
| Write-Error "test throw" -ErrorAction SilentlyContinue | Should Throw | ||
| } | ||
|
|
||
| It "Should throw a non-terminating error" { | ||
| Write-Error "test throw" -ErrorAction SilentlyContinue | ||
| Write-Error "test throw" -ErrorAction SilentlyContinue | ||
|
|
||
| 1 + 1 | Should Be 2 | ||
| 1 + 1 | Should Be 2 | ||
| } | ||
|
|
||
| It "Should trip an exception using the exception switch" { | ||
| $var = 0 | ||
| try | ||
| { | ||
| Write-Error -Exception -Message "test throw" | ||
| } | ||
| catch [System.Exception] | ||
| { | ||
|
|
||
| $var++ | ||
| } | ||
| finally | ||
| { | ||
| $var | Should Be 1 | ||
| } | ||
| $var = 0 | ||
| try | ||
| { | ||
| Write-Error -Exception -Message "test throw" | ||
| } | ||
| catch [System.Exception] | ||
| { | ||
|
|
||
| $var++ | ||
| } | ||
| finally | ||
| { | ||
| $var | Should Be 1 | ||
| } | ||
| } | ||
|
|
||
| It "Should output the error message to the `$error automatic variable" { | ||
| $theError = "Error: Too many input values." | ||
| write-error -message $theError -category InvalidArgument -ErrorAction SilentlyContinue | ||
| $theError = "Error: Too many input values." | ||
| write-error -message $theError -category InvalidArgument -ErrorAction SilentlyContinue | ||
|
|
||
| $error[0]| Should Be $theError | ||
| } | ||
|
|
||
| $error[0]| Should Be $theError | ||
| It "ErrorRecord should not be truncated" { | ||
| $longtext = "0123456789" | ||
| while ($longtext.Length -lt [console]::WindowWidth) { | ||
| $longtext += $longtext | ||
| } | ||
| pwsh -c Write-Error -Message $longtext 2>&1 > $testdrive\error.txt | ||
| $e = Get-Content -Path $testdrive\error.txt | ||
| $e.Count | Should BeExactly 4 | ||
| $e[0] | Should Match $longtext | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use more strong match pattern? I'm again worried about false positives.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Write-Error adds extra info prefixed to the text. The important bits for this test is the long text not getting choppedby a linebreak
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see - no false positives can be. Closed. |
||
| } | ||
| } | ||
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 the comment still actual?
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 believe the comment is saying that if we decide to support color themes (aka skins), this is one place to put the code for Write-Debug. Did a quick search for "read a skin" and found four places for Debug, Verbose, Warning, and ProgressPane.
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.
Thanks for clarify.
Closed.