Skip to content

Commit

Permalink
panic catch unwind
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 9, 2024
1 parent 0b562b2 commit 3d7a088
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ project-root = "0.2.2"
[profile.release]
debug-assertions = true
overflow-checks = true
panic = "unwind"
4 changes: 2 additions & 2 deletions src/case.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::fs;
use std::{fs, panic::RefUnwindSafe};

use crate::{Diagnostic, Driver, NodeModulesRunner, Source};

pub trait Case {
pub trait Case: RefUnwindSafe {
fn name(&self) -> &'static str;

fn run_test(&self, _source: &Source) -> bool {
Expand Down
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod transformer;
mod case;
mod driver;

use std::{fs, path::PathBuf, process::Command};
use std::{fs, panic::catch_unwind, path::PathBuf, process::Command};

use console::Style;
use similar::{ChangeTag, TextDiff};
Expand Down Expand Up @@ -128,7 +128,20 @@ impl NodeModulesRunner {

fn run_case(&self, case: &dyn Case) -> Result<(), Vec<Diagnostic>> {
println!("Running {}.", case.name());
let results = self.files.iter().map(|source| case.test(source)).collect::<Vec<_>>();
let results = self
.files
.iter()
.map(|source| {
catch_unwind(|| case.test(source)).map_err(|err| {
vec![Diagnostic {
case: case.name(),
path: source.path.clone(),
message: format!("{err:?}"),
}]
})
})
.flatten()
.collect::<Vec<_>>();
println!("Ran {} times.", results.len());
let diagnostics = results
.into_iter()
Expand Down

0 comments on commit 3d7a088

Please sign in to comment.