about summary refs log tree commit diff
path: root/library
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-04-14 13:33:44 +0000
committerbors <bors@rust-lang.org>2025-04-14 13:33:44 +0000
commit07d3fd1d9b9c1f07475b96a9d168564bf528db68 (patch)
tree68d8b3aef8e1a574def65116056d12d546265621 /library
parentc580c498a1fe144d7c5b2dfc7faab1a229aa288b (diff)
parentdc3a586eed198548316fcbfff2d5c28df0728750 (diff)
downloadrust-07d3fd1d9b9c1f07475b96a9d168564bf528db68.tar.gz
rust-07d3fd1d9b9c1f07475b96a9d168564bf528db68.zip
Auto merge of #138603 - xizheyin:issue-137405, r=chenyukang
Report line number of test when should_panic test failed

Closes #137405

---

try-job: x86_64-gnu-llvm-19-3
try-job: test-various
Diffstat (limited to 'library')
-rw-r--r--library/test/src/test_result.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/library/test/src/test_result.rs b/library/test/src/test_result.rs
index 959cd730fa4..a312894c25c 100644
--- a/library/test/src/test_result.rs
+++ b/library/test/src/test_result.rs
@@ -77,7 +77,12 @@ pub(crate) fn calc_result(
 
         // The test should have panicked, but didn't panic.
         (ShouldPanic::Yes, None) | (ShouldPanic::YesWithMessage(_), None) => {
-            TestResult::TrFailedMsg("test did not panic as expected".to_string())
+            let fn_location = if !desc.source_file.is_empty() {
+                &format!(" at {}:{}:{}", desc.source_file, desc.start_line, desc.start_col)
+            } else {
+                ""
+            };
+            TestResult::TrFailedMsg(format!("test did not panic as expected{}", fn_location))
         }
 
         // The test should not have panicked, but did panic.