Skip to content

Use string-specific pretty_assertions displayer in tests#2435

Merged
casey merged 3 commits intocasey:masterfrom
neunenak:string-comparison-test
Oct 30, 2024
Merged

Use string-specific pretty_assertions displayer in tests#2435
casey merged 3 commits intocasey:masterfrom
neunenak:string-comparison-test

Conversation

@neunenak
Copy link
Copy Markdown
Contributor

The pretty_assertions crate that the test harness is already using has a string-specific comparison implementation that can properly display ANSI escapes, which are pretty frequent in just tests.

When running e.g. cargo test unicode_escape_invalid_character:

Before:

failures:

---- string::unicode_escape_invalid_character stdout ----
Bad stderr: Diff < left / right > :
<"\u{1b}[31merror:\u{1b}[0m unicode escape sequence value `BadBad` greater than maximum valid code point `10FFFF`\n   \u{1b}[38;5;246m╭\u{1b}[0m\u{1b}[38;5;246m─\u{1b}[0m\u{1b}[38;5;246m[\u{1b}[0mjustfile:1:6\u{1b}[38;5;246m]\u{1b}[0m\n   \u{1b}[38;5;246m│\u{1b}[0m\n \u{1b}[38;5;246m1 │\u{1b}[0m \u{1b}[38;5;249mx\u{1b}[0m\u{1b}[38;5;249m \u{1b}[0m\u{1b}[38;5;249m:\u{1b}[0m\u{1b}[38;5;249m=\u{1b}[0m\u{1b}[38;5;249m \u{1b}[0m\"\\u{BadBad}\"\n\u{1b}[38;5;246m───╯\u{1b}[0m\n"
>"error: unicode escape sequence value `BadBad` greater than maximum valid code point `10FFFF`\n ——▶ justfile:1:6\n  │\n1 │ x := \"\\u{BadBad}\"\n  │      ^^^^^^^^^^^^\n"

thread 'string::unicode_escape_invalid_character' panicked at tests/string.rs:509:6:
Output mismatch.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

After:

failures:

---- string::unicode_escape_invalid_character stdout ----
Bad stderr: Diff < left / right > :
<error: unicode escape sequence value `BadBad` greater than maximum valid code point `10FFFF`
<   ╭─[justfile:1:6]
<   │
< 1 │ x := "\u{BadBad}"
<───╯
>error: unicode escape sequence value `BadBad` greater than maximum valid code point `10FFFF`
> ——▶ justfile:1:6
>  │
>1 │ x := "\u{BadBad}"
>  │      ^^^^^^^^^^^^


thread 'string::unicode_escape_invalid_character' panicked at tests/string.rs:509:6:
Output mismatch.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This should help with the test conversion that needs to happen in #2426

@casey
Copy link
Copy Markdown
Owner

casey commented Oct 30, 2024

Nice, this is much better!

@casey casey enabled auto-merge (squash) October 30, 2024 22:34
@casey casey merged commit a71f2a5 into casey:master Oct 30, 2024
@neunenak neunenak deleted the string-comparison-test branch October 30, 2024 22:50
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

Successfully merging this pull request may close these issues.

2 participants