Skip to content

Commit 37ffa73

Browse files
committed
Add guidance to re-enable panic messages in itests
1 parent 723f157 commit 37ffa73

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

itest/rust/src/framework/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,24 @@ pub fn passes_filter(filters: &[String], test_name: &str) -> bool {
171171

172172
// ----------------------------------------------------------------------------------------------------------------------------------------------
173173
// Toolbox for tests
174+
175+
/// Swaps panic hooks, to disable printing during expected panics. Also disables gdext's panic printing.
174176
pub fn suppress_panic_log<R>(callback: impl FnOnce() -> R) -> R {
175-
// Exchange panic hook, to disable printing during expected panics. Also disable gdext's panic printing.
177+
// DISABLE following lines to *temporarily* debug panics.
178+
// Note that they currently print "itest `{}` failed", even if the test doesn't fail (which isn't usually relevant in suppressed mode).
176179
let prev_hook = panic::take_hook();
177180
panic::set_hook(Box::new(
178181
|_panic_info| { /* suppress panic hook; do nothing */ },
179182
));
183+
184+
// Keep following lines.
180185
let prev_print_level = godot::private::set_error_print_level(0);
181186
let res = callback();
182-
panic::set_hook(prev_hook);
183187
godot::private::set_error_print_level(prev_print_level);
188+
189+
// DISABLE following line to *temporarily* debug panics.
190+
panic::set_hook(prev_hook);
191+
184192
res
185193
}
186194

itest/rust/src/framework/runner.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,11 @@ fn run_rust_test(test: &RustTestCase, ctx: &TestContext) -> TestOutcome {
444444
return TestOutcome::Skipped;
445445
}
446446

447-
// Explicit type to prevent tests from returning a value
447+
// This will appear in all panics, but those inside expect_panic() are suppressed.
448+
// So the "itest failed" message will only appear for unexpected panics, where tests indeed fail.
448449
let err_context = || format!("itest `{}` failed", test.name);
450+
451+
// Explicit type to prevent tests from returning a value.
449452
let success: Result<(), _> = godot::private::handle_panic(err_context, || (test.function)(ctx));
450453

451454
TestOutcome::from_bool(success.is_ok())

0 commit comments

Comments
 (0)