@@ -17,6 +17,12 @@ use sqllogictest::Runner;
1717use tempfile:: TempDir ;
1818
1919/// Preprocess DuckDB test file to remove DuckDB-specific directives
20+ ///
21+ /// This preprocessing:
22+ /// 1. Removes DuckDB-specific test directives (require, test-env, etc.)
23+ /// 2. Skips ATTACH/DETACH statements (handled in Rust)
24+ /// 3. Skips EXPLAIN statements (not testable in hybrid mode)
25+ /// 4. Otherwise lets tests fail naturally for better diagnostics
2026fn preprocess_test_file ( content : & str ) -> String {
2127 let mut output = String :: new ( ) ;
2228 let mut lines = content. lines ( ) . peekable ( ) ;
@@ -35,13 +41,32 @@ fn preprocess_test_file(content: &str) -> String {
3541 }
3642
3743 // Skip ATTACH/DETACH statements (we handle connection in Rust)
38- if trimmed == "statement ok"
39- && let Some ( next_line) = lines. peek ( )
40- {
41- let next_upper = next_line. trim ( ) . to_uppercase ( ) ;
42- if next_upper. starts_with ( "ATTACH " ) || next_upper. starts_with ( "DETACH " ) {
43- lines. next ( ) ; // Skip the ATTACH/DETACH statement
44- continue ;
44+ if trimmed == "statement ok" {
45+ if let Some ( next_line) = lines. peek ( ) {
46+ let next_upper = next_line. trim ( ) . to_uppercase ( ) ;
47+ if next_upper. starts_with ( "ATTACH " ) || next_upper. starts_with ( "DETACH " ) {
48+ lines. next ( ) ; // Skip the ATTACH/DETACH statement
49+ continue ;
50+ }
51+
52+ // Skip EXPLAIN statements (not testable - no consistent output format)
53+ if next_upper. starts_with ( "EXPLAIN " ) {
54+ lines. next ( ) ; // Skip the EXPLAIN statement
55+ continue ;
56+ }
57+ }
58+ }
59+
60+ // Skip query blocks with EXPLAIN
61+ if trimmed. starts_with ( "query" ) {
62+ if let Some ( next_line) = lines. peek ( ) {
63+ let next_upper = next_line. trim ( ) . to_uppercase ( ) ;
64+ if next_upper. starts_with ( "EXPLAIN " ) {
65+ // Skip the query directive, SQL, separator, and results
66+ lines. next ( ) ; // Skip SQL line
67+ skip_query_results ( & mut lines) ;
68+ continue ;
69+ }
4570 }
4671 }
4772
@@ -53,6 +78,31 @@ fn preprocess_test_file(content: &str) -> String {
5378 output
5479}
5580
81+ /// Skip query results until next directive
82+ fn skip_query_results ( lines : & mut std:: iter:: Peekable < std:: str:: Lines > ) {
83+ // Skip until we find the separator (----)
84+ while let Some ( line) = lines. peek ( ) {
85+ if line. trim ( ) == "----" {
86+ lines. next ( ) ;
87+ break ;
88+ }
89+ lines. next ( ) ;
90+ }
91+
92+ // Skip result lines until next directive
93+ while let Some ( line) = lines. peek ( ) {
94+ let trimmed = line. trim ( ) ;
95+ if trimmed. starts_with ( "query" )
96+ || trimmed. starts_with ( "statement" )
97+ || trimmed. starts_with ( "halt" )
98+ || trimmed. is_empty ( )
99+ {
100+ break ;
101+ }
102+ lines. next ( ) ;
103+ }
104+ }
105+
56106/// Run a DuckDB test file using the hybrid adapter
57107async fn run_hybrid_test ( test_file : & str ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
58108 let temp_dir = TempDir :: new ( ) ?;
0 commit comments