mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +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
|
@ -12,7 +12,7 @@ authors = ["rust-analyzer team"]
|
|||
[profile.dev]
|
||||
# Disabling debug info speeds up builds a bunch,
|
||||
# and we don't rely on it for debugging that much.
|
||||
debug = 1
|
||||
debug = 0
|
||||
|
||||
[profile.dev.package]
|
||||
# These speed up local tests.
|
||||
|
|
|
@ -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!",
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -293,6 +293,7 @@ fn minicore_smoke_test() {
|
|||
// This should be ignored since we conditionally remove code which creates single item use with braces
|
||||
config.disabled.insert("unused_braces".to_owned());
|
||||
config.disabled.insert("unused_variables".to_owned());
|
||||
config.disabled.insert("remove-unnecessary-else".to_owned());
|
||||
check_diagnostics_with_config(config, &source);
|
||||
}
|
||||
|
||||
|
|
|
@ -7864,8 +7864,8 @@ impl Iterator for S {
|
|||
file_id: FileId(
|
||||
1,
|
||||
),
|
||||
full_range: 6290..6498,
|
||||
focus_range: 6355..6361,
|
||||
full_range: 7791..7999,
|
||||
focus_range: 7856..7862,
|
||||
name: "Future",
|
||||
kind: Trait,
|
||||
container_name: "future",
|
||||
|
@ -7878,8 +7878,8 @@ impl Iterator for S {
|
|||
file_id: FileId(
|
||||
1,
|
||||
),
|
||||
full_range: 7128..7594,
|
||||
focus_range: 7172..7180,
|
||||
full_range: 8629..9095,
|
||||
focus_range: 8673..8681,
|
||||
name: "Iterator",
|
||||
kind: Trait,
|
||||
container_name: "iterator",
|
||||
|
|
|
@ -49,5 +49,5 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
|
||||
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<span class="keyword">let</span> <span class="variable declaration">foo</span> <span class="operator">=</span> <span class="enum_variant default_library library">Some</span><span class="parenthesis">(</span><span class="numeric_literal">92</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
<span class="keyword">let</span> <span class="variable declaration">nums</span> <span class="operator">=</span> <span class="module default_library library">iter</span><span class="operator">::</span><span class="function default_library library">repeat</span><span class="parenthesis">(</span><span class="variable">foo</span><span class="operator">.</span><span class="method consuming default_library library">unwrap</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
<span class="keyword">let</span> <span class="variable declaration">nums</span> <span class="operator">=</span> <span class="module default_library library">iter</span><span class="operator">::</span><span class="function default_library library">repeat</span><span class="parenthesis">(</span><span class="variable">foo</span><span class="operator">.</span><span class="method default_library library">unwrap</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
<span class="brace">}</span></code></pre>
|
|
@ -158,9 +158,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="macro">println</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"</span><span class="format_specifier">{</span><span class="variable">ничоси</span><span class="format_specifier">}</span><span class="string_literal macro">"</span><span class="comma macro">,</span> <span class="variable declaration macro">ничоси</span> <span class="operator macro">=</span> <span class="numeric_literal macro">92</span><span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
|
||||
<span class="macro">println</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"</span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="variable">x</span><span class="format_specifier">?</span><span class="format_specifier">}</span><span class="string_literal macro"> </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal macro"> "</span><span class="comma macro">,</span> <span class="unresolved_reference macro">thingy</span><span class="comma macro">,</span> <span class="unresolved_reference macro">n2</span><span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
<span class="macro default_library library">panic</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"</span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal macro">"</span><span class="comma macro">,</span> <span class="numeric_literal macro">0</span><span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
<span class="macro default_library library">panic</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"{}"</span><span class="comma macro">,</span> <span class="numeric_literal macro">0</span><span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
<span class="macro default_library library">panic</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"more </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal macro">"</span><span class="comma macro">,</span> <span class="numeric_literal macro">1</span><span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
<span class="macro default_library library">assert</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="bool_literal macro">true</span><span class="comma macro">,</span> <span class="string_literal macro">"</span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal macro">"</span><span class="comma macro">,</span> <span class="numeric_literal macro">1</span><span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
<span class="macro default_library library">assert</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="bool_literal macro">true</span><span class="comma macro">,</span> <span class="string_literal macro">"{}"</span><span class="comma macro">,</span> <span class="numeric_literal macro">1</span><span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
<span class="macro default_library library">assert</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="bool_literal macro">true</span><span class="comma macro">,</span> <span class="string_literal macro">"</span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal macro"> asdasd"</span><span class="comma macro">,</span> <span class="numeric_literal macro">1</span><span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
<span class="macro">toho</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"{}fmt"</span><span class="comma macro">,</span> <span class="numeric_literal macro">0</span><span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
<span class="keyword">let</span> <span class="variable declaration">i</span><span class="colon">:</span> <span class="builtin_type">u64</span> <span class="operator">=</span> <span class="numeric_literal">3</span><span class="semicolon">;</span>
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
//! env: option
|
||||
//! eq: sized
|
||||
//! error: fmt
|
||||
//! fmt: option, result, transmute, coerce_unsized
|
||||
//! fmt: option, result, transmute, coerce_unsized, copy, clone, derive
|
||||
//! fn:
|
||||
//! from: sized
|
||||
//! future: pin
|
||||
|
@ -919,6 +919,7 @@ pub mod fmt {
|
|||
type Opaque;
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[lang = "format_argument"]
|
||||
pub struct Argument<'a> {
|
||||
value: &'a Opaque,
|
||||
|
@ -986,6 +987,7 @@ pub mod fmt {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[lang = "format_arguments"]
|
||||
pub struct Arguments<'a> {
|
||||
pieces: &'a [&'static str],
|
||||
|
@ -1421,6 +1423,7 @@ mod panicking {
|
|||
}
|
||||
// endregion:panic
|
||||
|
||||
#[macro_use]
|
||||
mod macros {
|
||||
// region:panic
|
||||
#[macro_export]
|
||||
|
|
Loading…
Reference in a new issue