Skip to content

Tests marked as should_panic should report the line number of the test #137405

Closed
@joshka

Description

@joshka

It would be useful for being able to easily navigate to failing tests if the tests don't panic when they should. Specifically, providing the file and line number of the failing test allows a user to use the mouse to navigate directly in one step from a test run in a vscode terminal window to the location of the failing test.

Given:

#[test]
#[should_panic]
fn dont_panic() {
    // DON'T PANIC
}

This reports:

running 1 test
test dont_panic - should panic ... FAILED

successes:

successes:

failures:

---- dont_panic stdout ----
note: test did not panic as expected

failures:
    dont_panic

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Compare this with:

#[test]
fn do_panic() {
    panic!("Panic!");
}

which gives:

---- do_panic stdout ----

thread 'do_panic' panicked at src/lib.rs:9:5:
Panic!
stack backtrace:
...

Which in a vscode terminal looks like:

Image

Implementation Constraints:
Use filename:line:column format - don't use a custom formate like "file at line x". Noted specifically This has happened in some parts of the rust ecosystem in the past (in rustfmt IIRC), and it makes the automatic navigation not work right.

Metadata

Metadata

Assignees

Labels

A-libtestArea: `#[test]` / the `test` libraryC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libsRelevant to the library team, which will review and decide on the PR/issue.T-testing-devexRelevant to the testing devex team (testing DX), which will review and decide on the PR/issue.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions