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
Prettifier escapes strings #2320
base: main
Are you sure you want to change the base?
Conversation
Hi @som-snytt, we require contributors to sign our Contributor License Agreement, and we don't have yours on file. In order for us to review and merge your code, please access https://www.artima.com/cla/choose-type to sign our Contributor License Agreement. Your effort is highly appreciated. Thank you. |
@cla-bot[bot] check |
The cla-bot has been summoned, and re-checked this pull request! |
@som-snytt Hmm, I am not 100% if it is desired as default for everyone, how about if we make it as different flavor of Prettifier, e.g. Prettifier.escaping like Prettifier.basic that we have? |
It's never desirable to conceal information. I happened to notice that I'm unable to reason about "100%". The Scala REPL doesn't display strings in quotes, like your basic prettifier, because of decision paralysis. Also I don't know about ScalaTest expectations. The "ideal" might be The motivating case was https://discord.com/channels/632150470000902164/632150470000902166/1222916152771084298 It took that person only 15 mins (after posting their question) to realize that their data had embedded null bytes. I should have asked if they used a debugger. But it should have been obvious from the test output.
|
The failure is a friendly reminder that 2.11 did not yet understand how quotes work.
Force-pushed just that tweak. |
39b2e27
to
71702b8
Compare
@som-snytt We want to avoid breaking somebody tests when new version is released, while I do think your code makes sense. We also have an Differ to do the diff analysis, may be that's the better place to do the job. I'll try to take a deeper look today. |
I'm not sure I ever tried inserting null characters in strings in Java or Scala:
The REPL puts a ? there, but toString just skips over it:
ScalaTest should probably indicate there's an unprintable character in there also, but not sure in what way. A question mark would help point out that there's a hidden character, but would not reveal exaclty what it was. So if there were two different hidden characters in the exact same spot, you'd still see something like "cat?dog" did not equal "cat?dog". I wonder how other popular test frameworks deal with unprintable characters in strings. Perhaps we should do a quick survey. |
@som-snytt @bvenners Fyi I have an experimental branch here to display the escaped string in the analysis section: https://github.com/cheeseng/scalatest/tree/feature-escaping-string-differ For the following example code:
It will fail with:
|
I was about to comment that I'll leave this PR open as a placeholder; feel free to close at your convenience. I'm taking a look at a couple of usual frameworks to see if they produce interesting diffs (and also to remember how to use them). I'm interested to see if junit4
|
@som-snytt Just fyi I have submitted the following PR: We may switch it to main branch for the upcoming 3.3.0 release since the changes shall break binary-compat. |
A user on discord reported confusion when a test failed because of an embedded "null" character but the string was displayed "normal".
That case was a "contains" test, so a string "diff" would not help, unless a user could request a diff against every element in the collection under test.
This commit prettifies strings as Scala strings with the usual escapes, including Unicode escape if
isControl
.