Skip to content

Commit bb1acb4

Browse files
committed
Peek for panic message in test output
1 parent 6de838c commit bb1acb4

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ authors = ["rust-analyzer team"]
1212
[profile.dev]
1313
# Disabling debug info speeds up builds a bunch,
1414
# and we don't rely on it for debugging that much.
15-
debug = 1
15+
debug = 0
1616

1717
[profile.dev.package]
1818
# These speed up local tests.

crates/hir-ty/src/mir/eval.rs

+11
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,17 @@ impl MirEvalError {
428428
}
429429
Ok(())
430430
}
431+
432+
pub fn is_panic(&self) -> Option<&str> {
433+
let mut err = self;
434+
while let MirEvalError::InFunction(e, _) = err {
435+
err = e;
436+
}
437+
match err {
438+
MirEvalError::Panic(msg) => Some(msg),
439+
_ => None,
440+
}
441+
}
431442
}
432443

433444
impl std::fmt::Debug for MirEvalError {

crates/hir-ty/src/mir/eval/tests.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ fn check_pass_and_stdio(ra_fixture: &str, expected_stdout: &str, expected_stderr
7373
}
7474
}
7575

76+
fn check_panic(ra_fixture: &str, expected_panic: &str) {
77+
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
78+
let file_id = *file_ids.last().unwrap();
79+
let e = eval_main(&db, file_id).unwrap_err();
80+
assert_eq!(e.is_panic().unwrap_or_else(|| panic!("unexpected error: {:?}", e)), expected_panic);
81+
}
82+
7683
#[test]
7784
fn function_with_extern_c_abi() {
7885
check_pass(
@@ -96,13 +103,14 @@ fn panic_fmt() {
96103
// -> core::panicking::const_panic_fmt
97104
// -> #[rustc_const_panic_str] core::panicking::panic_display (hooked by CTFE for builtin panic)
98105
// -> Err(ConstEvalError::Panic)
99-
check_pass(
106+
check_panic(
100107
r#"
101108
//- minicore: fmt, panic
102109
fn main() {
103110
panic!("hello, world!");
104111
}
105112
"#,
113+
"hello, world!",
106114
);
107115
}
108116

@@ -112,14 +120,15 @@ fn panic_display() {
112120
// -> panic_2021 (builtin macro redirection)
113121
// -> #[rustc_const_panic_str] core::panicking::panic_display (hooked by CTFE for builtin panic)
114122
// -> Err(ConstEvalError::Panic)
115-
check_pass(
123+
check_panic(
116124
r#"
117125
//- minicore: fmt, panic
118126
119127
fn main() {
120128
panic!("{}", "hello, world!");
121129
}
122130
"#,
131+
"hello, world!",
123132
);
124133
}
125134

0 commit comments

Comments
 (0)