Skip to content

Commit f675b5e

Browse files
committed
Don't early exit on panics in rustc_tests command
1 parent 54f2111 commit f675b5e

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

crates/rust-analyzer/src/cli/rustc_tests.rs

+34-15
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ fn detect_errors_from_rustc_stderr_file(p: PathBuf) -> HashMap<DiagnosticCode, u
5555

5656
impl Tester {
5757
fn new() -> Result<Self> {
58-
let tmp_file = AbsPathBuf::assert("/tmp/ra-rustc-test.rs".into());
58+
let mut path = std::env::temp_dir();
59+
path.push("ra-rustc-test.rs");
60+
let tmp_file = AbsPathBuf::try_from(path).unwrap();
5961
std::fs::write(&tmp_file, "")?;
6062
let mut cargo_config = CargoConfig::default();
6163
cargo_config.sysroot = Some(RustLibSource::Discover);
@@ -122,26 +124,43 @@ impl Tester {
122124
change.change_file(self.root_file, Some(Arc::from(text)));
123125
self.host.apply_change(change);
124126
let diagnostic_config = DiagnosticsConfig::test_sample();
125-
let diags = self
126-
.host
127-
.analysis()
128-
.diagnostics(&diagnostic_config, ide::AssistResolveStrategy::None, self.root_file)
129-
.unwrap();
127+
130128
let mut actual = HashMap::new();
131-
for diag in diags {
132-
if !matches!(diag.code, DiagnosticCode::RustcHardError(_)) {
133-
continue;
134-
}
135-
if !should_have_no_error && !SUPPORTED_DIAGNOSTICS.contains(&diag.code) {
136-
continue;
129+
let panicked = match std::panic::catch_unwind(|| {
130+
self.host
131+
.analysis()
132+
.diagnostics(&diagnostic_config, ide::AssistResolveStrategy::None, self.root_file)
133+
.unwrap()
134+
}) {
135+
Err(e) => Some(e),
136+
Ok(diags) => {
137+
for diag in diags {
138+
if !matches!(diag.code, DiagnosticCode::RustcHardError(_)) {
139+
continue;
140+
}
141+
if !should_have_no_error && !SUPPORTED_DIAGNOSTICS.contains(&diag.code) {
142+
continue;
143+
}
144+
*actual.entry(diag.code).or_insert(0) += 1;
145+
}
146+
None
137147
}
138-
*actual.entry(diag.code).or_insert(0) += 1;
139-
}
148+
};
140149
// Ignore tests with diagnostics that we don't emit.
141150
ignore_test |= expected.keys().any(|k| !SUPPORTED_DIAGNOSTICS.contains(k));
142151
if ignore_test {
143152
println!("{p:?} IGNORE");
144153
self.ignore_count += 1;
154+
} else if let Some(panic) = panicked {
155+
if let Some(msg) = panic
156+
.downcast_ref::<String>()
157+
.map(String::as_str)
158+
.or_else(|| panic.downcast_ref::<&str>().copied())
159+
{
160+
println!("{msg:?} ")
161+
}
162+
println!("PANIC");
163+
self.fail_count += 1;
145164
} else if actual == expected {
146165
println!("{p:?} PASS");
147166
self.pass_count += 1;
@@ -225,11 +244,11 @@ impl flags::RustcTests {
225244
let tester = AssertUnwindSafe(&mut tester);
226245
let p = p.clone();
227246
move || {
247+
let _guard = stdx::panic_context::enter(p.display().to_string());
228248
let tester = tester;
229249
tester.0.test(p);
230250
}
231251
}) {
232-
println!("panic detected at test {:?}", p);
233252
std::panic::resume_unwind(e);
234253
}
235254
}

0 commit comments

Comments
 (0)