From 8e401615e5f6bff104005f3c93b2437ea83a82ae Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Wed, 11 Dec 2024 16:10:42 -0300 Subject: [PATCH] Use `catch_unwind` --- tooling/nargo_cli/src/cli/test_cmd.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tooling/nargo_cli/src/cli/test_cmd.rs b/tooling/nargo_cli/src/cli/test_cmd.rs index e3debcd50e..488176c531 100644 --- a/tooling/nargo_cli/src/cli/test_cmd.rs +++ b/tooling/nargo_cli/src/cli/test_cmd.rs @@ -1,6 +1,7 @@ use std::{ collections::{BTreeMap, HashMap}, io::Write, + panic::{catch_unwind, UnwindSafe}, path::PathBuf, sync::{mpsc, Mutex}, thread, @@ -57,7 +58,7 @@ pub(crate) struct TestCommand { struct Test<'a> { name: String, package_name: String, - runner: Box (TestStatus, String) + Send + 'a>, + runner: Box (TestStatus, String) + Send + UnwindSafe + 'a>, } struct TestResult { @@ -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 {