Skip to content

Commit 3db68cd

Browse files
committed
test: Make integration test a bit more robust
As part of debugging PRQL#2754, there are a few places the test can return early etc. While they're not the cause of the issue, it's worth removing them anyway
1 parent 14ce854 commit 3db68cd

File tree

1 file changed

+19
-25
lines changed
  • prql-compiler/tests/integration

1 file changed

+19
-25
lines changed

prql-compiler/tests/integration/main.rs

+19-25
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#![cfg(not(target_family = "wasm"))]
22

33
use std::collections::BTreeMap;
4-
use std::fmt::Write;
54
use std::{env, fs};
65

76
use anyhow::Context;
87
use insta::{assert_snapshot, glob};
8+
use itertools::Itertools;
99
use once_cell::sync::Lazy;
1010
use regex::Regex;
1111
use similar_asserts::assert_eq;
@@ -138,13 +138,8 @@ fn test_rdbms() {
138138
.and_then(|s| s.to_str())
139139
.unwrap_or_default();
140140

141-
// read
142141
let prql = fs::read_to_string(path).unwrap();
143142

144-
if prql.contains("skip_test") {
145-
return;
146-
}
147-
148143
let mut results = BTreeMap::new();
149144
for (dialect, con) in &mut connections {
150145
if !dialect.should_run_query(&prql) {
@@ -163,31 +158,30 @@ fn test_rdbms() {
163158
replace_booleans(&mut rows);
164159
remove_trailing_zeros(&mut rows);
165160

166-
results.insert(dialect.to_string(), rows);
167-
}
161+
let result = rows
162+
.iter()
163+
// Make a CSV so it's easier to compare
164+
.map(|r| r.iter().join(","))
165+
.join("\n");
168166

169-
if results.is_empty() {
170-
return;
167+
results.insert(dialect.to_string(), result);
171168
}
172169

173-
let first_result = match results.iter().next() {
174-
Some(v) => v,
175-
None => return,
176-
};
177-
for (k, v) in results.iter().skip(1) {
170+
let (first_dialect, first_result) =
171+
results.pop_first().expect("No results for {test_name}");
172+
173+
// Check the first result against the snapshot
174+
assert_snapshot!("results", first_result, &prql);
175+
176+
// Then check every other result against the first result
177+
results.iter().for_each(|(dialect, result)| {
178178
assert_eq!(
179-
*first_result.1, *v,
179+
*first_result, *result,
180180
"{} == {}: {test_name}",
181-
first_result.0, k
181+
first_dialect, dialect
182182
);
183-
}
184-
185-
let mut result_string = String::new();
186-
for row in first_result.1 {
187-
writeln!(&mut result_string, "{}", row.join(",")).unwrap_or_default();
188-
}
189-
assert_snapshot!("results", result_string, &prql);
190-
});
183+
})
184+
})
191185
}
192186

193187
fn setup_connection(con: &mut dyn DBConnection, runtime: &Runtime) {

0 commit comments

Comments
 (0)