Skip to content

Better error messages for #[should_panic] tests with expected strings #66304

Closed
@thomasetter

Description

@thomasetter

When running this test (playground):

#[test]
#[should_panic(expected = "foo\r\n")]
fn panic_test() {
    panic!("foo\n");
}

the output is

running 1 test
test panic_test ... FAILED

failures:

---- panic_test stdout ----
thread 'panic_test' panicked at 'foo
', src/lib.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
note: panic did not include expected string 'foo

'

failures:
    panic_test

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

which makes it hard to spot the difference in whitespace characters.

Would it be possible to change this to e.g.:

running 1 test
test panic_test ... FAILED

failures:

---- panic_test stdout ----
thread 'panic_test' panicked at 'foo
', src/lib.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
note: panic did not include expected string 'foo

'
   Panic message: "foo\n"
 Expected string: "foo\r\n"

failures:
    panic_test

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

This would improve the usability when running into these kinds of test failures and also make it more consistent with assert_eq which outputs both the left and the right value too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions