Skip to content

Commit

Permalink
Use catch_unwind
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Dec 11, 2024
1 parent a6ca811 commit 8e40161
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tooling/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
collections::{BTreeMap, HashMap},
io::Write,
panic::{catch_unwind, UnwindSafe},
path::PathBuf,
sync::{mpsc, Mutex},
thread,
Expand Down Expand Up @@ -57,7 +58,7 @@ pub(crate) struct TestCommand {
struct Test<'a> {
name: String,
package_name: String,
runner: Box<dyn FnOnce() -> (TestStatus, String) + Send + 'a>,
runner: Box<dyn FnOnce() -> (TestStatus, String) + Send + UnwindSafe + 'a>,
}

struct TestResult {
Expand Down Expand Up @@ -182,7 +183,16 @@ impl<'a> TestRunner<'a> {
};

let time_before_test = std::time::Instant::now();
let (status, output) = (test.runner)();
let (status, output) = match catch_unwind(test.runner) {
Ok((status, output)) => (status, output),
Err(_) => (
TestStatus::Fail {
message: "An unexpected error happened".to_string(),
error_diagnostic: None,
},
String::new(),
),
};
let time_to_run = time_before_test.elapsed();

let test_result = TestResult {
Expand Down

0 comments on commit 8e40161

Please sign in to comment.