Skip to content

Commit 3a45a54

Browse files
committed
Dynamically obtain line number of panic! expression
1 parent 2ac8d82 commit 3a45a54

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

itest/rust/src/object_tests/dynamic_call_test.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,14 @@ fn dynamic_call_with_panic() {
154154
#[cfg(not(target_os = "windows"))]
155155
let path = "itest/rust/src/object_tests/object_test.rs";
156156

157+
// Obtain line number dynamically, avoids tedious maintenance on code reorganization.
158+
let line = ObjPayload::get_panic_line();
159+
157160
let expected_error_message = format!(
158161
"godot-rust function call failed: Object::call(&\"do_panic\")\
159162
\n Source: ObjPayload::do_panic()\
160163
\n Reason: [panic] do_panic exploded\
161-
\n at {path}:893"
164+
\n at {path}:{line}"
162165
);
163166

164167
assert_eq!(call_error.to_string(), expected_error_message);

itest/rust/src/object_tests/object_test.rs

+5
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,11 @@ impl ObjPayload {
887887
fn do_panic(&self) {
888888
panic!("do_panic exploded");
889889
}
890+
891+
// Obtain the line number of the panic!() call above; keep equidistant to do_panic() method.
892+
pub fn get_panic_line() -> u32 {
893+
line!() - 5
894+
}
890895
}
891896

892897
// ----------------------------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)