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

Should-BeString: Doesn't handle escape character correctly in error message #2561

Open
3 tasks done
johlju opened this issue Aug 24, 2024 · 1 comment
Open
3 tasks done

Comments

@johlju
Copy link
Contributor

johlju commented Aug 24, 2024

Checklist

What is the issue?

If the actual value or expected value contain escape character (for example an ANSI sequence) the message are not shown correctly.

Expected Behavior

Should show the special character like escape characters. Also ANSI sequences should not be hidden as they are part of the strings being compared.

Steps To Reproduce

Describe 'Something' {
    It 'Escape in expected value should be handled correctly' {
        '31;3;5m' | Should-BeString "`e[313;5m"
    }

    It 'Escape in actual value should be handled correctly' {
        "`e31;3;5m" | Should-BeString '[31;3;5m'
    }

    It 'Escape in both expected and actual value should be handled correctly' {
        "`e31;3;5m" | Should-BeString "`e[31;3;5m"
    }
}

Outputs:

Starting discovery in 1 files.
Discovery found 11 tests in 30ms.
Running tests.
[-] Something.Escape in expected value should be handled correctly 10ms (9ms|2ms)
 Expected [string] '', but got [string] '31;3;5m'.
 at '31;3;5m' | Should-BeString "`e[313;5m", /Users/johlju/source/Viscalyx.Common/tests/Unit/Public/ConvertTo-AnsiSequence.tests.ps1:89
[-] Something.Escape in actual value should be handled correctly 24ms (22ms|2ms)
 Expected [string] '[31;3;5m', but got [string] '1;3;5m'.
 at "`e31;3;5m" | Should-BeString '[31;3;5m', /Users/johlju/source/Viscalyx.Common/tests/Unit/Public/ConvertTo-AnsiSequence.tests.ps1:93
[-] Something.Escape in both expected and actual value should be handled correctly 37ms (30ms|6ms)
 Expected [string] '', but got [string] '1;3;5m'.
 at "`e31;3;5m" | Should-BeString "`e[31;3;5m", /Users/johlju/source/Viscalyx.Common/tests/Unit/Public/ConvertTo-AnsiSequence.tests.ps1:97
Tests completed in 432ms
Tests Passed: 8, Failed: 3, Skipped: 0, Inconclusive: 0, NotRun: 0

Describe your environment

Pester version     : 6.0.0-alpha4 /Users/johlju/source/Viscalyx.Common/output/RequiredModules/Pester/6.0.0/Pester.psm1  
PowerShell version : 7.4.4
OS version         : Unix 14.6.1

Possible Solution?

Maybe convert special characters in actual and expected value to their unicode equivalent?

"`0`a`b`t`f`r`n`e" `
    -replace "`0", '' `
    -replace "`a", '' `
    -replace "`b", '' `
    -replace "`t", '' `
    -replace "`f", '' `
    -replace "`r", '' `
    -replace "`n", '' `
    -replace "`e", ''

Maybe this should go into the Format-Nicely function, so all strings are parsed? 🤔 Otherwise strings in expected and actual could also affect the output in the console (changing colors etc.)

Outputs:

␀␇␈␉␌␍␊␛
@nohwnd
Copy link
Member

nohwnd commented Oct 3, 2024

yes that would be good, I've been using lately for ANSI terminal testing and it has been a lifesaver to have it as printable character.

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

2 participants