Skip to content

Commit d547d9f

Browse files
committed
Fix release test; add guidance to re-enable itests panic messages
1 parent 723f157 commit d547d9f

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

godot-core/src/private.rs

-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ pub fn extract_panic_message(err: &(dyn Send + std::any::Any)) -> String {
225225
}
226226
}
227227

228-
#[doc(hidden)]
229228
pub fn format_panic_message(panic_info: &std::panic::PanicHookInfo) -> String {
230229
let mut msg = extract_panic_message(panic_info.payload());
231230

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())

itest/rust/src/object_tests/dynamic_call_test.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ fn dynamic_call_parameter_mismatch() {
140140
obj.free();
141141
}
142142

143+
// There seems to be a weird bug where running *only* this test with #[itest(focus)] causes panic, which then causes a
144+
// follow-up failure of Gd::bind_mut(), preventing benchmarks from being run. Doesn't happen with #[itest], when running all.
143145
#[itest]
144146
fn dynamic_call_with_panic() {
145147
let panic_message = Arc::new(Mutex::new(None));
@@ -176,13 +178,20 @@ fn dynamic_call_with_panic() {
176178
if cfg!(target_os = "windows") {
177179
path = path.replace('/', "\\")
178180
}
179-
// Obtain line number dynamically, avoids tedious maintenance on code reorganization.
181+
182+
// Obtain line number dynamically -- avoids tedious maintenance on code reorganization.
180183
let line = ObjPayload::get_panic_line();
181184
let context = error_context
182185
.map(|context| format!("\n Context: {context}"))
183186
.unwrap_or_default();
184187

185-
let expected_panic_message = format!("[panic {path}:{line}]\n do_panic exploded{context}");
188+
// In Debug, there is a context -> message is multi-line -> '\n' is inserted after [panic ...].
189+
// In Release, simpler message -> single line -> no '\n'.
190+
let expected_panic_message = if cfg!(debug_assertions) {
191+
format!("[panic {path}:{line}]\n do_panic exploded{context}")
192+
} else {
193+
format!("[panic {path}:{line}] do_panic exploded")
194+
};
186195

187196
assert_eq!(panic_message, expected_panic_message);
188197

0 commit comments

Comments
 (0)