Skip to content

Commit 6db42c0

Browse files
authored
Show line number of failed asserts (pgcentralfoundation#2175)
A little quality-of-life improvement: when a unit test fails, the test runner now shows the line number. For tests with several assertions, this is quite handy. Before: ``` Client Error assertion `left == right` failed left: "hello" right: "world" postgres location: lib.rs rust location: <unknown> ``` After: ``` Client Error assertion `left == right` failed left: "hello" right: "world" postgres location: lib.rs:22 rust location: <unknown> ``` Signed-off-by: Max Englander <[email protected]>
1 parent 9e7c27c commit 6db42c0

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

pgrx-tests/src/framework.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,11 @@ pub fn run_test(
150150
return Ok(());
151151
}
152152

153-
let pg_location = dberror.file().unwrap_or("<unknown>").to_string();
153+
let mut pg_location = dberror.file().unwrap_or("<unknown>").to_string();
154154
let rust_location = dberror.where_().unwrap_or("<unknown>").to_string();
155+
if let Some(lineno) = dberror.line() {
156+
pg_location += &format!(":{lineno}");
157+
}
155158

156159
(pg_location, rust_location, received_error_message.to_string())
157160
} else {

0 commit comments

Comments
 (0)