mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Peek for panic message in test output
This commit is contained in:
parent
6de838c255
commit
3b9a2af21f
9 changed files with 36 additions and 12 deletions
|
@ -428,6 +428,17 @@ impl MirEvalError {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn is_panic(&self) -> Option<&str> {
|
||||
let mut err = self;
|
||||
while let MirEvalError::InFunction(e, _) = err {
|
||||
err = e;
|
||||
}
|
||||
match err {
|
||||
MirEvalError::Panic(msg) => Some(msg),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for MirEvalError {
|
||||
|
|
|
@ -360,7 +360,7 @@ impl Evaluator<'_> {
|
|||
))
|
||||
};
|
||||
}
|
||||
let size = self.size_of_sized(&ty, locals, "begin panic arg")?;
|
||||
let size = self.size_of_sized(ty, locals, "begin panic arg")?;
|
||||
let pointee = arg.interval.get(self)?;
|
||||
arg = IntervalAndTy {
|
||||
interval: Interval::new(Address::from_bytes(pointee)?, size),
|
||||
|
|
|
@ -73,6 +73,13 @@ fn check_pass_and_stdio(ra_fixture: &str, expected_stdout: &str, expected_stderr
|
|||
}
|
||||
}
|
||||
|
||||
fn check_panic(ra_fixture: &str, expected_panic: &str) {
|
||||
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
|
||||
let file_id = *file_ids.last().unwrap();
|
||||
let e = eval_main(&db, file_id).unwrap_err();
|
||||
assert_eq!(e.is_panic().unwrap_or_else(|| panic!("unexpected error: {:?}", e)), expected_panic);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn function_with_extern_c_abi() {
|
||||
check_pass(
|
||||
|
@ -96,13 +103,14 @@ fn panic_fmt() {
|
|||
// -> core::panicking::const_panic_fmt
|
||||
// -> #[rustc_const_panic_str] core::panicking::panic_display (hooked by CTFE for builtin panic)
|
||||
// -> Err(ConstEvalError::Panic)
|
||||
check_pass(
|
||||
check_panic(
|
||||
r#"
|
||||
//- minicore: fmt, panic
|
||||
fn main() {
|
||||
panic!("hello, world!");
|
||||
}
|
||||
"#,
|
||||
"hello, world!",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -112,7 +120,7 @@ fn panic_display() {
|
|||
// -> panic_2021 (builtin macro redirection)
|
||||
// -> #[rustc_const_panic_str] core::panicking::panic_display (hooked by CTFE for builtin panic)
|
||||
// -> Err(ConstEvalError::Panic)
|
||||
check_pass(
|
||||
check_panic(
|
||||
r#"
|
||||
//- minicore: fmt, panic
|
||||
|
||||
|
@ -120,6 +128,7 @@ fn main() {
|
|||
panic!("{}", "hello, world!");
|
||||
}
|
||||
"#,
|
||||
"hello, world!",
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue