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
This commit is contained in:
commit
07d3fd1d9b
5 changed files with 98 additions and 2 deletions
|
@ -77,7 +77,12 @@ pub(crate) fn calc_result(
|
||||||
|
|
||||||
// The test should have panicked, but didn't panic.
|
// The test should have panicked, but didn't panic.
|
||||||
(ShouldPanic::Yes, None) | (ShouldPanic::YesWithMessage(_), None) => {
|
(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.
|
// The test should not have panicked, but did panic.
|
||||||
|
|
|
@ -5,7 +5,7 @@ test $DIR/failed-doctest-should-panic.rs - Foo (line 10) - should panic ... FAIL
|
||||||
failures:
|
failures:
|
||||||
|
|
||||||
---- $DIR/failed-doctest-should-panic.rs - Foo (line 10) stdout ----
|
---- $DIR/failed-doctest-should-panic.rs - Foo (line 10) stdout ----
|
||||||
note: test did not panic as expected
|
note: test did not panic as expected at $DIR/failed-doctest-should-panic.rs:10:0
|
||||||
|
|
||||||
failures:
|
failures:
|
||||||
$DIR/failed-doctest-should-panic.rs - Foo (line 10)
|
$DIR/failed-doctest-should-panic.rs - Foo (line 10)
|
||||||
|
|
46
tests/ui/test-attrs/test-should-panic-failed-show-span.rs
Normal file
46
tests/ui/test-attrs/test-should-panic-failed-show-span.rs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
//@ compile-flags: --test
|
||||||
|
//@ run-flags: --test-threads=1 --nocapture
|
||||||
|
//@ run-fail
|
||||||
|
//@ check-run-results
|
||||||
|
//@ exec-env:RUST_BACKTRACE=0
|
||||||
|
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
|
||||||
|
//@ normalize-stdout: "TypeId\(0x[0-9a-f]+\)" -> "TypeId($$HEX)"
|
||||||
|
//@ needs-threads
|
||||||
|
//@ needs-unwind (panic)
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn should_panic_with_any_message() {
|
||||||
|
panic!("Panic!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic = "message"]
|
||||||
|
fn should_panic_with_message() {
|
||||||
|
panic!("message");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn should_panic_with_any_message_does_not_panic() {
|
||||||
|
// DON'T PANIC
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic = "message"]
|
||||||
|
fn should_panic_with_message_does_not_panic() {
|
||||||
|
// DON'T PANIC
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic = "message"]
|
||||||
|
fn should_panic_with_substring_panics_with_incorrect_string() {
|
||||||
|
panic!("ZOMGWTFBBQ");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic = "message"]
|
||||||
|
#[expect(non_fmt_panics)]
|
||||||
|
fn should_panic_with_substring_panics_with_non_string_value() {
|
||||||
|
panic!(123);
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
thread 'should_panic_with_any_message' panicked at $DIR/test-should-panic-failed-show-span.rs:14:5:
|
||||||
|
Panic!
|
||||||
|
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||||
|
|
||||||
|
thread 'should_panic_with_message' panicked at $DIR/test-should-panic-failed-show-span.rs:20:5:
|
||||||
|
message
|
||||||
|
|
||||||
|
thread 'should_panic_with_substring_panics_with_incorrect_string' panicked at $DIR/test-should-panic-failed-show-span.rs:38:5:
|
||||||
|
ZOMGWTFBBQ
|
||||||
|
|
||||||
|
thread 'should_panic_with_substring_panics_with_non_string_value' panicked at $DIR/test-should-panic-failed-show-span.rs:45:5:
|
||||||
|
Box<dyn Any>
|
|
@ -0,0 +1,32 @@
|
||||||
|
|
||||||
|
running 6 tests
|
||||||
|
test should_panic_with_any_message - should panic ... ok
|
||||||
|
test should_panic_with_any_message_does_not_panic - should panic ... FAILED
|
||||||
|
test should_panic_with_message - should panic ... ok
|
||||||
|
test should_panic_with_message_does_not_panic - should panic ... FAILED
|
||||||
|
test should_panic_with_substring_panics_with_incorrect_string - should panic ... FAILED
|
||||||
|
test should_panic_with_substring_panics_with_non_string_value - should panic ... FAILED
|
||||||
|
|
||||||
|
failures:
|
||||||
|
|
||||||
|
---- should_panic_with_any_message_does_not_panic stdout ----
|
||||||
|
note: test did not panic as expected at $DIR/test-should-panic-failed-show-span.rs:25:4
|
||||||
|
---- should_panic_with_message_does_not_panic stdout ----
|
||||||
|
note: test did not panic as expected at $DIR/test-should-panic-failed-show-span.rs:31:4
|
||||||
|
---- should_panic_with_substring_panics_with_incorrect_string stdout ----
|
||||||
|
note: panic did not contain expected string
|
||||||
|
panic message: `"ZOMGWTFBBQ"`,
|
||||||
|
expected substring: `"message"`
|
||||||
|
---- should_panic_with_substring_panics_with_non_string_value stdout ----
|
||||||
|
note: expected panic with string value,
|
||||||
|
found non-string value: `TypeId($HEX)`
|
||||||
|
expected substring: `"message"`
|
||||||
|
|
||||||
|
failures:
|
||||||
|
should_panic_with_any_message_does_not_panic
|
||||||
|
should_panic_with_message_does_not_panic
|
||||||
|
should_panic_with_substring_panics_with_incorrect_string
|
||||||
|
should_panic_with_substring_panics_with_non_string_value
|
||||||
|
|
||||||
|
test result: FAILED. 2 passed; 4 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue