mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 15:14:32 +00:00
Don't early exit on panics in rustc_tests command
This commit is contained in:
parent
54f2111f69
commit
f675b5ead8
1 changed files with 34 additions and 15 deletions
|
@ -55,7 +55,9 @@ fn detect_errors_from_rustc_stderr_file(p: PathBuf) -> HashMap<DiagnosticCode, u
|
||||||
|
|
||||||
impl Tester {
|
impl Tester {
|
||||||
fn new() -> Result<Self> {
|
fn new() -> Result<Self> {
|
||||||
let tmp_file = AbsPathBuf::assert("/tmp/ra-rustc-test.rs".into());
|
let mut path = std::env::temp_dir();
|
||||||
|
path.push("ra-rustc-test.rs");
|
||||||
|
let tmp_file = AbsPathBuf::try_from(path).unwrap();
|
||||||
std::fs::write(&tmp_file, "")?;
|
std::fs::write(&tmp_file, "")?;
|
||||||
let mut cargo_config = CargoConfig::default();
|
let mut cargo_config = CargoConfig::default();
|
||||||
cargo_config.sysroot = Some(RustLibSource::Discover);
|
cargo_config.sysroot = Some(RustLibSource::Discover);
|
||||||
|
@ -122,12 +124,16 @@ impl Tester {
|
||||||
change.change_file(self.root_file, Some(Arc::from(text)));
|
change.change_file(self.root_file, Some(Arc::from(text)));
|
||||||
self.host.apply_change(change);
|
self.host.apply_change(change);
|
||||||
let diagnostic_config = DiagnosticsConfig::test_sample();
|
let diagnostic_config = DiagnosticsConfig::test_sample();
|
||||||
let diags = self
|
|
||||||
.host
|
let mut actual = HashMap::new();
|
||||||
|
let panicked = match std::panic::catch_unwind(|| {
|
||||||
|
self.host
|
||||||
.analysis()
|
.analysis()
|
||||||
.diagnostics(&diagnostic_config, ide::AssistResolveStrategy::None, self.root_file)
|
.diagnostics(&diagnostic_config, ide::AssistResolveStrategy::None, self.root_file)
|
||||||
.unwrap();
|
.unwrap()
|
||||||
let mut actual = HashMap::new();
|
}) {
|
||||||
|
Err(e) => Some(e),
|
||||||
|
Ok(diags) => {
|
||||||
for diag in diags {
|
for diag in diags {
|
||||||
if !matches!(diag.code, DiagnosticCode::RustcHardError(_)) {
|
if !matches!(diag.code, DiagnosticCode::RustcHardError(_)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -137,11 +143,24 @@ impl Tester {
|
||||||
}
|
}
|
||||||
*actual.entry(diag.code).or_insert(0) += 1;
|
*actual.entry(diag.code).or_insert(0) += 1;
|
||||||
}
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
// Ignore tests with diagnostics that we don't emit.
|
// Ignore tests with diagnostics that we don't emit.
|
||||||
ignore_test |= expected.keys().any(|k| !SUPPORTED_DIAGNOSTICS.contains(k));
|
ignore_test |= expected.keys().any(|k| !SUPPORTED_DIAGNOSTICS.contains(k));
|
||||||
if ignore_test {
|
if ignore_test {
|
||||||
println!("{p:?} IGNORE");
|
println!("{p:?} IGNORE");
|
||||||
self.ignore_count += 1;
|
self.ignore_count += 1;
|
||||||
|
} else if let Some(panic) = panicked {
|
||||||
|
if let Some(msg) = panic
|
||||||
|
.downcast_ref::<String>()
|
||||||
|
.map(String::as_str)
|
||||||
|
.or_else(|| panic.downcast_ref::<&str>().copied())
|
||||||
|
{
|
||||||
|
println!("{msg:?} ")
|
||||||
|
}
|
||||||
|
println!("PANIC");
|
||||||
|
self.fail_count += 1;
|
||||||
} else if actual == expected {
|
} else if actual == expected {
|
||||||
println!("{p:?} PASS");
|
println!("{p:?} PASS");
|
||||||
self.pass_count += 1;
|
self.pass_count += 1;
|
||||||
|
@ -225,11 +244,11 @@ impl flags::RustcTests {
|
||||||
let tester = AssertUnwindSafe(&mut tester);
|
let tester = AssertUnwindSafe(&mut tester);
|
||||||
let p = p.clone();
|
let p = p.clone();
|
||||||
move || {
|
move || {
|
||||||
|
let _guard = stdx::panic_context::enter(p.display().to_string());
|
||||||
let tester = tester;
|
let tester = tester;
|
||||||
tester.0.test(p);
|
tester.0.test(p);
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
println!("panic detected at test {:?}", p);
|
|
||||||
std::panic::resume_unwind(e);
|
std::panic::resume_unwind(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue