From 40d781864bb0d61c46969736d06b6108a660582d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 10 Oct 2023 09:46:10 +0200 Subject: [PATCH] avoid confusing loop in catch_panic test --- tests/pass/panic/catch_panic.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/pass/panic/catch_panic.rs b/tests/pass/panic/catch_panic.rs index e4a7f8e348..f73b8f101b 100644 --- a/tests/pass/panic/catch_panic.rs +++ b/tests/pass/panic/catch_panic.rs @@ -5,6 +5,7 @@ use std::cell::Cell; use std::panic::{catch_unwind, AssertUnwindSafe}; +use std::process; thread_local! { static MY_COUNTER: Cell = Cell::new(0); @@ -62,27 +63,29 @@ fn main() { // Built-in panics; also make sure the message is right. test(Some("index out of bounds: the len is 3 but the index is 4"), |_old_val| { let _val = [0, 1, 2][4]; - loop {} + process::abort() }); test(Some("attempt to divide by zero"), |_old_val| { let _val = 1 / 0; - loop {} + process::abort() }); test(Some("align_offset: align is not a power-of-two"), |_old_val| { let _ = std::ptr::null::().align_offset(3); - loop {} + process::abort() }); // Assertion and debug assertion test(None, |_old_val| { assert!(false); - loop {} - }); - test(None, |_old_val| { - debug_assert!(false); - loop {} + process::abort() }); + if cfg!(debug_assertions) { + test(None, |_old_val| { + debug_assert!(false); + process::abort() + }); + } eprintln!("Success!"); // Make sure we get this in stderr }