You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a user I'd like to be able to see hex output of the expected and actual strings when a tests fails for Should-BeString. This would be very useful in situations when working with large complex string output of file formats like JaCoCo or other formats that fail when a single character is wrong, and where it can be very difficult to find where the string is not equal.
Currently where I had this problem with tests I have had a helper function that did similar output using Write-Verbose -Verbose and was called in a MockWith or ParameterFilter. Always thought it would be a good enhancement to Pester to have it built-in, but haven't had the time until now to make something better.
Maybe this is something that can be helpful for others and can be part of Pester?
How should it work?
Suggest adding an optional parameter to Should-BeString, for example -Output 'Hex'. The error message in this case should include the formatted hex output.
It 'Should output to console' {
$expected="This is a test string with control and`n`nspecial characters: !@#$%^&*()"$actual="This Is a test string with control and`r`nspecial characters: !@#$%^&*()"$actual| Should-BeString -Expected $expected-Output 'Hex'
}
Suggest it output something similar (inspired from Format-Hex):
Proof of concept
I have made a proof of concept in the module Viscalyx.Assert (preview available in PowerShell Gallery). I called it Should-BeBlockString (alias to Assert-BlockString) in lack of a better name (always hoped it would be part of Should-BeString).
It works like this:
Describe 'PoC' {
It 'Should output hex to console' {
$expected="This is a test string with control and`n`nspecial characters: !@#$%^&*()"$actual="This Is a test string with control and`r`nspecial characters: !@#$%^&*()"$actual| Should-BeBlockString -Expected $expected
}
}
That outputs this:
Alternative
If this is not a good fit for Pester it can live on in a separate module. 🙂
The text was updated successfully, but these errors were encountered:
Checklist
Summary of the feature request
As a user I'd like to be able to see hex output of the expected and actual strings when a tests fails for
Should-BeString
. This would be very useful in situations when working with large complex string output of file formats like JaCoCo or other formats that fail when a single character is wrong, and where it can be very difficult to find where the string is not equal.Currently where I had this problem with tests I have had a helper function that did similar output using
Write-Verbose -Verbose
and was called in aMockWith
orParameterFilter
. Always thought it would be a good enhancement to Pester to have it built-in, but haven't had the time until now to make something better.Maybe this is something that can be helpful for others and can be part of Pester?
How should it work?
Suggest adding an optional parameter to
Should-BeString
, for example-Output 'Hex'
. The error message in this case should include the formatted hex output.Suggest it output something similar (inspired from
Format-Hex
):Proof of concept
I have made a proof of concept in the module Viscalyx.Assert (preview available in PowerShell Gallery). I called it
Should-BeBlockString
(alias toAssert-BlockString
) in lack of a better name (always hoped it would be part ofShould-BeString
).It works like this:
That outputs this:
Alternative
If this is not a good fit for Pester it can live on in a separate module. 🙂
The text was updated successfully, but these errors were encountered: