@@ -29,7 +29,7 @@ mod engines;
2929mod setup;
3030mod utils;
3131
32- const TEST_DIRECTORY : & str = "tests/sqllogictests/test_files" ;
32+ const TEST_DIRECTORY : & str = "tests/sqllogictests/test_files/ " ;
3333const PG_COMPAT_FILE_PREFIX : & str = "pg_compat_" ;
3434
3535#[ tokio:: main]
@@ -47,40 +47,37 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
4747
4848 let options = Options :: new ( ) ;
4949
50- let files: Vec < _ > = read_test_files ( & options) ;
51-
52- info ! ( "Running test files {:?}" , files) ;
53-
54- for path in files {
55- let file_name = path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
56-
50+ for ( path, relative_path) in read_test_files ( & options) {
5751 if options. complete_mode {
58- run_complete_file ( & path, file_name ) . await ?;
52+ run_complete_file ( & path, relative_path ) . await ?;
5953 } else if options. postgres_runner {
60- run_test_file_with_postgres ( & path, file_name ) . await ?;
54+ run_test_file_with_postgres ( & path, relative_path ) . await ?;
6155 } else {
62- run_test_file ( & path, file_name ) . await ?;
56+ run_test_file ( & path, relative_path ) . await ?;
6357 }
6458 }
6559
6660 Ok ( ( ) )
6761}
6862
69- async fn run_test_file ( path : & PathBuf , file_name : String ) -> Result < ( ) , Box < dyn Error > > {
70- println ! ( "Running with DataFusion runner: {}" , path. display( ) ) ;
71- let ctx = context_for_test_file ( & file_name) . await ;
72- let mut runner = sqllogictest:: Runner :: new ( DataFusion :: new ( ctx, file_name) ) ;
63+ async fn run_test_file (
64+ path : & Path ,
65+ relative_path : PathBuf ,
66+ ) -> Result < ( ) , Box < dyn Error > > {
67+ info ! ( "Running with DataFusion runner: {}" , path. display( ) ) ;
68+ let ctx = context_for_test_file ( & relative_path) . await ;
69+ let mut runner = sqllogictest:: Runner :: new ( DataFusion :: new ( ctx, relative_path) ) ;
7370 runner. run_file_async ( path) . await ?;
7471 Ok ( ( ) )
7572}
7673
7774async fn run_test_file_with_postgres (
78- path : & PathBuf ,
79- file_name : String ,
75+ path : & Path ,
76+ relative_path : PathBuf ,
8077) -> Result < ( ) , Box < dyn Error > > {
8178 info ! ( "Running with Postgres runner: {}" , path. display( ) ) ;
8279
83- let postgres_client = Postgres :: connect ( file_name ) . await ?;
80+ let postgres_client = Postgres :: connect ( relative_path ) . await ?;
8481
8582 sqllogictest:: Runner :: new ( postgres_client)
8683 . run_file_async ( path)
@@ -90,17 +87,15 @@ async fn run_test_file_with_postgres(
9087}
9188
9289async fn run_complete_file (
93- path : & PathBuf ,
94- file_name : String ,
90+ path : & Path ,
91+ relative_path : PathBuf ,
9592) -> Result < ( ) , Box < dyn Error > > {
9693 use sqllogictest:: { default_validator, update_test_file} ;
9794
9895 info ! ( "Using complete mode to complete: {}" , path. display( ) ) ;
9996
100- let ctx = context_for_test_file ( & file_name) . await ;
101- let mut runner = sqllogictest:: Runner :: new ( DataFusion :: new ( ctx, file_name) ) ;
102-
103- info ! ( "Using complete mode to complete {}" , path. display( ) ) ;
97+ let ctx = context_for_test_file ( & relative_path) . await ;
98+ let mut runner = sqllogictest:: Runner :: new ( DataFusion :: new ( ctx, relative_path) ) ;
10499 let col_separator = " " ;
105100 let validator = default_validator;
106101 update_test_file ( path, & mut runner, col_separator, validator)
@@ -110,18 +105,42 @@ async fn run_complete_file(
110105 Ok ( ( ) )
111106}
112107
113- fn read_test_files ( options : & Options ) -> Vec < PathBuf > {
114- std:: fs:: read_dir ( TEST_DIRECTORY )
115- . unwrap ( )
116- . map ( |path| path. unwrap ( ) . path ( ) )
117- . filter ( |path| options. check_test_file ( path. as_path ( ) ) )
118- . filter ( |path| options. check_pg_compat_file ( path. as_path ( ) ) )
119- . collect ( )
108+ fn read_test_files < ' a > (
109+ options : & ' a Options ,
110+ ) -> Box < dyn Iterator < Item = ( PathBuf , PathBuf ) > + ' a > {
111+ Box :: new (
112+ read_dir_recursive ( TEST_DIRECTORY )
113+ . map ( |path| {
114+ (
115+ path. clone ( ) ,
116+ PathBuf :: from (
117+ path. to_string_lossy ( ) . strip_prefix ( TEST_DIRECTORY ) . unwrap ( ) ,
118+ ) ,
119+ )
120+ } )
121+ . filter ( |( _, relative_path) | options. check_test_file ( relative_path) )
122+ . filter ( |( path, _) | options. check_pg_compat_file ( path. as_path ( ) ) ) ,
123+ )
124+ }
125+
126+ fn read_dir_recursive < P : AsRef < Path > > ( path : P ) -> Box < dyn Iterator < Item = PathBuf > > {
127+ Box :: new (
128+ std:: fs:: read_dir ( path)
129+ . expect ( "Readable directory" )
130+ . map ( |path| path. expect ( "Readable entry" ) . path ( ) )
131+ . flat_map ( |path| {
132+ if path. is_dir ( ) {
133+ read_dir_recursive ( path)
134+ } else {
135+ Box :: new ( std:: iter:: once ( path) )
136+ }
137+ } ) ,
138+ )
120139}
121140
122141/// Create a SessionContext, configured for the specific test
123- async fn context_for_test_file ( file_name : & str ) -> SessionContext {
124- match file_name {
142+ async fn context_for_test_file ( relative_path : & Path ) -> SessionContext {
143+ match relative_path . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) {
125144 "aggregate.slt" | "select.slt" => {
126145 info ! ( "Registering aggregate tables" ) ;
127146 let ctx = SessionContext :: new ( ) ;
@@ -185,14 +204,15 @@ impl Options {
185204 /// To be compatible with this, treat the command line arguments as a
186205 /// filter and that does a substring match on each input. returns
187206 /// true f this path should be run
188- fn check_test_file ( & self , path : & Path ) -> bool {
207+ fn check_test_file ( & self , relative_path : & Path ) -> bool {
189208 if self . filters . is_empty ( ) {
190209 return true ;
191210 }
192211
193212 // otherwise check if any filter matches
194- let path_str = path. to_string_lossy ( ) ;
195- self . filters . iter ( ) . any ( |filter| path_str. contains ( filter) )
213+ self . filters
214+ . iter ( )
215+ . any ( |filter| relative_path. to_string_lossy ( ) . contains ( filter) )
196216 }
197217
198218 /// Postgres runner executes only tests in files with specific names
0 commit comments