Skip to content

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

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

Closed
joshka opened this issue Feb 21, 2025 · 3 comments · Fixed by #138603
Closed

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

joshka opened this issue Feb 21, 2025 · 3 comments · Fixed by #138603
Assignees
Labels
A-libtest Area: `#[test]` / the `test` library C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-testing-devex Relevant to the testing devex team (testing DX), which will review and decide on the PR/issue.

Comments

@joshka
Copy link
Contributor

joshka commented Feb 21, 2025

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.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 21, 2025
@jieyouxu jieyouxu added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-libtest Area: `#[test]` / the `test` library T-libs Relevant to the library team, which will review and decide on the PR/issue. T-testing-devex Relevant to the testing devex team (testing DX), which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 22, 2025
@xizheyin
Copy link
Contributor

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

@joshka
Copy link
Contributor Author

joshka commented Mar 16, 2025

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.

@xizheyin
Copy link
Contributor

@rustbot claim

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 18, 2025
Report line number of test when should_panic test failed

Closing rust-lang#137405

r? `@joshka`
Zalathar added a commit to Zalathar/rust that referenced this issue Apr 7, 2025
Report line number of test when should_panic test failed

Closing rust-lang#137405

r? `@joshka`
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 7, 2025
Report line number of test when should_panic test failed

Closing rust-lang#137405

r? `@joshka`
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 7, 2025
Report line number of test when should_panic test failed

Closes rust-lang#137405

---

try-job: x86_64-gnu-llvm-19-3
try-job: test-various
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 7, 2025
Report line number of test when should_panic test failed

Closes rust-lang#137405

---

try-job: x86_64-gnu-llvm-19-3
try-job: test-various
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 8, 2025
Report line number of test when should_panic test failed

Closes rust-lang#137405

---

try-job: x86_64-gnu-llvm-19-3
try-job: test-various
ChrisDenton added a commit to ChrisDenton/rust that referenced this issue Apr 13, 2025
Report line number of test when should_panic test failed

Closes rust-lang#137405

---

try-job: x86_64-gnu-llvm-19-3
try-job: test-various
@bors bors closed this as completed in 07d3fd1 Apr 14, 2025
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Apr 19, 2025
Report line number of test when should_panic test failed

Closes rust-lang#137405

---

try-job: x86_64-gnu-llvm-19-3
try-job: test-various
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: `#[test]` / the `test` library C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-testing-devex Relevant to the testing devex team (testing DX), which will review and decide on the PR/issue.
Projects
Development

Successfully merging a pull request may close this issue.

4 participants