Skip to content

Commit 065b6b9

Browse files
committed
Enhance error handling in SQL tests and update SQL syntax
- Added a new function `format_error` to improve error reporting in SQL test assertions, capturing detailed error descriptions and backtraces. - Updated SQL syntax in `sqrt.sql` to use `INT` instead of `integer` for consistency with SQL standards.
1 parent a102ae1 commit 065b6b9

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

tests/sql_test_files/data/sqrt.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
set result = sqrt(9.0);
2-
select 3 as expected, cast($result as integer) as actual;
2+
select 3 as expected, cast($result as INT) as actual;

tests/sql_test_files/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ async fn run_sql_test(
120120
}
121121
}
122122

123+
fn format_error(obj: &serde_json::Map<String, serde_json::Value>) -> Option<String> {
124+
if obj.get("component").and_then(|v| v.as_str()) != Some("error") {
125+
return None;
126+
}
127+
let mut msg = String::new();
128+
if let Some(desc) = obj.get("description").and_then(|v| v.as_str()) {
129+
msg.push_str(desc);
130+
}
131+
if let Some(bt) = obj.get("backtrace").and_then(|v| v.as_array()) {
132+
for frame in bt {
133+
if let Some(s) = frame.as_str() {
134+
msg.push_str(&format!("\n {}", s));
135+
}
136+
}
137+
}
138+
Some(msg)
139+
}
140+
123141
fn assert_json_test(body: &str, test_file: &std::path::Path) {
124142
let rows: Vec<serde_json::Value> = serde_json::from_str(body)
125143
.unwrap_or_else(|_| panic!("Invalid JSON: {}", test_file.display()));
@@ -136,6 +154,10 @@ fn assert_json_test(body: &str, test_file: &std::path::Path) {
136154
None => continue,
137155
};
138156

157+
if let Some(err) = format_error(obj) {
158+
panic!("Error in {}:\n{}", test_file.display(), err);
159+
}
160+
139161
let actual = obj
140162
.get("actual")
141163
.cloned()

0 commit comments

Comments
 (0)