Skip to content

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

Closed

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.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 21, 2025
  2. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    A-libtestArea: `#[test]` / the `test` library
    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.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 22, 2025
  3. xizheyin commented on Mar 16, 2025

    @xizheyin
    Member

    Is this currently being done by anyone? If not, I can try it. @joshka

  4. joshka commented on Mar 16, 2025

    @joshka
    ContributorAuthor

    Not as far as I'm aware. I'd encourage you to go for it. This doesn't seem like it would have any downside, so I think perhaps a PR would be good here.

  5. xizheyin commented on Mar 16, 2025

    @xizheyin
    Member

    @rustbot claim

  6. added a commit that references this issue on Mar 18, 2025
  7. added a commit that references this issue on Apr 7, 2025
  8. added 4 commits that reference this issue on Apr 7, 2025
  9. added a commit that references this issue on Apr 13, 2025
    d96c85c
  10. added a commit that references this issue on Apr 14, 2025
    07d3fd1
  11. added a commit that references this issue on Apr 19, 2025
    543820f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions