1
1
#![ cfg( not( target_family = "wasm" ) ) ]
2
2
3
3
use std:: collections:: BTreeMap ;
4
- use std:: fmt:: Write ;
5
4
use std:: { env, fs} ;
6
5
7
6
use anyhow:: Context ;
8
7
use insta:: { assert_snapshot, glob} ;
8
+ use itertools:: Itertools ;
9
9
use once_cell:: sync:: Lazy ;
10
10
use regex:: Regex ;
11
11
use similar_asserts:: assert_eq;
@@ -138,13 +138,8 @@ fn test_rdbms() {
138
138
. and_then( |s| s. to_str( ) )
139
139
. unwrap_or_default( ) ;
140
140
141
- // read
142
141
let prql = fs:: read_to_string( path) . unwrap( ) ;
143
142
144
- if prql. contains( "skip_test" ) {
145
- return ;
146
- }
147
-
148
143
let mut results = BTreeMap :: new( ) ;
149
144
for ( dialect, con) in & mut connections {
150
145
if !dialect. should_run_query( & prql) {
@@ -163,31 +158,30 @@ fn test_rdbms() {
163
158
replace_booleans( & mut rows) ;
164
159
remove_trailing_zeros( & mut rows) ;
165
160
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 " ) ;
168
166
169
- if results. is_empty( ) {
170
- return ;
167
+ results. insert( dialect. to_string( ) , result) ;
171
168
}
172
169
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) | {
178
178
assert_eq!(
179
- * first_result. 1 , * v ,
179
+ * first_result, * result ,
180
180
"{} == {}: {test_name}" ,
181
- first_result . 0 , k
181
+ first_dialect , dialect
182
182
) ;
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
+ } )
191
185
}
192
186
193
187
fn setup_connection ( con : & mut dyn DBConnection , runtime : & Runtime ) {
0 commit comments